HIERARCHICAL ALV

HIERARCHICAL ALV:

           Hierarchical alv used to display the output in hierarchical manner.

 Based on the given purchasing document number display the purchasing document (EBELN,               BEDAT, LIFNR) & purchasing document item details (EBELP, MENGE, MEINS, NETPR) in           hierarchical manner as shown in the below by using ALV.



PROGRAM:
*&---------------------------------------------------------------------*
*& Report  ZR_HIERARCHICAL_ALV
*&
*&---------------------------------------------------------------------*

REPORT ZR_HIERARCHICAL_ALV.
TABLES EKKO.

*SELECTION SCREEN
SELECTION-SCREEN BEGIN OF BLOCK WITH FRAME.
SELECT-OPTIONS SO_EBELN FOR EKKO-EBELN.
SELECTION-SCREEN END OF BLOCK A.

*TYPES DECLARATION
TYPES BEGIN OF TY_EKKO,
        EBELN 
TYPE EKKO-EBELN,
        BEDAT 
TYPE EKKO-BEDAT,
        LIFNR 
TYPE EKKO-LIFNR,
        
END OF TY_EKKO,
        
BEGIN OF TY_EKPO,
        EBELN 
TYPE EKPO-EBELN,
        EBELP 
TYPE EKPO-EBELP,
        MENGE 
TYPE EKPO-MENGE,
        MEINS 
TYPE EKPO-MEINS,
        NETPR 
TYPE EKPO-NETPR,
        
END OF TY_EKPO.

*DECLARE WORK AREA AND INTERNAL TABLES
DATA : WA_EKKO TYPE TY_EKKO,
       IT_EKKO 
TYPE TABLE OF TY_EKKO,
       WA_EKPO 
TYPE TY_EKPO,
       IT_EKPO 
TYPE TABLE OF TY_EKPO,
       IT_FCAT 
TYPE SLIS_T_FIELDCAT_ALV,
       WA_FCAT 
LIKE LINE OF IT_FCAT,
       WA_KEY 
TYPE SLIS_KEYINFO_ALV.

*GET DATA
SELECT EBELN BEDAT LIFNR
       
FROM EKKO
       
INTO TABLE IT_EKKO
       
WHERE EBELN IN SO_EBELN.
SELECT EBELN EBELP MENGE MEINS NETPR
       
FROM EKPO
       
INTO TABLE IT_EKPO
       
WHERE EBELN IN SO_EBELN.

*FILL FIELDCATLOG
WA_FCAT
-FIELDNAME 'EBELN'.
WA_FCAT
-COL_POS '1'.
WA_FCAT
-SELTEXT_M 'PUR DOC'.
WA_FCAT
-TABNAME 'IT_EKKO'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT
-FIELDNAME 'BEDAT'.
WA_FCAT
-COL_POS '2'.
WA_FCAT
-SELTEXT_M 'DOC DATE'.
WA_FCAT
-TABNAME 'IT_EKKO'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-FIELDNAME 'LIFNR'.
WA_FCAT
-COL_POS '3'.
WA_FCAT
-SELTEXT_M 'VENDOR NO'.
WA_FCAT
-TABNAME 'IT_EKKO'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.

WA_FCAT
-FIELDNAME 'EBELN'.
WA_FCAT
-COL_POS '1'.
WA_FCAT
-SELTEXT_M 'PUR DOC'.
WA_FCAT
-TABNAME 'IT_EKPO'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT
-FIELDNAME 'EBELP'.
WA_FCAT
-COL_POS '2'.
WA_FCAT
-SELTEXT_M 'ITEM'.
WA_FCAT
-TABNAME 'IT_EKPO'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT
-FIELDNAME 'MENGE'.
WA_FCAT
-COL_POS '3'.
WA_FCAT
-SELTEXT_M 'QTY'.
WA_FCAT
-TABNAME 'IT_EKPO'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT
-FIELDNAME 'MEINS'.
WA_FCAT
-COL_POS '4'.
WA_FCAT
-SELTEXT_M 'UOM'.
WA_FCAT
-TABNAME 'IT_EKPO'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT
-FIELDNAME 'NETPR'.
WA_FCAT
-COL_POS '5'.
WA_FCAT
-SELTEXT_M 'NET PRICE'.
WA_FCAT
-TABNAME 'IT_EKPO'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
*FILLING KEYINFO WORKAREA
WA_KEY
-HEADER01 'EBELN'.
WA_KEY
-ITEM01 'EBELN'.

*DISPLAY OUTPUT
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
  
EXPORTING
*   I_INTERFACE_CHECK              = ' '
*   I_CALLBACK_PROGRAM             =
*   I_CALLBACK_PF_STATUS_SET       = ' '
*   I_CALLBACK_USER_COMMAND        = ' '
*   IS_LAYOUT                      =
   IT_FIELDCAT                    
IT_FCAT
*   IT_EXCLUDING                   =
*   IT_SPECIAL_GROUPS              =
*   IT_SORT                        =
*   IT_FILTER                      =
*   IS_SEL_HIDE                    =
*   I_SCREEN_START_COLUMN          = 0
*   I_SCREEN_START_LINE            = 0
*   I_SCREEN_END_COLUMN            = 0
*   I_SCREEN_END_LINE              = 0
*   I_DEFAULT                      = 'X'
*   I_SAVE                         = ' '
*   IS_VARIANT                     =
*   IT_EVENTS                      =
*   IT_EVENT_EXIT                  =
    I_TABNAME_HEADER               
'IT_EKKO'
    I_TABNAME_ITEM                 
'IT_EKPO'
*   I_STRUCTURE_NAME_HEADER        =
*   I_STRUCTURE_NAME_ITEM          =
    IS_KEYINFO                     
WA_KEY
*   IS_PRINT                       =
*   IS_REPREP_ID                   =
*   I_BYPASSING_BUFFER             =
*   I_BUFFER_ACTIVE                =
*   IR_SALV_HIERSEQ_ADAPTER        =
*   IT_EXCEPT_QINFO                =
*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER        =
*   ES_EXIT_CAUSED_BY_USER         =
  
TABLES
    T_OUTTAB_HEADER                
IT_EKKO
    T_OUTTAB_ITEM                  
IT_EKPO
* EXCEPTIONS
*   PROGRAM_ERROR                  = 1
*   OTHERS                         = 2
          
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.


OUTPUT: