Register Login

Regarding REUSE_ALV_HIERSEQ_LIST_DISPLAY

Updated May 18, 2018

REPORT ztestalv2 .
TYPE-POOLS slis. " ALV Global types

CONSTANTS:
gc_forname_top_ of_page TYPE slis_formname VALUE \'TOP_OF_PAGE\'.
DATA: events TYPE slis_t_event.
DATA: lc_glay TYPE lvc_s_glay.
DATA: ls_layout TYPE slis_layout_ alv.
DATA: fieldcat TYPE slis_t_fieldcat_ alv WITH HEADER LINE.

DATA: gt_list_top_ of_page TYPE slis_t_listheader.
DATA: BEGIN OF gs_data,
checkbox.
INCLUDE STRUCTURE vbak.
DATA: END OF gs_data.
DATA :
gt_data LIKE TABLE OF gs_data WITH HEADER LINE,
gt_subdata LIKE TABLE OF gs_data WITH HEADER LINE.
PARAMETERS :
p_max TYPE num4 DEFAULT \'10\' OBLIGATORY.

CONSTANTS :
c_x VALUE \'X\'.

*----------- --------- --------- --------- --------- --------- --------- -*
START-OF-SELECTION.

PERFORM f_read_data.

*----------- --------- --------- --------- --------- --------- --------- -*
END-OF-SELECTION.

PERFORM f_display_data.

*----------- --------- --------- --------- --------- --------- --------- -*
* Form f_read_data
*----------- --------- --------- --------- --------- --------- --------- -*
FORM f_read_data.

SELECT *
INTO CORRESPONDING FIELDS OF TABLE gt_data
UP TO p_max ROWS
FROM vbak.

ENDFORM. " F_READ_DATA
*----------- --------- --------- --------- --------- --------- --------- *
* FORM f_display_data *
*----------- --------- --------- --------- --------- --------- --------- *
FORM f_display_data.


PERFORM build_alv_layout.

PERFORM build_field_ catalogs.

PERFORM eventtab_build CHANGING events.

lc_glay-edt_ cll_cb = \'X\'.
CALL FUNCTION \'REUSE_ALV_GRID_ DISPLAY\'
EXPORTING
i_callback_program = sy-cprog
i_callback_user_ command = \'USER_COMMAND\'
i_structure_ name = \'GS_DATA\'
is_layout = ls_layout
it_events = events[]
i_grid_settings = lc_glay
it_fieldcat = fieldcat[]
i_callback_pf_ status_set = \'SET_PF_STATUS\'
* i_save = \'A\'
TABLES
t_outtab = gt_data.

ENDFORM. "f_display_data

*----------- --------- --------- --------- --------- --------- --------- -*
* FORM USER_COMMAND *
*----------- --------- --------- --------- --------- --------- --------- -*
FORM user_command USING i_ucomm TYPE syucomm
is_selfield TYPE slis_selfield. "#EC CALLED

CASE i_ucomm.
WHEN \'&OK\'.
CLEAR GT_SUBDATA.
REFRESH GT_SUBDATA.
LOOP AT gt_data WHERE checkbox = \'X\'.
gt_subdata = gt_data.
APPEND gt_subdata.
ENDLOOP.
PERFORM sub_display_ subdata.
ENDCASE.

ENDFORM. " USER_COMMAND

*&------------ --------- --------- --------- --------- --------- --------- --*
*& Form TOP_OF_PAGE
*&------------ --------- --------- --------- --------- --------- --------- --*
* text
*----------- --------- --------- --------- --------- --------- --------- ----*
FORM top_of_page.
REFRESH gt_list_top_ of_page.
CLEAR gt_list_top_ of_page.

PERFORM comment_build USING gt_list_top_ of_page.

* Output Sanyo logo on report header

CALL FUNCTION \'REUSE_ALV_COMMENTAR Y_WRITE\'
EXPORTING
* i_logo = \'SANYO_RED\'
it_list_commentary = gt_list_top_ of_page.
ENDFORM. "TOP_OF_PAGE

*&------------ --------- --------- --------- --------- --------- --------- --*
*& Form SET_PF_STATUS
*&------------ --------- --------- --------- --------- --------- --------- --*
* text
*----------- --------- --------- --------- --------- --------- --------- ----*
* -->RT_EXTAB text
*----------- --------- --------- --------- --------- --------- --------- ----*
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS \'ZNEWSTATUS1\'.
ENDFORM. "SET_PF_STATUS
*&------------ --------- --------- --------- --------- --------- --------- ---*
*& Form build_alv_layout
*&------------ --------- --------- --------- --------- --------- --------- ---*
* text
*----------- --------- --------- --------- --------- --------- --------- -----*
* --> p1 text
* <-- p2 text
*----------- --------- --------- --------- --------- --------- --------- -----*
FORM build_alv_layout .
ls_layout-zebra = c_x.
ls_layout-cell_ merge = c_x.
ls_layout-colwidth_ optimize = c_x.
ENDFORM. " build_alv_layout
*&------------ --------- --------- --------- --------- --------- --------- ---*
*& Form build_field_ catalogs
*&------------ --------- --------- --------- --------- --------- --------- ---*
* text
*----------- --------- --------- --------- --------- --------- --------- -----*
* --> p1 text
* <-- p2 text
*----------- --------- --------- --------- --------- --------- --------- -----*
FORM build_field_ catalogs .
fieldcat-fieldname = \'CHECKBOX\'.
fieldcat-key = c_x.
fieldcat-checkbox = c_x.
fieldcat-input = c_x.
fieldcat-edit = c_x.
APPEND fieldcat.
CLEAR fieldcat.

