2015 Sep 23 11:06 PM
Hello,
I have poured through the discussions and have not found an answer to this particular question.
What I want to do is in a Function Module, is build a structure of a SAP table based on the table name pass to the function module. I do not want to pass back a table nor XML. Just EXPORT the structure like if you were defining the parameter in the Function Module with an Associated Type.
Can someone help me?
Regards, Dean.
2015 Sep 24 6:52 AM
AFAIK it's not possible because FM parameters should be defined in dictionary. But you can export fieldcatalog to create your dynamic structure/table later.
2015 Sep 24 8:25 AM
2015 Sep 24 1:16 PM
2015 Sep 24 1:23 PM
A Ref to data is an object defined as 'Type Ref To Data'. This is populated by a reference to whatever object you like using the command:
Get Reference Of my_object into o_Ref.
By then DeReferencing that reference into a Field Symbol you can access the orginal object as Normal:
Assign o_Ref->* to <f_Original>.
Since Type Ref To Data is just one type you can pass back muitple different 'actual' data types using the same parameter.
Rich
2015 Sep 24 8:38 AM
Or, as I did on a previous project, use a table that contained a structure name and a table of XSEQUENCEs.
Then use CL_ABAP_CONV_OUT_CE to populate that in the FM, and CL_ABAP_CONV_IN_CE to decode it in the calling program using the associated structure name.
In that way you can pass mutliple tables or structures using just one table parameter and without having to keep the original data hanging around.
Rich
2015 Sep 24 11:58 AM
Not quite sure what you are trying to achieve but have a look at this:
FUNCTION ztest.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(TABNAME) TYPE TABNAME DEFAULT 'T100'
*" CHANGING
*" REFERENCE(ET_TAB1) TYPE ANY TABLE
*"----------------------------------------------------------------------
DATA: l_dref_table TYPE REF TO data.
FIELD-SYMBOLS: <fs_tabnam> TYPE STANDARD TABLE.
CREATE DATA l_dref_table TYPE STANDARD TABLE OF (tabname).
ASSIGN l_dref_table->* TO <fs_tabnam>.
APPEND INITIAL LINE TO <fs_tabnam>.
et_tab1[] = <fs_tabnam>[].
ENDFUNCTION.
2015 Sep 24 1:20 PM
Hello Surbjeet,
I tried this...
FUNCTION ZTEST
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_TABNAME) TYPE TABNAME
*" EXPORTING
*" REFERENCE(ES_STRUCTURE)
*-- Create Internal Table Structure
perform create_dynamically.
* Create dynamic work area and assign to Field Symbol
create data gdyn_line like line of <gfs_table>.
*-- Capture Key Structure
assign gdyn_line->* to <gfs_line>.
ES_STRUCTURE = <gfs_line>.
ENDFUNCTION.
This didn't work. Is only by passing a table the only possibility?
2015 Sep 24 1:46 PM
Hi Dean,
Which bit is not working? Can you explain you requirement more clearly? If you only want to pass back a structure try this:
FUNCTION ztest.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(TABNAME) TYPE TABNAME DEFAULT 'T100'
*" CHANGING
*" REFERENCE(E_TAB_STRUC) TYPE ANY
*"----------------------------------------------------------------------
DATA: l_dref_table_workarea TYPE REF TO data.
FIELD-SYMBOLS <fs> TYPE any.
CREATE DATA l_dref_table_workarea TYPE (tabname).
ASSIGN l_dref_table_workarea->* TO <fs>.
e_tab_struc = <fs>.
ENDFUNCTION.
2015 Sep 24 2:41 PM
Hell Surbjeet,
When I do this and test the FM, I am prompted for a value for the E-TAB_STRUC and during execution I get a dump with this error...
Conversion of type "TABLE OF FLAT_STRUCTURE" to type "C LENGTH 200" not
supported.
Any suggestions?
2015 Sep 24 3:13 PM
In the second example that I posted the changing parameter E_TAB_STRUC is of TYPE ANY (in the first example it was TYPE ANY TABLE). Make sure you declare this properly.
The second example can be called like this:
DATA: lw_t100 TYPE t100.
CALL FUNCTION 'ZTEST'
EXPORTING
tabname = 'T100'
CHANGING
e_tab_struc = lw_t100.
2015 Sep 24 4:27 PM
When I do that I get..
Message No. FL819
Diagnosis
The system could not generate a syntactically correct test frame for function module ZTEST You therefore cannot test the function module using the test environment. You have probably used an ABAP feature in the interface definition that is not yet supported in the test environment.
The error message is:
You cannot use generic types for fields. The table types "ANY" and "INDEX" are generic
System Response
Procedure
Check whether you can change the interface of the function module so that it is possible to generate the test frame. If this is not possible,you will have to write your own utility for testing the function module.
Procedure for System Administration
2015 Sep 24 4:32 PM
Here is the code and the results..
FUNCTION ZTEST .
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(TABNAME) TYPE TABNAME
*" CHANGING
*" REFERENCE(EC_STRUCTURE) TYPE ANY
*"----------------------------------------------------------------------
DATA: l_dref_table_workarea TYPE REF TO data.
FIELD-SYMBOLS <fs> TYPE any.
CREATE DATA l_dref_table_workarea TYPE (tabname).
ASSIGN l_dref_table_workarea->* TO <fs>.
EC_STRUCTURE = <fs>.
ENDFUNCTION.
Execute...
Press SAVE and results are..
2015 Sep 24 5:29 PM
Hi Dean,
You need to fill the return structure however you want, I left it empty. Add these lines to see data returned in the structure:
DATA: l_dref_table_workarea TYPE REF TO data.
FIELD-SYMBOLS <fi> TYPE any.
FIELD-SYMBOLS <fs> TYPE any.
CREATE DATA l_dref_table_workarea TYPE (tabname).
ASSIGN l_dref_table_workarea->* TO <fs>.
ASSIGN COMPONENT 'SPRSL' OF STRUCTURE <fs> TO <fi>.
<fi> = sy-langu.
ASSIGN COMPONENT 'ARBGB' OF STRUCTURE <fs> TO <fi>.
<fi> = 'Z001'.
ASSIGN COMPONENT 'MSGNR' OF STRUCTURE <fs> TO <fi>.
<fi> = '001'.
ASSIGN COMPONENT 'TEXT' OF STRUCTURE <fs> TO <fi>.
<fi> = 'Testing'.
e_tab_struc = <fs>.
From calling program the structure is filled as: