REPORT z_alv_hierseq_list.

*---------------------------------------------------------------------*
* Program with FM REUSE_ALV_HIERSEQ_LIST_DISPLAY
*
*---------------------------------------------------------------------*
* Author : Michel PIOUD - Updated 21 Dec 2007
*
* HomePage : http://www.oocities.com/mpioud
*
*---------------------------------------------------------------------*
TYPE-POOLS: slis.
" ALV Global types
*---------------------------------------------------------------------*
CONSTANTS :
c_x VALUE 'X',
c_gt_vbap TYPE slis_tabname VALUE 'GT_VBAP',
c_gt_vbak TYPE slis_tabname VALUE 'GT_VBAK'.
*---------------------------------------------------------------------*
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.
"#EC NEEDED
PARAMETERS p_max(02) TYPE n DEFAULT '10' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(27) v_2 FOR FIELD p_expand. "#EC NEEDED
PARAMETERS p_expand AS CHECKBOX DEFAULT c_x.
SELECTION-SCREEN END OF LINE.
*---------------------------------------------------------------------*
TYPES :
* 1st Table
BEGIN OF ty_vbak,
vbeln TYPE vbak-vbeln,
" Sales document
kunnr TYPE vbak-kunnr,
" Sold-to party
netwr TYPE vbak-netwr,
" Net Value of the Sales Order
erdat TYPE vbak-erdat,
" Creation date
waerk TYPE vbak-waerk,
" SD document currency
expand TYPE xfeld,
END OF ty_vbak,
* 2nd Table
BEGIN OF ty_vbap,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
arktx TYPE vbap-arktx,
netwr TYPE vbap-netwr,
waerk TYPE vbap-waerk,
END OF ty_vbap.

"
"
"
"
"
"

Sales document
Sales document
Material number
Material description
Net Value of the Sales Order
SD document currency

*---------------------------------------------------------------------*
DATA :
* 1st Table
gt_vbak TYPE TABLE OF ty_vbak,
* 2nd Table
gt_vbap TYPE TABLE OF ty_vbap.
*---------------------------------------------------------------------*
INITIALIZATION.
v_1 = 'Maximum of records to read'.
v_2 = 'With ''EXPAND'' field'.
*---------------------------------------------------------------------*
START-OF-SELECTION.
* Read Sales Document: Header Data

. 'VBAK' ''. ls_fieldcat-cfieldname = &4." Sort table slis_fieldcat_alv. ls_layout-expand_fieldname ENDIF. 'VBAK' 'WAERK'. slis_keyinfo_alv. " Field with currency unit append ls_fieldcat to lt_fieldcat. ls_fieldcat-tabname = &1. slis_t_sortinfo_alv. * Macro definition DEFINE m_fieldcat. DEFINE m_sort. IF gt_vbak[] IS NOT INITIAL. ENDIF. ls_fieldcat-ref_tabname = &3. PERFORM f_display. c_x. END-OF-DEFINITION. table 'VBAK' ''. slis_layout_alv." Field catalog ls_layout-group_change_edit = ls_layout-colwidth_optimize = ls_layout-zebra = ls_layout-detail_popup = ls_layout-get_selinfos = IF p_expand = c_x. c_x. lt_sort. * Build field catalog and sort m_fieldcat c_gt_vbak 'VBELN' m_fieldcat c_gt_vbak 'KUNNR' m_fieldcat c_gt_vbak 'NETWR' c_x. ls_sort-tabname = ls_sort-fieldname ls_sort-up append ls_sort to END-OF-DEFINITION. ls_fieldcat-fieldname = &2. = c_x. = &2. = 'EXPAND'. c_x.SELECT FROM UP INTO * vbeln kunnr netwr waerk erdat vbak TO p_max ROWS CORRESPONDING FIELDS OF TABLE gt_vbak. slis_sortinfo_alv. c_x. *---------------------------------------------------------------------* END-OF-SELECTION. Read Sales Document: Item Data SELECT vbeln posnr matnr arktx netwr waerk FROM vbap INTO CORRESPONDING FIELDS OF TABLE gt_vbap FOR ALL ENTRIES IN gt_vbak WHERE vbeln = gt_vbak-vbeln. DATA: ls_layout ls_keyinfo ls_sort lt_sort ls_fieldcat lt_fieldcat TYPE TYPE TYPE TYPE TYPE TYPE &1. slis_t_fieldcat_alv. *---------------------------------------------------------------------* * Form F_DISPLAY *---------------------------------------------------------------------* FORM f_display.

" F_LIST_DISPLAY *---------------------------------------------------------------------* * Form USER_COMMAND * *---------------------------------------------------------------------* FORM user_command USING i_ucomm TYPE sy-ucomm is_selfield TYPE slis_selfield. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. m_fieldcat c_gt_vbak 'ERDAT' 'VBAK' ''. ''. ''. ls_keyinfo-item01 = 'VBELN'. ls_keyinfo-item02 = 'POSNR'. . ENDCASE. * Display Sales Order CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN. IF sy-subrc EQ 0. CASE i_ucomm. ''. m_sort c_gt_vbak 'KUNNR'. WHEN c_gt_vbap. IF sy-subrc <> 0. 'WAERK'. ENDFORM. "#EC CALLED DATA ls_vbak TYPE ty_vbak.m_fieldcat c_gt_vbak 'WAERK' 'VBAK' ''. ENDIF. " Pick CASE is_selfield-tabname. * Sales order number SET PARAMETER ID 'AUN' FIELD ls_vbak-vbeln. ENDIF. m_sort c_gt_vbap 'NETWR'. WHEN c_gt_vbak. ls_keyinfo-header01 = 'VBELN'. * Dipslay Hierarchical list CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY' EXPORTING i_callback_program = sy-cprog i_callback_user_command = 'USER_COMMAND' is_layout = ls_layout it_fieldcat = lt_fieldcat it_sort = lt_sort i_tabname_header = c_gt_vbak i_tabname_item = c_gt_vbap is_keyinfo = ls_keyinfo i_save = 'A' TABLES t_outtab_header = gt_vbak t_outtab_item = gt_vbap EXCEPTIONS program_error = 1 OTHERS = 2. WHEN '&IC1'. READ TABLE gt_vbak INDEX is_selfield-tabindex INTO ls_vbak. m_fieldcat m_fieldcat m_fieldcat m_fieldcat m_fieldcat c_gt_vbap c_gt_vbap c_gt_vbap c_gt_vbap c_gt_vbap 'POSNR' 'MATNR' 'ARKTX' 'NETWR' 'WAERK' 'VBAP' 'VBAP' 'VBAP' 'VBAP' 'VBAP' ''.

" USER_COMMAND ****************** END OF PROGRAM Z_ALV_HIERSEQ_LIST ****************** .ENDCASE. ENDFORM.

Sign up to vote on this title
UsefulNot useful