fieldcat-ref_ tabname = \'GS_DATA\'.
fieldcat-fieldname = \'VBELN\'.
fieldcat-key = c_x.
APPEND fieldcat.
CLEAR fieldcat.
ENDFORM. " build_field_ catalogs
*&------------ --------- --------- --------- --------- --------- --------- ---*
*& Form eventtab_build
*&------------ --------- --------- --------- --------- --------- --------- ---*
* text
*----------- --------- --------- --------- --------- --------- --------- -----*
* <--P_EVENTS text
*----------- --------- --------- --------- --------- --------- --------- -----*
FORM eventtab_build CHANGING lt_events TYPE slis_t_event.
FIELD-SYMBOLS: <lt_events> LIKE LINE OF lt_events.

CALL FUNCTION \'REUSE_ALV_EVENTS_ GET\'
EXPORTING
i_list_type = 0
IMPORTING
et_events = lt_events.

* Define TOP_OF_PAGE event
READ TABLE lt_events WITH KEY name = slis_ev_top_ of_page
ASSIGNING <lt_events>.
IF sy-subrc EQ 0.
MOVE gc_forname_top_ of_page TO <lt_events>-form.
ENDIF.

ENDFORM. " eventtab_build
*&------------ --------- --------- --------- --------- --------- --------- ---*
*& Form comment_build
*&------------ --------- --------- --------- --------- --------- --------- ---*
* text
*----------- --------- --------- --------- --------- --------- --------- -----*
* -->P_GT_LIST_TOP_ OF_PAGE text
*----------- --------- --------- --------- --------- --------- --------- -----*
FORM comment_build CHANGING gt_top_of_page TYPE slis_t_listheader.
DATA: gs_line TYPE slis_listheader.

CLEAR gs_line.
gs_line-typ = \'H\'.
gs_line-info = \'Display SO data\'.
APPEND gs_line TO gt_top_of_page.

CLEAR gs_line.
gs_line-typ = \'S\'.
gs_line-key = \'Report ID:\'.
gs_line-info = sy-repid.
APPEND gs_line TO gt_top_of_page.

CLEAR gs_line.
gs_line-typ = \'S\'.
gs_line-key = \'User:\'.
gs_line-info = sy-uname.
APPEND gs_line TO gt_top_of_page.

CLEAR gs_line.
gs_line-typ = \'S\'.
gs_line-key = \'Date:\'.
WRITE sy-datum TO gs_line-info MM/DD/YYYY.
APPEND gs_line TO gt_top_of_page.

CLEAR gs_line.
gs_line-typ = \'S\'.
gs_line-key = \'Time:\'.
WRITE sy-uzeit TO gs_line-info USING EDIT MASK \'__:__:__\'.
APPEND gs_line TO gt_top_of_page.
ENDFORM. " comment_build
*&------------ --------- --------- --------- --------- --------- --------- ---*
*& Form SUB_DISPLAY_ SUBDATA
*&------------ --------- --------- --------- --------- --------- --------- ---*
* text
*----------- --------- --------- --------- --------- --------- --------- -----*
* --> p1 text
* <-- p2 text
*----------- --------- --------- --------- --------- --------- --------- -----*
FORM sub_display_ subdata .
DATA:
x_fieldcat_subdata TYPE slis_fieldcat_ alv,
it_fieldcat_ subdata TYPE slis_t_fieldcat_ alv.

x_fieldcat_subdata- tabname = \'GT_DATA\'.
x_fieldcat_subdata- fieldname = \'VBELN\'.
x_fieldcat_subdata- key = c_x.
APPEND x_fieldcat_subdata TO it_fieldcat_ subdata.
CLEAR x_fieldcat_subdata.

x_fieldcat_subdata- tabname = \'GT_DATA\'.
x_fieldcat_subdata- fieldname = \'ERDAT\'.
APPEND x_fieldcat_subdata TO it_fieldcat_ subdata.
CLEAR x_fieldcat_subdata.

x_fieldcat_subdata- tabname = \'GT_DATA\'.
x_fieldcat_subdata- fieldname = \'ERZET\'.
APPEND x_fieldcat_subdata TO it_fieldcat_ subdata.
CLEAR x_fieldcat_subdata.

x_fieldcat_subdata- tabname = \'GT_DATA\'.
x_fieldcat_subdata- fieldname = \'ERNAM\'.
APPEND x_fieldcat_subdata TO it_fieldcat_ subdata.
CLEAR x_fieldcat_subdata.


CALL FUNCTION \'REUSE_ALV_FIELDCATA LOG_MERGE\'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = \'GT_DATA\'
i_inclname = sy-repid
CHANGING
ct_fieldcat = it_fieldcat_ subdata
EXCEPTIONS
inconsistent_ interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CALL FUNCTION \'REUSE_ALV_GRID_ DISPLAY\'
EXPORTING
i_callback_program = sy-repid
is_layout = lS_layout
it_fieldcat = it_fieldcat_ SUBDATA
i_screen_start_ column = 1
i_screen_start_ line = 1
i_screen_end_ column = 100
i_screen_end_ line = 10
TABLES
t_outtab = GT_SUBDATA

EXCEPTIONS
program_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

ENDFORM. " SUB_DISPLAY_ SUBDATA


×