*&---------------------------------------------------------------------*
*& 包括 ZFIR002_ALV
*&---------------------------------------------------------------------*
TYPE-POOLS : SLIS.
DATA: "定义ALV显示所需要的变量
IT_EVENTS TYPE SLIS_T_EVENT,
IT_LIST_HEADER TYPE SLIS_T_LISTHEADER,
WA_ALV_FIELD TYPE SLIS_FIELDCAT_ALV,
IT_ALV_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
CNS_PF_STATUS TYPE SLIS_FORMNAME VALUE 'ALV_PF_STATUS',
CNS_PF_STATUS_DETAIL TYPE SLIS_FORMNAME VALUE 'ALV_PF_STATUS_DETAIL',
CNS_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'ALV_USER_COMMAND',
CNS_USER_COMMAND_DETAIL TYPE SLIS_FORMNAME VALUE 'ALV_USER_COMMAND_DETAIL'.
*&---------------------------------------------------------------------*
*& Form frm_eventtab_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->LI_EVENTS text
*----------------------------------------------------------------------*
FORM FRM_EVENTTAB_BUILD USING
LI_EVENTS TYPE SLIS_T_EVENT.
DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = LI_EVENTS.
READ TABLE LI_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
INTO LS_EVENT.
IF SY-SUBRC = 0.
MOVE 'FRM_TOP_OF_PAGE' TO LS_EVENT-FORM.
APPEND LS_EVENT TO LI_EVENTS.
ENDIF.
ENDFORM. "FRM_EVENTTAB_BUILD
*&---------------------------------------------------------------------*
*& Form frm_alv_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->LI_PRT text
*----------------------------------------------------------------------*
FORM FRM_BUILD_HEADER USING
LI_LIST_HEADER TYPE SLIS_T_LISTHEADER.
* PERFORM frm_appen_header USING 'H' cns_title li_list_header.
* PERFORM frm_appen_header USING 'S' cns_riqi li_list_header.
** PERFORM frm_appen_header USING 'S' cns_lrzx li_list_header.
* PERFORM frm_appen_header USING 'S' cns_bzdw li_list_header.
* PERFORM frm_appen_header USING 'S' cns_zblx li_list_header.
* PERFORM frm_appen_header USING 'S' cns_hbdw li_list_header.
ENDFORM. "frm_build_header
*&---------------------------------------------------------------------*
*& Form FRM_APPEN_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->L_TYPE text
* -->L_INFO text
* -->LI_LIST_HEADERN text
*----------------------------------------------------------------------*
FORM FRM_APPEN_HEADER USING
L_TYPE TYPE C
L_INFO TYPE ANY
LI_LIST_HEADERN TYPE SLIS_T_LISTHEADER .
DATA:L_WA_LIST_HEADER LIKE LINE OF LI_LIST_HEADERN.
L_WA_LIST_HEADER-TYP = L_TYPE.
L_WA_LIST_HEADER-INFO = L_INFO.
L_WA_LIST_HEADER-KEY = ''.
APPEND L_WA_LIST_HEADER TO LI_LIST_HEADERN.
ENDFORM. "FRM_APPEN_HEADER
*&---------------------------------------------------------------------*
*& Form FRM_TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM FRM_TOP_OF_PAGE. "回调函数写标题
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_LIST_HEADER.
ENDFORM. "FRM_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form frm_add_fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_L_WK_CON text
* -->P_WA_NAME text
* -->P_WA_TXT text
* -->P_WA_LENGTH text
*----------------------------------------------------------------------*
FORM FRM_ADD_FIELDCAT USING P_L_WK_CON TYPE CHAR20
P_WA_NAME TYPE CHAR30
P_WA_TXT TYPE CHAR20
P_WA_LENGTH TYPE CHAR20.
WA_ALV_FIELD-COL_POS = P_L_WK_CON.
WA_ALV_FIELD-FIELDNAME = P_WA_NAME.
WA_ALV_FIELD-REPTEXT_DDIC = P_WA_TXT.
WA_ALV_FIELD-OUTPUTLEN = P_WA_LENGTH.
WA_ALV_FIELD-FIX_COLUMN = 'X'.
WA_ALV_FIELD-JUST = ' '.
WA_ALV_FIELD-NO_ZERO = 'X'.
IF P_WA_NAME = 'BELNR'.
* WA_ALV_FIELD-CHECKBOX = '1'.
* WA_ALV_FIELD-EDIT = 'X'.
WA_ALV_FIELD-KEY = 'X'.
WA_ALV_FIELD-FIX_COLUMN = 'X'.
ELSE.
WA_ALV_FIELD-KEY = ''.
WA_ALV_FIELD-FIX_COLUMN = ''.
* CLEAR WA_ALV_FIELD-NO_ZERO.
ENDIF.
APPEND WA_ALV_FIELD TO IT_ALV_FIELDCAT.
ENDFORM. "FRM_ADD_FIELDCAT
*&---------------------------------------------------------------------*
*& Form alv_pf_status
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM ALV_PF_STATUS USING
RT_EXTAB TYPE SLIS_T_EXTAB. "状态栏
SET PF-STATUS 'STU001'.
ENDFORM. "ALV_PF_STATUS
*&---------------------------------------------------------------------*
*& Form alv_pf_status_DETAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM ALV_PF_STATUS_DETAIL USING
RT_EXTAB TYPE SLIS_T_EXTAB. "状态栏
SET PF-STATUS 'STU002'.
ENDFORM. "ALV_PF_STATUS
*&---------------------------------------------------------------------*
*& Form alv_user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM ALV_USER_COMMAND USING
R_UCOMM LIKE SY-UCOMM "功能操作
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN 'EXIT'.
CLEAR R_UCOMM.
LEAVE PROGRAM.
WHEN 'BACK'.
CLEAR R_UCOMM.
LEAVE TO SCREEN 0 .
WHEN 'CANCEL'.
CLEAR R_UCOMM.
LEAVE TO SCREEN 0.
WHEN '&IC1'.
DATA:L_YEAR(4) TYPE C.
L_YEAR = WA_PRT-BUDAT+0(4).
READ TABLE IT_PRT INTO WA_PRT INDEX RS_SELFIELD-TABINDEX.
SET PARAMETER ID 'BLN' FIELD WA_PRT-BELNR.
SET PARAMETER ID 'BUK' FIELD WA_PRT-BUKRS.
SET PARAMETER ID 'GJR' FIELD L_YEAR.
CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
WHEN 'PRINT'.
PERFORM FRM_PRINT.
WHEN OTHERS .
ENDCASE.
RS_SELFIELD-REFRESH = 'X'. "ALV被修改时会自动刷新,没有修改不进行刷新
ENDFORM. "ALV_USER_COMMAND
*&---------------------------------------------------------------------*
*& Form ALV_USER_COMMAND_DETAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM ALV_USER_COMMAND_DETAIL USING
P_UCOMM LIKE SY-UCOMM "功能操作
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE P_UCOMM.
WHEN '&IC1'.
WHEN OTHERS.
ENDCASE.
RS_SELFIELD-REFRESH = 'X'. "ALV被修改时会自动刷新,没有修改不进行刷新
ENDFORM. "ALV_USER_COMMAND_DETAIL
*&---------------------------------------------------------------------*
*& Form FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_IT_PRT text
*----------------------------------------------------------------------*
FORM FRM_ALV_DISPLAY TABLES P_P_IT_PRT.
"插入正确名称 <...>.
* PERFORM frm_eventtab_build USING it_events.
* PERFORM frm_build_header USING it_list_header.
DATA:IT_LAYOUT TYPE SLIS_LAYOUT_ALV.
IT_LAYOUT-ZEBRA = 'X'. "能隔行换色(斑马线)
IT_LAYOUT-BOX_FIELDNAME = 'BOX'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = CNS_PF_STATUS
I_CALLBACK_USER_COMMAND = CNS_USER_COMMAND
IT_FIELDCAT = IT_ALV_FIELDCAT
IS_LAYOUT = IT_LAYOUT
* it_events = it_events
TABLES
T_OUTTAB = P_P_IT_PRT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " FRM_ALV_DISPLAY
*& 包括 ZFIR002_ALV
*&---------------------------------------------------------------------*
TYPE-POOLS : SLIS.
DATA: "定义ALV显示所需要的变量
IT_EVENTS TYPE SLIS_T_EVENT,
IT_LIST_HEADER TYPE SLIS_T_LISTHEADER,
WA_ALV_FIELD TYPE SLIS_FIELDCAT_ALV,
IT_ALV_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
CNS_PF_STATUS TYPE SLIS_FORMNAME VALUE 'ALV_PF_STATUS',
CNS_PF_STATUS_DETAIL TYPE SLIS_FORMNAME VALUE 'ALV_PF_STATUS_DETAIL',
CNS_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'ALV_USER_COMMAND',
CNS_USER_COMMAND_DETAIL TYPE SLIS_FORMNAME VALUE 'ALV_USER_COMMAND_DETAIL'.
*&---------------------------------------------------------------------*
*& Form frm_eventtab_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->LI_EVENTS text
*----------------------------------------------------------------------*
FORM FRM_EVENTTAB_BUILD USING
LI_EVENTS TYPE SLIS_T_EVENT.
DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = LI_EVENTS.
READ TABLE LI_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
INTO LS_EVENT.
IF SY-SUBRC = 0.
MOVE 'FRM_TOP_OF_PAGE' TO LS_EVENT-FORM.
APPEND LS_EVENT TO LI_EVENTS.
ENDIF.
ENDFORM. "FRM_EVENTTAB_BUILD
*&---------------------------------------------------------------------*
*& Form frm_alv_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->LI_PRT text
*----------------------------------------------------------------------*
FORM FRM_BUILD_HEADER USING
LI_LIST_HEADER TYPE SLIS_T_LISTHEADER.
* PERFORM frm_appen_header USING 'H' cns_title li_list_header.
* PERFORM frm_appen_header USING 'S' cns_riqi li_list_header.
** PERFORM frm_appen_header USING 'S' cns_lrzx li_list_header.
* PERFORM frm_appen_header USING 'S' cns_bzdw li_list_header.
* PERFORM frm_appen_header USING 'S' cns_zblx li_list_header.
* PERFORM frm_appen_header USING 'S' cns_hbdw li_list_header.
ENDFORM. "frm_build_header
*&---------------------------------------------------------------------*
*& Form FRM_APPEN_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->L_TYPE text
* -->L_INFO text
* -->LI_LIST_HEADERN text
*----------------------------------------------------------------------*
FORM FRM_APPEN_HEADER USING
L_TYPE TYPE C
L_INFO TYPE ANY
LI_LIST_HEADERN TYPE SLIS_T_LISTHEADER .
DATA:L_WA_LIST_HEADER LIKE LINE OF LI_LIST_HEADERN.
L_WA_LIST_HEADER-TYP = L_TYPE.
L_WA_LIST_HEADER-INFO = L_INFO.
L_WA_LIST_HEADER-KEY = ''.
APPEND L_WA_LIST_HEADER TO LI_LIST_HEADERN.
ENDFORM. "FRM_APPEN_HEADER
*&---------------------------------------------------------------------*
*& Form FRM_TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM FRM_TOP_OF_PAGE. "回调函数写标题
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_LIST_HEADER.
ENDFORM. "FRM_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form frm_add_fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_L_WK_CON text
* -->P_WA_NAME text
* -->P_WA_TXT text
* -->P_WA_LENGTH text
*----------------------------------------------------------------------*
FORM FRM_ADD_FIELDCAT USING P_L_WK_CON TYPE CHAR20
P_WA_NAME TYPE CHAR30
P_WA_TXT TYPE CHAR20
P_WA_LENGTH TYPE CHAR20.
WA_ALV_FIELD-COL_POS = P_L_WK_CON.
WA_ALV_FIELD-FIELDNAME = P_WA_NAME.
WA_ALV_FIELD-REPTEXT_DDIC = P_WA_TXT.
WA_ALV_FIELD-OUTPUTLEN = P_WA_LENGTH.
WA_ALV_FIELD-FIX_COLUMN = 'X'.
WA_ALV_FIELD-JUST = ' '.
WA_ALV_FIELD-NO_ZERO = 'X'.
IF P_WA_NAME = 'BELNR'.
* WA_ALV_FIELD-CHECKBOX = '1'.
* WA_ALV_FIELD-EDIT = 'X'.
WA_ALV_FIELD-KEY = 'X'.
WA_ALV_FIELD-FIX_COLUMN = 'X'.
ELSE.
WA_ALV_FIELD-KEY = ''.
WA_ALV_FIELD-FIX_COLUMN = ''.
* CLEAR WA_ALV_FIELD-NO_ZERO.
ENDIF.
APPEND WA_ALV_FIELD TO IT_ALV_FIELDCAT.
ENDFORM. "FRM_ADD_FIELDCAT
*&---------------------------------------------------------------------*
*& Form alv_pf_status
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM ALV_PF_STATUS USING
RT_EXTAB TYPE SLIS_T_EXTAB. "状态栏
SET PF-STATUS 'STU001'.
ENDFORM. "ALV_PF_STATUS
*&---------------------------------------------------------------------*
*& Form alv_pf_status_DETAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM ALV_PF_STATUS_DETAIL USING
RT_EXTAB TYPE SLIS_T_EXTAB. "状态栏
SET PF-STATUS 'STU002'.
ENDFORM. "ALV_PF_STATUS
*&---------------------------------------------------------------------*
*& Form alv_user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM ALV_USER_COMMAND USING
R_UCOMM LIKE SY-UCOMM "功能操作
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN 'EXIT'.
CLEAR R_UCOMM.
LEAVE PROGRAM.
WHEN 'BACK'.
CLEAR R_UCOMM.
LEAVE TO SCREEN 0 .
WHEN 'CANCEL'.
CLEAR R_UCOMM.
LEAVE TO SCREEN 0.
WHEN '&IC1'.
DATA:L_YEAR(4) TYPE C.
L_YEAR = WA_PRT-BUDAT+0(4).
READ TABLE IT_PRT INTO WA_PRT INDEX RS_SELFIELD-TABINDEX.
SET PARAMETER ID 'BLN' FIELD WA_PRT-BELNR.
SET PARAMETER ID 'BUK' FIELD WA_PRT-BUKRS.
SET PARAMETER ID 'GJR' FIELD L_YEAR.
CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
WHEN 'PRINT'.
PERFORM FRM_PRINT.
WHEN OTHERS .
ENDCASE.
RS_SELFIELD-REFRESH = 'X'. "ALV被修改时会自动刷新,没有修改不进行刷新
ENDFORM. "ALV_USER_COMMAND
*&---------------------------------------------------------------------*
*& Form ALV_USER_COMMAND_DETAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM ALV_USER_COMMAND_DETAIL USING
P_UCOMM LIKE SY-UCOMM "功能操作
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE P_UCOMM.
WHEN '&IC1'.
WHEN OTHERS.
ENDCASE.
RS_SELFIELD-REFRESH = 'X'. "ALV被修改时会自动刷新,没有修改不进行刷新
ENDFORM. "ALV_USER_COMMAND_DETAIL
*&---------------------------------------------------------------------*
*& Form FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_IT_PRT text
*----------------------------------------------------------------------*
FORM FRM_ALV_DISPLAY TABLES P_P_IT_PRT.
"插入正确名称 <...>.
* PERFORM frm_eventtab_build USING it_events.
* PERFORM frm_build_header USING it_list_header.
DATA:IT_LAYOUT TYPE SLIS_LAYOUT_ALV.
IT_LAYOUT-ZEBRA = 'X'. "能隔行换色(斑马线)
IT_LAYOUT-BOX_FIELDNAME = 'BOX'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = CNS_PF_STATUS
I_CALLBACK_USER_COMMAND = CNS_USER_COMMAND
IT_FIELDCAT = IT_ALV_FIELDCAT
IS_LAYOUT = IT_LAYOUT
* it_events = it_events
TABLES
T_OUTTAB = P_P_IT_PRT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " FRM_ALV_DISPLAY