Wednesday, June 11, 2008

Displaying Two ALV Grid on Screen

In this tutorial I will try to explain how to display multiple ALV Grid on a single screen. This is a very simple concept, to render or to draw a ALV grid on a screen you need a CONTAINER. Usually we create a CONTAINER with class CL_GUI_CUSTOM_CONTAINER and pass this CONTAINER object while creating ALV grid in parameter I_PARENT. Now to display multiple ALV grid you need multiple CONTAINER, here the class CL_GUI_EAST_SPLITTER_CONTAINER comes in the picture. This class divides a particular CONTAINER into two and give you two CONTAINER in return. How it divides depend on the parameter you pass while creating object. You can divide it horizontally by passing argument CL_GUI_EAST_SPLITTER_CONTAINER=>ORIENTATION_HORIZONTAL or vertically by passing argument CL_GUI_EAST_SPLITTER_CONTAINER=>orientation_VERTICAL. Since it will give you two CONTAINER you can further divide resulting CONATINER into two. So each time you create a object of CL_GUI_EAST_SPLITTER_CONTAINER you get one more CONTAINER. Finally you can use these CONATINER to create ALV Grids, or any GUI controls for example CL_GUI_ALV_TREE or CL_GUI_MOVIE (SAP Movie Control.. sounds interesting).

If you are confuse with above explanation then just forgot it and see the example. I have created a SCREEN 100 with custom container name 'CONTAINER'.



Below is the code for above screen shot.

REPORT zreport.
TABLES : scarr .
DATA : it_scarr TYPE TABLE OF scarr .
 
DATA : ob_custom TYPE REF TO cl_gui_custom_container ,
ob_split1 TYPE REF TO cl_gui_easy_splitter_container ,
ob_split2 TYPE REF TO cl_gui_easy_splitter_container ,
ob_grid1 TYPE REF TO cl_gui_alv_grid ,
ob_grid2 TYPE REF TO cl_gui_alv_grid ,
ob_grid3 TYPE REF TO cl_gui_alv_grid .
 
SELECT-OPTIONS : s_carrid FOR scarr-carrid .
 
START-OF-SELECTION .
 
SELECT *
INTO TABLE it_scarr
FROM scarr
WHERE carrid IN s_carrid .
 
CALL SCREEN 100 .
 
*&---------------------------------------------------------------------*
*& Module status_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*

 
MODULE status_0100 OUTPUT.
SET TITLEBAR 'ZTITLE01' .
SET PF-STATUS 'ZPF01' .

* This will create a container
CREATE OBJECT ob_custom
EXPORTING
container_name = 'CONTAINER' . 
 
* This spit the container OB_CUSTOM into two
CREATE OBJECT ob_split1
EXPORTING
parent = ob_custom
orientation = cl_gui_easy_splitter_container=>orientation_vertical .
 
* Now we have two container
* OB_SPLIT1->TOP_LEFT_CONTAINER
* OB_SPLIT1->BOTTOM_RIGHT_CONTAINER
* Since these two are itself a container we can further devide them into two.
* Let try to divide OB_SPLIT1->BOTTOM_RIGHT_CONTAINER into two

 
CREATE OBJECT ob_split2
EXPORTING
parent = ob_split1->bottom_right_container
orientation = cl_gui_easy_splitter_container=>orientation_horizontal .
 
* Now we have total 3 container available with us
* OB_SPLIT1->TOP_LEFT_CONTAINER
* OB_SPLIT2->TOP_LEFT_CONTAINER
* OB_SPLIT2->BOTTOM_RIGHT_CONTAINER
* Note that OB_SPLIT1->BOTTOM_RIGHT_CONTAINER is not available because we divided
* that into two.
* Now Put a grid in each container

 
CREATE OBJECT ob_grid1
EXPORTING
i_parent = ob_split1->top_left_container .
 
CREATE OBJECT ob_grid2
EXPORTING
i_parent = ob_split2->top_left_container .
 
CREATE OBJECT ob_grid3
EXPORTING
i_parent = ob_split2->bottom_right_container .
 
CALL METHOD ob_grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'SCARR'
CHANGING
it_outtab = it_scarr.
 
