Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Passing Fields for Lookup into Function Module

Former Member
0 Likes
529

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
493

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.

3 REPLIES 3
Read only

Former Member
0 Likes
494

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.

Read only

0 Likes
493

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]".

Read only

0 Likes
493

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.