Skip to Content
Author's profile photo Former Member

Displaying ALV in Splitter Container with heading using OOABAP

Author: Avinash Palavai, SAP Technical Consultant, Atos India Pvt. Ltd.

Introduction:

      Splitter Container can be used to display data either from two or more tables or from a single table based on particular conditions in ALV format using a single container at a time.

The classes that are used for achieving this are as follows,


1. CL_GUI_CUSTOM_CONTAINER .

2. CL_GUI_SPLITTER_CONTAINER .

3. CL_GUI_CONTAINER .

4. CL_GUI_ALV_GRID .

5. CL_DD_DOCUMENT.

Procedure:

1. First we have to design a modulepool screen (Screen No.100 ) with two custom controls, each for ALV and Heading as below,

Capture.PNG

2. Name the first control as “HEADING”.

Capture.PNG

3. Name the second control as “MAIN_CONT”.

Capture.PNG

4. Save and activate the screen.

5. Do the below coding in the report program.

6. Here i took a case of displaying the material details of a particular material type ‘ZSEM’, in the parent split alv list and                        the descriptions of those materials that are listed in parent split alv in child split alv.

7. The heading being maintained for this ALV is ‘Material Master Report’.

************************************Coding******************************************

*REPORT  ZOOALV_WITH_SPLITTER.

DATA : O_CC TYPE REF TO CL_GUI_CUSTOM_CONTAINER .

DATA : O_SC TYPE REF TO CL_GUI_SPLITTER_CONTAINER .

DATA : O_PART1 TYPE REF TO  CL_GUI_CONTAINER .

DATA : O_PART2 TYPE REF TO  CL_GUI_CONTAINER .

DATA : ALV_GRID1 TYPE REF TO CL_GUI_ALV_GRID .

DATA : ALV_GRID2 TYPE REF TO CL_GUI_ALV_GRID .

DATA : I_MARA TYPE TABLE OF MARA .

DATA : I_MAKT TYPE TABLE OF MAKT .

DATA : DD TYPE REF TO CL_DD_DOCUMENT.

   START-OF-SELECTION .


   call SCREEN 100.


*&———————————————————————*

*&      Module  STATUS_0100  OUTPUT

*&———————————————————————*

*       text

*———————————————————————-*

MODULE STATUS_0100 OUTPUT.

*  SET PF-STATUS ‘xxxxxxxx’.

*  SET TITLEBAR ‘xxx’.

   PERFORM create_objects.

   PERFORM spli_main_cont .

   PERFORM DISP_HEADING.

   PERFORM disp_alv1 .

   PERFORM disp_alv2 .

ENDMODULE.                 ” STATUS_0100  OUTPUT

*&———————————————————————*

*&      Form  CREATE_OBJECTS

*&———————————————————————*

*       text

*———————————————————————-*

*  –>  p1        text

*  <–  p2        text

*———————————————————————-*

FORM CREATE_OBJECTS .

   CREATE OBJECT O_CC

     EXPORTING

       CONTAINER_NAME = ‘MAIN_CONT’.

  CREATE OBJECT DD

*  EXPORTING

*    STYLE  =

*    BACKGROUND_COLOR =

*    BDS_STYLESHEET =

*    NO_MARGINS =

. ENDFORM.                    ” CREATE_OBJECTS


*&———————————————————————*

*&      Form  SPLI_MAIN_CONT

*&———————————————————————*

*       text

*———————————————————————-*

*  –>  p1        text

*  <–  p2        text

*———————————————————————-*

FORM SPLI_MAIN_CONT .

   CREATE OBJECT O_SC

     EXPORTING

       PARENT  = O_CC

       ROWS    = 2

       COLUMNS = 1.

   CALL METHOD O_SC->GET_CONTAINER

     EXPORTING

       ROW       = 1

       COLUMN    = 1

     RECEIVING

       CONTAINER = O_PART1.

   CALL METHOD O_SC->GET_CONTAINER

     EXPORTING

       ROW       = 2

       COLUMN    = 1

     RECEIVING

       CONTAINER = O_PART2.

ENDFORM.                    ” SPLI_MAIN_CONT


*&———————————————————————*

*&      Form  DISP_ALV1

*&———————————————————————*

*       text

*———————————————————————-*

*  –>  p1        text

*  <–  p2        text

*———————————————————————-*

