‎2011 Jul 01 1:25 PM
Hi experts,
i have function (below) which reads "dynamically" data from table which is specify as input parameter, the data are "saved" in <ft>.
How can i return <ft> as output parameter of function module (table) ?
function
import parameter - > IC_TABLE
***
source code
data : lt_OPTIONS type standard table of RFC_DB_OPT,
lt_fields type standard table of rfc_db_fld,
lt_data type standard table of tab512,
la_rfcdata type tab512,
la_rfcfields type rfc_db_fld,
lr_dref type ref to data.
field-symbols: <ft> type table.
field-symbols: <structure> type any.
field-symbols: <field_to> type any.
field-symbols: <field_from> type any.
CALL FUNCTION 'RFC_READ_TABLE'
EXPORTING
query_table = IC_TABLE
DELIMITER = ' '
NO_DATA = ' '
ROWSKIPS = 0
ROWCOUNT = 0
tables
OPTIONS = lt_OPTIONS
fields = lt_fields
data = lt_data
EXCEPTIONS
TABLE_NOT_AVAILABLE = 1
TABLE_WITHOUT_DATA = 2
OPTION_NOT_VALID = 3
FIELD_NOT_VALID = 4
NOT_AUTHORIZED = 5
DATA_BUFFER_EXCEEDED = 6
OTHERS = 7.
create data lr_dref type table of (ic_table).
assign lr_dref->* to <ft>.
Fill data from OLTP table into ct_table.
assign local copy of initial line of <ft> to <structure>.
loop at lt_data into la_rfcdata.
loop at lt_fields into la_rfcfields.
assign component sy-tabix of structure <structure> to <field_to>.
if sy-subrc is initial.
assign la_rfcdata+la_rfcfields-offset(la_rfcfields-length)
to <field_from>.
<field_to> = <field_from>.
endif.
endloop.
append <structure> to <ft>.
endloop.
***
Thanks in advance
Martin
‎2011 Jul 01 3:22 PM
My first thought would be to try to create an export parameter of TYPE ANY TABLE or TYPE STANDARD TABLE. I haven't tried it so I'm not positive it will work though.
Another option would be to return a reference to the table, instead of returning the table itself. The calling program could then assign that reference to a field symbol.
‎2011 Jul 01 3:22 PM
My first thought would be to try to create an export parameter of TYPE ANY TABLE or TYPE STANDARD TABLE. I haven't tried it so I'm not positive it will work though.
Another option would be to return a reference to the table, instead of returning the table itself. The calling program could then assign that reference to a field symbol.
‎2011 Jul 04 2:26 PM
Hi Martin,
parameters with generic types are not allowed. So TYPE ANY TABLE etc. will not work. As Alex alreads said, you could return a reference to your table.
Your parameter should be typed like:
re_table type ref to data.At the end of your function module get a reference of your table into your parameter:
get reference of <ft> into re_tableAfter the call of your function module you can now handle and work with your table as wished:
* Declaration
data: re_table type ref to data.
field-symbols: <my_table> type standard table.
* Assign reference to fieldsymbol
assign re_table->* to <my_table>
if sy-subrc NE 0.
" Error: Could not assign reference
endif.
Best regards,
Fabian