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 Grid with 2 Headers - OOPS

Former Member
0 Kudos

Hi,

I've a requirement wherein the ALV should have 2 Headers like this:

     Header 1                                   Header 2

Col1      Col2     Col 3                 Col 4   Col 5     Col 6

I'm using

CALL METHOD g_grid->set_table_for_first_display

for the Grid Display.

How can I achieve this? Can someone help me on this?

Thanks,
Sowmya

23 REPLIES 23

Former Member
0 Kudos

Hi,

I think this is possible only in case of LIST display that is using the FM 'REUSE_ALV_LIST_DISPLAY'.

Former Member
0 Kudos

Hi,

Looking at your screenshot, you can make use of FM - REUSE_ALV_GRID_DISPLAY to split the header into two in your report. You will need to use

I_CALLBACK_HTML_TOP_OF_PAGE.

Try this.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM          = REPID
      I_CALLBACK_HTML_TOP_OF_PAGE = 'HTML_TOP_OF_PAGE'
      IT_FIELDCAT                 = FCAT
    TABLES
      T_OUTTAB                    = IT.

  

FORM HTML_TOP_OF_PAGE USING LW_DOCUMENT TYPE REF TO CL_DD_DOCUMENT .

  DATA : DOCTABLE TYPE REF TO CL_DD_TABLE_ELEMENT,
         COL1_T1  TYPE REF TO CL_DD_AREA,
         COL2_T1  TYPE REF TO CL_DD_AREA.

* add quick table with five columns
  CALL METHOD LW_DOCUMENT->ADD_TABLE
    EXPORTING
      NO_OF_COLUMNS = 2
      BORDER        = '1'
      WITH_HEADING  = 'X'
      WIDTH         = '100%'
    IMPORTING
      TABLE         = DOCTABLE.

* Filling columns in row
  CALL METHOD DOCTABLE->ADD_COLUMN
    EXPORTING
      WIDTH  = '50%'
    IMPORTING
      COLUMN = COL1_T1.

* Filling columns in row

  CALL METHOD DOCTABLE->ADD_COLUMN
    EXPORTING
      WIDTH  = '50%'
    IMPORTING
      COLUMN = COL2_T1.

  CALL METHOD DOCTABLE->NEW_ROW.

*Now adding the texts

  DATA: LW_TEXT1 TYPE SDYDO_TEXT_ELEMENT VALUE 'Danish',
        LW_TEXT2 TYPE SDYDO_TEXT_ELEMENT VALUE 'Manish'.

  CALL METHOD COL1_T1->ADD_TEXT
    EXPORTING
      TEXT = LW_TEXT1.

  CALL METHOD COL2_T1->ADD_TEXT
    EXPORTING
      TEXT = LW_TEXT2.

ENDFORM.                    "html_top_of_page

Regards,

Danish.

0 Kudos

Thanks Danish. But in my report, I'm using

CALL METHOD g_grid->set_table_for_first_display

for the Grid Display.

Can the above feature be achieved using OOPs in set_table_for_first_display?

Thanks & Regards,

Sowmya

0 Kudos

Dear All,

I am also looking for a solution to this requirement. How to display multiple headers using CL_GUI_ALV_GRID. Thank you.

Regards,

kartik

0 Kudos

Hi,

Will you please chk this link http://scn.sap.com/thread/1821069  and http://scn.sap.com/thread/875426

you may get the possible ways to solve your problem.

thanks.

ankit_doshi
Participant
0 Kudos

Hi,

Create a reference variable of type cl_gui_easy_splitter_container, like this

Data : e_split        TYPE REF TO cl_gui_easy_splitter_container.

create an object for the same:

         CREATE OBJECT e_split

           EXPORTING

             parent      = e_container

             orientation = cl_gui_easy_splitter_container=>orientation_horizontal.

and now create an alv object like this:

CREATE OBJECT e_alv_grid

           EXPORTING

             i_parent          = e_split->top_left_container

           EXCEPTIONS

             error_cntl_create = 1

             error_cntl_init   = 2

             error_cntl_link   = 3

             error_dp_create   = 4

             OTHERS            = 5.

0 Kudos

How on earth do you propose to provide two headers by splitting a container?

I request a detailed code please.

Former Member
0 Kudos

Hi Sowmya

You can use splitter in docking container to display to ALV on single page.

chk the example

Example :

Data: o_docking type ref to cl_gui_custom_container,
          container_1 type ref to cl_gui_container,
          container_2 type ref to cl_gui_container,
         

          o_grid1 type ref to cl_gui_alv_grid,
          o_grid2 type ref to cl_gui_alv_grid.

         

         splitter_1     type ref to cl_gui_splitter_container.

create object o_docking
       exporting
      container_name = 'CONTAINER'.

create object splitter_1
      exporting
      parent  = o_docking
      rows    = 1
      columns = 2.

*getting the reference for the splited container (row 1 & col 1 container)

call method splitter_1->get_container
      exporting
          row       = 1
          column    = 1
     receiving
          container = container_1.

*getting the reference for the splited container (row 1 & col 2 container)
call method splitter_1->get_container
       exporting
           row       = 1
          column    = 2
       receiving
          container = container_2.

create object o_docking
      exporting
          container_name = 'CONTAINER'.

create object o_grid1
     exporting
         i_parent = container_1.

call method o_grid1->set_table_for_first_display
     exporting
        i_structure_name     = 'ZCA_ITEM_DETAILS'
        it_toolbar_excluding = pt_exclude
     changing
        it_outtab            = itab.

  