CALL METHOD ob_grid2->set_table_for_first_display
EXPORTING
i_structure_name = 'SCARR'
CHANGING
it_outtab = it_scarr.
 
CALL METHOD ob_grid3->set_table_for_first_display
EXPORTING
i_structure_name = 'SCARR'
CHANGING
it_outtab = it_scarr.
 
ENDMODULE. " status_0100 OUTPUT
 
*&---------------------------------------------------------------------*
*& Module user_command_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*

MODULE user_command_0100 INPUT.

IF sy-ucomm = 'BACK' OR sy-ucomm = 'EXIT' .
FREE : ob_grid1 ,
ob_grid2 ,
ob_grid3 ,
ob_split1 ,
ob_split2 ,
ob_custom .

LEAVE TO SCREEN 0 .
ENDIF.

ENDMODULE. " user_command_0100 INPUT


Recommended blogs
Display ALV Grid (OOP) Fullscreen
Use of Application Log FMs to display Message List/Log
Creating custom page format for sapscript/smartform
Reset ALV Export Option for User

24 comments:

  1. Great explanation! I was curious whether you could essentially split a screen into thirds (top/middle/bottom) by splitting vertically twice. Can you do this, or does a secondary split have to be opposite of the first?

    Thanks!!!

    ReplyDelete
  2. I think in above code if you replace the second split by

    CREATE OBJECT ob_split2 EXPORTING parent = ob_split1->bottom_right_container orientation = cl_gui_easy_splitter_container=>orientation_vertical .

    then you will get the desire result.

    ReplyDelete
  3. Hi, I'm getting an error: ASSERTION_FAILED scrolling down in the first ALV Grid. Have you ever got it????

    ReplyDelete
  4. when i run the code am getting error
    Dynpro does not exist.

    ReplyDelete
  5. Have you defined screen 100 with custom container in it?

    ReplyDelete
  6. what is procedure to define ?
    pls..

    ReplyDelete
  7. how to identify in wich ALV we triggered event?
    (in my case double click)

    ReplyDelete
  8. Usually we write a local class with method and assiciate that method double click of ALV grid. Write a local class for each ALV grid and register their method with double click.

    ReplyDelete
    Replies
    1. Could you explain this in detail.
      I need to create different action buttons for different ALVs.

      Thanks & Regards

      Amit Pal
      Mob:+91-9999026862

      Delete
  9. clearly explained, but i need to know abt the screen 100 used here, do we need to draw the windows on the screen or is it a empty screen.

    ReplyDelete
  10. You need to create screen 100. Put a custom container with name 'CONTAINER'

    ReplyDelete
  11. i tried with this example.It is working fine.Here when i divide the Container (using split container using TOP_LEFT and BOTTOM_RIGHT) it is dividing the screen into two equal portions. How can i control this. I want the top Container to be minimal and below as bigger one. Can i control this. I tried with SET_HEIGHT method.But did't work. Can you look into this if get time.

    Thanks in Advance.

    ReplyDelete
  12. If you are using class CL_GUI_EASY_SPLITTER_CONTAINER as shown in above example, just pass SASH_POSITION parameter in constructor to control the position.

    Its position in percentage

    ReplyDelete
  13. Is there a way to make it dynamic?
    As in a scenario where there are multiple company code records and each company code is a separate ALV grid

    ReplyDelete
  14. is there a way to make it dynamic...so we could control the no. of ALV grids based on the data in the internal table?

    ReplyDelete
  15. hi, nice code. i'have tried and it works!. But i'm searching the abap code to display this such result using OOP ALV without using Screen/Container

    ReplyDelete
  16. Is it necessary to use CL_GUI_EASY_SPLITTER_CONTAINER? Can't we use CL_GUI_SPLITTER_CONTAINER? What is the difference between the two?

    ReplyDelete
  17. Is it possible to i_structure_name = 'st', where 'st' is define in the abap code and not in the dictionary?

    ReplyDelete
  18. Is it possible to i_structure_name = 'st', where 'st' is define in the abap code and not in the dictionary?

    i_structure_name = 'ST' , ST should be defined in dictionary.

    ReplyDelete
  19. Its not working , so kindly explain me to do..........

    ReplyDelete
    Replies
    1. have you defined screen 100, titlebar and pf status ZPF01?

      Delete