REPORT z_alv_list_block_2.
*---------------------------------------------------------------------*
* Demo of FM REUSE_ALV_LIST_DISPLAY - Several Lists *
*---------------------------------------------------------------------*
* Author : Michel PIOUD *
* Email : mpioud@yahoo.fr HomePage : http://www.geocities.com/mpioud *
*---------------------------------------------------------------------*
* Macro definition
DEFINE m_fieldcat.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
DEFINE m_sort.
ls_sort-fieldname = &1.
ls_sort-up = 'X'.
append ls_sort to lt_sort.
END-OF-DEFINITION.
TYPE-POOLS: slis. " ALV Global types
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max. "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '02' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
DATA:
gs_layout TYPE slis_layout_alv,
* 1st Table
BEGIN OF gt_kna1 OCCURS 0, " Data displayed
kunnr LIKE kna1-kunnr, " Customer number
ernam LIKE kna1-ernam, " Name of Person who Created
erdat LIKE kna1-erdat, " Creation date
name1 LIKE kna1-name1, " Name 1
END OF gt_kna1,
* 2nd Table
BEGIN OF gt_mara OCCURS 0,
ernam LIKE mara-ernam, " Name of Person who Created
matnr LIKE mara-matnr, " Material number
ersda LIKE mara-ersda, " Creation date
brgew LIKE mara-brgew, " Gross weight
END OF gt_mara,
* 3rd Table
BEGIN OF gt_vbak OCCURS 0,
vkorg LIKE vbak-vkorg, " Sales organization
kunnr LIKE vbak-kunnr, " Sold-to party
vbeln LIKE vbak-vbeln, " Sales document
netwr LIKE vbak-netwr, " Net Value of the Sales Order
waerk LIKE vbak-waerk, " SD document currency
END OF gt_vbak.
*---------------------------------------------------------------------*
INITIALIZATION.
v_1 = 'Maximum of records to read'.
*---------------------------------------------------------------------*
START-OF-SELECTION.
* Read data
SELECT * FROM kna1
UP TO p_max ROWS
INTO CORRESPONDING FIELDS OF TABLE gt_kna1.
SELECT * FROM mara
UP TO p_max ROWS
INTO CORRESPONDING FIELDS OF TABLE gt_mara.
SELECT * FROM vbak
UP TO p_max ROWS
INTO CORRESPONDING FIELDS OF TABLE gt_vbak.
PERFORM f_display_data.
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM user_command USING i_ucomm LIKE sy-ucomm
is_selfield TYPE slis_selfield. "#EC CALLED
CASE i_ucomm.
WHEN '&IC1'. " Pick
CASE is_selfield-sel_tab_field(7).
WHEN 'GT_MARA'.
WHEN 'GT_KNA1'.
WHEN 'GT_VBAK'.
READ TABLE gt_vbak INDEX is_selfield-tabindex.
IF sy-subrc EQ 0.
SET PARAMETER ID 'AUN' FIELD gt_vbak-vbeln.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDCASE.
ENDFORM. " USER_COMMAND
*---------------------------------------------------------------------*
* Form f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.
DATA :
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv, " Field catalog
ls_sort TYPE slis_sortinfo_alv,
lt_sort TYPE slis_t_sortinfo_alv, " Sort table
lt_events TYPE slis_t_event,
ls_event TYPE slis_alv_event.
gs_layout-group_change_edit = 'X'.
gs_layout-colwidth_optimize = 'X'.
gs_layout-zebra = 'X'.
gs_layout-detail_popup = 'X'.
gs_layout-get_selinfos = 'X'.
* Build field catalog and sort table
m_fieldcat 'KUNNR' 'KNA1'.
m_fieldcat 'ERNAM' 'KNA1'.
m_fieldcat 'ERDAT' 'KNA1'.
m_fieldcat 'NAME1' 'KNA1'.
m_sort 'KUNNR'.
* Build Event Table
MOVE 'TOP_OF_PAGE' TO ls_event-name.
MOVE 'TOP_OF_PAGE' TO ls_event-form.
APPEND ls_event TO lt_events.
MOVE 'END_OF_LIST' TO ls_event-name.
MOVE 'END_OF_LIST' TO ls_event-form.
APPEND ls_event TO lt_events.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = lt_fieldcat
is_layout = gs_layout
it_events = lt_events
it_sort = lt_sort
TABLES
t_outtab = gt_kna1.
ENDFORM. " F_DISPLAY_DATA
*---------------------------------------------------------------------*
* FORM top_of_page *
*---------------------------------------------------------------------*
FORM top_of_page. "#EC CALLED
ULINE.
WRITE : sy-uname, sy-title(56) CENTERED, sy-datum.
ULINE.
ENDFORM. " TOP_OF_PAGE
*---------------------------------------------------------------------*
* FORM End_of_list *
*---------------------------------------------------------------------*
FORM end_of_list. "#EC CALLED
DATA :
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv, " Field catalog
ls_sort TYPE slis_sortinfo_alv,
lt_sort TYPE slis_t_sortinfo_alv, " Sort table
lt_events TYPE slis_t_event,
ls_event TYPE slis_alv_event.
* Build field catalog and sort table
m_fieldcat 'MATNR' 'MARA'.
m_fieldcat 'ERNAM' 'MARA'.
m_fieldcat 'ERSDA' 'MARA'.
m_fieldcat 'BRGEW' 'MARA'.
m_sort 'MATNR'.
* Build Event Table
MOVE 'END_OF_LIST' TO ls_event-name.
MOVE 'END_OF_LIST_2' TO ls_event-form.
APPEND ls_event TO lt_events.
gs_layout-list_append = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
it_fieldcat = lt_fieldcat
is_layout = gs_layout
it_sort = lt_sort
it_events = lt_events
TABLES
t_outtab = gt_mara.
ENDFORM. " END_OF_LIST
*---------------------------------------------------------------------*
* FORM End_of_list_2 *
*---------------------------------------------------------------------*
FORM end_of_list_2. "#EC CALLED
DATA :
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv, " Field catalog
ls_sort TYPE slis_sortinfo_alv,
lt_sort TYPE slis_t_sortinfo_alv, " Sort table
lt_events TYPE slis_t_event,
ls_event TYPE slis_alv_event.
* Build field catalog and sort table
m_fieldcat 'VBELN' 'VBAK'.
m_fieldcat 'VKORG' 'VBAK'.
m_fieldcat 'KUNNR' 'VBAK'.
m_fieldcat 'NETWR' 'VBAK'.
m_fieldcat 'WAERK' 'VBAK'.
m_sort 'VBELN'.
* Build Event Table
MOVE 'TOP_OF_PAGE' TO ls_event-name.
MOVE 'TOP_OF_PAGE' TO ls_event-form.
APPEND ls_event TO lt_events.
gs_layout-list_append = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
it_fieldcat = lt_fieldcat
is_layout = gs_layout
it_sort = lt_sort
it_events = lt_events
TABLES
t_outtab = gt_vbak.
ENDFORM. " END_OF_LIST_2
************* END OF PROGRAM Z_ALV_LIST_BLOCK_2 **********************
유용하게 사용하겠습니다. 감사합니다^^