create object o_docking
     exporting
        container_name = 'CONTAINER'.

create object o_grid2
     exporting
        i_parent = container_2.

  

call method o_grid2->set_table_for_first_display
     exporting
         i_structure_name = 'ZCA_HEAD_DETAIL'
     changing
        it_outtab        = itab2.

Regards

Harshit gandhi

0 Kudos

You didnt understand the question.

Its not about Header and Item tables display on the single screen in two containers.

Its two headers the OP wants. Please refer to screenshot in question.

0 Kudos

Hi all,

this question is almost as old as the ALV grid.

No, definitely not possible!

The column headers are designed to be 1 line. You can not merge or split cells in header line. ALV is not excel.

I did not try the search function in new SCN (is there any?) but I'm sure we have this discussion here frequently.

Even in web dynpro SALV which has lot's of features that classic ALV/SALV has not, it is the same.

Just take this as SAP style - nobody will never get confused by multi-line header columns 🙂

Regards

Clemens

former_member182040
Active Contributor
0 Kudos

Check following code following example is not OOPS But it will help you to develop :

TYPE-POOLS: slis, icon.

DATA: ld_fieldcat  TYPE  slis_fieldcat_alv.
DATA: t_alv_fieldcat      TYPE slis_t_fieldcat_alv WITH HEADER LINE,
Alv_Layout TYPE SLIS_LAYOUT_ALV .
DATA : it_fld TYPE slis_t_fieldcat_alv ,
        it_evt TYPE slis_t_event     ,
        wa_fld TYPE slis_fieldcat_alv   ,
        wa_evt TYPE slis_alv_event      ,
        wa_lay TYPE slis_layout_alv     .

data:
       BEGIN OF itab OCCURS 0,
         carrid like sflight-carrid,
         connid like sflight-connid,
         planetype like sflight-planetype,
         seatsmax like sflight-seatsmax,
       END OF itab.

START-OF-SELECTION.

SELECT carrid connid planetype seatsmax
        FROM sflight
        INTO TABLE itab.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
     IMPORTING
       et_events = it_evt.

   READ TABLE it_evt INTO wa_evt
        WITH KEY name = slis_ev_after_line_output .
   wa_evt-form = slis_ev_after_line_output .
   MODIFY it_evt FROM wa_evt INDEX sy-tabix .

   READ TABLE it_evt INTO wa_evt
        WITH KEY name = slis_ev_top_of_page .
   wa_evt-form = slis_ev_top_of_page .
   MODIFY it_evt FROM wa_evt INDEX sy-tabix .

   CLEAR: ld_fieldcat.
   ld_fieldcat-tabname       = 'ITAB'.
   ld_fieldcat-fieldname     = 'CARRID'.
   ld_fieldcat-ref_tabname   = 'SFLIGHT'.
   ld_fieldcat-outputlen     = '10'.
   APPEND ld_fieldcat TO t_alv_fieldcat.
   CLEAR ld_fieldcat.

   CLEAR: ld_fieldcat.
   ld_fieldcat-tabname       = 'ITAB'.
   ld_fieldcat-fieldname     = 'CONNID'.
   ld_fieldcat-ref_tabname   = 'SFLIGHT'.
   ld_fieldcat-outputlen     = '10'.
   APPEND ld_fieldcat TO t_alv_fieldcat.
   CLEAR ld_fieldcat.

     CLEAR: ld_fieldcat.
   ld_fieldcat-tabname       = 'ITAB'.
   ld_fieldcat-fieldname     = 'PLANETYPE'.
   ld_fieldcat-ref_tabname   = 'SFLIGHT'.
   ld_fieldcat-outputlen     = '10'.
   APPEND ld_fieldcat TO t_alv_fieldcat.
   CLEAR ld_fieldcat.

   CLEAR: ld_fieldcat.
   ld_fieldcat-tabname       = 'ITAB'.
   ld_fieldcat-fieldname     = 'SEATSMAX'.
   ld_fieldcat-ref_tabname   = 'SFLIGHT'.
   ld_fieldcat-outputlen     = '10'.
   APPEND ld_fieldcat TO t_alv_fieldcat.
   CLEAR ld_fieldcat.

"This is where we exclude the standard ALV columns

ALV_LAYOUT-no_colhead = 'X' .

   CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
     EXPORTING
       IS_LAYOUT = ALV_LAYOUT
       i_bypassing_buffer = 'X'
       i_callback_program = sy-repid
       it_fieldcat        = t_alv_fieldcat[]
       it_events          it_evt
       i_save             = 'A'
     TABLES
       t_outtab           = ITAB. "internal table

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

FORM top_of_page .

"Uline for creating a horizontal line

ULINE AT 1(45) .

"Format color for header background

FORMAT COLOR 7 .
"This is where we manually create the header text,
"in this example I'm using 2 lines header, if you
"want to have 3 lines header or more, you can just
"add new write command.

WRITE: / sy-vline , 02 'HEADER 1',
23 SY-VLINE, 25 'HEADER 2', 45 SY-VLINE.

WRITE: / sy-vline , 02 'CARRID' ,12 sy-vline, 14 'CONNID',
23 SY-VLINE, 25 'PLANE ', 34 SY-VLINE, 36 'SEATS MAX', 45 SY-VLINE.

ENDFORM.

You can check the following thread same issue discuss :

http://scn.sap.com/thread/1338012

0 Kudos