FORM DISP_ALV1 .

   CREATE OBJECT ALV_GRID1

     EXPORTING

       I_PARENT = O_PART1.

   SELECT * FROM MARA

      INTO TABLE I_MARA “UP TO 100 ROWS.

         WHERE MTART = ‘ZSEM’ .

     SORT I_MARA BY MATNR ASCENDING.

   CALL METHOD ALV_GRID1->SET_TABLE_FOR_FIRST_DISPLAY

     EXPORTING

       I_STRUCTURE_NAME = ‘MARA’

     CHANGING

       IT_OUTTAB        = I_MARA.

ENDFORM .                                                   “DISP_ALV1


*&———————————————————————*

*&      Form  DISP_ALV2

*&———————————————————————*

*       text

*———————————————————————-*

*  –>  p1        text

*  <–  p2        text

*———————————————————————-*

FORM DISP_ALV2 .

   CREATE OBJECT ALV_GRID2

     EXPORTING

       I_PARENT = O_PART2.

   SELECT * FROM MAKT

      INTO TABLE I_MAKT

      FOR ALL ENTRIES IN I_MARA

       WHERE MATNR = I_MARAMATNR.

     DELETE ADJACENT DUPLICATES FROM I_MAKT COMPARING MATNR.

   CALL METHOD ALV_GRID2->SET_TABLE_FOR_FIRST_DISPLAY

     EXPORTING

       I_STRUCTURE_NAME = ‘MAKT’

     CHANGING

       IT_OUTTAB        = I_MAKT.

ENDFORM.                                                    ” DISP_ALV2


*&———————————————————————*

*&      Form  DISP_HEADING

*&———————————————————————*

*       text

*———————————————————————-*

*  –>  p1        text

*  <–  p2        text

*———————————————————————-*

form DISP_HEADING .

      DATA : HEAD TYPE  SDYDO_ATTRIBUTE .

HEAD = CL_DD_DOCUMENT=>HEADING .

CALL METHOD DD->ADD_TEXT

   EXPORTING

     TEXT          = ‘MATERIAL MASTER REPORT’

     SAP_STYLE     = HEAD .

CALL METHOD DD->DISPLAY_DOCUMENT

    EXPORTING

      CONTAINER          = ‘HEADING’.

ENDFORM.                    ” DISP_HEADING

8. Save  and activate the entire program. Execute (F8),

Capture.PNG

9. The result clearly illustrates the purpose and advantage of displaying the ALV in Splitter Container.

Assigned tags

      4 Comments
      Comments are closed.
      Author's profile photo Former Member
      Former Member

      I got a syntax error for the line:

          heading = cl_dd_document=>heading .

      Rob

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hello Rob,

      Updated the code.

      DATA : HEAD TYPE  SDYDO_ATTRIBUTE .

      HEAD = CL_DD_DOCUMENT=>HEADING .

      Thanks ...

      Author's profile photo Wolfgang Dörner
      Wolfgang Dörner

      Hey!

      You can show 2 ALVs on a dynpro much easier:

      Create a dynpro (no custom control needed in the example below this is "2000").

      Then you can add following code. Here new SALV-Model (cl_salv_table) is used. If you want you can add one more row to the splitter-container and then put your header document in it.

      "creating docking container as parent for splitter, setting up on empty dynpro
           create object lo_dck_cont
             exporting
               repid     = sy-repid
               dynnr     = '2000'
               side      = cl_gui_docking_container=>dock_at_top
               extension = 2000                                    "ratio = 95
               style     = cl_gui_control=>ws_child.

           "create splitter on docking
           create object lo_spl_ctrl
             exporting
               parent  = lo_dck_cont
               rows    = 2
               columns = 1.

      *--create salv1---------------------------*
               cl_salv_table=>factory(
                 exporting      

                     r_container    = lo_spl_ctrl->get_container( row = 1 column = 1 )   
                 importing
                   r_salv_table   = lo_alv1

                 changing
                   t_table        = lt_data2
               ).

      *--create salv2---------------------------*
               cl_salv_table=>factory(
                 exporting

                     r_container    = lo_spl_ctrl->get_container( row = 2 column = 1 )   
                 importing
                   r_salv_table   = lo_alv2
                 changing
                   t_table        = lt_data2
               ).


      *--show---------------------------*

      lo_alv1->display( ).

      lo_alv2->display( ).


      Author's profile photo Vinod Kumar
      Vinod Kumar

      All known OO (S)ALV scenarios are well explained in the blog Against All Odds - Programming of Communicating (S)ALV Grid Controls written by Uwe Schieferstein way back in 2010.

      Unfortunately the source code mentioned in the blog seems to be unformatted after migration to new SCN. (may be due to different formatting options)

      Regards, Vinod