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"
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.
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.
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>
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.
沒有留言:
張貼留言