I don't see how your example is related in any way to using set_table_for_first_display. Also your example falls flat as soon as the user changes the layout and removes columns from the display. The column headings no longer line up.

As Chinmay and Clemens say splitting the header is not possible. It looks like op maybe able to use a split container, if it fits the requirement.

Che

0 Kudos

Hi Krupa, Thanks for the reply. But I'm looking for the code in OOPS.

-Sowmya

Former Member
0 Kudos

Hi,

    use below picece of code and change the postion values according to get header1or header2  exactly upto  col5.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTING

      i_callback_program     = sy-repid

      it_fieldcat            =  gt_fieldcat

      it_events              =  it_evt

    TABLES

      t_outtab               = gt_out.

write logic in under top-of-page.

form top_of_page.

WRITE : /5'Report output.

  ULINE AT 1(1000) .

  FORMAT COLOR 7 .

  WRITE: sy-vline,

         274 sy-vline,  277(40)'header1' CENTERED,

         368 sy-vline,  370(20)'header2' CENTERED,

         380 sy-vline.

endform.

Note:while prpparing fcat dont want to pass col_pos

CLEAR gs_fieldcat.

*  gs_fieldcat-col_pos   = '36'.

  gs_fieldcat-fieldname = 'FNAME'.

  gs_fieldcat-tabname   = 'GT_OUT '.

  gs_fieldcat-outputlen = 11.

  gs_fieldcat-seltext_m = 'Col1'.

  APPEND gs_fieldcat TO gt_fieldcat.

  CLEAR gs_fieldcat.   

Regards,

Gurunath Kumar D

rajesh_kumar2
Active Participant
0 Kudos

Hello Sowmya ,

If I have understood your requirement correctly , you are looking for some thing link the output below using

CALL METHOD g_grid->set_table_for_first_display .

Please check the code below for getting this done.

*&---------------------------------------------------------------------*

*& Report  Z_ALV_2_HEADERS

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

REPORT  z_alv_2_headers.

DATA: it_mara TYPE STANDARD TABLE OF mara ,

       it_marc TYPE STANDARD TABLE OF marc.

*Declaration

DATA: gr1_splitter_1   TYPE REF TO cl_gui_splitter_container,

       gr1_container    TYPE REF TO cl_gui_custom_container,

       gr1_container_11 TYPE REF TO cl_gui_container,

       gr1_container_12 TYPE REF TO cl_gui_container,

       gr1_container_21 TYPE REF TO cl_gui_container,

       gr1_container_22 TYPE REF TO cl_gui_container,

       grid1            TYPE REF TO cl_gui_alv_grid,

       grid2            TYPE REF TO cl_gui_alv_grid,

       gr_document1     TYPE REF TO cl_dd_document,

       gr_document2     TYPE REF TO cl_dd_document,

       v_cln(255)       TYPE c.       "No. of lines

DATA : ty_toolbar      TYPE stb_button.

DATA : e_object        TYPE REF TO cl_alv_event_toolbar_set,

        io_alv_toolbar  TYPE REF TO cl_alv_event_toolbar_set.

CLASS : lcl_events_grid1 DEFINITION DEFERRED,

         lcl_events_grid2 DEFINITION DEFERRED.

DATA:g_container  TYPE scrfname VALUE 'CCONTAINER'.

DATA: gr_events_grid1 TYPE REF TO lcl_events_grid1,

       gs_loyout1 TYPE lvc_s_layo,

       gs_loyout2 TYPE lvc_s_layo.

"Alv toolbar

DATA: event_receiver1  TYPE REF TO lcl_events_grid1,

       event_receiver2  TYPE REF TO lcl_events_grid2.

*---------------------------------------------------------------------*

*       CLASS lcl_events_grid1 DEFINITION

*---------------------------------------------------------------------*

CLASS lcl_events_grid1 DEFINITION.

   PUBLIC SECTION.

*--for placing buttons

     METHODS handle_toolbar_set

         FOR EVENT toolbar OF cl_gui_alv_grid

            IMPORTING

               e_object

               e_interactive.

*---user command on clicking a button

     METHODS handle_user_command

         FOR EVENT user_command OF cl_gui_alv_grid

             IMPORTING

                  e_ucomm.

ENDCLASS.                    "lcl_events_grid1 DEFINITION

*---------------------------------------------------------------------*

*       CLASS lcl_events_grid2 DEFINITION

*---------------------------------------------------------------------*

CLASS lcl_events_grid2 DEFINITION.

   PUBLIC SECTION.

*--for placing buttons

     METHODS handle_toolbar_set

         FOR EVENT toolbar OF cl_gui_alv_grid

            IMPORTING

               e_object

               e_interactive.

*---user command on clicking a button

     METHODS handle_user_command

         FOR EVENT user_command OF cl_gui_alv_grid

             IMPORTING

                  e_ucomm.

ENDCLASS.                    "lcl_events_grid2 DEFINITION

*---------------------------------------------------------------------*

*       CLASS lcl_events_grid1 IMPLEMENTATION

*---------------------------------------------------------------------*

CLASS lcl_events_grid1 IMPLEMENTATION.

