Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ALV Hierarchy

Former Member
0 Kudos

I am facing a problem with this code... i finally want to see a hierarchical buliding blocks with Header as IT_MARA and Item as IT_MARC... I have used the same fieldcatalog for both these... but I am getting into short dump.. please tell me how to correct this...



REPORT  Z_50657_ALV_EX3
        NO STANDARD PAGE HEADING
        LINE-COUNT 65(3)
        LINE-SIZE 220
        MESSAGE-ID ZZ.

************************************************************************
*                             Type Pools                               *
************************************************************************

TYPE-POOLS: SLIS, ICON.

************************************************************************
*                              Tables                                  *
************************************************************************

TABLES: MARA, "General Material Data
        MAKT. "Material Descriptions

************************************************************************
*                         Internal Tables                              *
************************************************************************

DATA: BEGIN OF IT_MARA OCCURS 0,
      MATNR LIKE MARA-MATNR,
      MTART LIKE MARA-MTART,
      MATKL LIKE MARA-MATKL,
      MEINS LIKE MARA-MEINS,
      NTGEW LIKE MARA-NTGEW,
      END OF IT_MARA.

*WERKS ladgr mtvfp dispr dismm dispo

DATA: BEGIN OF IT_MAKT OCCURS 0,
      MATNR LIKE MAKT-MATNR,
      MAKTX LIKE MAKT-MAKTX,
      END OF IT_MAKT.


DATA: BEGIN OF IT_MARC OCCURS 0,
      MATNR LIKE MARC-MATNR,
      WERKS LIKE MARC-WERKS,
      LADGR LIKE MARC-LADGR,
      MTVFP LIKE MARC-MTVFP,
      DISPR LIKE MARC-DISPR,
      DISMM LIKE MARC-DISMM,
      DISPO LIKE MARC-DISPO,
      END OF IT_MARC.

DATA: BEGIN OF ITAB_FINAL OCCURS 0,
      MATNR LIKE MARA-MATNR,
      MTART LIKE MARA-MTART,
      MATKL LIKE MARA-MATKL,
      MEINS LIKE MARA-MEINS,
      NTGEW LIKE MARA-NTGEW,
      MAKTX LIKE MAKT-MAKTX,
      WERKS LIKE MARC-WERKS,
      LADGR LIKE MARC-LADGR,
      MTVFP LIKE MARC-MTVFP,
      DISPR LIKE MARC-DISPR,
      DISMM LIKE MARC-DISMM,
      DISPO LIKE MARC-DISPO,
      END OF ITAB_FINAL.

************************************************************************
*                       Work Area                               *
************************************************************************

DATA: X_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
      IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

DATA: X_FIELDCAT1 TYPE SLIS_FIELDCAT_ALV,
      IT_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV.

DATA: X_FIELDCAT2 TYPE SLIS_FIELDCAT_ALV,
      IT_FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV.

DATA: WA_SORT TYPE SLIS_SORTINFO_ALV,
      IT_SORT TYPE SLIS_T_SORTINFO_ALV.

DATA: L_LAYOUT TYPE SLIS_LAYOUT_ALV,
      L_LAYOUT1 TYPE SLIS_LAYOUT_ALV,
      L_LAYOUT2 TYPE SLIS_LAYOUT_ALV.

DATA: GT_XEVENTS TYPE SLIS_T_EVENT,
      GT_YEVENTS TYPE SLIS_T_EVENT,
      GT_ZEVENTS TYPE SLIS_T_EVENT.

DATA : GT_PRINT TYPE SLIS_PRINT_ALV.           " print table

DATA : IT_HEADER TYPE SLIS_TABNAME,
       IT_ITEM TYPE SLIS_TABNAME.

DATA: IT_KEYINFO TYPE SLIS_KEYINFO_ALV.


************************************************************************
*                       Selection-Screen                               *
************************************************************************


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS: S_MATNR FOR MARA-MATNR,
                S_MTART FOR MARA-MTART.

SELECTION-SCREEN END OF BLOCK B1.



************************************************************************
*                     At  Selection-Screen                             *
************************************************************************
*VALIDATION





************************************************************************
*                       Start of Selection                             *
************************************************************************

START-OF-SELECTION.

*POPULATION OF DATA INTO INTERNAL TABLE ITAB
  PERFORM GET_DATA.

  PERFORM DEFINE_FIELDCAT.

  PERFORM DEFINE_LAYOUT.

  PERFORM FIELDCATALOG_MERGE.

  PERFORM SORT_FUNC.

  PERFORM HIER_BLOCKS.


************************************************************************
*                       End of Selection                             *
************************************************************************

END-OF-SELECTION.

  PERFORM FINAL_DISPLAY.

