Search This Blog

Search This Blog

ALV Heirarchy Report

REPORT  ZCLASS_G16 LINE-SIZE 150.

  TABLES VBAK.

  SELECT-OPTIONS S_VBELN FOR VBAK-VBELN.

  DATA: BEGIN OF IT_VBAK OCCURS 0,
          VBELN LIKE VBAK-VBELN,
          ERDAT LIKE VBAK-ERDAT,
          ERNAM LIKE VBAK-ERNAM,
          KUNNR LIKE VBAK-KUNNR,
          EXP(1),
        END OF IT_VBAK.

  DATA: BEGIN OF IT_VBAP OCCURS 0,
          VBELN  TYPE  VBAP-VBELN,
          POSNR  TYPE  VBAP-POSNR,
          MATNR  TYPE  VBAP-MATNR,
          NETWR  TYPE  VBAP-NETWR,
          EXP(1),
        END OF IT_VBAP.

  TYPE-POOLS SLIS.

  DATA IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

  DATA WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
  DATA WA_KEY TYPE SLIS_KEYINFO_ALV.
  DATA WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
  DATA IT_SORT TYPE SLIS_T_SORTINFO_ALV.
  DATA WA_SORT TYPE SLIS_SORTINFO_ALV.

  START-OF-SELECTION.

    SELECT VBELN
           ERDAT
           ERNAM
           KUNNR INTO TABLE IT_VBAK
                 FROM VBAK
                 WHERE VBELN IN S_VBELN.

    IF NOT IT_VBAK[] IS INITIAL.
      SORT IT_VBAK BY VBELN.

      SELECT VBELN
             POSNR
             MATNR
             NETWR INTO TABLE IT_VBAP
                   FROM VBAP
                   FOR ALL ENTRIES IN IT_VBAK
                   WHERE VBELN = IT_VBAK-VBELN.

    ENDIF.

  END-OF-SELECTION.

*-- VBAK
    WA_FIELDCAT-FIELDNAME = 'VBELN'.
    WA_FIELDCAT-TABNAME = 'IT_VBAK'.
    WA_FIELDCAT-SELTEXT_L = 'Sales Doc'.
    WA_FIELDCAT-KEY = 'X'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-FIELDNAME = 'ERDAT'.
    WA_FIELDCAT-TABNAME = 'IT_VBAK'.
    WA_FIELDCAT-SELTEXT_L = 'Date'.
    WA_FIELDCAT-OUTPUTLEN = 10.
    WA_FIELDCAT-EDIT_MASK = '__-__-____'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.


    WA_FIELDCAT-FIELDNAME = 'ERNAM'.
    WA_FIELDCAT-TABNAME = 'IT_VBAK'.
    WA_FIELDCAT-SELTEXT_L = 'USER'.
    WA_FIELDCAT-EDIT = 'X'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.


    WA_FIELDCAT-FIELDNAME = 'KUNNR'.
    WA_FIELDCAT-TABNAME = 'IT_VBAK'.
    WA_FIELDCAT-SELTEXT_L = 'Cutomer'.
    WA_FIELDCAT-EMPHASIZE = 'C710'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

*-- VBAP
    WA_FIELDCAT-FIELDNAME = 'VBELN'.
    WA_FIELDCAT-TABNAME = 'IT_VBAP'.
    WA_FIELDCAT-SELTEXT_L = 'Sales Doc'.
    WA_FIELDCAT-KEY = 'X'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-FIELDNAME = 'POSNR'.
    WA_FIELDCAT-TABNAME = 'IT_VBAP'.
    WA_FIELDCAT-SELTEXT_L = 'Item NO'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-FIELDNAME = 'MATNR'.
    WA_FIELDCAT-TABNAME = 'IT_VBAP'.
    WA_FIELDCAT-SELTEXT_L = 'Mat No'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

    WA_FIELDCAT-FIELDNAME = 'NETWR'.
    WA_FIELDCAT-TABNAME = 'IT_VBAP'.
    WA_FIELDCAT-SELTEXT_L = 'Amount'.
    WA_FIELDCAT-DO_SUM = 'X'.

    APPEND WA_FIELDCAT TO IT_FIELDCAT.
    CLEAR WA_FIELDCAT.

*--KEY
    WA_KEY-HEADER01 = 'VBELN'(001).
    WA_KEY-ITEM01 = 'VBELN'(001).


*--Layout- Expand
    WA_LAYOUT-EXPAND_FIELDNAME = 'EXP'.

    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                      = WA_LAYOUT
       IT_FIELDCAT                    = IT_FIELDCAT
*   IT_EXCLUDING                   =
*   IT_SPECIAL_GROUPS              =
*   IT_SORT                        =  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_VBAK'
        I_TABNAME_ITEM                 = 'IT_VBAP'
*   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_VBAK
        T_OUTTAB_ITEM                  = IT_VBAP
* EXCEPTIONS
*   PROGRAM_ERROR                  = 1
*   OTHERS                         = 2
              .
    IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.