*---method for handling toolbar

   METHOD handle_toolbar_set.

     CLEAR ty_toolbar.

     CLEAR ty_toolbar.

     ty_toolbar-function  = 'REFRESH'. "name of btn to  catch click

     ty_toolbar-butn_type = 0.

     ty_toolbar-icon      = '@42@'.

     APPEND ty_toolbar    TO e_object->mt_toolbar.

   ENDMETHOD.                    "handle_toolbar_set

   METHOD handle_user_command.

     DATA: wr_data_changed TYPE REF TO cl_alv_changed_data_protocol.

     DATA: lt_rows TYPE   lvc_t_row,

           lt_index TYPE  lvc_s_row-index.

     CASE e_ucomm.

       WHEN 'REFRESH'.

         PERFORM get_data_9010.

         CALL METHOD grid1->refresh_table_display.

     ENDCASE.

   ENDMETHOD.                    "handle_user_command

ENDCLASS.                    "lcl_events_grid1 IMPLEMENTATION

*---------------------------------------------------------------------*

*       CLASS lcl_events_grid2 IMPLEMENTATION

*---------------------------------------------------------------------*

CLASS lcl_events_grid2 IMPLEMENTATION.

*---method for handling toolbar

   METHOD handle_toolbar_set.

     CLEAR ty_toolbar.

     CLEAR ty_toolbar.

     ty_toolbar-function  = 'REFRESH'. "name of btn to  catch click

     ty_toolbar-butn_type = 0.

     ty_toolbar-icon      = '@42@'.

     APPEND ty_toolbar    TO e_object->mt_toolbar.

   ENDMETHOD.                    "handle_toolbar_set

   METHOD handle_user_command.

     DATA: wr_data_changed TYPE REF TO cl_alv_changed_data_protocol.

     DATA: lt_rows TYPE   lvc_t_row,

           lt_index TYPE  lvc_s_row-index.

     CASE e_ucomm.

       WHEN 'REFRESH'.

         PERFORM get_data_9010.

         CALL METHOD grid2->refresh_table_display.

     ENDCASE.

   ENDMETHOD.                    "handle_user_command

ENDCLASS.                    "lcl_events_grid2 IMPLEMENTATION

START-OF-SELECTION.

   CALL SCREEN 9010.

*&---------------------------------------------------------------------*

*& Module STATUS_9010 OUTPUT                                    *

*&---------------------------------------------------------------------*

MODULE status_9010 OUTPUT.

   SET PF-STATUS 'TEST'.

   SET TITLEBAR 'TEST' .

   PERFORM get_data_9010.

   PERFORM display_data_for_9010.

ENDMODULE.                    "status_9010 OUTPUT #status_9010 output

*&---------------------------------------------------------------------*

*& Module USER_COMMAND_9010 INPUT                      *

*&---------------------------------------------------------------------*

MODULE user_command_9010 INPUT.

   CALL METHOD cl_gui_cfw=>dispatch.

   CASE sy-ucomm.

     WHEN 'BACK' OR 'EXIT' OR 'CANC'.

       PERFORM free_objects.

       LEAVE TO SCREEN 0.

     WHEN OTHERS.

       LEAVE LIST-PROCESSING.

   ENDCASE.

ENDMODULE.                    "status_9010 OUTPUT #user_command_9010 input

*&---------------------------------------------------------------------*

*&      Form  GET_DATA_9010

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM get_data_9010 .

   SELECT * FROM mara

            INTO CORRESPONDING FIELDS OF TABLE it_mara

            UP TO 20 ROWS

            WHERE matnr NE space.

   SELECT * FROM marc

            INTO CORRESPONDING FIELDS OF TABLE it_marc

            UP TO 20 ROWS

            WHERE matnr  NE space.

ENDFORM.                    " GET_DATA_9010

*&---------------------------------------------------------------------*

*&      Form  DISPLAY_DATA_FOR_9010

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM display_data_for_9010 .

   PERFORM create_containers_9010.

   PERFORM create_layouts_9010.

   PERFORM display_alv_data_9010.

ENDFORM.                    " DISPLAY_DATA_FOR_9010

*&---------------------------------------------------------------------*

*&      Form  CREATE_CONTAINERS_9010

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM create_containers_9010 .

*creating object reference for container

   CREATE OBJECT gr1_container

   EXPORTING

      container_name = 'CCONTAINER'.

*pass name of container created in screen no 9010

*splitting the main container into 1 row & 2 coloum

   CREATE OBJECT gr1_splitter_1

    EXPORTING

       parent     = gr1_container

       rows       = 2

       columns    = 2.

*first set type of splitter bar

     CALL METHOD gr1_splitter_1->SET_ROW_SASH

       EXPORTING

         ID    = 1             "first conatiner (actually splitter bar)

         type  = cl_gui_splitter_container=>type_movable

         value = cl_gui_splitter_container=>TRUE.

*now set its value in % of entire costum control

*(so here first container will occupy 10% of enitre custom control space).

CALL METHOD gr1_splitter_1->set_row_height

   EXPORTING

     id                = 1

     height            = 20 .

*getting the reference for the splited container (row 1 & col 1 container)

   CALL METHOD gr1_splitter_1->get_container

     EXPORTING

       row       = 1

       column    = 1

     RECEIVING

       container = gr1_container_11.

*getting the reference for the splited container (row 2 & col 1 container)

   CALL METHOD gr1_splitter_1->get_container

     EXPORTING

       row       = 2

       column    = 1

     RECEIVING

       container = gr1_container_12.

*getting the reference for the splited container (row 1 & col 2 container)

   CALL METHOD gr1_splitter_1->get_container

     EXPORTING

       row       = 1

       column    = 2

     RECEIVING

       container = gr1_container_21.