*&--------------------------------------------------------------------*
*&      Form  GET_DATA
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM GET_DATA.

  SELECT MATNR
         MTART
         MATKL
         MEINS
         NTGEW
         FROM MARA INTO TABLE IT_MARA
         WHERE MATNR IN S_MATNR AND MTART IN S_MTART .

  ITAB_FINAL[] = IT_MARA[].

  SELECT MATNR
         MAKTX
         FROM MAKT INTO TABLE IT_MAKT
         FOR ALL ENTRIES IN IT_MARA
         WHERE MATNR = IT_MARA-MATNR.

  SELECT MATNR
         WERKS
         LADGR
         MTVFP
         DISPR
         DISMM
         DISPO FROM MARC INTO TABLE IT_MARC
         FOR ALL ENTRIES IN IT_MARA
         WHERE MATNR = IT_MARA-MATNR.


  LOOP AT ITAB_FINAL.

    LOOP AT IT_MAKT WHERE MATNR = ITAB_FINAL-MATNR.

      MOVE IT_MAKT-MAKTX TO ITAB_FINAL-MAKTX.
      MODIFY ITAB_FINAL INDEX SY-TABIX.

    ENDLOOP.

  ENDLOOP.


  LOOP AT ITAB_FINAL.

    LOOP AT IT_MARC WHERE MATNR = ITAB_FINAL-MATNR.

      ITAB_FINAL-WERKS = IT_MARC-WERKS.
      MODIFY ITAB_FINAL INDEX SY-TABIX.

      ITAB_FINAL-LADGR = IT_MARC-LADGR.
      MODIFY ITAB_FINAL INDEX SY-TABIX.

      ITAB_FINAL-MTVFP = IT_MARC-MTVFP.
      MODIFY ITAB_FINAL INDEX SY-TABIX.

      ITAB_FINAL-DISPR = IT_MARC-DISPR.
      MODIFY ITAB_FINAL INDEX SY-TABIX.

      ITAB_FINAL-DISMM = IT_MARC-DISMM.
      MODIFY ITAB_FINAL INDEX SY-TABIX.

      ITAB_FINAL-DISPO = IT_MARC-DISPO.
      MODIFY ITAB_FINAL INDEX SY-TABIX.


    ENDLOOP.

  ENDLOOP.


ENDFORM.                    "GET_DATA



*&--------------------------------------------------------------------*
*&      Form  DEFINE_FIELDCAT
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM DEFINE_FIELDCAT.

  X_FIELDCAT-FIELDNAME = 'MTART'.
  X_FIELDCAT-TABNAME = 'IT_MARA'.
  X_FIELDCAT-SELTEXT_L = ''.
  X_FIELDCAT-OUTPUTLEN = 15.
  APPEND X_FIELDCAT TO IT_FIELDCAT.
  CLEAR X_FIELDCAT.

  X_FIELDCAT-FIELDNAME = 'MATKL'.
  X_FIELDCAT-TABNAME = 'IT_MARA'.
  X_FIELDCAT-OUTPUTLEN = 15.
  APPEND X_FIELDCAT TO IT_FIELDCAT.
  CLEAR X_FIELDCAT.

  X_FIELDCAT-FIELDNAME = 'NTGEW'.
  X_FIELDCAT-TABNAME = 'IT_MARA'.
  X_FIELDCAT-DO_SUM = 'X'.
  X_FIELDCAT-OUTPUTLEN = 15.
  APPEND X_FIELDCAT TO IT_FIELDCAT.
  CLEAR X_FIELDCAT.

ENDFORM.                    "DEFINE_FIELDCAT

*&--------------------------------------------------------------------*
*&      Form  DEFINE_LAYOUT
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM DEFINE_LAYOUT.

  L_LAYOUT-ZEBRA = 'X'.
  L_LAYOUT-SUBTOTALS_TEXT = 'GEN SUBTOT'.
  L_LAYOUT-WINDOW_TITLEBAR = 'DETAILS'.
  L_LAYOUT-TOTALS_TEXT = 'TOTAL VALUE'.

  L_LAYOUT1-ZEBRA = 'X'.
  L_LAYOUT2-ZEBRA = 'X'.

ENDFORM.                    "DEFINE_LAYOUT

*&--------------------------------------------------------------------*
*&      Form  FIELDCATALOG_MERGE
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM FIELDCATALOG_MERGE.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      I_PROGRAM_NAME         = SY-REPID
      I_INTERNAL_TABNAME     = 'IT_MARA'
      I_INCLNAME             = SY-REPID
    CHANGING
      CT_FIELDCAT            = IT_FIELDCAT
    EXCEPTIONS
      INCONSISTENT_INTERFACE = 1
      PROGRAM_ERROR          = 2
      OTHERS                 = 3.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.



  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      I_PROGRAM_NAME         = SY-REPID
      I_INTERNAL_TABNAME     = 'IT_MAKT'
      I_INCLNAME             = SY-REPID
    CHANGING
      CT_FIELDCAT            = IT_FIELDCAT
    EXCEPTIONS
      INCONSISTENT_INTERFACE = 1
      PROGRAM_ERROR          = 2
      OTHERS                 = 3.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.




  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      I_PROGRAM_NAME         = SY-REPID
      I_INTERNAL_TABNAME     = 'IT_MARC'
      I_INCLNAME             = SY-REPID
    CHANGING
      CT_FIELDCAT            = IT_FIELDCAT2
    EXCEPTIONS
      INCONSISTENT_INTERFACE = 1
      PROGRAM_ERROR          = 2
      OTHERS                 = 3.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    "FIELDCATALOG_MERGE


