Multilevel hierarchy ALV report of Mother WBS

Hi ABAP Guru,
I have created a Mother WBS sturcture which has been created in CJ91 tcode. I need a same hierarchy alv report same structure as shown in cj91 t code. Please help me out.
I have created a alv reort on that but when I make change in mother WBS, the new added wbs is comming in my report at last. PLease help me out.

Hi Manish,
              I am able to see WBS Elements in MB51 Report after going to detailed list from the initial output page. In this detailed output the sender and receiver WBS Elements are getting displayed incorrectly.From that screen only,if I go to Material document list,sender and receiver WBS Elements are getting displayed correctly.
Regards,
B P Singh

Similar Messages

  • How to display 3 level hierarchy alv report using SALV

    Hi ,
          I need to display a Hierarchy ALV report with 3 level.I thought of trying CL_SALV_HIERSEQ_TABLE but i am able to display only two level report.
          How can i display the 3 - level heirarchy report using SALV. I don't want to use SALV_TREE.
          Regards,
          Aditya Tanguturi.

    Hi Aditya,
    Please check this thread
    Is it possible to display more than 2 levels us... | SCN
    Thanks !
    Amit

  • Hierarchial ALV report

    Hi Friends,
    I have created a Hierarchial ALV report using OOP concept (Class Builder). The output is OK but it is displaying the unwanted columns in the header part.
    The code written is as follows.
    =====================================================
    REPORT ZMMSTKH.
    DATA: G_ALV_TREE         TYPE REF TO CL_GUI_ALV_TREE,
          G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
    DATA: GT_ZSD_BILLINFO      TYPE ZSD_BILLINFO  OCCURS 0,      "Output-Table
          OK_CODE LIKE SY-UCOMM,
          SAVE_OK LIKE SY-UCOMM,           "OK-Code
          G_MAX TYPE I VALUE 255.
    DATA  CCONTAINER1.
    DATA LS_FIELDCAT TYPE LVC_S_FCAT.
    DATA GT_FIELDCAT_LVC TYPE LVC_S_FCAT OCCURS 0.
    DATA IT_FIELDCATALOG TYPE LVC_S_FCAT OCCURS 0.
    END-OF-SELECTION.
      CALL SCREEN 100.
    *&      Module  PBO  OUTPUT
          process before output
    MODULE PBO OUTPUT.
      SET PF-STATUS 'MAIN100'.
      SET TITLEBAR 'MAINTITLE'.
      IF G_ALV_TREE IS INITIAL.
        PERFORM INIT_TREE.
        CALL METHOD CL_GUI_CFW=>FLUSH
          EXCEPTIONS
            CNTL_SYSTEM_ERROR = 1
            CNTL_ERROR        = 2.
        IF SY-SUBRC NE 0.
          CALL FUNCTION 'POPUP_TO_INFORM'
            EXPORTING
              TITEL = 'Automation Queue failure'(801)
              TXT1  = 'Internal error:'(802)
              TXT2  = 'A method in the automation queue'(803)
              TXT3  = 'caused a failure.'(804).
        ENDIF.
      ENDIF.
    ENDMODULE.                             " PBO  OUTPUT
    *&      Module  PAI  INPUT
          process after input
    MODULE PAI INPUT.
      SAVE_OK = OK_CODE.
      CLEAR OK_CODE.
      CASE SAVE_OK.
        WHEN 'EXIT' OR 'BACK' OR 'CANC'.
          PERFORM EXIT_PROGRAM.
        WHEN OTHERS.
          CALL METHOD CL_GUI_CFW=>DISPATCH.
      ENDCASE.
      CALL METHOD CL_GUI_CFW=>FLUSH.
    ENDMODULE.                             " PAI  INPUT
    *&      Form  init_tree
          text
    -->  p1        text
    <--  p2        text
    FORM INIT_TREE.
      DATA: L_TREE_CONTAINER_NAME(30) TYPE C.
      L_TREE_CONTAINER_NAME = 'CCONTAINER1'(001).
      CREATE OBJECT G_CUSTOM_CONTAINER
         EXPORTING
               CONTAINER_NAME = L_TREE_CONTAINER_NAME
         EXCEPTIONS
               CNTL_ERROR                  = 1
               CNTL_SYSTEM_ERROR           = 2
               CREATE_ERROR                = 3
               LIFETIME_ERROR              = 4
               LIFETIME_DYNPRO_DYNPRO_LINK = 5.
      IF SY-SUBRC <> 0.
        MESSAGE X208(00) WITH 'ERROR'(100).
      ENDIF.
      CREATE OBJECT G_ALV_TREE
        EXPORTING
            PARENT              = G_CUSTOM_CONTAINER
            NODE_SELECTION_MODE = CL_GUI_COLUMN_TREE=>NODE_SEL_MODE_SINGLE
            ITEM_SELECTION      = 'X'
            NO_HTML_HEADER      = 'X'
            NO_TOOLBAR          = ''
        EXCEPTIONS
            CNTL_ERROR                   = 1
            CNTL_SYSTEM_ERROR            = 2
            CREATE_ERROR                 = 3
            LIFETIME_ERROR               = 4
            ILLEGAL_NODE_SELECTION_MODE  = 5
            FAILED                       = 6
            ILLEGAL_COLUMN_NAME          = 7.
      IF SY-SUBRC <> 0.
        MESSAGE X208(00) WITH 'ERROR'.                          "#EC NOTEXT
      ENDIF.
      DATA L_HIERARCHY_HEADER TYPE TREEV_HHDR.
      PERFORM BUILD_HIERARCHY_HEADER CHANGING L_HIERARCHY_HEADER.
      PERFORM ZF_CREATE_FIELDCAT.
      CALL METHOD G_ALV_TREE->SET_TABLE_FOR_FIRST_DISPLAY
        EXPORTING
          I_STRUCTURE_NAME    = 'zsd_billinfo'
          IS_HIERARCHY_HEADER = L_HIERARCHY_HEADER
        CHANGING
          IT_OUTTAB           = GT_ZSD_BILLINFO. "table must be empty !
      IT_FIELDCATALOG = GT_FIELDCAT_LVC[].
      PERFORM CREATE_HIERARCHY.
      CALL METHOD G_ALV_TREE->FRONTEND_UPDATE.
    ENDFORM.                               " init_tree
    *&      Form  build_hierarchy_header
    FORM BUILD_HIERARCHY_HEADER CHANGING
                                   P_HIERARCHY_HEADER TYPE TREEV_HHDR.
      P_HIERARCHY_HEADER-HEADING = 'Region / Material'(300).
    p_hierarchy_header-tooltip = 'PO No'(400).
      P_HIERARCHY_HEADER-WIDTH = 30.
      P_HIERARCHY_HEADER-WIDTH_PIX = ' '.
    ENDFORM.                               " build_hierarchy_header
    *&      Form  exit_program
          free object and leave program
    FORM EXIT_PROGRAM.
      CALL METHOD G_CUSTOM_CONTAINER->FREE.
      LEAVE PROGRAM.
    ENDFORM.                               " exit_program
    *&      Form  create_hierarchy
          text
    -->  p1        text
    <--  p2        text
    FORM CREATE_HIERARCHY.
      DATA: LS_ZSD_BILLINFO TYPE ZSD_BILLINFO,
            LT_ZSD_BILLINFO TYPE ZSD_BILLINFO OCCURS 0,
           l_bukrs like zsd_billinfo-bukrs,
           l_vbeln like zsd_billinfo-vbeln,
           l_fkdat like zsd_billinfo-fkdat,
           l_fkart like zsd_billinfo-fkart,
           l_vkorg like zsd_billinfo-vkorg,
           l_spart like zsd_billinfo-spart,
            L_BZIRK LIKE ZSD_BILLINFO-BZIRK,
            L_BZIRK_LAST LIKE ZSD_BILLINFO-BZIRK,
           l_vkbur like zsd_billinfo-vkbur,
            L_WERKS LIKE ZSD_BILLINFO-WERKS,
            L_WERKS_LAST LIKE ZSD_BILLINFO-WERKS,
            L_MATNR LIKE ZSD_BILLINFO-MATNR,
            L_MATNR_LAST LIKE ZSD_BILLINFO-MATNR,
            L_FKIMG LIKE ZSD_BILLINFO-FKIMG,
            L_NETWR LIKE ZSD_BILLINFO-NETWR.
      DATA: L_BUKRS_KEY TYPE LVC_NKEY,
            L_BZIRK_KEY TYPE LVC_NKEY,
            L_WERKS_KEY TYPE LVC_NKEY,
            L_MATNR_KEY TYPE LVC_NKEY,
           l_vbeln_key type lvc_nkey,
            L_LAST_KEY TYPE LVC_NKEY.
      SELECT BUKRS BZIRK WERKS MATNR FKIMG FROM ZSD_BILLINFO
      INTO CORRESPONDING FIELDS OF
      TABLE LT_ZSD_BILLINFO
      WHERE  SPART = 'CT' AND
             FKART = 'ZVAT'.
    select * from zsd_billinfo    into table lt_zsd_billinfo
    where  spart = 'CT' and
            fkart = 'ZVAT'.
      SORT LT_ZSD_BILLINFO BY BZIRK WERKS MATNR.
      LOOP AT LT_ZSD_BILLINFO INTO LS_ZSD_BILLINFO.
        L_BZIRK = LS_ZSD_BILLINFO-BZIRK.
        L_WERKS = LS_ZSD_BILLINFO-WERKS.
        L_MATNR = LS_ZSD_BILLINFO-MATNR.
        IF L_BZIRK <> L_BZIRK_LAST.
          L_BZIRK_LAST = L_BZIRK.
          PERFORM ADD_BZIRK USING    L_BZIRK
                                 CHANGING L_BZIRK_KEY.
          CLEAR L_WERKS_LAST.
        ENDIF.
        IF L_WERKS <> L_WERKS_LAST.
          L_WERKS_LAST = L_WERKS.
          PERFORM ADD_WERKS_LINE USING    LS_ZSD_BILLINFO
                                      L_WERKS_KEY
                              CHANGING L_WERKS_KEY.
          IF L_MATNR <> L_MATNR_LAST.
            L_MATNR_LAST = L_MATNR.
            PERFORM ADD_MATNR_LINE USING    LS_ZSD_BILLINFO
                                        L_MATNR_KEY
                                CHANGING L_MATNR_KEY.
          ENDIF.
          PERFORM ADD_COMPLETE_LINE USING  LS_ZSD_BILLINFO
                                           L_MATNR_KEY
                                  CHANGING L_LAST_KEY.
        ENDIF.
    *if l_matnr <> l_matnr_last.
         l_matnr_last = l_matnr.
             perform add_matnr_line using    ls_zsd_billinfo
                                         l_matnr_key
                                 changing l_matnr_key.
       endif.
       perform add_complete_line using  ls_zsd_billinfo
                                        l_matnr_key
                               changing l_last_key.
      ENDLOOP.
    ENDFORM.                               " create_hierarchy
    *&      Form  add_month
    *&      Form  add_ebeln
    FORM ADD_BZIRK  USING     P_BZIRK TYPE C
                              P_RELAT_KEY TYPE LVC_NKEY
                    CHANGING  P_NODE_KEY TYPE LVC_NKEY.
      DATA: L_NODE_TEXT TYPE LVC_VALUE,
            LS_ZSD_BILLINFO TYPE ZSD_BILLINFO,
            L_BZIRK(12) TYPE C.            "output string for month
      CALL METHOD G_ALV_TREE->ADD_NODE
        EXPORTING
          I_RELAT_NODE_KEY = P_RELAT_KEY
          I_RELATIONSHIP   = CL_GUI_COLUMN_TREE=>RELAT_LAST_CHILD
          I_NODE_TEXT      = L_NODE_TEXT
          IS_OUTTAB_LINE   = LS_ZSD_BILLINFO
        IMPORTING
          E_NEW_NODE_KEY   = P_NODE_KEY.
    ENDFORM.                               " add_month
    FORM ADD_WERKS_LINE USING     PS_ZSD_BILLINFO TYPE ZSD_BILLINFO
                                   P_RELAT_KEY TYPE LVC_NKEY
                         CHANGING  P_NODE_KEY TYPE LVC_NKEY.
      DATA: L_NODE_TEXT TYPE LVC_VALUE,
            LS_ZSD_BILLINFO TYPE ZSD_BILLINFO.
      L_NODE_TEXT =  PS_ZSD_BILLINFO-WERKS.
      CALL METHOD G_ALV_TREE->ADD_NODE
        EXPORTING
          I_RELAT_NODE_KEY = P_RELAT_KEY
          I_RELATIONSHIP   = CL_GUI_COLUMN_TREE=>RELAT_LAST_CHILD
          I_NODE_TEXT      = L_NODE_TEXT
          IS_OUTTAB_LINE   = LS_ZSD_BILLINFO
        IMPORTING
          E_NEW_NODE_KEY   = P_NODE_KEY.
    ENDFORM.                               " add_carrid_line
    FORM ADD_MATNR_LINE USING     PS_ZSD_BILLINFO TYPE ZSD_BILLINFO
                                   P_RELAT_KEY TYPE LVC_NKEY
                         CHANGING  P_NODE_KEY TYPE LVC_NKEY.
      DATA: L_NODE_TEXT TYPE LVC_VALUE,
            LS_ZSD_BILLINFO TYPE ZSD_BILLINFO.
      L_NODE_TEXT =  PS_ZSD_BILLINFO-MATNR.
      CALL METHOD G_ALV_TREE->ADD_NODE
        EXPORTING
          I_RELAT_NODE_KEY = P_RELAT_KEY
          I_RELATIONSHIP   = CL_GUI_COLUMN_TREE=>RELAT_LAST_CHILD
          I_NODE_TEXT      = L_NODE_TEXT
          IS_OUTTAB_LINE   = LS_ZSD_BILLINFO
        IMPORTING
          E_NEW_NODE_KEY   = P_NODE_KEY.
    ENDFORM.                               " add_carrid_line
    **&      Form  add_complete_line
    FORM ADD_COMPLETE_LINE USING   PS_ZSD_BILLINFO TYPE ZSD_BILLINFO
                                   P_RELAT_KEY TYPE LVC_NKEY
                         CHANGING  P_NODE_KEY TYPE LVC_NKEY.
      DATA: L_NODE_TEXT TYPE LVC_VALUE.
      WRITE PS_ZSD_BILLINFO-BZIRK TO L_NODE_TEXT.
      CALL METHOD G_ALV_TREE->ADD_NODE
        EXPORTING
          I_RELAT_NODE_KEY = P_RELAT_KEY
          I_RELATIONSHIP   = CL_GUI_COLUMN_TREE=>RELAT_LAST_CHILD
          IS_OUTTAB_LINE   = PS_ZSD_BILLINFO
          I_NODE_TEXT      = L_NODE_TEXT
        IMPORTING
          E_NEW_NODE_KEY   = P_NODE_KEY.
    ENDFORM.                               " add_complete_line
    *&      Form  zf_create_fieldcat
          text
    FORM ZF_CREATE_FIELDCAT.
      CLEAR LS_FIELDCAT.
      LS_FIELDCAT-FIELDNAME = 'FKIMG'.
      LS_FIELDCAT-REF_TABLE = 'zsd_billinfo'.
      LS_FIELDCAT-NO_OUT = 'X'.
      LS_FIELDCAT-KEY = ''.
      APPEND LS_FIELDCAT TO GT_FIELDCAT_LVC.
    ENDFORM. " ZF_CREATE_FIELDCAT
    =================================================
    Kindly look into the code and guide me the solution.
    TIA.
    Regards,
    Mark K

    hi
    good
    i tried your ALV report but it is giving some error due to some ztable you have used in your progam,
    you can go to se38 and give there BCALV* and press f4, you ll find lots of ALV example related to OOP concept, you can test them and use them as per your requirement.
    thnaks
    mrutyun^

  • Need hierarchy alv report base on salv_demo_hierseq_simple

    Hi friends,
    i need to do a hierarchy alv report,
    i copied example code from program salv_demo_hierseq_simple and changes the selection screen +changed the  select from tables.
    my problem is that the results is one big list of data,
    i dont have to open and close lines.
    is anyone can help me with what could the problem be?
    thanks,
    dana.

    Guys,
              Any Idea on this.

  • Hot Spot in Hierarchial ALV REPORT

    Hi
    I am using Hierarchial Report.
    I have to give hotspot to a field for VBELN in the header item.
    When i click the vbeln value it has to take me to the transaction VA03, with the values.
    but my vbeln value is not getting passed to this workarea.
    Please explain about my error.
    SET PARAMETER ID 'AUN' FIELD wa_headerdata-vbeln.
          CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.

    Refer the following code:
      CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
        EXPORTING
          i_callback_program       = lv_repid
    *      I_CALLBACK_PF_STATUS_SET = ' '
          I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'                
          is_layout                = gs_layout
          it_fieldcat              = gt_fieldcat
    *      IT_EXCLUDING             =
    *      IT_SPECIAL_GROUPS        = GT_SP_GROUP
          it_sort                  = gt_sort
    *       FORM USER_COMMAND                                          *
    *       --> R_UCOMM                                                *
    *       --> RS_SELFIELD                                            *
    FORM user_command USING r_ucomm LIKE sy-ucomm
                      rs_selfield TYPE slis_selfield.
    * Check function code
      CASE r_ucomm.
        WHEN '&IC1'.
    *   Check field clicked on within ALVgrid report
        IF rs_selfield-fieldname = 'EBELN'.
    *     Read data table, using index of row user clicked on
          READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
    *     Set parameter ID for transaction screen field
          SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
    *     Sxecute transaction ME23N, and skip initial data entry screen
          CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
        ENDIF.
      ENDCASE.
    ENDFORM.

  • Hierarchial ALV

    Hi Friends,
    I have created a Hierarchial ALV report using OOP concept (Class Builder). The output is OK but it is displaying the unwanted columns in the header part.
    The code written is as follows.
    =====================================================
    data: gt_zsd_abcd type zsd_abcd occurs 0, "Output-Table
    data l_hierarchy_header type treev_hhdr.
    perform build_hierarchy_header changing l_hierarchy_header.
    call method g_alv_tree->set_table_for_first_display
    exporting
    i_structure_name = 'zsd_abcd'
    is_hierarchy_header = l_hierarchy_header
    changing
    it_outtab = gt_zsd_abcd. "table must be empty !
    perform create_hierarchy.
    call method g_alv_tree->frontend_update.
    =====================================================
    I would like know as to how to display only the required columns in the header part.
    Pls guide me.
    TIA.
    Regards,
    Mark K

    in the changing parameter you have to pass a fieldcatalog conaining only those columns you want to display .
    call method g_alv_tree->set_table_for_first_display
    exporting
    i_structure_name = 'zsd_abcd'
    is_hierarchy_header = l_hierarchy_header
    changing
    it_outtab = gt_zsd_abcd. "table must be empty !
    it_fieldcatalog     = gt_fieldcat_lvc[].
    you can fill the catalog like this :
    FORM zf_create_fieldcat.
      DATA ls_fieldcat TYPE lvc_s_fcat.
    Main Asset Number
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname = 'ANLN1'.
      ls_fieldcat-ref_table = 'ANLA'.
      ls_fieldcat-no_out = 'X'.
      ls_fieldcat-key = ''.
      APPEND ls_fieldcat TO gt_fieldcat_lvc.
    Asset Subnumber
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname = 'ANLN2'.
      ls_fieldcat-ref_table = 'ANLA'.
      ls_fieldcat-no_out = 'X'.
      ls_fieldcat-key = ''.
      APPEND ls_fieldcat TO gt_fieldcat_lvc.
    Assigned to WBS
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname = 'XLOEV'.
      ls_fieldcat-ref_table = 'ANLA'.
      ls_fieldcat-coltext   = 'Assigned to WBS'(003).
      ls_fieldcat-tooltip   = ls_fieldcat-coltext.
      ls_fieldcat-seltext   = ls_fieldcat-coltext.
      ls_fieldcat-outputlen = '3'.
      APPEND ls_fieldcat TO gt_fieldcat_lvc.
    Value
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname = 'URWRT'.
      ls_fieldcat-ref_table = 'ANLA'.
      ls_fieldcat-coltext   = 'Value'(004).
      ls_fieldcat-tooltip   = ls_fieldcat-coltext.
      ls_fieldcat-seltext   = ls_fieldcat-coltext.
      APPEND ls_fieldcat TO gt_fieldcat_lvc.
    Asset description
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname = 'TXT50'.
      ls_fieldcat-ref_table = 'ANLA'.
      APPEND ls_fieldcat TO gt_fieldcat_lvc.
    ENDFORM.                               " ZF_CREATE_FIELDCAT

  • Hierarchial ALV using OOP

    Hi Friends,
    I have created a Hierarchial ALV report using OOP concept (Class Builder). The output is OK but it is displaying the unwanted columns in the header part.
    The code written is as follows.
    =====================================================
    data: gt_zsd_abcd      type zsd_abcd  occurs 0,      "Output-Table
    data l_hierarchy_header type treev_hhdr.
      perform build_hierarchy_header changing l_hierarchy_header.
      call method g_alv_tree->set_table_for_first_display
        exporting
          i_structure_name    = 'zsd_abcd'
          is_hierarchy_header = l_hierarchy_header
        changing
          it_outtab           = gt_zsd_abcd. "table must be empty !
      perform create_hierarchy.
      call method g_alv_tree->frontend_update.
    =====================================================
    I would like know as to how to display only the required columns in the header part.
    Pls guide me.
    TIA.
    Regards,
    Mark K

    Hi Mark,
    i got it, in your case you will get all the fields present in the structure you mentioned in the method.
    so if you want only Purchase Order then you need to Build the fieldcat only for that field and then pass that fieldcat to the method. and don't pass the structure in this case.
      call method alv_tree_control->set_table_for_first_display
       exporting
                 is_variant           = l_variant
                 i_save               = 'A'
                 i_default            = 'X'
                 is_hierarchy_header  = l_hierarchy_header
                 it_special_groups    = l_special_groups
                 it_toolbar_excluding = l_toolbar_excluding
       changing
              <b>it_fieldcatalog      = l_field_catalog</b>
                 it_outtab            = l_output_tbl.
    Regards
    vijay

  • Alv reports sample example req..

    can anybody help me out with a simple example regarding ALV Reports.(simple ALV Reports , Blocked ALV Reports & Hierarchy ALV Reports).
    or pls send me a word document regarding the same ..to [email protected]
    response is highly appreciated..
    bye--
    Pradeepa

    Following document should get you started.
    <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907">An Easy Reference For ALV Grid Control.pdf</a>
    tip : if you do a <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/advancedsearch?query=alv%20grid&cat=sdn_all">search for alv grid</a> on the sdn homepage, this is the first result.
    Message was edited by:
            Dries Horions

  • How to handle different Unit of measures in ALV reports? Quantity/Price

    Anyone knows how to handle different unit of measures for quantity or price in hierarchy ALV reports?

    hi,
    use the below fields:
    Link to measurement unit
    •qfieldname (measurement unit field name)
    only relevant for quantity columns with unit link.
    Name of the internal output table field containing the measurement unit associated with the quantity field FIELDCAT-FIELDNAME.
    The field in FIELDCAT-QFIELDNAME must have its own field catalog entry.
    •qtabname (internal measurement unit field output table)
    value set: SPACE, output table field name
    Name of the internal output table containing the FIELDCAT-QFIELDNAME field.
    regards,
    madhumitha

  • Display output fields in Hierarchy format in ALV report

    Hi,
    I have a requirement to display the output fileds in ALV report, the output format is like this . The output field should be in ALV format, under each purchase order its corresponding line item should appear.
    Pruchase Order  4700000581  
    company code        item
            9001                     10
            9001                     20.
            9001                     30.
    Pruchase Order  4700000174  
            9001                     10
            9001                     20.
    Can any one please help me how to do this in ALV report.

    Hi
    This can be achieved using the Heirarchial ALV list
    see the sample and do it
    REPORT ZALV5_OBJECTS.
    TABLES : EKKO.
    TYPE-POOLS : SLIS.
    TYPES : BEGIN OF TY_EKKO,
    EBELN TYPE EKPO-EBELN,
    EBELP TYPE EKPO-EBELP,
    STATU TYPE EKPO-STATU,
    AEDAT TYPE EKPO-AEDAT,
    MATNR TYPE EKPO-MATNR,
    MENGE TYPE EKPO-MENGE,
    MEINS TYPE EKPO-MEINS,
    NETPR TYPE EKPO-NETPR,
    PEINH TYPE EKPO-PEINH,
    END OF TY_EKKO.
    DATA: IT_EKKO TYPE STANDARD TABLE OF TY_EKKO INITIAL SIZE 0,
    IT_EKPO TYPE STANDARD TABLE OF TY_EKKO INITIAL SIZE 0,
    IT_EMPTYTAB TYPE STANDARD TABLE OF TY_EKKO INITIAL SIZE 0,
    WA_EKKO TYPE TY_EKKO,
    WA_EKPO TYPE TY_EKKO.
    DATA: OK_CODE LIKE SY-UCOMM, "OK-Code
    SAVE_OK LIKE SY-UCOMM.
    *ALV data declarations
    DATA: FIELDCATALOG TYPE LVC_T_FCAT WITH HEADER LINE.
    DATA: GD_FIELDCAT TYPE LVC_T_FCAT,
    GD_TAB_GROUP TYPE SLIS_T_SP_GROUP_ALV,
    GD_LAYOUT TYPE SLIS_LAYOUT_ALV.
    *ALVtree data declarations
    CLASS CL_GUI_COLUMN_TREE DEFINITION LOAD.
    CLASS CL_GUI_CFW DEFINITION LOAD.
    DATA: GD_TREE TYPE REF TO CL_GUI_ALV_TREE,
    GD_HIERARCHY_HEADER TYPE TREEV_HHDR,
    GD_REPORT_TITLE TYPE SLIS_T_LISTHEADER,
    GD_LOGO TYPE SDYDO_VALUE,
    GD_VARIANT TYPE DISVARIANT.
    *Create container for alv-tree
    DATA: GD_TREE_CONTAINER_NAME(30) TYPE C,
    GD_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
    *Includes
    *INCLUDE ZDEMO_ALVTREEO01. "Screen PBO Modules
    *INCLUDE ZDEMO_ALVTREEI01. "Screen PAI Modules
    *INCLUDE ZDEMO_ALVTREEF01. "ABAP Subroutines(FORMS)
    *Start-of-selection.
    START-OF-SELECTION.
    ALVtree setup data
    PERFORM DATA_RETRIEVAL.
    PERFORM BUILD_FIELDCATALOG.
    PERFORM BUILD_LAYOUT.
    PERFORM BUILD_HIERARCHY_HEADER CHANGING GD_HIERARCHY_HEADER.
    PERFORM BUILD_REPORT_TITLE USING GD_REPORT_TITLE GD_LOGO.
    PERFORM BUILD_VARIANT.
    Display ALVtree report
    CALL SCREEN 100.
    *& Form data_retrieval
    text
    --> p1 text
    <-- p2 text
    FORM DATA_RETRIEVAL .
    SELECT EBELN
    UP TO 10 ROWS
    FROM EKKO
    INTO CORRESPONDING FIELDS OF TABLE IT_EKKO.
    LOOP AT IT_EKKO INTO WA_EKKO.
    SELECT EBELN EBELP STATU AEDAT MATNR MENGE MEINS NETPR PEINH
    FROM EKPO
    APPENDING TABLE IT_EKPO
    WHERE EBELN EQ WA_EKKO-EBELN.
    ENDLOOP.
    ENDFORM. " data_retrieval
    *& Form build_fieldcatalog
    text
    --> p1 text
    <-- p2 text
    FORM BUILD_FIELDCATALOG .
    Please not there are a number of differences between the structure of
    ALVtree fieldcatalogs and ALVgrid fieldcatalogs.
    For example the field seltext_m is replace by scrtext_m in ALVtree.
    FIELDCATALOG-FIELDNAME = 'EBELN'. "Field name in itab
    FIELDCATALOG-SCRTEXT_M = 'Purchase Order'. "Column text
    FIELDCATALOG-COL_POS = 0. "Column position
    FIELDCATALOG-OUTPUTLEN = 15. "Column width
    FIELDCATALOG-EMPHASIZE = 'X'. "Emphasize (X or SPACE)
    FIELDCATALOG-KEY = 'X'. "Key Field? (X or SPACE)
    fieldcatalog-do_sum = 'X'. "Sum Column?
    fieldcatalog-no_zero = 'X'. "Don't display if zero
    APPEND FIELDCATALOG TO GD_FIELDCAT.
    CLEAR FIELDCATALOG.
    FIELDCATALOG-FIELDNAME = 'EBELP'.
    FIELDCATALOG-SCRTEXT_M = 'PO Iten'.
    FIELDCATALOG-OUTPUTLEN = 15.
    FIELDCATALOG-COL_POS = 1.
    APPEND FIELDCATALOG TO GD_FIELDCAT..
    CLEAR FIELDCATALOG.
    FIELDCATALOG-FIELDNAME = 'STATU'.
    FIELDCATALOG-SCRTEXT_M = 'Status'.
    FIELDCATALOG-OUTPUTLEN = 15.
    FIELDCATALOG-COL_POS = 2.
    APPEND FIELDCATALOG TO GD_FIELDCAT..
    CLEAR FIELDCATALOG.
    FIELDCATALOG-FIELDNAME = 'AEDAT'.
    FIELDCATALOG-SCRTEXT_M = 'Item change date'.
    FIELDCATALOG-OUTPUTLEN = 15.
    FIELDCATALOG-COL_POS = 3.
    APPEND FIELDCATALOG TO GD_FIELDCAT..
    CLEAR FIELDCATALOG.
    FIELDCATALOG-FIELDNAME = 'MATNR'.
    FIELDCATALOG-SCRTEXT_M = 'Material Number'.
    FIELDCATALOG-OUTPUTLEN = 15.
    FIELDCATALOG-COL_POS = 4.
    APPEND FIELDCATALOG TO GD_FIELDCAT..
    CLEAR FIELDCATALOG.
    FIELDCATALOG-FIELDNAME = 'MENGE'.
    FIELDCATALOG-SCRTEXT_M = 'PO quantity'.
    FIELDCATALOG-OUTPUTLEN = 15.
    FIELDCATALOG-COL_POS = 5.
    APPEND FIELDCATALOG TO GD_FIELDCAT..
    CLEAR FIELDCATALOG.
    FIELDCATALOG-FIELDNAME = 'MEINS'.
    FIELDCATALOG-SCRTEXT_M = 'Order Unit'.
    FIELDCATALOG-OUTPUTLEN = 15.
    FIELDCATALOG-COL_POS = 6.
    APPEND FIELDCATALOG TO GD_FIELDCAT..
    CLEAR FIELDCATALOG.
    FIELDCATALOG-FIELDNAME = 'NETPR'.
    FIELDCATALOG-SCRTEXT_M = 'Net Price'.
    FIELDCATALOG-OUTPUTLEN = 15.
    FIELDCATALOG-COL_POS = 7.
    FIELDCATALOG-DATATYPE = 'CURR'.
    APPEND FIELDCATALOG TO GD_FIELDCAT..
    CLEAR FIELDCATALOG.
    FIELDCATALOG-FIELDNAME = 'PEINH'.
    FIELDCATALOG-SCRTEXT_M = 'Price Unit'.
    FIELDCATALOG-OUTPUTLEN = 15.
    FIELDCATALOG-COL_POS = 8.
    APPEND FIELDCATALOG TO GD_FIELDCAT..
    CLEAR FIELDCATALOG.
    ENDFORM. " build_fieldcatalog
    *& Form build_layout
    text
    --> p1 text
    <-- p2 text
    FORM BUILD_LAYOUT .
    GD_LAYOUT-NO_INPUT = 'X'.
    GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
    GD_LAYOUT-TOTALS_TEXT = 'Totals'(201).
    gd_layout-totals_only = 'X'.
    gd_layout-f2code = 'DISP'. "Sets fcode for when double
    "click(press f2)
    gd_layout-zebra = 'X'.
    gd_layout-group_change_edit = 'X'.
    gd_layout-header_text = 'helllllo'
    ENDFORM. " build_layout
    *& Form build_hierarchy_header
    text
    <--P_GD_HIERARCHY_HEADER text
    FORM BUILD_HIERARCHY_HEADER CHANGING
    P_HIERARCHY_HEADER TYPE TREEV_HHDR.
    P_HIERARCHY_HEADER-HEADING = 'Hierarchy Header'(013).
    P_HIERARCHY_HEADER-TOOLTIP = 'This is the Hierarchy Header !'(014).
    P_HIERARCHY_HEADER-WIDTH = 30.
    P_HIERARCHY_HEADER-WIDTH_PIX = ''.
    ENDFORM. " build_hierarchy_header
    *& Form build_report_title
    text
    -->P_GD_REPORT_TITLE text
    -->P_GD_LOGO text
    FORM BUILD_REPORT_TITLE USING PT_REPORT_TITLE TYPE SLIS_T_LISTHEADER
    P_GD_LOGO TYPE SDYDO_VALUE.
    DATA: LS_LINE TYPE SLIS_LISTHEADER,
    LD_DATE(10) TYPE C.
    List Heading Line(TYPE H)
    CLEAR LS_LINE.
    LS_LINE-TYP = 'H'.
    ls_line-key "Not Used For This Type(H)
    LS_LINE-INFO = 'PO ALVTree Display'.
    APPEND LS_LINE TO PT_REPORT_TITLE.
    Status Line(TYPE S)
    LD_DATE(2) = SY-DATUM+6(2).
    LD_DATE+2(1) = '/'.
    LD_DATE3(2) = SY-DATUM4(2).
    LD_DATE+5(1) = '/'.
    LD_DATE+6(4) = SY-DATUM(4).
    LS_LINE-TYP = 'S'.
    LS_LINE-KEY = 'Date'.
    LS_LINE-INFO = LD_DATE.
    APPEND LS_LINE TO PT_REPORT_TITLE.
    Action Line(TYPE A)
    CLEAR LS_LINE.
    LS_LINE-TYP = 'A'.
    CONCATENATE 'Report: ' SY-REPID INTO LS_LINE-INFO SEPARATED BY SPACE.
    APPEND LS_LINE TO PT_REPORT_TITLE.
    ENDFORM. " build_report_title
    *& Form build_variant
    text
    --> p1 text
    <-- p2 text
    FORM BUILD_VARIANT .
    Set repid for storing variants
    GD_VARIANT-REPORT = SY-REPID.
    ENDFORM. " build_variant
    Reward points for useful Answers
    Regards
    Anji

  • Need a sample program for hierarchial oops ALV report

    Hello experts,
                     I Need a sample program for hierarchial oops ALV report.

    Hi,
       Check the following sample code...
    T A B L E S
    tables : ekko.
      data definition
    types : begin of ty_ekko,
              ebeln type ekko-ebeln,
              lifnr type ekko-lifnr,
              bsart type ekko-bsart,
              aedat type ekko-aedat,
              ernam type ekko-ernam,
            end of ty_ekko.
    types : begin of ty_eket,
               ebeln type ekpo-ebeln,
               ebelp type ekpo-ebelp,
               werks type ekpo-werks,
               matnr type ekpo-matnr,
               menge type eket-menge,
               wamng type eket-wamng,
               netpr type ekpo-netpr,
            end of ty_eket.
    data : it_ekko type table of ty_ekko,
           it_eket type table of ty_eket.
    data: ob_hieralv type ref to cl_salv_hierseq_table.
    data: it_binding type salv_t_hierseq_binding,
          is_binding type salv_s_hierseq_binding.
    S E L C T O P T I O N S
    select-options : s_ebeln for ekko-ebeln.
    S T A R T O F S E L E C T I O N
    start-of-selection.
    select ebeln
           lifnr
           bsart
           aedat
           ernam from ekko
    into corresponding fields of table it_ekko
    where ebeln in s_ebeln.
    if sy-subrc eq 0.
    select aebeln aebelp
           awerks amatnr
           bmenge bwamng
           a~netpr from ekpo as a join eket as b
                     on  amandt = bmandt
                     and aebeln = bebeln
                     and aebelp = bebelp
                   into corresponding fields of table it_eket
                  where a~ebeln in s_ebeln.
    endif.
    is_binding-master = 'EBELN'.
    is_binding-slave = 'EBELN'.
    append is_binding to it_binding.
    *TRY.
    call method cl_salv_hierseq_table=>factory
    exporting
    t_binding_level1_level2 = it_binding
    importing
    r_hierseq = ob_hieralv
    changing
    t_table_level1 = it_ekko
    t_table_level2 = it_eket .
    *CATCH cx_salv_data_error .
    *CATCH cx_salv_not_found .
    *ENDTRY.
    call method ob_hieralv->display( ).
    Cheers,
    Ram

  • WBS Conversin in ALV report

    hii
    i am creating one PS report . made an ALV report displaying WBS PRPS-POSID. but in out put this is showing in no format
    but i need in WBS detail like P-01-0023.
    Please tell me how will convert it .
    Thanks

    Dear Chandrashekhar,
    If you encounter with conversion problem, the best way is to browse the database table in which the filed is present.
    Ex: For WBS, PRPS>POSID>Double click on Data Element PS_POSID>Double click on Domain PS_POSID> Double click on Conversion Routine --> You will get the required Function Modules.
    Regards
    Pavan

  • ALV Report with hierarchy

    hi guys,
    i am new to this forum. and need your help.
    i am developing a alv report for bom explosion.
    now the requirement is to show the material number node and the details like price, qty etc. in front of that.
    if the user clicks on the node he will see next level of materials nodes with similar details and so on. there can be more than 50 levels so manually adding nodes is not possible.
    i have checked bcalvtree programs but those programs wont help.
    Please suggest me any classes and methods to solve this problem......
    regards
    aj

    Hi,
    If u want to present ur report in tree format, u can use the following function module.
    U can go with ur normal query for selecting the data from database. While presenting it use the following fun. module.
    DATA : WA_KEYINFO TYPE SLIS_KEYINFO_ALV,
           WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
    DATA : IT_SALES_ITEM LIKE TABLE OF STRU WITH HEADER LINE.
    DATA : BEGIN OF  STRU_HEADER,
             EXPAND,
             ICONS(4),
             KUNNR LIKE VBAK-KUNNR, "Header field
            END OF STRU_HEADER.
    DATA :IT_SALES_HEADER LIKE TABLE OF STRU_HEADER WITH HEADER LINE.
      WA_KEYINFO-HEADER01 = 'KUNNR'. " Specify field eg.KUNNR
      WA_KEYINFO-ITEM01   = 'KUNNR'. " Specify field eg.KUNNR
      WA_LAYOUT-LIGHTS_FIELDNAME = 'ICONS'.
      WA_LAYOUT-EXPAND_FIELDNAME = 'EXPAND'.
      WA_LAYOUT-LIGHTS_TABNAME   = 'IT_Sales_Item'. "Specify Internal Table name
      WA_LAYOUT-BOX_TABNAME      = 'IT_Sales_Item'. "Specify Internal Table name
      CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
        EXPORTING
         I_CALLBACK_PROGRAM             = SY-REPID
         IS_LAYOUT                      = WA_LAYOUT
         IT_FIELDCAT                    = FCAT
          I_TABNAME_HEADER              = 'IT_Sales_Header'
          I_TABNAME_ITEM                = 'IT_Sales_Item'
          IS_KEYINFO                    = WA_KEYINFO
        TABLES
          T_OUTTAB_HEADER               = IT_SALES_HEADER
          T_OUTTAB_ITEM                 = IT_SALES_ITEM.
    Try with the above code.
    U can define ur own structure instead of IT_Sales_Item.

  • Summing up a Column in ALV report

    Hi All,
    I have developed an ALV Report which will display Invoices and other details.
    Now i need to display the sum of NETWR column, if user wish to select that column and click the "SUM" icon.
    As of now, if i select the NETWR column and click 'SUM" column, i am getting Runtime error.
    How to resolve this issue?
    Regards
    Pavan

    Hi Pavan,
    ALV GRID CONTROL:
    This task is performed by the SAP Control Framework.
    The R/3 System allows you to create custom controls using ABAP Objects. The application server is the Automation Client, which drives the custom controls (automation server) at the front end.
    If custom controls are to be included on the frontend, then the SAPGUI acts as a container for them.
    Custom controls can be ActiveX Controls or JavaBeans.
    The system has to use a Remote Function Call (RFC) to transfer methods for creating and using a control to the front end.
    ABAP objects are used to implement the controls in programs.
    An SAP Container can contain other controls (for example, SAP ALV Grid Control, Tree Control, SAP Picture Control, SAP Splitter Control, and so on). It administers these controls logically in one collection and provides a physical area for the display.
    Every control exists in a container. Since containers are themselves controls, they can be nested within one another. The container becomes the parent of its control. SAP containers are divided into five groups:
    SAP custom container: Displays within an area defined in Screen Painter on screens or sub screens.
    Class: CL_GUI_CUSTOM_CONTAINER
    SAP dialog box container: Displays in a modeless dialog box or as a full screen. Class:
    CL_GUI_DIALOGBOX_CONTAINER
    SAP docking container: Displays as docked, resizable sub-window with the option of displaying it as a modeless dialog box. Class: CL_GUI_DOCKING_CONTAINER
    SAP splitter container: Displays and groups several controls in one area - that is, splits the area into cells Class: CL_GUI_SPLITTER_CONTAINER
    SAP easy splitter container: Displays controls in two cells, which the user can resize using a split bar. Class: CL_GUI_EASY_SPLITTER_CONTAINER.
    In the control, you can adjust the column width by dragging, or use the 'Optimum width' function to adjust the column width to the data currently displayed. You can also change the column sequence by selecting a column and dragging it to a new position.
    Standard functions are available in the control toolbar. The details display displays the fields in the line on which the cursor is positioned in a modal dialog box.
    The sort function in the ALV Control is available for as many columns as required. You can set complex sort criteria and sort columns in either ascending or descending order.
    You can use the 'Search' function to search for a string (generic search without *) within a selected area by line or column.
    You can use the 'Sum' function to create totals for one or more numeric columns. You can then use the "Subtotals" function to set up control level lists: You can use the 'Subtotal' function to structure control level lists: select the columns (non-numeric columns only) that you want to use and the corresponding control level totals are displayed.
    For 'Print' and 'Download' the whole list is always processed, not just the sections displayed on the screen.
    You can define display variants to meet your own specific requirements. For information on saving variants, see 'Advanced Techniques'.
    The ALV grid control is a generic tool for displaying lists in screens. The control offers standard functions such as sorting by any column, adding numeric columns, and fixed lead columns .
    Data collection is performed in the program (with SELECT statements, for example) or by using a logical database. The data records are saved in an internal table and passed on to the ALV control along with a field description.
    The field description contains information about the characteristics of each column, such as the column header and output length. This information can defined either globally in the Dictionary (structure in the Dictionary) or in the field catalog in the program itself. You can also merge both techniques.
    The ALV link is a standard function of Query and QuickViewer. If multiline queries or Quick View lists have been defined, they will automatically be compressed to a single line and output in the ALV control as a long, single line list.
    Use Screen Painter to create a sub screen container for the ALV grid control. The control requires an area where it can be displayed in the screen. You have to create a container control that determines this area.
    Use the corresponding icon in the Screen Painter layout to create the container control. The size of area "MY_CONTROL_AREA" determines the subsequent size of the ALV control.
    The valid GUI status must be set at the PBO event in the flow logic of the ALV subscreen container.
    The OK_CODE processing for the cancel functions must be programmed at the PAI event.
    The reference variables for the custom container and the ALV grid control must be declared.
    To create reference variables, use ABAP statement TYPE REF TO .
    The global classes you need to do this are called cl_gui_custom_container (for the custom container control) and cl_gui_alv_grid (for the ALV grid control).
    The global classes are defined in the Class Builder. You can use the Class Builder to display information for the methods, their parameters, exceptions, and so on.
    Use ABAP statement CREATE OBJECT to create the objects for the container and the ALV control. Objects Are instances of a class.
    When an object is created (CREATE), method CONSTRUCTOR of the corresponding class is executed. The parameters of method CONSTRUCTOR determine which parameters have to be supplied with data when the object is created. In the above example, object alv_grid is given the name of the container control (g_custom_container) in exporting parameter i_parent, which links the two controls. For information on which parameters method CONSTRUCTOR possesses and which of these parameters are required, see the Class Builder.
    Objects should only be created once during the program. To ensure that this is the case, enclose the CREATE OBJECT statement(s) in an IF IS INITIAL. ... ENDIF clause. The objects must be generated before the control is displayed for the first time - that is, during the PBO event of the ALV subscreen container.
    To display the requested dataset in the ALV control, the data must be passed on to the control as an internal table, and a field description must exist indicating the order in which the columns will be output.
    In the simplest case, the field description can use a structure from the Dictionary. The Dictionary also determines the technical field attributes like type and length, as well as the semantic attributes like short and long texts. The ALV control uses this information to determine the column widths and headers. The column sequence is determined by the field sequence in the structure.
    If no suitable structure is active in the Dictionary, or you want to output internal program fields in the control, then you will have to define information like the output length and column header in the field catalog.
    In a typical program run, the dataset is read first (SELECT ....), the internal table is filled with the data to display (... INTO TABLE ...), and ABAP statement CALL SCREEN is then used to call the ALV sub screen container.
    The data transfer to the ALV control takes place during the call of method
    set_table_for_first_display from class cl_gui_alv_grid. The method call must be programmed at the PBO event of the ALV subscreen container.
    The name of the Dictionary structure that supplies the field description is specified in exporting parameter i_structure_name. The name of the internal table that contains the data records to display is specified in changing parameter it_outtab.
    The field description for the ALV control can be ta ken from an active Dictionary structure (fully automatic), by passing a field catalog (manual), or through a mixture of the two options (merge).
    The field catalog is in internal table with type lvc_t_fcat. This type is defined globally in the Dictionary.
    Each line in the field catalog table corresponds to a column in the ALV control.
    The field characteristics (= column characteristics) are defined in the field catalog. The field catalog is in internal table with type lvc_t_fcat. Each line that is explicitly described in the ALV control corresponds to a column in the field catalog table.
    The link to the data records to output that are saved in internal table is established through field name . This name must be specified in column "fieldname" in the field catalog.
    This field can be classified through a Dictionary reference (ref_table and ref_field) or by specifying an ABAP data type (inttype).
    Column headers and field names in the detail view of an ALV control line can be determined in the field catalog in coltext and seltext, respectively.
    The position of a field during output can be determined with col_pos in the field catalog.
    If you want to hide a column, fill field no_out with an "X" in the field catalog. Hidden fields can be displayed again in a user display variant.
    Icons can be displayed in the ALV control. If you want a column to be interpreted as an icon, then the icon name must be known to the program (include .) and icon = "X" must be specified for this column in the field catalog.
    The above example shows a semi-automatic field description: Part of the field description comes from the Dictionary structure (sflight), while another part is explicitly defined in the field catalog (gt_fieldcat).
    The field catalog (internal table) is filled in the program and is passed on together with the name of the Dictionary structure during the method call. The information is merged accordingly in method set_table_for_first_display.
    For a user to save display variants, parameters is_variant and i_save must be passed on during method call set_table_for_first_screen. To assign display variants uniquely to a program, at least the program name must be supplied in the transferred structure (gs_variant).
    Program names can be up to 30 characters long.
    If you only pass on the current parameters for is_variant, then existing variants can be loaded, but no new ones can be saved. If you use parameter i_save, you must pass on a variant structure with is_variant.
    I_SAVE = SPACE No variants can be saved.
    I_SAVE = 'U' The user can only save user-specific variants.
    I_SAVE = 'X' The user can only save general (shared) variants.
    I_SAVE = 'A' The user can save both user-specific and general (shared) variants.
    You can use parameter is_layout of method set_table_for_first_display, for example, to define the header in the ALV control and the detail display.
    To do this, define a query area in the program in accordance with Dictionary structure lvc_s_layo, and pass on the text to display in field -grid_title or -detailtitl.
    If you want to create print lists with zebra stripes, set field -zebra to "X". You can display a print preview for print lists by requesting standard function "Print".
    All parameters of method SET_TABLE_FOR_FIRST_DISPLAY from global class
    CL_GUI_ALV_GRID are defined in the Class Builder.
    Events are defined in global class cl_gui_alv_grid; you can use these events to implement user interaction within the program. To respond to a double -click on a table line, you must respond to event DOUBLE_CLICK.
    You receive control in the program, allowing you to implement interactive reporting - such as a full screen details list. The events for cl_gui_alv_grid are located in the Class Builder.
    To define an implement a local class in the program, you use a handler method. In this handler method, you program the functionality to trigger by a double -click in the output table.
    To activate a handler method at runtime, a class or an object from that class registers itself with an event using command SET HANDLER. The names of the IMPORTING parameters in the handler method correspond to the names of the EXPORTING parameters of the related event.
    In the above example, the local class is LCL_ILS and the handler method is ON_DBLCLICK. An object - ALV_DBLCLICK - is created and registers itself for event DOUBLE_CLICK.
    You can query parameter e_row-index to determine which output line was requested by the double -click. This parameter corresponds to the line number of the output table (internal table with the data records to output). If you need information for the selected line, you have to read it with READ TABLE itab INDEX e_row-index.
    This subsequent read in the output table generally corresponds to the HIDE area in conventional reporting. You first have to make sure that the user has double -clicked a line in the output table (similar to the valid line selection with the HIDE technique).
    A field group can contain global data objects, but not data objects that have been defined locally in a subroutine or function module.
    You can use INSERT to specify both fields and field symbols. This makes it possible to dynamically insert a data object referred to by a field symbol into a field group at runtime. Any field symbols that have not been assigned are ignored, which means no new field is inserted into the field group.
    The EXTRACT statement writes all the fields of a field group as one record to a sequential dataset (transport takes place with similarly named fields). If a HEADER field group is defined, then its fields are placed ahead of each record as sort keys. You can then sort the dataset with SORT and process it with LOOP ...ENDLOOP. In this case, no further EXTRACT is possible.
    The INSERT statement is not a declarative statement: This means field groups can also be expanded in the program flow section.
    As soon as the first dataset of a field group has been extracted with EXTRACT, that field group can no longer be expanded with INSERT. In particular, the HEADER field group cannot be expanded after the first EXTRACT (regardless of the field group).
    When the GET events are processed, the logical database automatically writes hexadecimal zeros in all the fields of a node when it returns to an upper-level node in the hierarchy. Since the HEADER normally contains sort fields for all field groups, these hexadecimal zeros in the HEADER serve as a type of hierarchy key: The more zeros there are, the further up in the control level hierarchy you go.
    &#61550;&#61472;The SORT statement sorts the extract dataset in accordance with the defined field sequence in field group HEADER. The addition BY ... sets a new sort key.
    Each must be either a field of field group HEADER or a field group that consists only of fields of the field group HEADER. You can use the additions ASCENDING and DESCENDING to determine whether the fields are sorted in ascending (default) or descending order.
    Fields containing X'00' in the logical databases are always displayed before all other values during a SORT.
    Processing of an extract dataset always takes places within a LOOP. The contents of the extract dataset field are placed in program fields with the same names.
    The group change always involves the fields of the HEADER. Single record processing for extract datasets is performed using language element AT ( = field group).
    CNT() is not a statement, but instead a field that is automatically create d and filled when is a non-numeric field from field group HEADER and is part of the sort key. At the end of the group, CNT() contains the number of different values that the field recorded in this group level.
    SUM() is not a statement, but instead a field that is automatically created and filled when is a numeric field of an extract dataset. At the end of the group, SUM() contains the control total of field .
    *** and CNT are only available at the end of the group level or at AT LAST.
    Single record processing for extract datasets AT WITH is only performed when field group is immediately followed by field group in the temporary dataset.
    Loops over an extract dataset cannot be nested. However, several contiguous loops are permitted.
    The sequence of the control level changes within the LOOP must correspond to the sort sequence.
    Totals can only be calculated within control footer processing.
    Extracts allow only appends (EXTRACT), sorting (SORT) and sequential processing (LOOP).
    Once a SORT or LOOP has occurred, the intermediate dataset is frozen and cannot be expanded with EXTRACT. Operations that insert into or delete from EXTRACT datasets are not supported.
    Extracts allow for several record types (FIELD-GROUPS) with fields that can be set dynamically (INSERT is not a declarative statement!). Internal tables have a single, statically-defined line type.
    Internal tables use the sequence of table fields according to the declaration for the hierarchy of the control leve l. The control level structure for internal tables is therefore static, and is independent of which criteria were used to sort the internal table.
    Extracts do not depend on the field sequence for control level processing: a re-sort or a completely different control level process can take place. The control level structure for extract datasets is therefore dynamic. It corresponds exactly to the sort key of the extract dataset. The sort key is the sequence of fields from the field group HEADER, and is used to sort the extract dataset.
    Extracts rely on the compiler to determine which combinations of group levels and a cumulating field the control level totals desire. The desired control level totals are determined by the processing of LOOP ... ENDLOOP blocks. Internal tables build the control level total with the SUM statement.
    This procedure leads to high resource depletion for totaling control levels in internal tables.
    Regards,
    Chandru

  • Create alv report

    hi friends,
    i have urgent reqirement pls help on this topic
    ·     Created an ALV report that displays Purchase document details in hierarchical manner using predefined function modules.
    thanks
    ravi

    Hi Ravi,
    Check this example.
    *& Report  ZDEMO_ALVTREE                                               *
    *& Example of a simple ALV Grid Report                                 *
    *& The basic requirement for this demo is to display a number of       *
    *& fields from the EKPO and EKKO table in a tree structure.            *
                             Amendment History                           *
    REPORT  zdemo_alvgrid                 .
    *Data Declaration
    TABLES:     ekko.
    TYPE-POOLS: slis.                                 "ALV Declarations
    TYPES: BEGIN OF t_ekko,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
      menge TYPE ekpo-menge,
      meins TYPE ekpo-meins,
      netpr TYPE ekpo-netpr,
      peinh TYPE ekpo-peinh,
    END OF t_ekko.
    DATA: it_ekko     TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          it_ekpo     TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          it_emptytab TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          wa_ekko     TYPE t_ekko,
          wa_ekpo     TYPE t_ekko.
    DATA: ok_code like sy-ucomm,           "OK-Code
          save_ok like sy-ucomm.
    *ALV data declarations
    DATA: fieldcatalog  TYPE lvc_t_fcat WITH HEADER LINE.
    DATA: gd_fieldcat   TYPE lvc_t_fcat,
          gd_tab_group  TYPE slis_t_sp_group_alv,
          gd_layout     TYPE slis_layout_alv.
    *ALVtree data declarations
    CLASS cl_gui_column_tree DEFINITION LOAD.
    CLASS cl_gui_cfw DEFINITION LOAD.
    DATA: gd_tree             TYPE REF TO cl_gui_alv_tree,
          gd_hierarchy_header TYPE treev_hhdr,
          gd_report_title     TYPE slis_t_listheader,
          gd_logo             TYPE sdydo_value,
          gd_variant          TYPE disvariant.
    *Create container for alv-tree
    DATA: l_tree_container_name(30) TYPE c,
          l_custom_container        TYPE REF TO cl_gui_custom_container.
    *Includes
    *INCLUDE ZDEMO_ALVTREEO01. "Screen PBO Modules
    *INCLUDE ZDEMO_ALVTREEI01. "Screen PAI Modules
    *INCLUDE ZDEMO_ALVTREEF01. "ABAP Subroutines(FORMS)
    *Start-of-selection.
    START-OF-SELECTION.
    ALVtree setup data
        PERFORM data_retrieval.
        PERFORM build_fieldcatalog.
        PERFORM build_layout.
        PERFORM build_hierarchy_header CHANGING gd_hierarchy_header.
        PERFORM build_report_title USING gd_report_title gd_logo.
        PERFORM build_variant.
    Display ALVtree report
      call screen 100.
    *&      Form  DATA_RETRIEVAL
          Retrieve data into Internal tables
    FORM data_retrieval.
      SELECT ebeln
       UP TO 10 ROWS
        FROM ekko
        INTO corresponding fields of TABLE it_ekko.
      loop at it_ekko into wa_ekko.
        SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
          FROM ekpo
          appending TABLE it_ekpo
         where ebeln eq wa_ekko-ebeln.
      endloop.
    ENDFORM.                    " DATA_RETRIEVAL
    *&      Form  BUILD_FIELDCATALOG
          Build Fieldcatalog for ALV Report
    FORM build_fieldcatalog.
    Please not there are a number of differences between the structure of
    ALVtree fieldcatalogs and ALVgrid fieldcatalogs.
    For example the field seltext_m is replace by scrtext_m in ALVtree.
      fieldcatalog-fieldname   = 'EBELN'.           "Field name in itab
      fieldcatalog-scrtext_m   = 'Purchase Order'.  "Column text
      fieldcatalog-col_pos     = 0.                 "Column position
      fieldcatalog-outputlen   = 15.                "Column width
      fieldcatalog-emphasize   = 'X'.               "Emphasize  (X or SPACE)
      fieldcatalog-key         = 'X'.               "Key Field? (X or SPACE)
    fieldcatalog-do_sum      = 'X'.              "Sum Column?
    fieldcatalog-no_zero     = 'X'.              "Don't display if zero
      APPEND fieldcatalog TO gd_fieldcat.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'EBELP'.
      fieldcatalog-scrtext_m   = 'PO Iten'.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-col_pos     = 1.
      APPEND fieldcatalog TO gd_fieldcat..
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-scrtext_m   = 'Status'.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-col_pos     = 2.
      APPEND fieldcatalog TO gd_fieldcat..
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'AEDAT'.
      fieldcatalog-scrtext_m   = 'Item change date'.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-col_pos     = 3.
      APPEND fieldcatalog TO gd_fieldcat..
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-scrtext_m   = 'Material Number'.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-col_pos     = 4.
      APPEND fieldcatalog TO gd_fieldcat..
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MENGE'.
      fieldcatalog-scrtext_m   = 'PO quantity'.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-col_pos     = 5.
      APPEND fieldcatalog TO gd_fieldcat..
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-scrtext_m   = 'Order Unit'.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-col_pos     = 6.
      APPEND fieldcatalog TO gd_fieldcat..
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-scrtext_m   = 'Net Price'.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-datatype     = 'CURR'.
      APPEND fieldcatalog TO gd_fieldcat..
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'PEINH'.
      fieldcatalog-scrtext_m   = 'Price Unit'.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-col_pos     = 8.
      APPEND fieldcatalog TO gd_fieldcat..
      CLEAR  fieldcatalog.
    ENDFORM.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
          Build layout for ALV grid report
    FORM build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-totals_text       = 'Totals'(201).
    gd_layout-totals_only        = 'X'.
    gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
                                            "click(press f2)
    gd_layout-zebra             = 'X'.
    gd_layout-group_change_edit = 'X'.
    gd_layout-header_text       = 'helllllo'.
    ENDFORM.                    " BUILD_LAYOUT
    *&      Form  build_hierarchy_header
          build hierarchy-header-information
         -->P_L_HIERARCHY_HEADER  structure for hierarchy-header
    FORM build_hierarchy_header CHANGING
                                   p_hierarchy_header TYPE treev_hhdr.
      p_hierarchy_header-heading = 'Hierarchy Header'(013).
      p_hierarchy_header-tooltip = 'This is the Hierarchy Header !'(014).
      p_hierarchy_header-width = 30.
      p_hierarchy_header-width_pix = ''.
    ENDFORM.                               " build_hierarchy_header
    *&      Form  BUILD_REPORT_TITLE
          Build table for ALVtree header
    <->  p1        Header details
    <->  p2        Logo value
    FORM build_report_title CHANGING
          pt_report_title  TYPE slis_t_listheader
          pa_logo             TYPE sdydo_value.
      DATA: ls_line TYPE slis_listheader,
            ld_date(10) TYPE c.
    List Heading Line(TYPE H)
      CLEAR ls_line.
      ls_line-typ  = 'H'.
    ls_line-key     "Not Used For This Type(H)
      ls_line-info = 'PO ALVTree Display'.
      APPEND ls_line TO pt_report_title.
    Status Line(TYPE S)
      ld_date(2) = sy-datum+6(2).
      ld_date+2(1) = '/'.
      ld_date3(2) = sy-datum4(2).
      ld_date+5(1) = '/'.
      ld_date+6(4) = sy-datum(4).
      ls_line-typ  = 'S'.
      ls_line-key  = 'Date'.
      ls_line-info = ld_date.
      APPEND ls_line TO pt_report_title.
    Action Line(TYPE A)
      CLEAR ls_line.
      ls_line-typ  = 'A'.
      CONCATENATE 'Report: ' sy-repid INTO ls_line-info  SEPARATED BY space.
      APPEND ls_line TO pt_report_title.
    ENDFORM.
    *&      Form  BUILD_VARIANT
          Build variant
    form build_variant.
    Set repid for storing variants
      gd_variant-report = sy-repid.
    endform.                    " BUILD_VARIANT
    *Includes
    *include zdemo_alvtreeo01. "Screen PBO Modules
    *include zdemo_alvtreei01. "Screen PAI Modules
    *include zdemo_alvtreef01. "ABAP Subroutines(FORMS)
    *Start-of-selection.
    start-of-selection.
    Screen flow logic code
    PROCESS BEFORE OUTPUT.
    MODULE STATUS_0100.
    PROCESS AFTER INPUT.
    MODULE USER_COMMAND_0100.
    ***INCLUDE Z......O01 .
    *&      Module  STATUS_0100  OUTPUT
          PBO Module
    module status_0100 output.
    SET PF-STATUS 'xxxxxxxx'.
    SET TITLEBAR 'xxx'.
    endmodule.                 " STATUS_0100  OUTPUT
    ***INCLUDE Z......I01 .
    *&      Module  USER_COMMAND_0100  INPUT
          PAI Module
    module user_command_0100 input.
    endmodule.                 " USER_COMMAND_0100  INPUT
       INCLUDE Z......I01                                                *
    *&      Module  USER_COMMAND_0100  INPUT
          text
    module user_command_0100 input.
      DATA return TYPE REF TO cl_gui_event.
      save_ok = ok_code.
      case ok_code.
        when 'BACK' or '%EX' or 'RW'.
        Exit program
          leave to screen 0.
      Process ALVtree user actions     
        when others.
          call method cl_gui_cfw=>get_current_event_object
                  receiving
                     event_object = return.
          call method cl_gui_cfw=>dispatch.
      endcase.
    endmodule.                 " USER_COMMAND_0100  INPUT
    Add following code to 'STATUS_0100'(PBO module)
      Create container for alv-tree
        PERFORM create_alvtree_container.
    Add following code to 'Z......F01' INCLUDE
    *&      Form  CREATE_ALVTREE_CONTAINER
          Create container for alv-tree
    FORM create_alvtree_container.
      gd_tree_container_name = 'SCREEN_CONTAINER'.
      create object gd_custom_container
          exporting
                container_name = gd_tree_container_name
          exceptions
                cntl_error                  = 1
                cntl_system_error           = 2
                create_error                = 3
                lifetime_error              = 4
                lifetime_dynpro_dynpro_link = 5.
      if sy-subrc <> 0.
        message x208(00) with 'ERROR'.                        
      endif.
    ENDFORM.
    Add following code to 'STATUS_0100'(PBO module)
    Create tree control
    PERFORM create_object_in_container.
    Add following code to 'Z......F01' INCLUDE
    *&      Form  CREATE_OBJECT_IN_CONTAINER
          Create ALVtree control
    FORM create_object_in_container.
      create object gd_tree
        exporting
            parent              = gd_custom_container
            node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
            item_selection      = 'X'
            no_html_header      = ''
            no_toolbar          = ''
        exceptions
            cntl_error                   = 1
            cntl_system_error            = 2
            create_error                 = 3
            lifetime_error               = 4
            illegal_node_selection_mode  = 5
            failed                       = 6
            illegal_column_name          = 7.
      if sy-subrc <> 0.
        message x208(00) with 'ERROR'.                        
      endif.
    ENDFORM.
    Add following code to 'STATUS_0100'(PBO module)
    Create empty ALVtree control ready for first display
      PERFORM create_empty_alvtree_control.
    Add following code to 'Z......F01' INCLUDE
    *&      Form  CREATE_EMPTY_ALVTREE_CONTROL
          Create empty tree control
    FORM create_empty_alvtree_control.
    Create emty tree-control
      CLEAR: it_emptytab.
      REFRESH: it_emptytab.
      CALL METHOD gd_tree->set_table_for_first_display
         EXPORTING
                   is_hierarchy_header  = gd_hierarchy_header
                   it_list_commentary   = gd_report_title
                   i_logo               = gd_logo
                  i_background_id      = 'ALV_BACKGROUND'
                   i_save               = 'A'
                   is_variant            = gd_variant
         CHANGING
                   it_outtab            =  it_emptytab      "Must be empty
                   it_fieldcatalog      =  gd_fieldcat.
    ENDFORM.                    " CREATE_EMPTY_ALVTREE_CONTROL
    Add following code to 'STATUS_0100'(PBO module)
    Create ALVtree Hierarchy
      PERFORM create_alvtree_hierarchy.
    Add following code to 'Z......F01' INCLUDE
    *&      Form  CREATE_ALVTREE_HIERARCHY
          text
          Builds ALV tree display, (inserts nodes, subnodes etc)
    form create_alvtree_hierarchy.
      data: ls_sflight type sflight,
            lt_sflight type sflight occurs 0.
      data: ld_ebeln_key type lvc_nkey,
            ld_ebelp_key type lvc_nkey.
      loop at it_ekko into wa_ekko.
        perform add_ekko_node using      wa_ekko
                                changing ld_ebeln_key.
        loop at it_ekpo into wa_ekpo where ebeln eq wa_ekko-ebeln.
          perform add_ekpo_line using      wa_ekpo
                                           ld_ebeln_key
                                  changing ld_ebelp_key.
        endloop.
      endloop.
    calculate totals
      call method gd_tree->update_calculations.
    this method must be called to send the data to the frontend
      call method gd_tree->frontend_update.
    endform.                    " CREATE_ALVTREE_HIERARCHY
    *&      Form  ADD_EKKO_NODE
          text
         -->P_WA_EKPO  text
         -->P_0553   text
         <--P_EBELN_KEY  text
    form add_ekko_node using    ps_ekko like wa_ekko
                                value(p_relate_key)
                       changing p_node_key.
    data: ld_node_text type lvc_value,
           ls_sflight type sflight.
    Set item-layout
      data: lt_item_layout type lvc_t_layi,
            ls_item_layout type lvc_s_layi.
      ls_item_layout-t_image   = '@3P@'.
      ls_item_layout-fieldname = gd_tree->c_hierarchy_column_name.
      ls_item_layout-style     = cl_gui_column_tree=>style_default.
      ld_node_text             = ps_ekko-ebeln.
      append ls_item_layout to lt_item_layout.
    Add node
      call method gd_tree->add_node
        exporting
              i_relat_node_key = p_relate_key
              i_relationship   = cl_gui_column_tree=>relat_last_child
              i_node_text      = ld_node_text
              is_outtab_line   = ps_ekko
              it_item_layout   = lt_item_layout
           importing
              e_new_node_key = p_node_key.
    endform.                    " ADD_EKKO_NODE
    *&      Form  ADD_EKPO_LINE
          text
         -->P_WA_EKPO  text
         -->P_LD_EBELN_KEY  text
         <--P_LD_EBELP_KEY  text
    form add_ekpo_line using    ps_ekpo like wa_ekpo
                                value(p_relate_key)
                       changing p_node_key.
    data: ld_node_text type lvc_value,
           ls_sflight type sflight.
    Set item-layout
      data: lt_item_layout type lvc_t_layi,
            ls_item_layout type lvc_s_layi.
      ls_item_layout-t_image   = '@3P@'.
      ls_item_layout-fieldname = gd_tree->c_hierarchy_column_name.
      ls_item_layout-style     = cl_gui_column_tree=>style_default.
      ld_node_text             = ps_ekpo-ebelp.
      append ls_item_layout to lt_item_layout.
    Add node
      call method gd_tree->add_node
        exporting
              i_relat_node_key = p_relate_key
              i_relationship   = cl_gui_column_tree=>relat_last_child
              i_node_text      = ld_node_text
              is_outtab_line   = ps_ekpo
              it_item_layout   = lt_item_layout
           importing
              e_new_node_key = p_node_key.
    endform.                    " ADD_EKPO_LINE
    ***INCLUDE ZDEMO_ALVTREEO01 .
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS1'.
    SET TITLEBAR 'xxx'.
    If ALVtree already exists then it  mush not be re-created as this
    will cause a runtime error.
      IF gd_tree IS INITIAL.
      Create ALVtree (must be performed within screen PBO module)
        PERFORM create_alvtree_container.
        PERFORM create_object_in_container.
        PERFORM create_empty_alvtree_control.
        PERFORM create_alvtree_hierarchy.
      ENDIF.
      CALL METHOD cl_gui_cfw=>flush.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    ***INCLUDE ZDEMO_ALVTREEO01 .
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS1'.
    SET TITLEBAR 'xxx'.
    If ALVtree already exists then it  mush not be re-created as this
    will cause a runtime error.
      IF gd_tree IS INITIAL.
    Create ALVtree (must be performed within screen PBO module)
        PERFORM create_alvtree_container.
        PERFORM create_object_in_container.
        PERFORM create_empty_alvtree_control.
        PERFORM create_alvtree_hierarchy.
      ENDIF.
      CALL METHOD cl_gui_cfw=>flush.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    or
    The following code allows the easy creation of the example ALVtree report. Simply copy and past it into
    the appropriate includes(PBO and FORM).
      INCLUDE ZDEMO_ALVTREEF01                                           *
    *&      Form  CREATE_ALVTREE_CONTAINER
          Create container for ALVtree report
    form create_alvtree_container.
    Create container for alv-tree
      gd_tree_container_name = 'SCREEN_CONTAINER'.
      create object gd_custom_container
          exporting
                container_name = gd_tree_container_name
          exceptions
                cntl_error                  = 1
                cntl_system_error           = 2
                create_error                = 3
                lifetime_error              = 4
                lifetime_dynpro_dynpro_link = 5.
      if sy-subrc <> 0.
        message x208(00) with 'ERROR'.
      endif.
    endform.                    " CREATE_ALVTREE_CONTAINER
    *&      Form  CREATE_OBJECT_IN_CONTAINER
          Create ALVtree object in container
    form create_object_in_container.
    Create tree control
      create object gd_tree
        exporting
            parent              = gd_custom_container
            node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
            item_selection      = 'X'
            no_html_header      = ''
            no_toolbar          = ''
        exceptions
            cntl_error                   = 1
            cntl_system_error            = 2
            create_error                 = 3
            lifetime_error               = 4
            illegal_node_selection_mode  = 5
            failed                       = 6
            illegal_column_name          = 7.
      if sy-subrc <> 0.
        message x208(00) with 'ERROR'.
      endif.
    endform.                    " CREATE_OBJECT_IN_CONTAINER
    *&      Form  BUILD_REPORT_TITLE
          Build table for ALVtree header
    <->  p1        Header details
    <->  p2        Logo value
    FORM build_report_title CHANGING
          pt_report_title  TYPE slis_t_listheader
          pa_logo             TYPE sdydo_value.
      DATA: ls_line TYPE slis_listheader,
            ld_date(10) TYPE c.
    List Heading Line(TYPE H)
      CLEAR ls_line.
      ls_line-typ  = 'H'.
    ls_line-key     "Not Used For This Type(H)
      ls_line-info = 'PO ALVTree Display'.
      APPEND ls_line TO pt_report_title.
    Status Line(TYPE S)
      ld_date(2) = sy-datum+6(2).
      ld_date+2(1) = '/'.
      ld_date3(2) = sy-datum4(2).
      ld_date+5(1) = '/'.
      ld_date+6(4) = sy-datum(4).
      ls_line-typ  = 'S'.
      ls_line-key  = 'Date'.
      ls_line-info = ld_date.
      APPEND ls_line TO pt_report_title.
    Action Line(TYPE A)
      CLEAR ls_line.
      ls_line-typ  = 'A'.
      CONCATENATE 'Report: ' sy-repid INTO ls_line-info  SEPARATED BY space.
      APPEND ls_line TO pt_report_title.
    ENDFORM.                    " BUILD_REPORT_TITLE
    *&      Form  CREATE_EMPTY_ALVTREE_CONTROL
          Create empty tree control
    FORM create_empty_alvtree_control.
    Create emty tree-control
      CLEAR: it_emptytab.
      REFRESH: it_emptytab.
      CALL METHOD gd_tree->set_table_for_first_display
         EXPORTING
                   is_hierarchy_header  = gd_hierarchy_header
                   it_list_commentary   = gd_report_title
                   i_logo               = gd_logo
                  i_background_id      = 'ALV_BACKGROUND'
                   i_save               = 'A'
                   is_variant            = gd_variant
         CHANGING
                   it_outtab            =  it_emptytab      "Must be empty
                   it_fieldcatalog      =  gd_fieldcat.
    ENDFORM.                    " CREATE_EMPTY_ALVTREE_CONTROL
    *&      Form  CREATE_ALVTREE_HIERARCHY
          text
          Builds ALV tree display, (inserts nodes, subnodes etc)
    form create_alvtree_hierarchy.
      data: ls_sflight type sflight,
            lt_sflight type sflight occurs 0.
      data: ld_ebeln_key type lvc_nkey,
            ld_ebelp_key type lvc_nkey.
      loop at it_ekko into wa_ekko.
        perform add_ekko_node using      wa_ekko
                                changing ld_ebeln_key.
        loop at it_ekpo into wa_ekpo where ebeln eq wa_ekko-ebeln.
          perform add_ekpo_line using      wa_ekpo
                                           ld_ebeln_key
                                  changing ld_ebelp_key.
        endloop.
      endloop.
    calculate totals
      call method gd_tree->update_calculations.
    this method must be called to send the data to the frontend
      call method gd_tree->frontend_update.
    endform.                    " CREATE_ALVTREE_HIERARCHY
    *&      Form  ADD_EKKO_NODE
          text
         -->P_WA_EKPO  text
         -->P_0553   text
         <--P_EBELN_KEY  text
    form add_ekko_node using    ps_ekko like wa_ekko
                                value(p_relate_key)
                       changing p_node_key.
    data: ld_node_text type lvc_value,
           ls_sflight type sflight.
    Set item-layout
      data: lt_item_layout type lvc_t_layi,
            ls_item_layout type lvc_s_layi.
      ls_item_layout-t_image   = '@3P@'.
      ls_item_layout-fieldname = gd_tree->c_hierarchy_column_name.
      ls_item_layout-style     = cl_gui_column_tree=>style_default.
      ld_node_text             = ps_ekko-ebeln.
      append ls_item_layout to lt_item_layout.
    Add node
      call method gd_tree->add_node
        exporting
              i_relat_node_key = p_relate_key
              i_relationship   = cl_gui_column_tree=>relat_last_child
              i_node_text      = ld_node_text
              is_outtab_line   = ps_ekko
              it_item_layout   = lt_item_layout
           importing
              e_new_node_key = p_node_key.
    endform.                    " ADD_EKKO_NODE
    *&      Form  ADD_EKPO_LINE
          text
         -->P_WA_EKPO  text
         -->P_LD_EBELN_KEY  text
         <--P_LD_EBELP_KEY  text
    form add_ekpo_line using    ps_ekpo like wa_ekpo
                                value(p_relate_key)
                       changing p_node_key.
    data: ld_node_text type lvc_value,
           ls_sflight type sflight.
    Set item-layout
      data: lt_item_layout type lvc_t_layi,
            ls_item_layout type lvc_s_layi.
      ls_item_layout-t_image   = '@3P@'.
      ls_item_layout-fieldname = gd_tree->c_hierarchy_column_name.
      ls_item_layout-style     = cl_gui_column_tree=>style_default.
      ld_node_text             = ps_ekpo-ebelp.
      append ls_item_layout to lt_item_layout.
    Add node
      call method gd_tree->add_node
        exporting
              i_relat_node_key = p_relate_key
              i_relationship   = cl_gui_column_tree=>relat_last_child
              i_node_text      = ld_node_text
              is_outtab_line   = ps_ekpo
              it_item_layout   = lt_item_layout
           importing
              e_new_node_key = p_node_key.
    endform.                    " ADD_EKPO_LINE
    Reward if useful.
    Regards,
    Chitra

Maybe you are looking for