Saturday, August 5, 2017

Minimal ALV code to display data from internal table

Displaying data via ALV is very popular among ABAP programmers. ALV or so called SAP List Viewer (in fact it shouldn’t it be called SLV? funny though) is a user interface element for displaying tabular data in applications. It has a format data very familiar to SAP users. By default it offers a lot of functions like sorting, filtering, summing data in tables etc. Moreover it can be relatively easy enhanced by custom or application specific functions (custom button in ALV’s toolbar etc.). The ALV is sometimes called ALV grid control as the data is displayed in the table or grid.

There are few of Function Modules and classes/methods that can be used by ABAP programmer to leverage power of the ALV. In my case I was wondering what can be minimal ABAP code that could display data from internal table of ABAP program.

I came up with below to example program demonstrating minimal ABAP code for the ALV grid:

REPORT zmm_minimal_alv_01.
 
SELECT * FROM usr02 INTO TABLE @DATA(lt_users).
 
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    i_structure_name = 'USR02'
    i_grid_title     = 'Title of the ALV grid:'
  TABLES
    t_outtab         = lt_users.

In the example a I’m passing an information about data to be displayed by a structure with general layout specifications for list layout. In this case the structure (USR02) is present in ABAP Dictionary. In case it would be a custom one no persistently present in the ABAP Dictionary I would need to either pass it via internal table (IMPORT param IS_LAYOUT) with the set of information to be outputted or to pass it via a field catalog (IMPORT param IT_FIELDCAT) in the form of an internal table.

By adding import param i_grid_title a title of the grid can be added:

REPORT zmm_minimal_alv_02.

SELECT * FROM usr02 INTO TABLE @DATA(lt_users).

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    i_structure_name = 'USR02'
    i_grid_title     = 'Title of the ALV grid:'
  TABLES
    t_outtab         = lt_users.

By adding below import param it is possible to display the grid in new popup window and params can control position of that popup:

REPORT zmm_minimal_alv_03.
 
SELECT * FROM usr02 INTO TABLE @DATA(lt_users).
 
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    i_structure_name = 'USR02'
    i_grid_title     = 'Title of the ALV grid:'
    i_screen_start_column = 10
    i_screen_start_line   = 20
    i_screen_end_column   = 200
    i_screen_end_line     = 50
  TABLES

    t_outtab         = lt_users.

Just to add also FM POPUP_WITH_TABLE_DISPLAY could be used to display data from the internal table in simple way however it is not the ALV.


Source code of the example can be found here: github.com/softy12/MINIMAL_ALV

2 comments:

Antelio I. Abe said...

Try Fucntion Module: HR_IT_SHOW_ANY_TABLE_ON_ALV

Martin Maruskin said...

Hi Antelio,

thanks for a hint. However as I;m specializing on BW there is no such a FM in the BW systems. It looks like it is available in ECC systems as part of HR (HCM) module.

cheers