*&--------------------------------------------------------------------*
*&      Form  SORT_FUNC
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM SORT_FUNC.

  WA_SORT-SPOS = '1'.
  WA_SORT-FIELDNAME = 'MTART'.
  WA_SORT-TABNAME = 'IT_MARA'.
  WA_SORT-UP = 'X'.
  APPEND WA_SORT TO IT_SORT.
  CLEAR WA_SORT.

  WA_SORT-SPOS = '2'.
  WA_SORT-FIELDNAME = 'MATKL'.
  WA_SORT-TABNAME = 'IT_MARA'.
  WA_SORT-UP = 'X'.
  APPEND WA_SORT TO IT_SORT.
  CLEAR WA_SORT.

  WA_SORT-SPOS = '3'.
  WA_SORT-FIELDNAME = 'NTGEW'.
  WA_SORT-TABNAME = 'IT_MARA'.
  WA_SORT-UP = 'X'.
  WA_SORT-SUBTOT = 'X'.
  APPEND WA_SORT TO IT_SORT.
  CLEAR WA_SORT.

ENDFORM.                    "SORT_FUNC

*&--------------------------------------------------------------------*
*&      Form  FINAL_DISPLAY
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM FINAL_DISPLAY.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
      IS_LAYOUT                  = L_LAYOUT
      IT_FIELDCAT                = IT_FIELDCAT
      I_TABNAME                  = 'IT_MARA'
      IT_EVENTS                  = GT_XEVENTS
      IT_SORT                    = IT_SORT
    TABLES
      T_OUTTAB                   = IT_MARA
    EXCEPTIONS
      PROGRAM_ERROR              = 1
      MAXIMUM_OF_APPENDS_REACHED = 2
      OTHERS                     = 3.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.



  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
      IS_LAYOUT                  = L_LAYOUT1
      IT_FIELDCAT                = IT_FIELDCAT
      I_TABNAME                  = 'IT_MAKT'
      IT_EVENTS                  = GT_YEVENTS
    TABLES
      T_OUTTAB                   = IT_MAKT
    EXCEPTIONS
      PROGRAM_ERROR              = 1
      MAXIMUM_OF_APPENDS_REACHED = 2
      OTHERS                     = 3.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
      IS_LAYOUT                  = L_LAYOUT2
      IT_FIELDCAT                = IT_FIELDCAT2
      I_TABNAME                  = 'IT_MARC'
      IT_EVENTS                  = GT_ZEVENTS
    TABLES
      T_OUTTAB                   = IT_MARC
    EXCEPTIONS
      PROGRAM_ERROR              = 1
      MAXIMUM_OF_APPENDS_REACHED = 2
      OTHERS                     = 3.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
    EXPORTING
      IS_PRINT = GT_PRINT.

  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    "FINAL_DISPLAY

*&--------------------------------------------------------------------*
*&      Form  hier_blocks
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM HIER_BLOCKS.

  CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
    EXPORTING
*     I_INTERFACE_CHECK              = ' '
     I_CALLBACK_PROGRAM             = sy-repid
*     I_CALLBACK_PF_STATUS_SET       = ' '
*     I_CALLBACK_USER_COMMAND        = ' '
*     IS_LAYOUT                      =
     IT_FIELDCAT                    = it_fieldcat
*     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_HEADER
      I_TABNAME_ITEM                 = IT_ITEM
*     I_STRUCTURE_NAME_HEADER        =
*     I_STRUCTURE_NAME_ITEM          =
      IS_KEYINFO                     = IT_KEYINFO
*     IS_PRINT                       =
*     IS_REPREP_ID                   =
*     I_BYPASSING_BUFFER             =
*     I_BUFFER_ACTIVE                =
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER        =
*     ES_EXIT_CAUSED_BY_USER         =
    TABLES
      T_OUTTAB_HEADER                = IT_MARA
      T_OUTTAB_ITEM                  = IT_MARC
*   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.


endform.

Message was edited by: Rahul Kavuri

1 REPLY 1

former_member188685
Active Contributor
0 Kudos

Hi Rahul,

first of all don't try to use Block list and Hierarchial list combination. but you can use

<b>CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_HS_APPEND'</b>

instead of heirachial display fm.

and refer the sample program BALVBT01.

Regards

vijay