Creating a Function module in ABAP to take any table and write it to the screen


SAP List Viewer is used to add an ALV component and provides a flexible environment to display lists and tabular structure. A standard output consists of header, toolbar, and an output table. The user can adjust the settings to add column display, aggregations, and sorting options using additional dialog boxes.

You can use following code to display any table:

DATA: go_alv TYPE REF TO cl_salv_table.
   CALL METHODcl_salv_table=>factory
   IMPORTING
      r_salv_table = go_alv
   CHANGING
      t_table     = itab.
 go_alv->display( ).

Another Dynamic Way to Output Any Internal Table is by using field-symbol, this is a particular field type in ABAP. Without going into the details of it, you must know that a field symbol works like a pointer without pointer arithmetic, but has a value semantics.

FIELD-SYMBOLS:<row> TYPE ANY.

FIELD-SYMBOLS:<comp> TYPE ANY.

The typing ANY is necessary because the field symbol should be able to refer to data of any type. And this is what our loop looks like now using a dynamic assignment to the various components of the work area:

LOOP ATitab_flight INTO row.
   DO.
      ASSIGN COMPONENTsy-index OF STRUCTURE <row> TO <wa_comp>.
      IF sy-subrc <>0.
         SKIP.
      EXIT.
      ENDIF.
         WRITE <wa_comp>.
   ENDDO.
ENDLOOP

Updated on: 12-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements