How to return back a structure of dynamic tables in a Function Module
I'm currently working on a Remote Function Module that should return back a multiple dynamic internal tables.
My FM can generate the dynamic iTables and return them back.
The Problem is that the OUTPUT is not correctly.
How can I define a structure containing a tabname and tablecontent,
Where the tabname is the name of the internal Table like 'MARA' and the tablecontent is containing the data of the Table 'MARA'.
So, this structure should contain a huge number of dynamic tables with their table-data and -name.
We all know that the size of each table must be allocated at the Runtime.
I know how to get the itabs and return them back, but I don't know how to return a structure like this.
Where each table muss be allocated separatly.
And the mother's table must be a structure.
-> Node 1 : 'T001W'
-> Table of 'T001W'
-> Node 2 : 'MARA'
-> Table of 'MARA'
I would recommend to use XML to retrieve the data from the remote system. The RFC-fm takes a table name as input and should return all table entries on the remote system.
DATA: gd_xstring TYPE xstring, gd_tabname TYPE tabname. DATA: ldo_data TYPE REF TO data. FIELD-SYMBOLS: <lt_itab> TYPE TABLE. gd_tabname = 'MARA'. CALL FUNCTION 'Z_MY_RFC_FUNC' DESTINATION '<rfc_destination>' IMPORTING id_tabname = gd_tabname EXPORTING ed_xstring = gd_xstring EXCEPTIONS ... CREATE DATA ldo_data TYPE TABLE OF (gd_tabname). ASSIGN ldo_data->* TO <lt_itab>. " Convert xstring back into XML CALL TRANSFORMATION id_ident SOURCE XML gd_xstring RESULT itab = <lt_itab>.
Within the RFC-fm you dynamically create your itab and do the selection:
FUNCTION 'Z_MY_RFC_FUNC'. DATA: ldo_data TYPE REF TO data. FIELD-SYMBOLS: <lt_itab> TYPE TABLE. CREATE DATA ldo_data TYPE TABLE OF (id_tabname). ASSIGN ldo_data->* TO <lt_itab>. SELECT * FROM (id_tabname) INTO TABLE <lt_itab>. CALL TRANSFORMATION id_ident SOURCE itab = <lt_itab> RESULT XML ed_xstring. ENDFUNCTION.
The advantage of using xstring (instead of string) is that you exclude any problems with Unicde this way.