On selecting the header record, corresponding item record is shown. This has been done using hierarchical ALV:
*&---------------------------------------------------------------------* *& Report YHIERARCHY *& *&---------------------------------------------------------------------* *& HIERARCHICAL ALV *& Help: http://sapabap-4.blogspot.in/2015/11/alv-hierarchical-report.html *&---------------------------------------------------------------------* * REPORT yhierarchy. TYPE-POOLS: slis. TYPES: BEGIN OF gty_ekko. INCLUDE STRUCTURE ekko. TYPES: expand. TYPES: END OF gty_ekko. DATA: gt_ekko TYPE TABLE OF gty_ekko, gt_ekpo TYPE TABLE OF ekpo, gt_fcat TYPE slis_t_fieldcat_alv, gt_tmp TYPE slis_t_fieldcat_alv, gs_fcat TYPE slis_fieldcat_alv, gs_layout TYPE slis_layout_alv, gs_key TYPE slis_keyinfo_alv "FOR HIERARCHICAL ALV . START-OF-SELECTION. SELECT * FROM ekko INTO TABLE gt_ekko UP TO 10 ROWS. SELECT * FROM ekpo INTO TABLE gt_ekpo FOR ALL ENTRIES IN gt_ekko WHERE ebeln = gt_ekko-ebeln . DATA lv_col TYPE i VALUE 0. IF gt_ekko IS NOT INITIAL. lv_col = lv_col + 1. gs_fcat-col_pos = lv_col. gs_fcat-fieldname = 'EBELN'. gs_fcat-tabname = 'IT_EKKO'. gs_fcat-seltext_l = 'Purchase Order'. APPEND gs_fcat TO gt_fcat. CLEAR gs_fcat. lv_col = lv_col + 1. gs_fcat-col_pos = lv_col. gs_fcat-fieldname = 'BUKRS'. gs_fcat-tabname = 'IT_EKKO'. gs_fcat-seltext_l = 'Company Code'. APPEND gs_fcat TO gt_fcat. CLEAR gs_fcat. lv_col = lv_col + 1. gs_fcat-col_pos = lv_col. gs_fcat-fieldname = 'AEDAT'. gs_fcat-tabname = 'IT_EKKO'. gs_fcat-seltext_l = 'Creation Date'. APPEND gs_fcat TO gt_fcat. CLEAR gs_fcat. lv_col = lv_col + 1. gs_fcat-col_pos = lv_col. gs_fcat-fieldname = 'ERNAM'. gs_fcat-tabname = 'IT_EKKO'. gs_fcat-seltext_l = 'Created By'. APPEND gs_fcat TO gt_fcat. CLEAR gs_fcat. lv_col = lv_col + 1. gs_fcat-col_pos = lv_col. gs_fcat-fieldname = 'LIFNR'. gs_fcat-tabname = 'IT_EKKO'. gs_fcat-seltext_l = 'Vendor'. APPEND gs_fcat TO gt_fcat. CLEAR gs_fcat. lv_col = lv_col + 1. gs_fcat-col_pos = lv_col. gs_fcat-fieldname = 'BEDAT'. gs_fcat-tabname = 'IT_EKKO'. gs_fcat-seltext_l = 'Purchasing Document Date'. APPEND gs_fcat TO gt_fcat. CLEAR gs_fcat. ENDIF. IF gt_ekpo IS NOT INITIAL. lv_col = lv_col + 1. gs_fcat-col_pos = lv_col. gs_fcat-fieldname = 'EBELN'. gs_fcat-tabname = 'IT_EKPO'. gs_fcat-seltext_l = 'Purchase Order'. APPEND gs_fcat TO gt_fcat. CLEAR gs_fcat. lv_col = lv_col + 1. gs_fcat-col_pos = lv_col. gs_fcat-fieldname = 'EBELP'. gs_fcat-tabname = 'IT_EKPO'. gs_fcat-seltext_l = 'Item'. APPEND gs_fcat TO gt_fcat. CLEAR gs_fcat. lv_col = lv_col + 1. gs_fcat-col_pos = lv_col. gs_fcat-fieldname = 'MATKL'. gs_fcat-tabname = 'IT_EKPO'. gs_fcat-seltext_l = 'Material Group'. APPEND gs_fcat TO gt_fcat. CLEAR gs_fcat. lv_col = lv_col + 1. gs_fcat-col_pos = lv_col. gs_fcat-fieldname = 'AEDAT'. gs_fcat-tabname = 'IT_EKPO'. gs_fcat-seltext_l = 'Creation Date'. APPEND gs_fcat TO gt_fcat. CLEAR gs_fcat. lv_col = lv_col + 1. gs_fcat-col_pos = lv_col. gs_fcat-fieldname = 'MENGE'. gs_fcat-tabname = 'IT_EKPO'. gs_fcat-seltext_l = 'PO Quantity'. APPEND gs_fcat TO gt_fcat. CLEAR gs_fcat. lv_col = lv_col + 1. gs_fcat-col_pos = lv_col. gs_fcat-fieldname = 'MEINS'. gs_fcat-tabname = 'IT_EKPO'. gs_fcat-seltext_l = 'Unit'. APPEND gs_fcat TO gt_fcat. CLEAR gs_fcat. lv_col = lv_col + 1. gs_fcat-col_pos = lv_col. gs_fcat-fieldname = 'NETPR'. gs_fcat-tabname = 'IT_EKPO'. gs_fcat-seltext_l = 'Net Price'. APPEND gs_fcat TO gt_fcat. CLEAR gs_fcat. lv_col = lv_col + 1. gs_fcat-col_pos = lv_col. gs_fcat-fieldname = 'PEINH'. gs_fcat-tabname = 'IT_EKPO'. gs_fcat-seltext_l = 'Price Unit'. APPEND gs_fcat TO gt_fcat. CLEAR gs_fcat. ENDIF. CONSTANTS: lc_expand TYPE slis_fieldname VALUE 'EXPAND'. gs_layout-zebra = 'X'. "Zebra looks gs_layout-colwidth_optimize = 'X'. "Column width optimized gs_layout-expand_fieldname = 'EXPAND'. "Expand operation gs_layout-window_titlebar = 'Hierarchical PO Header & Item Display'. gs_key-header01 = 'EBELN'. "Purchase Order number gs_key-item01 = 'EBELN'. "is the key for header & item table CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY' EXPORTING i_callback_program = sy-repid is_layout = gs_layout it_fieldcat = gt_fcat i_tabname_header = 'IT_EKKO' i_tabname_item = 'IT_EKPO' is_keyinfo = gs_key TABLES t_outtab_header = gt_ekko t_outtab_item = gt_ekpo EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF.
No comments:
Post a Comment