*getting the reference for the splited container (row 2 & col 2 container)

   CALL METHOD gr1_splitter_1->get_container

     EXPORTING

       row       = 2

       column    = 2

     RECEIVING

       container = gr1_container_22.

ENDFORM.                    " CREATE_CONTAINERS_9010

*&---------------------------------------------------------------------*

*&      Form  CREATE_LAYOUTS_9010

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM create_layouts_9010 .

*----------------------------------------------------------------------*

*         FOR LAYOUT

*----------------------------------------------------------------------*

   DATA : l_title1   TYPE c LENGTH 70,

          l_title2   TYPE c LENGTH 70.

   gs_loyout1-zebra = 'X'.

   gs_loyout1-detailinit = 'X'.

   gs_loyout1-cwidth_opt = 'X'.

   CONCATENATE 'Material Master Header' 'from MARA'

                INTO l_title1 SEPARATED BY space.

*  gs_loyout1-grid_title = l_title1.

   gs_loyout2-zebra = 'X'.

   gs_loyout2-detailinit = 'X'.

   gs_loyout2-cwidth_opt = 'X'.

   CONCATENATE 'Material Plant Header' 'from MARC'

                INTO l_title2 SEPARATED BY space.

*  gs_loyout2-grid_title = l_title2.

ENDFORM.                    " CREATE_LAYOUTS_9010

*&---------------------------------------------------------------------*

*&      Form  DISPLAY_ALV_DATA_9010

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM display_alv_data_9010 .

*populating first internal table to the container

   CREATE OBJECT gr1_container

   EXPORTING

      container_name = g_container.

   CREATE OBJECT grid1

   EXPORTING

      i_parent = gr1_container_12.

*   Creating the document

   CREATE OBJECT gr_document1

   EXPORTING

       style  = 'ALV_GRID'.

** Create the Top of page event for the ALV report

*  PERFORM fill_top_of_page.

*----------------------------------------------------------------------*

*         FOR ALV event Handling

*----------------------------------------------------------------------*

   CREATE OBJECT event_receiver1.

*set even handlers

   SET HANDLER event_receiver1->handle_toolbar_set   FOR grid1.

   SET HANDLER event_receiver1->handle_user_command  FOR grid1.

* Create the Top of page event for the ALV report1

   PERFORM fill_top_of_page1.

*----------------------------------------------------------------------*

*         FOR ALV Grid Display

*----------------------------------------------------------------------*

   CALL METHOD grid1->set_table_for_first_display

     EXPORTING

       i_structure_name = 'MARA'

       is_layout        = gs_loyout1

     CHANGING

       it_outtab        = it_mara.

*populating second internal table

   CREATE OBJECT gr1_container

   EXPORTING

      container_name = g_container.

   CREATE OBJECT grid2

   EXPORTING

      i_parent = gr1_container_22.

*   Creating the document

   CREATE OBJECT gr_document2

   EXPORTING

       style  = 'ALV_GRID'.

* Calling the method of ALV to process top of page

   CALL METHOD grid2->list_processing_events

     EXPORTING

       i_event_name = 'TOP_OF_PAGE'

       i_dyndoc_id  = gr_document2.

* Create the Top of page event for the ALV report2

   PERFORM fill_top_of_page2.

*----------------------------------------------------------------------*

*         FOR ALV event Handling

*----------------------------------------------------------------------*

   CREATE OBJECT event_receiver2.

*set even handlers

   SET HANDLER event_receiver2->handle_toolbar_set   FOR grid2.

   SET HANDLER event_receiver2->handle_user_command  FOR grid2.

   CALL METHOD grid2->set_table_for_first_display

     EXPORTING

       i_structure_name = 'MARC'

       is_layout        = gs_loyout2

     CHANGING

       it_outtab        = it_marc.

ENDFORM.                    " DISPLAY_ALV_DATA_9010

*&---------------------------------------------------------------------*

*&      Form  FILL_TOP_OF_PAGE1

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM fill_top_of_page1 .

*--------------------For 1st Alv -----------------------*

* Calling the methods for dynamic text

   CALL METHOD gr_document1->add_text

     EXPORTING

       text         = 'Material Master from MARA'

       sap_emphasis = cl_dd_area=>strong. " For bold

* Adding GAP

   CALL METHOD gr_document1->add_gap

     EXPORTING

       width = 10.

* Adding Text

   CALL METHOD gr_document1->add_text

     EXPORTING

       text = v_cln.

* Adding Line

   CALL METHOD gr_document1->new_line.

* Adding Picture

   CALL METHOD gr_document1->add_picture

     EXPORTING

       picture_id = 'TRVPICTURE01'

       width      = '100'.

* Adding Line

   CALL METHOD gr_document1->new_line.

* Display the data

   CALL METHOD gr_document1->display_document

     EXPORTING

       parent = gr1_container_11.

* Calling the method of ALV to process top of page

   CALL METHOD grid1->list_processing_events

     EXPORTING

       i_event_name = 'TOP_OF_PAGE'

       i_dyndoc_id  = gr_document1.

ENDFORM.                    " FILL_TOP_OF_PAGE1

*&---------------------------------------------------------------------*

*&      Form  FILL_TOP_OF_PAGE2

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM fill_top_of_page2 .

* ------------------For 2nd Alv  ---------------------------

* Calling the methods for dynamic text

   CALL METHOD gr_document2->add_text

     EXPORTING

       text         = 'Material and Plant Data From MARC'

       sap_emphasis = cl_dd_area=>strong. " For bold

