2017年2月18日 星期六

ABAP/4 : How to trigger double click in ALV & WRITE REPORT

當 ALV 顯示出文件時,希望能透過 Double Click 在文件號碼時,能夠使用 Call Transaction 進到該文件 SAP Standard TCode 畫面時,則可進行下面的程式撰寫



主要的語法在於建立 ALV 時的 USER_COMMAND 以及自訂 ALV 的 STATUS,透過 STATUS 去設定 Double Click CODE,並且在 USER_COMMAND 中設定 Double Clock 後要處理的程式

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
*     I_CALLBACK_PROGRAM                = ' '  "Defualt SY-CPROG
*     I_CALLBACK_PF_STATUS_SET          = ' '  "DEFINE DOUBLE CLICK CODE
*     I_CALLBACK_USER_COMMAND           = ' '  "PROCESS DOUBLE CLICK CODE

在程式建立一個 STATUS,並設定 F2 Choose 的 FUNCTION CODE 為 "&IC1"


或是使用 SE41 複製 SAPLKKBL STANDARD 的 STATUS 到目前程式


並且為 ALV Function Module REUSE_ALV_GRID_DISPLAY 加入 I_CALLBACK_PROGRAM,  I_CALLBACK_PF_STATUS_SET, I_CALLBACK_USER_COMMAND 的 Event

1. 加入 type pools for ALV

TYPE-POOLS: slis.

2. RFC 加入 I_CALLBACK_PROGRAM & I_CALLBACK_PF_STATUS_SET 設定 ALV STATUS

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    I_CALLBACK_PROGRAM                = SY-CPROG
    I_CALLBACK_PF_STATUS_SET          = 'SET_ALV_STATUS'
    I_CALLBACK_USER_COMMAND           = 'SET_USER_COMMAND'

3. 加入 I_CALLBACK_PF_STATUS_SET 呼叫的 FORM SET_ALV_STATUS

FORM set_alv_status USING tab TYPE slis_t_extab.
  SET PF-STATUS 'ALV001'.
ENDFORM.                    "set_alv_status

4. 加入 SET_USER_COMMAND FORM,其中 pf_ucomm 接收 user 按下 STATUS 的
   COMMAND CODE,ps_selfield 為目前點選 ALV 的位置相關位置

*&---------------------------------------------------------------------*
*&      Form  ALV_USER_COMMAND
*&---------------------------------------------------------------------*
FORM SET_USER_COMMAND USING pf_ucomm LIKE sy-ucomm
                            ps_selfield TYPE slis_selfield.

  CASE pf_ucomm.
    WHEN '&IC1'.
      IF ps_selfield-fieldname = 'BELNR'.
        READ TABLE it_bseg INDEX ps_selfield-tabindex.
        IF sy-subrc EQ 0.
          SET PARAMETER ID 'BLN' FIELD it_bseg-belnr.
          SET PARAMETER ID 'BUR' FIELD it_bseg-bukrs.
          SET PARAMETER ID 'GJR' FIELD it_bseg-gjahr.
          CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
          SET PARAMETER ID 'BLN' FIELD ''.
          SET PARAMETER ID 'BUR' FIELD ''.
          SET PARAMETER ID 'GJR' FIELD ''.
        ENDIF.
      ENDIF.
  ENDCASE.

ENDFORM.

可在 SET_USER_COMMAND 設 DEBUG 看該 STRUCTURE 的值

以下是完整的 CODE

REPORT Z_ERIC_EX1.

TYPE-POOLS: slis.

TABLES : BSEG.

DATA : IT_BSEG LIKE STANDARD TABLE OF BSEG WITH HEADER LINE.

SELECT-OPTIONS : S_BUKRS FOR BSEG-BUKRS,
                 S_GJAHR FOR BSEG-GJAHR,
                 S_BELNR FOR BSEG-BELNR.

SELECTION-SCREEN SKIP.

PARAMETERS : I_MAX TYPE I DEFAULT '10'.

SELECTION-SCREEN SKIP.

START-OF-SELECTION.

  SELECT * UP TO I_MAX ROWS INTO CORRESPONDING FIELDS OF TABLE IT_BSEG
    FROM BSEG
   WHERE BUKRS IN S_BUKRS
     AND GJAHR In S_GJAHR
     AND BELNR IN S_BELNR.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM                = SY-CPROG            "CURRENT PROGRAM
      I_CALLBACK_PF_STATUS_SET          = 'SET_ALV_STATUS'    "THIS PROGRAM FORM
      I_CALLBACK_USER_COMMAND           = 'SET_USER_COMMAND'  "THIS PROGRAM FORM 
      I_STRUCTURE_NAME                  = 'BSEG'
    TABLES
      T_OUTTAB                          = IT_BSEG
    EXCEPTIONS
      PROGRAM_ERROR                     = 1
      OTHERS                            = 2.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&      Form  ALV_PF_STATUS
*&---------------------------------------------------------------------*
FORM SET_ALV_STATUS USING tab TYPE slis_t_extab.

  SET PF-STATUS 'ALV_STATUS'.

ENDFORM.                    "ALV_PF_STATUS

