REPORT z_demo_2_alv_list.
*---------------------------------------------------------------------*
* This program is an example with 2 ALV Grid lists *
* The Sales Orders are displayed in the first list *
* When a line is selected, the items of the order are displayed in *
* the second list *
*---------------------------------------------------------------------*
* Author : Michel PIOUD *
* Email : mpioud@yahoo.fr HomePage : http://www.geocities.com/mpioud *
*---------------------------------------------------------------------*
* Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
ls_fieldcat-cfieldname = &3.
ls_fieldcat-qfieldname = &4.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
*---------------------------------------------------------------------*
TYPE-POOLS: slis. " ALV Global types
*---------------------------------------------------------------------*
TYPES:
BEGIN OF ty_vbak,
vkorg TYPE vbak-vkorg, " Sales organization
kunnr TYPE vbak-kunnr, " Sold-to party
vbeln TYPE vbak-vbeln, " Sales document
netwr TYPE vbak-netwr, " Net Value of the Sales Order
waerk TYPE vbak-waerk, " Currency
END OF ty_vbak,
BEGIN OF ty_vbap,
vbeln TYPE vbap-vbeln, " Sales document
posnr TYPE vbap-posnr, " Sales document item
matnr TYPE vbap-matnr, " Material number
arktx TYPE vbap-arktx, " Short text for sales order item
kwmeng TYPE vbap-kwmeng, " Order quantity
vrkme TYPE vbap-vrkme, " Quantity Unit
netwr TYPE vbap-netwr, " Net value of the order item
waerk TYPE vbap-waerk, " Currency
END OF ty_vbap.
*---------------------------------------------------------------------*
DATA :
gs_vbak TYPE ty_vbak,
* Data displayed in the first list
gt_vbak TYPE TABLE OF ty_vbak,
* Data displayed in the second list
gt_vbap TYPE TABLE OF ty_vbap.
*---------------------------------------------------------------------*
SELECT-OPTIONS :
s_vkorg FOR gs_vbak-vkorg, " Sales organization
s_kunnr FOR gs_vbak-kunnr, " Sold-to party
s_vbeln FOR gs_vbak-vbeln. " Sales document
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max. "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
*---------------------------------------------------------------------*
INITIALIZATION.
v_1 = 'Maximum of records to read'.
*---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM f_read_data_vbak.
PERFORM f_display_data_vbak.
*---------------------------------------------------------------------*
* Form f_read_data_vbak
*---------------------------------------------------------------------*
FORM f_read_data_vbak.
SELECT vkorg kunnr vbeln netwr waerk
INTO CORRESPONDING FIELDS OF TABLE gt_vbak
UP TO p_max ROWS
FROM vbak
WHERE kunnr IN s_kunnr
AND vbeln IN s_vbeln
AND vkorg IN s_vkorg
and vbtyp = 'C'. " C = Sales Orders.
ENDFORM. " F_READ_DATA_VBAK
*---------------------------------------------------------------------*
* Form f_display_data_vbak
*---------------------------------------------------------------------*
FORM f_display_data_vbak.
DATA:
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv.
* Build the field catalog
m_fieldcat 'VKORG' 'VBAK' '' ''.
m_fieldcat 'KUNNR' 'VBAK' '' ''.
m_fieldcat 'VBELN' 'VBAK' '' ''.
m_fieldcat 'NETWR' 'VBAK' 'WAERK' ''.
m_fieldcat 'WAERK' 'VBAK' '' ''.
* Display the first list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = lt_fieldcat
TABLES
t_outtab = gt_vbak.
ENDFORM. " F_DISPLAY_DATA_VBAK
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM user_command USING u_ucomm TYPE syucomm
us_selfield TYPE slis_selfield. "#EC CALLED
CASE u_ucomm.
WHEN '&IC1'.
READ TABLE gt_vbak INDEX us_selfield-tabindex INTO gs_vbak.
CHECK sy-subrc EQ 0.
PERFORM f_read_data_vbap. " Read data from VBAP
PERFORM f_display_data_vbap.
ENDCASE.
ENDFORM. " USER_COMMAND
*---------------------------------------------------------------------*
* Form f_read_data_vbap
*---------------------------------------------------------------------*
FORM f_read_data_vbap.
SELECT vbeln posnr matnr arktx kwmeng vrkme netwr waerk
INTO CORRESPONDING FIELDS OF TABLE gt_vbap
FROM vbap
WHERE vbeln = gs_vbak-vbeln.
ENDFORM. " F_READ_DATA_VBAP
*---------------------------------------------------------------------*
* Form f_display_data_vbap
*---------------------------------------------------------------------*
FORM f_display_data_vbap.
DATA:
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv.
* Build the field catalog
m_fieldcat 'VBELN' 'VBAP' '' ''.
m_fieldcat 'POSNR' 'VBAP' '' ''.
m_fieldcat 'MATNR' 'VBAP' '' ''.
m_fieldcat 'ARKTX' 'VBAP' '' ''.
m_fieldcat 'KWMENG' 'VBAP' '' 'VRKME'.
m_fieldcat 'VRKME' 'VBAP' '' ''.
m_fieldcat 'NETWR' 'VBAP' 'WAERK' ''.
m_fieldcat 'WAERK' 'VBAP' '' ''.
* Display the second list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = lt_fieldcat
TABLES
t_outtab = gt_vbap.
ENDFORM. " F_DISPLAY_DATA_VBAP
***************** END OF PROGRAM Z_DEMO_2_ALV_LIST ******************
유용하게 사용하겠습니다. 감사합니다^^