* Adding GAP

   CALL METHOD gr_document2->add_gap

     EXPORTING

       width = 10.

* Adding Text

   CALL METHOD gr_document2->add_text

     EXPORTING

       text = v_cln.

* Adding Line

   CALL METHOD gr_document2->new_line.

* Adding Picture

   CALL METHOD gr_document2->add_picture

     EXPORTING

       picture_id = 'TRVPICTURE00'

       width      = '100'.

* Adding Line

   CALL METHOD gr_document2->new_line.

* Display the data

   CALL METHOD gr_document2->display_document

     EXPORTING

       parent = gr1_container_21.

ENDFORM.                    " FILL_TOP_OF_PAGE2

*&---------------------------------------------------------------------*

*&      Form  free_objects

*&---------------------------------------------------------------------*

*       Free Objects

*----------------------------------------------------------------------*

FORM free_objects .

   CALL METHOD grid1->free

     EXCEPTIONS

       cntl_error        = 1

       cntl_system_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 METHOD grid2->free

     EXCEPTIONS

       cntl_error        = 1

       cntl_system_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 METHOD gr1_container->free

     EXCEPTIONS

       cntl_error        = 1

       cntl_system_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.                    " free_objects

0 Kudos

Thanks a lot Rajesh. Perhaps, my requirement is not like this. I've provided the screenshot in my question.

0 Kudos

Hello Sowmya,

So are you trying to build two headers for a single AVL display. Is that right ?

The output would something like this :

Even this can be attained. Please check the code below 

========================================================================

   *&---------------------------------------------------------------------*
*& Report  Z_ALV_2_HEADERS_1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  z_alv_2_headers_1.

DATA: it_mara TYPE STANDARD TABLE OF mara .


*Declaration
DATA: gr1_splitter_1   TYPE REF TO cl_gui_splitter_container,
      gr1_splitter_2   TYPE REF TO cl_gui_splitter_container,
      gr1_container    TYPE REF TO cl_gui_custom_container,
      gr1_container_11 TYPE REF TO cl_gui_container,
      gr1_container_12 TYPE REF TO cl_gui_container,
      gr1_container_21 TYPE REF TO cl_gui_container,
      grid1            TYPE REF TO cl_gui_alv_grid,
      gr_document1     TYPE REF TO cl_dd_document,
      gr_document2     TYPE REF TO cl_dd_document,
      v_cln(255)       TYPE c.       "No. of lines

DATA : ty_toolbar      TYPE stb_button.
DATA : e_object        TYPE REF TO cl_alv_event_toolbar_set,
       io_alv_toolbar  TYPE REF TO cl_alv_event_toolbar_set.

CLASS : lcl_events_grid1 DEFINITION DEFERRED.


DATA:g_container  TYPE scrfname VALUE 'CCONTAINER'.

DATA: gr_events_grid1 TYPE REF TO lcl_events_grid1,
      gs_loyout1 TYPE lvc_s_layo.



"Alv toolbar
DATA: event_receiver1  TYPE REF TO lcl_events_grid1.



*---------------------------------------------------------------------*
*       CLASS lcl_events_grid1 DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_events_grid1 DEFINITION.
  PUBLIC SECTION.
*--for placing buttons
    METHODS handle_toolbar_set
        FOR EVENT toolbar OF cl_gui_alv_grid
           IMPORTING
              e_object
              e_interactive.

*---user command on clicking a button
    METHODS handle_user_command
        FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING
                 e_ucomm.
ENDCLASS.                    "lcl_events_grid1 DEFINITION
*---------------------------------------------------------------------*
*       CLASS lcl_events_grid1 IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_events_grid1 IMPLEMENTATION.

*---method for handling toolbar
  METHOD handle_toolbar_set.
    CLEAR ty_toolbar.
    CLEAR ty_toolbar.
    ty_toolbar-function  = 'REFRESH'. "name of btn to  catch click
    ty_toolbar-butn_type = 0.
    ty_toolbar-icon      = '@42@'.
    APPEND ty_toolbar    TO e_object->mt_toolbar.
  ENDMETHOD.                    "handle_toolbar_set
  METHOD handle_user_command.
    DATA: wr_data_changed TYPE REF TO cl_alv_changed_data_protocol.
    DATA: lt_rows TYPE   lvc_t_row,
          lt_index TYPE  lvc_s_row-index.
    CASE e_ucomm.
      WHEN 'REFRESH'.
        PERFORM get_data_9010.
        CALL METHOD grid1->refresh_table_display.
    ENDCASE.
  ENDMETHOD.                    "handle_user_command
ENDCLASS.                    "lcl_events_grid1 IMPLEMENTATION



START-OF-SELECTION.

  CALL SCREEN 9010.

*&---------------------------------------------------------------------*
*& Module STATUS_9010 OUTPUT                                    *
*&---------------------------------------------------------------------*
MODULE status_9010 OUTPUT.
  SET PF-STATUS 'TEST'.
  SET TITLEBAR 'TEST' .

  PERFORM get_data_9010.
  PERFORM display_data_for_9010.

ENDMODULE.                    "status_9010 OUTPUT #status_9010 output
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9010 INPUT                      *
*&---------------------------------------------------------------------*
MODULE user_command_9010 INPUT.

  CALL METHOD cl_gui_cfw=>dispatch.

  CASE sy-ucomm.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      PERFORM free_objects.
      LEAVE TO SCREEN 0.
    WHEN OTHERS.
      LEAVE LIST-PROCESSING.
  ENDCASE.
