Application Development and Automation 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: 
Read only

Object oriented programming with header

Former Member
0 Likes
921

Hi,

Can I display two header in the same ALV output?  I have been trying with no success. I am using two table ;

TABLE1 : VBAK            and           TABLE : VBAP.

Please check my code.

Thanks in advance.

REPORT  ZALV_GRID2.
tables :knb1,vbak,vbap.
type-POOLs: slis.
DATA:
   gd_okcode TYPE ui_func,

   gd_repid LIKE sy-repid,


*
   go_docking TYPE REF TO cl_gui_docking_container,
   go_docking1 TYPE REF TO cl_gui_docking_container,
   go_splitter TYPE REF TO cl_gui_splitter_container,
   go_splitter_2 TYPE REF TO cl_gui_splitter_container,
   go_cell_top TYPE REF TO cl_gui_container,
   go_cell_bottom TYPE REF TO cl_gui_container,
   go_cell_left tYPE REF TO cl_gui_container,
   go_cell_right TYPE REF TO cl_gui_container,
   go_grid1 TYPE REF TO cl_gui_alv_grid,
   go_grid2 TYPE REF TO cl_gui_alv_grid,
   o_document type ref to cl_dd_document,
    o_top_container type ref to cl_gui_container,
     v_ln TYPE i,             "No. of lines
        v_cln(255) TYPE c,
             GRAPHIC_PARENT1 TYPE REF TO CL_GUI_CONTAINER,
       GRAPHIC_PARENT2 TYPE REF TO CL_GUI_CONTAINER,

   go_grid3 TYPE REF TO cl_gui_alv_grid.


DATA:
   It_knb1 TYPE  knb1 OCCURS 0," WITH HEADER LINE,
   it_vbak TYPE  vbak OCCURS 0,"with HEADER LINE  ,
   it_vbap TYPE  vbap OCCURS 0." with HEADER LINE.
   DATA: O_ALV TYPE REF TO CL_SALV_TABLE.

"start-of-selection.

PARAMETERS:  p_vbeln TYPE vbeln DEFAULT '0000000001'."  DEFAULT '1101'.
"SELECTION-SCREEN:end of block s1.

*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.

   PUBLIC SECTION.
     CLASS-METHODS:
       handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
         IMPORTING
           e_row
           e_column
           es_row_no
           sender.  " sending control, i.e. ALV grid that raised event



ENDCLASS.                    "lcl_eventhandler DEFINITION

*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.


   METHOD handle_double_click.
*   define local data
     DATA:
       wa_knb1 TYPE knb1,
       wa_vbak TYPE vbak,
       wa_vbap TYPE vbap.


*   Distinguish according to sending grid instance
     CASE sender.
       WHEN go_grid1.


      SELECT * FROM vbap INTO TABLE it_vbap
           "  FOR ALL ENTRIES IN it_vbak
              WHERE vbeln = P_VBELN."it_vbak-vbeln.

    READ TABLE it_vbak into wa_vbak index e_row-index.


         CALL METHOD go_grid1->set_current_cell_via_id
           EXPORTING
*              IS_ROW_ID    =
*              IS_COLUMN_ID =
             is_row_no    = es_row_no.
ENDCASE.

  CALL METHOD cl_gui_cfw=>set_new_ok_code
     EXPORTING
       new_code = 'ORDERS'.
CASE sender.


       WHEN go_grid2.
          SELECT  * FROM  VBAP INTO CORRESPONDING FIELDS OF TABLE It_VBAP
          WHERE  vbeln = WA_vbak-vbeln.
         READ TABLE it_vbaP INTO wa_vbaP INDEX e_row-index.
         CHECK ( not WA_vbak-vbeln IS INITIAL ).

         CALL METHOD go_grid2->set_current_cell_via_id
           EXPORTING
*              IS_ROW_ID    =
*              IS_COLUMN_ID =
             is_row_no    = es_row_no.

   CALL METHOD cl_gui_cfw=>set_new_ok_code
     EXPORTING
       new_code = 'ORDER_DETAILS'.



       WHEN go_grid3.
         READ TABLE it_vbap INTO wa_vbap INDEX e_row-index.
         CHECK ( not wa_vbap-matnr IS INITIAL ).

         SET PARAMETER ID 'MAT' FIELD wa_vbap-matnr.
         CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.

       WHEN OTHERS.
*        RETURN.
     ENDCASE.


     ENDMETHOD.                    "handle_double_click



ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION

START-OF-SELECTION.

   SELECT  *  FROM vbak INTO table it_vbak
     WHERE vbeln = p_VBELN.

  "Create docking container
   CREATE OBJECT go_docking
     EXPORTING
       parent                      = cl_gui_container=>screen0
       ratio                       = 90
     EXCEPTIONS
       OTHERS                      = 6.
   IF sy-subrc = 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.
