ABAP Program for Creating an ALV Grid in 3 lines

Now you can create an ALV Grid very fast; you don’t need to define a layout, a fieldcatalog, a container and all the other small things we usually define in an ALV Grid. If we don’t need to finetune the ALV Grid and just want to display a list on the screen or to the printer, here is a very simple way to proceed.

ALV Grid Output

Sample Code looks like:

DATA: l_alv      TYPE REF TO   cl_gui_alv_grid,
      lt_MARA TYPE TABLE OF MARA.
  SELECT * FROM MARA INTO TABLE lt_MARA UP TO 10 ROWS.
* Creation of the ALV object, when we use cl_gui_container=>screen0 as parent, the ALVGrid control will
* automatically use the full screen to display the grid, NO CONTAINER DEFINITION IS REQUIRED !
CREATE OBJECT l_alv
  EXPORTING
    i_parent = cl_gui_container=>screen0.

* calling the display of the grid, the system will automatically create the fieldcatalog based
* on the table name you pass in parameter

CALL METHOD l_alv->set_table_for_first_display
  EXPORTING
    i_structure_name = ’MARA’
  CHANGING
    it_outtab        = lt_MARA.

* Define a ‘empty’ selection screen, for ALV to be based on
SELECTION-SCREEN BEGIN OF SCREEN 1001.

SELECTION-SCREEN END OF SCREEN 1001.

CALL SELECTION-SCREEN 1001.

You might also be interested in these posts:

  1. ABAP Program to add Colors in ALV Grid
  2. ABAP Program with Editable ALV Grid Contents
  3. ABAP Program for ALV Grid, the OOPS way
  4. Displaying Icons in ALV Grid using ABAP
  5. ABAP Program to Display OAER pictures on Screen

One Response to “ABAP Program for Creating an ALV Grid in 3 lines”
shekhar Posted on August 27, 2011 at 11:43 PM

please anyone tell me how to upload images in alv oops

Post a Comment