ENDMODULE.                    "status_9010 OUTPUT #user_command_9010 input

*&---------------------------------------------------------------------*
*&      Form  GET_DATA_9010
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data_9010 .
  SELECT * FROM mara
           INTO CORRESPONDING FIELDS OF TABLE it_mara
           UP TO 20 ROWS
           WHERE matnr NE space.

ENDFORM.                    " GET_DATA_9010

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_DATA_FOR_9010
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_data_for_9010 .

  PERFORM create_containers_9010.
  PERFORM create_layouts_9010.
  PERFORM display_alv_data_9010.

ENDFORM.                    " DISPLAY_DATA_FOR_9010
*&---------------------------------------------------------------------*
*&      Form  CREATE_CONTAINERS_9010
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM create_containers_9010 .

*creating object reference for container
  CREATE OBJECT gr1_container
  EXPORTING
     container_name = 'CCONTAINER'.

*pass name of container created in screen no 9010
*splitting the main container into 2 row & 1 coloum
  CREATE OBJECT gr1_splitter_1
   EXPORTING
      parent     = gr1_container
      rows       = 2
      columns    = 1.

*getting the reference for the splited container (row 1 & col 1 container)
  CALL METHOD gr1_splitter_1->get_container
    EXPORTING
      row       = 1
      column    = 1
    RECEIVING
      container = gr1_container_11.

*getting the reference for the splited container (row 1 & col 2 container)
  CALL METHOD gr1_splitter_1->get_container
    EXPORTING
      row       = 2
      column    = 1
    RECEIVING
      container = gr1_container_21.

*splitting the 1st row container in to 1 rows & 2 coloum
  CREATE OBJECT gr1_splitter_2
  EXPORTING
     parent     = gr1_container_11
     rows      = 1
     columns   = 2.

*getting the reference for the splited container2 (row 1 & col 2 container)
  CALL METHOD gr1_splitter_2->get_container
    EXPORTING
      row       = 1
      column    = 1
    RECEIVING
      container = gr1_container_11.

*getting the reference for the splited container2 (row 2 & col 1 container)
  CALL METHOD gr1_splitter_2->get_container
    EXPORTING
      row       = 1
      column    = 2
    RECEIVING
      container = gr1_container_12.


*first set type of splitter bar
    CALL METHOD gr1_splitter_1->SET_ROW_SASH
      EXPORTING
        ID    = 1             "first conatiner (actually splitter bar)
        type  = cl_gui_splitter_container=>type_movable
        value = cl_gui_splitter_container=>TRUE.

*now set its value in % of entire costum control
*(so here first container will occupy 10% of enitre custom control space).
CALL METHOD gr1_splitter_1->set_row_height
  EXPORTING
    id                = 1
    height            = 20 .

ENDFORM.                    " CREATE_CONTAINERS_9010
*&---------------------------------------------------------------------*
*&      Form  CREATE_LAYOUTS_9010
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM create_layouts_9010 .

*----------------------------------------------------------------------*
*         FOR LAYOUT
*----------------------------------------------------------------------*
  DATA : l_title1   TYPE c LENGTH 70,
         l_title2   TYPE c LENGTH 70.

  gs_loyout1-zebra = 'X'.
  gs_loyout1-detailinit = 'X'.
  gs_loyout1-cwidth_opt = 'X'.
  CONCATENATE 'Material Master Header' 'from MARA'
               INTO l_title1 SEPARATED BY space.
*  gs_loyout1-grid_title = l_title1.

ENDFORM.                    " CREATE_LAYOUTS_9010
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_DATA_9010
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_alv_data_9010 .

*populating first internal table to the container
  CREATE OBJECT gr1_container
  EXPORTING
     container_name = g_container.

  CREATE OBJECT grid1
  EXPORTING
     i_parent = gr1_container_21.

*   Creating the document
  CREATE OBJECT gr_document1
  EXPORTING
      style  = 'ALV_GRID'.

** Create the Top of page event for the ALV report
*  PERFORM fill_top_of_page.

*----------------------------------------------------------------------*
*         FOR ALV event Handling
*----------------------------------------------------------------------*
  CREATE OBJECT event_receiver1.

*set even handlers
  SET HANDLER event_receiver1->handle_toolbar_set   FOR grid1.
  SET HANDLER event_receiver1->handle_user_command  FOR grid1.

* Create the Top of page event for the ALV report1
  PERFORM fill_top_of_page1.

*----------------------------------------------------------------------*
*         FOR ALV Grid Display
*----------------------------------------------------------------------*
  CALL METHOD grid1->set_table_for_first_display
    EXPORTING
      i_structure_name = 'MARA'
      is_layout        = gs_loyout1
    CHANGING
      it_outtab        = it_mara.

*   Creating the document
  CREATE OBJECT gr_document2
  EXPORTING
      style  = 'ALV_GRID'.

* Calling the method of ALV to process top of page
  CALL METHOD grid1->list_processing_events
    EXPORTING
      i_event_name = 'TOP_OF_PAGE'
      i_dyndoc_id  = gr_document2.

* Create the Top of page event for the ALV report2
  PERFORM fill_top_of_page2.

ENDFORM.                    " DISPLAY_ALV_DATA_9010
*&---------------------------------------------------------------------*
*&      Form  FILL_TOP_OF_PAGE1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_top_of_page1 .
*--------------------For 1st Alv -----------------------*
* Calling the methods for dynamic text
  CALL METHOD gr_document1->add_text
    EXPORTING
      text         = 'Material Master from MARA'
      sap_emphasis = cl_dd_area=>strong. " For bold