* Create splitter container
   CREATE OBJECT go_splitter
     EXPORTING
       parent            = go_docking
       rows              = 1
       columns           = 2
*      NO_AUTODEF_PROGID_DYNNR =
*      NAME              =
     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.
*
* Get cell container
   CALL METHOD go_splitter->get_container
     EXPORTING
       row       = 1
       column    = 1
     RECEIVING
       container = go_cell_left.
   CALL METHOD go_splitter->get_container
     EXPORTING
       row       = 1
       column    = 2
     RECEIVING
       container = go_cell_right.


  "Create 2nd splitter container
   CREATE OBJECT go_splitter_2
     EXPORTING
       parent            = go_cell_left
       rows              = 2
       columns           = 1
*      NO_AUTODEF_PROGID_DYNNR =
*      NAME              =
     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.
*
* Get cell container
   CALL METHOD go_splitter_2->get_container
     EXPORTING
       row       = 1
       column    = 1
     RECEIVING
       container = go_cell_top.
   CALL METHOD go_splitter_2->get_container
     EXPORTING
       row       = 2
       column    = 1
     RECEIVING
       container = go_cell_bottom.
*
*
* Create ALV grids
   CREATE OBJECT go_grid1
     EXPORTING
       i_parent          = go_cell_top
     EXCEPTIONS
       OTHERS            = 5.
   IF sy-subrc = 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.

*
   CREATE OBJECT go_grid2
     EXPORTING
       i_parent          = go_cell_right
     EXCEPTIONS
       OTHERS            = 5.
   IF sy-subrc = 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.
*
   CREATE OBJECT go_grid3
     EXPORTING
       i_parent          = go_cell_right
     EXCEPTIONS
       OTHERS            = 5.
   IF sy-subrc = 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.

* Set event handler
   sET HANDLER: lcl_eventhandler=>handle_double_click FOR go_grid1.
   SET HANDLER: lcl_eventhandler=>handle_double_click FOR go_grid2.
   SET HANDLER: lcl_eventhandler=>handle_double_click FOR go_grid3.


* Display data
   CALL METHOD go_grid1->set_table_for_first_display
     EXPORTING
       i_structure_name = 'VBAK'
     CHANGING
       it_outtab        = It_VBAK
     EXCEPTIONS
       OTHERS           = 4.
   IF sy-subrc = 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.

   REFRESH: it_vbak.
   CALL METHOD go_grid2->set_table_for_first_display
     EXPORTING
       i_structure_name = 'VBAP'
     CHANGING
       it_outtab        = it_vbaP    " empty !!!
     EXCEPTIONS
       OTHERS           = 4.
   IF sy-subrc = 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.


*  REFRESH: it_vbap.
   CALL METHOD go_grid3->set_table_for_first_display
     EXPORTING
       i_structure_name = 'VBAP'
     CHANGING
       it_outtab        = it_vbap    " empty !!!
     EXCEPTIONS
       OTHERS           = 4.
   IF sy-subrc = 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.

   gd_repid = sy-repid.

* Link the docking container to the target dynpro
   CALL METHOD go_docking->link
     EXPORTING
       repid                       = gd_repid  "syst-repid
       dynnr                       = '0100'
*      CONTAINER                   =
     EXCEPTIONS
       OTHERS                      = 4.
   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 SCREEN '0100'.

END-OF-SELECTION.


perform display.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module STATUS_0100 output.
   SET PF-STATUS 'STATUS_0100'.
   "SET TITLEBAR 'xxx'.


CALL METHOD go_grid2->refresh_table_display
*    EXPORTING
*      IS_STABLE      =
*      I_SOFT_REFRESH =
     EXCEPTIONS
       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.


  "Refresh display of detail ALV list
   CALL METHOD go_grid3->refresh_table_display
*    EXPORTING
*      IS_STABLE      =
*      I_SOFT_REFRESH =
     EXCEPTIONS
       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.



endmodule.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module USER_COMMAND_0100 input.

   CASE SY-UCOMM.
     WHEN 'BACK'.
"call screen '1000'.
   LEAVE program.

*   User has pushed button "Display Orders"
     WHEN 'ORDERS'.
       PERFORM customer_show_orders.

     WHEN 'ORDER_DETAILS'.
       PERFORM order_show_details.

     WHEN OTHERS.
   ENDCASE.

   CLEAR: gd_okcode.

ENDMODULE.                   " USER_COMMAND_0100  INPUT


