Reputation: 171
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.
Upvotes: 3
Views: 5617
Reputation: 277
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( ).
Upvotes: 9
Reputation: 1521
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.
Upvotes: 1
Reputation: 18483
It is possible, but you have to think about a lot of stuff:
All things considered, this is not a trivial task. This is best left to the existing components.
Upvotes: 0