‎2010 Dec 07 7:00 PM
I want to create an remote enabled function module that imports field names and table name and returns the table values.
This test works:
SELECT bukrs butxt FROM (tablename)
INTO (lookup_t-FIELD1,lookup_t-FIELD2).
APPEND lookup_t.
ENDSELECT.
When I attempt to dynamically send the column names, I get the error that...
Incorrect expression "(FIELD2)" in the aggregate function
SELECT (field1) (field2) FROM (tablename)
INTO (lookup_t-FIELD1,lookup_t-FIELD2).
APPEND lookup_t.
ENDSELECT.
What do I need to do to get multiple dynamic column names to work? It works when I just use a single column (field1).
Thanks
Edited by: Keith Wendel on Dec 7, 2010 1:00 PM
‎2010 Dec 07 7:52 PM
hello,
You can not use (field1) (field2) like pattern...only one open and close bracket patter supported
If you want to use multiple dynamic fields use like:
concatenate 'field1' 'field2' into field1 separated by space.and use only (field1)
Hope it will help.
‎2010 Dec 07 7:52 PM
hello,
You can not use (field1) (field2) like pattern...only one open and close bracket patter supported
If you want to use multiple dynamic fields use like:
concatenate 'field1' 'field2' into field1 separated by space.and use only (field1)
Hope it will help.
‎2010 Dec 07 8:04 PM
I think you have me closer, but what if field1 and field2 are just variable names and I need the imported values?
This concatenation gives me "field1 field2" instead of my actual "[value of field1] [value of field 2]".
‎2010 Dec 07 8:08 PM
I wouldn't do it that way - I would just grab the fields afterwards. You can adjust the code below to assign your values and append instead of writing and add some more error handling:
DATA: lr_dref TYPE REF TO data.
DATA: lv_tabname TYPE tabname.
DATA: lv_name1 TYPE fieldname,
lv_name2 TYPE fieldname.
FIELD-SYMBOLS: <lfs_tab> TYPE table,
<lfs_line> TYPE ANY,
<lfs_field1> TYPE ANY,
<lfs_field2> TYPE ANY.
lv_tabname = 'KNA1'.
TRY.
CREATE DATA lr_dref TYPE TABLE OF (lv_tabname).
ASSIGN lr_dref->* TO <lfs_tab>.
CATCH cx_sy_create_data_error.
* Do something
ENDTRY.
SELECT * FROM (lv_tabname) INTO TABLE <lfs_tab> UP TO 50 ROWS.
lv_name1 = 'KUNNR'.
lv_name2 = 'NAME1'.
LOOP AT <lfs_tab> ASSIGNING <lfs_line>.
ASSIGN COMPONENT lv_name1 OF STRUCTURE <lfs_line> TO <lfs_field1>.
ASSIGN COMPONENT lv_name2 OF STRUCTURE <lfs_line> TO <lfs_field2>.
WRITE:/ <lfs_field1>, <lfs_field2>.
ENDLOOP.