* Adding GAP
  CALL METHOD gr_document1->add_gap
    EXPORTING
      width = 10.

* Adding Text
  CALL METHOD gr_document1->add_text
    EXPORTING
      text = v_cln.

* Adding Line
  CALL METHOD gr_document1->new_line.

* Adding Picture
  CALL METHOD gr_document1->add_picture
    EXPORTING
      picture_id = 'TRVPICTURE01'
      width      = '100'.

* Adding Line
  CALL METHOD gr_document1->new_line.

* Display the data
  CALL METHOD gr_document1->display_document
    EXPORTING
      parent = gr1_container_11.

* Calling the method of ALV to process top of page
  CALL METHOD grid1->list_processing_events
    EXPORTING
      i_event_name = 'TOP_OF_PAGE'
      i_dyndoc_id  = gr_document1.
ENDFORM.                    " FILL_TOP_OF_PAGE1
*&---------------------------------------------------------------------*
*&      Form  FILL_TOP_OF_PAGE2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_top_of_page2 .
* ------------------For 2nd Alv  ---------------------------
* Calling the methods for dynamic text
  CALL METHOD gr_document2->add_text
    EXPORTING
      text         = 'Material and Plant Data From MARC'
      sap_emphasis = cl_dd_area=>strong. " For bold

* Adding GAP
  CALL METHOD gr_document2->add_gap
    EXPORTING
      width = 10.

* Adding Text
  CALL METHOD gr_document2->add_text
    EXPORTING
      text = v_cln.

* Adding Line
  CALL METHOD gr_document2->new_line.

* Adding Picture
  CALL METHOD gr_document2->add_picture
    EXPORTING
      picture_id = 'TRVPICTURE00'
      width      = '100'.

* Adding Line
  CALL METHOD gr_document2->new_line.

* Display the data
  CALL METHOD gr_document2->display_document
    EXPORTING
      parent = gr1_container_12.
ENDFORM.                    " FILL_TOP_OF_PAGE2
*&---------------------------------------------------------------------*
*&      Form  free_objects
*&---------------------------------------------------------------------*
*       Free Objects
*----------------------------------------------------------------------*
FORM free_objects .
  CALL METHOD grid1->free
    EXCEPTIONS
      cntl_error        = 1
      cntl_system_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 METHOD gr1_container->free
    EXCEPTIONS
      cntl_error        = 1
      cntl_system_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.                    " free_objects

========================================================================

0 Kudos

Hi,

if you think 2 separate ALV grids are the same as one grid with 2 headers, then this is it. But in this solution you can never have focus on both grids, scrolling, events, display, layout, just everything will not be in sync.

But thanks for the nice DD objects coding.

Regards

Clemens

raymond_giuseppi
Active Contributor
0 Kudos

It is not possible to have two header with a single ALV grid. (FAQ)

You could, with pain and work manage two ALV grids in adjacent containers, but you will have to maintain 2 display variants, and have to position one ALV when the other change (e.g. if user uses scrolling) using event after_refresh and method refresh_table_display. You will also need to synchronize filters and sort order of course... (or to disable those options in the grid)

Regards,

Raymond

Former Member
0 Kudos

Hi Sowmya,

By using alv oo some what difficult to handle the two headers in alv as per your screenshot .better to go normal alv,what i had provide in previous post.kindly,check once it will works fine.

Regards,

Gurunath

former_member210621
Participant
0 Kudos

Hi Sowmya,

Follow the steps to meet the requirement:

1. Place the container where you want to display two headers.

2. Split that container vertically into two containers say left container and right container.

3. Left container will display details for Header 1 and right container will display details for Header 2.

4. Create the field catalog, and use FM for each Headers to display reapective details.

-Ketan.

Former Member
0 Kudos

Hi,

You may use split container.....!

Regards,

venkat.

0 Kudos

Hi,

I am not sure if this is a solution and if your requirement is actual:

You should be able to add a line to the subtotal, respectively total - then use option display total at the beggining.

   just after set_table_for_first_display:

    field-symbols:
      <ft_outputsum> type itty_output, your output structure
      <fs_outputsum> type ity_output.

        call method icl_grid->get_subtotals
         importing
            ep_collect00 = is_sumline.

        field-symbols: <fs_val> type any.
        assign is_sumline->* to <ft_outputsum>.

        read table <ft_outputsum> assigning <fs_outputsum> index 1.

        if sy-subrc = 0 and <fs_outputsum> is assigned.

          assign component 'VBELN' of structure <fs_outputsum> to <fs_val>
                           casting like is_output-vbeln.
          <fs_val> = 'Monat:'(h04).

          unassign <fs_val>.
          assign component 'MATNR' of structure <fs_outputsum> to <fs_val>
                casting like is_output-matnr.
          <fs_val> = iv_month.
          unassign <fs_val>.

          assign component 'MAKTX' of structure <fs_outputsum> to <fs_val>
               casting like is_output-maktx.
          concatenate 'Jahr:'(h05) sy-datum(4) into <fs_val> separated by space.
          unassign <fs_val>.

          modify <ft_outputsum> from <fs_outputsum> index 1.
        endif.

       call method icl_grid->refresh_table_display
          exporting
            i_soft_refresh = 'X'
          exceptions
            finished       = 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.