Create OO ALV without Container

A container acts as an onscreen control location which accommodates all the other possible controls for user interface and navigation. These controls can hold anything, it can be a tree, picture, text editor, splitter or for our example an OO ALV container.

All the controllers should live in a container and allow for easy nesting.

There are specific container controls for docking, dialog box, splitter, easy splitter and a generic custom controller.

SAP Custom container is defined in dialog programming, there are some limitations with these containers in the sense it has to be defined for a certain length and height and could cause inconvenience for an end user. There is a much better way to have an ALV control have a free flowing empty container for easy user interfacing and navigation.

alv-without-container

Usually, you will need to create a container in SE51 in order for the OO ALV to be displayed in the container. Now, there is a neat little workaround to it. Check this below ABAP Program to create an ALV without creating the container and it takes the hassle away from always having a container. This method of creating an OO ALV without the container will always fill the entire screen since you are using a predefined container provided by the SAP ABAP class ‘CL_GUI_CONTAINER’.

DATA: gr_alvgrid             TYPE REF TO cl_gui_alv_grid.
*----Creating ALV Grid instance
CREATE OBJECT gr_alvgrid
EXPORTING
i_parent          = cl_gui_container=>screen0
EXCEPTIONS
error_cntl_create = 1
error_cntl_init   = 2
error_cntl_link   = 3
error_dp_create   = 4
OTHERS = 5.
IF sy-subrc NE 0.
ENDIF.

Now call the method GR_ALVGRID of course with relevant parameters

CALL METHOD gr_alvgrid->set_table_for_first_display
CALL SCREEN 100.  "< == Just double click and activate the screen.

Follow through for the complete list of ALV tutorials.

Comments