FORM customer_show_orders .
* define local data
   DATA:
     ld_row      TYPE i,
     wa_VBAK     TYPE VBAK.

   CALL METHOD go_grid1->get_current_cell
     IMPORTING
       e_row = ld_row.

   READ TABLE It_VBAK INTO wa_VBAK INDEX ld_row.
   CHECK ( syst-subrc = 0 ).


ENDFORM.                    " CUSTOMER_SHOW_ORDERS

FORM order_show_details .
* define local data
   DATA:
     ld_row      TYPE i,
     wa_vbaP     TYPE vbaP.

   CALL METHOD go_grid2->get_current_cell
     IMPORTING
       e_row = ld_row.

   READ TABLE it_vbaP INTO wa_vbaP INDEX ld_row.
   CHECK ( syst-subrc = 0 ).

   "SELECT * FROM  vbap INTO TABLE it_vbap
         " WHERE  vbeln  = wa_vbak-vbeln.

ENDFORM.                    " ORDER_SHOW_DETAILS
*&---------------------------------------------------------------------*
*&      Form  DISP_HEADING
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form DISPLAY .



endform.                    " DISPLAY

1 ACCEPTED SOLUTION
Read only

bernat_loscos
Explorer
0 Likes
874

Hi Raj,

You can try to define two layouts:

DATA: l_layout  TYPE lvc_s_layo,

      l_layout2  TYPE lvc_s_layo.

     

      l_layout-grid_title = 'Table 1'.

      l_layout2-grid_title = 'Table 2'.

     

      CALL METHOD go_grid1->set_table_for_first_display

     EXPORTING      

       i_structure_name = 'VBAK'

       is_layout        = l_layout

     CHANGING

       it_outtab        = It_VBAK

     EXCEPTIONS

       OTHERS           = 4.

     

      CALL METHOD go_grid2->set_table_for_first_display

     EXPORTING

       i_structure_name = 'VBAP'

       is_layout        = l_layout2

     CHANGING

       it_outtab        = it_vbaP    " empty !!!

     EXCEPTIONS

       OTHERS           = 4.

      

             

Regards,

6 REPLIES 6
Read only

bernat_loscos
Explorer
0 Likes
875

Hi Raj,

You can try to define two layouts:

DATA: l_layout  TYPE lvc_s_layo,

      l_layout2  TYPE lvc_s_layo.

     

      l_layout-grid_title = 'Table 1'.

      l_layout2-grid_title = 'Table 2'.

     

      CALL METHOD go_grid1->set_table_for_first_display

     EXPORTING      

       i_structure_name = 'VBAK'

       is_layout        = l_layout

     CHANGING

       it_outtab        = It_VBAK

     EXCEPTIONS

       OTHERS           = 4.

     

      CALL METHOD go_grid2->set_table_for_first_display

     EXPORTING

       i_structure_name = 'VBAP'

       is_layout        = l_layout2

     CHANGING

       it_outtab        = it_vbaP    " empty !!!

     EXCEPTIONS

       OTHERS           = 4.

      

             

Regards,

Read only

0 Likes
874

Thanks,

Bernat Loscos. Very helpful answer. Thanks a lot once again.
Read only

former_member192854
Active Participant
0 Likes
874

Hi Raj,

if you use this factory method, and you add it to your container:


DATA lo_alv_vbak TYPE REF TO cl_salv_table.

DATA lt_vbak TYPE STANDARD TABLE OF vbak.

* Perform your vbak selection

* Perform your splitter / container story

cl_salv_table=>factory(

  EXPORTING

    r_container  = o_top_container

  IMPORTING

    r_salv_table = lo_alv_vbak

  CHANGING

    t_table      = lt_vbak ).

Then you can use the LO_ALV object instance to create a header for each alv:


DATA lo_header TYPE REF TO cl_salv_form_layout_grid.

DATA lo_label TYPE REF TO cl_salv_form_label.

CREATE OBJECT lo_header.

lo_label = lo_header->create_label( row = 1 column = 1 ).

lo_label->set_text( 'This is my label for VBAK' ).

lo_alv_vbak->set_top_of_list( lo_header ).

And you can have another object instance - or reuse the above ones, for your other header.

Best,

Sander

Read only

Former Member
0 Likes
874

Thanks for help.

But I want PAGE HEADER like TOP-OF-PAGE.

Read only

0 Likes
874

Hi Raj, are you sure this is not like TOP-OF-PAGE?

Best,

Sander

Read only

Former Member
0 Likes
874

Yes, I'd like to trigger TOP_OF_PAGE event in an ALV report using CL_GUI_ALV_GRID class. I would also like to use the object of class CL_DD_DOCUMENT.

Please help me with a sample code as i'm a fresher.