I'm pretty new to this. I'm currently studying abap for my job and I have a problem that I can't seem to work out. How would I go about creating a Function Module that takes any kind of internal table and write it to the screen? I'm looking for a very generic solution that can work with any kind of internal table as input.
Asked
Active
Viewed 4,735 times
3 Answers
9
This is the exact reason SAP has developed ALV (ABAP List Viewer). One of the shortest way to display any (non-nested) table is the following.
DATA: go_alv TYPE REF TO cl_salv_table.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = go_alv
CHANGING
t_table = itab.
go_alv->display( ).

Guillaume
- 277
- 5
- 15
1
This would be the simplest way for a table whose line type is only flat data objects, taken from page 33 of This SAP Development Guide.
FIELD-SYMBOLS: <row> TYPE ANY,
<comp> TYPE ANY.
LOOP AT itab INTO <row>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <row> TO <wa_comp>.
IF sy-subrc <> 0.
SKIP.
EXIT.
ENDIF.
WRITE <wa_comp>.
ENDDO.
ENDLOOP.
A more robust way would be to use introspection containing Run-Time Type Services, a set of classes that let you introspect the details of a data object. This would give you the details mentioned by vwegert. An even better option would be to put it in an ALV grid.

Eric
- 1,511
- 1
- 15
- 28
0
It is possible, but you have to think about a lot of stuff:
- column widths, dynamically sizing columns
- currency fields / fields with units
- date formatting in a multi-lingual environment
- tables may contain arbitrary data, including nested tables
All things considered, this is not a trivial task. This is best left to the existing components.

vwegert
- 18,371
- 3
- 37
- 55