OOPS ABAP REPORT ON INTERACTIVE ALV WITH 2 ALV' GRIDS ON SINGLE SCREEN


REPORT zoops_interactive_2alvs.

***************************************************************************
"INCLUDE FOR INTERNAL TABLE,WORK AREA AND OBJECT DECLARATION.
***************************************************************************

INCLUDE zoops_interactive_2alvs_top.

*&---------------------------------------------------------------------*
*&  Include           ZOOPS_INTERACTIVE_2ALVS_TOP
*&---------------------------------------------------------------------*
CLASS LCL_ABAP DEFINITION DEFERRED .
DATA : I_VBAK TYPE TABLE OF VBAK .
DATA : WA_VBAK TYPE  VBAK .
DATA : I_VBAP TYPE TABLE OF  VBAP .
DATA : WA_VBAP TYPE  VBAP .
DATA : ALV_CONT TYPE REF TO  CL_GUI_CUSTOM_CONTAINER.    "FOR VBAK
DATA : ALV_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA : ALV_CONT2 TYPE REF TO  CL_GUI_CUSTOM_CONTAINER.   " FOR VBAP
DATA ALV_GRID2 TYPE REF TO CL_GUI_ALV_GRID.
DATA : OBJ TYPE REF TO LCL_ABAP .


***************************************************************************
" SELECT OPTIONS.

************************************************************************

INCLUDE zoops_interactive_2alvs_sel.


*&---------------------------------------------------------------------*
*&  Include           ZOOPS_INTERACTIVE_2ALVS_SEL
*&---------------------------------------------------------------------*
TABLESVBAK,VBAP.
SELECT-OPTIONS SO_VBELN FOR VBAK-VBELN.




*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_HANDLER DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_abap DEFINITION .
  
PUBLIC SECTION .
    
METHODS : vbak_method
              
FOR EVENT double_click
              
OF cl_gui_alv_grid
              
IMPORTING e_row .
ENDCLASS   .                    "LCL_EVENT_HANDLER DEFINITION
START-OF-SELECTION.

  
CALL SCREEN 100.     " CREATE TWO CONTAINER



*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.
  
IF alv_cont IS INITIAL .
    
PERFORM create_obj .
    
PERFORM get_data.
    
PERFORM display_alv .

    
CREATE OBJECT obj .
    
SET HANDLER obj->vbak_method FOR alv_grid .

  
ELSE.
    
PERFORM create_obj2 .
    
PERFORM display_alv2.
  
ENDIF .
ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  create_obj
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM create_obj .
  
CREATE OBJECT alv_cont
    
EXPORTING
      container_name 
'ALV_CONT'.
  
CREATE OBJECT alv_grid
    
EXPORTING
      i_parent 
alv_cont"GIVE CONTAINER INSTANCE
ENDFORM.                    create_obj
*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data .

  
SELECT FROM vbak
     
INTO CORRESPONDING FIELDS OF TABLE i_vbak
     
WHERE vbeln IN so_vbeln.
ENDFORM.                    get_data
*&---------------------------------------------------------------------*
*&      Form  display_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_alv .
  
CALL METHOD alv_grid->set_table_for_first_display
    
EXPORTING
      i_structure_name 
'VBAK'
    
CHANGING
      it_outtab        
i_vbak.
ENDFORM.                    display_alv
*&---------------------------------------------------------------------*
*&      Form  create_obj2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM create_obj2 .
  
IF alv_cont2 IS INITIAL "CREATE ONLY FOR FIRST TIME
    
CREATE OBJECT alv_cont2
      
EXPORTING
        container_name 
'ALV_CONT2'.
    
CREATE OBJECT alv_grid2
      
EXPORTING
        i_parent 
alv_cont2"GIVE CONTAINER INSTANCE
  
ENDIF .
ENDFORM.                    " create_obj2
*&---------------------------------------------------------------------*
*&      Form  display_alv2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_alv2 .
  
CALL METHOD alv_grid2->set_table_for_first_display
    
EXPORTING
      i_structure_name 
'VBAP'
    
CHANGING
      it_outtab        
i_vbap.
*
ENDFORM.                    " display_alv2
*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_HANDLER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_abap IMPLEMENTATION .

  
METHOD   vbak_method .
    
CLEAR wa_vbak.
    
READ TABLE i_vbak INTO wa_vbak INDEX e_row-index .
    
SELECT FROM vbap
    
INTO CORRESPONDING FIELDS OF TABLE i_vbap
    
WHERE vbeln wa_vbak-vbeln .
    
CALL SCREEN 100.
  
ENDMETHOD .                    "HANDLE_DC_EVENT
ENDCLASS   .
                    "LCL_EVENT_HANDLER IMPLEMENTATION



**************************************************************************
FOR THIS REPORT WE HAVE USED DOUBLE_CLICK EVENT IN THE CLASS (CL_GUI_ALV_GRID).
*****************************************************************************



OUTPUT



HERE I JUST DOUBLE CLICK ON SALES DOC NUM 4970 , IT SHOWS VBAP ITEM DATA 
SIDE BY SIDE ON A SINGLE SCREEN.