*&---------------------------------------------------------------------*
*&      Form  ALV_USER_COMMAND
*&---------------------------------------------------------------------*
FORM SET_USER_COMMAND USING pf_ucomm LIKE sy-ucomm
                            ps_selfield TYPE slis_selfield.

  CASE pf_ucomm.
    WHEN '&IC1'.
      IF ps_selfield-fieldname = 'BELNR'.
        READ TABLE it_bseg INDEX ps_selfield-tabindex.
        IF sy-subrc EQ 0.
          SET PARAMETER ID 'BLN' FIELD it_bseg-belnr.
          SET PARAMETER ID 'BUR' FIELD it_bseg-bukrs.
          SET PARAMETER ID 'GJR' FIELD it_bseg-gjahr.
          CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
          SET PARAMETER ID 'BLN' FIELD ''.
          SET PARAMETER ID 'BUR' FIELD ''.
          SET PARAMETER ID 'GJR' FIELD ''.
        ENDIF.
      ENDIF.
  ENDCASE.

ENDFORM.



接下來說明透過 WRITE REPORT 實現 Double Click Report 的功能,其主要的與法需透過下面的寫法

1. Trigger double click event block in repoert 

    AT LINE-SELECTION. 

2. get user double click component name

    DATA : G_FIELD(20) TYPE C.    

    GET CURSOR FIELD g_field.

3. Hide information in report line internal table

    HIDE : <variat>

透過上面三種功能,即可實現點擊畫面上的文件號碼後,即透過 Call Transaction 'FB03' 去顯示 FI Document


SAMPLE CODE

REPORT Y_EX_AT_LINESELECTION.

TABLES : BSEG.

DATA : BEGIN OF IT_BSEG_HEADER OCCURS 0,
         BUKRS TYPE STRING VALUE 'BUKRS',
         BELNR TYPE STRING VALUE 'DOC NO',
         GJAHR TYPE STRING VALUE 'YEAR',
         HKONT TYPE STRING VALUE 'ACCOUNT',
       END OF IT_BSEG_HEADER.

DATA : WA_BSEG LIKE BSEG.
DATA : G_FIELD(20) TYPE C.

DATA : L_BELNR LIKE BSEG-BELNR,
       L_GJAHR LIKE BSEG-GJAHR,
       L_BUKRS LIKE BSEG-BELNR.

TOP-OF-PAGE.
  WRITE: 1(10) IT_BSEG_HEADER-BUKRS,
         20(10) IT_BSEG_HEADER-BELNR,
         30(10) IT_BSEG_HEADER-GJAHR,
         40(10) IT_BSEG_HEADER-HKONT.
  ULINE.

AT LINE-SELECTION.
  "Get user double clikc field name
  GET CURSOR FIELD g_field.
  "index of details list : index for first display detail list
  IF g_field = 'WA_BSEG-BELNR' AND sy-lsind = 1.
    SET PARAMETER ID 'BLN' FIELD L_BELNR.
    SET PARAMETER ID 'BUK' FIELD L_BUKRS.
    SET PARAMETER ID 'GJR' FIELD L_GJAHR.
    CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
    CLEAR: L_GJAHR, L_BELNR, L_BUKRS.
  ENDIF.

SELECT-OPTIONS : S_BUKRS FOR BSEG-BUKRS,
                 S_GJAHR FOR BSEG-GJAHR,
                 S_BELNR FOR BSEG-BELNR.

SELECTION-SCREEN SKIP.

PARAMETERS : I_MAX TYPE I DEFAULT '10'.

START-OF-SELECTION.

  SELECT * UP TO I_MAX ROWS INTO CORRESPONDING FIELDS OF WA_BSEG
    FROM BSEG
   WHERE BUKRS IN S_BUKRS
     AND GJAHR In S_GJAHR
     AND BELNR IN S_BELNR.

    WRITE:/ WA_BSEG-BUKRS UNDER IT_BSEG_HEADER-BUKRS,
            WA_BSEG-BELNR UNDER IT_BSEG_HEADER-BELNR,
            WA_BSEG-GJAHR UNDER IT_BSEG_HEADER-GJAHR,
            WA_BSEG-HKONT UNDER IT_BSEG_HEADER-HKONT.

    "HIDE INFO IN ABAP/4 HIDE INTERNAL TABLE
    L_GJAHR = WA_BSEG-GJAHR.
    L_BELNR = WA_BSEG-BELNR.
    L_BUKRS = WA_BSEG-BUKRS.
    HIDE: L_GJAHR, L_BELNR, L_BUKRS.
  ENDSELECT.

  CLEAR: L_GJAHR, L_BELNR, L_BUKRS.

END-OF-SELECTION.

沒有留言:

張貼留言

How to install & specified python version or distreibtuion package version in google colab

在買了 RTX 3080 要來 挖礦...  嗯~是跑機器學習後,結果發現了 GOOGLE COLAB,其實之前在「GAN 對抗式生成網路」一書就有看到,但資訊人就是什麼都想自己安裝,在本機用 Anaconda + pyCharm 弄了 GPU 環境,結果有天從新竹回家發現家裡沒...