0

In ABAP we can insert value into internal table with:

   insert wa into table my_table.

Question is, if the name of my_table can only be determined at runtime, how to tackle it? Something like following doesn't work unfortunately:

   insert wa into table ('my_table').

I tried with dynamic name in bracket but no success.

1 Answer 1

3

Use ASSIGN ('dobj_name') TO <fs_name>:

FIELD-SYMBOLS <any_table> TYPE ANY TABLE.
ASSIGN ('my_table') TO <any_table>.

Minimal reproducible program:

DATA my_table TYPE TABLE OF i.
DATA wa TYPE i.
FIELD-SYMBOLS <any_table> TYPE ANY TABLE.
ASSIGN ('my_table') TO <any_table>.
INSERT wa INTO TABLE <any_table>. " inserts one line in MY_TABLE

Other writing:

FIELD-SYMBOLS <any_table> TYPE ANY TABLE.
DATA(itab_name) = 'my_table'.
ASSIGN (itab_name) TO <any_table>.

Link to the ABAP documentation: ASSIGN, dynamic_dobj

Sign up to request clarification or add additional context in comments.

1 Comment

Further information for consideration: it's possible to SORT such a table dynamically: ``` sort <my_table> by ('comp1') ('comp2') ... ('comp9'). ``` or ``` sort <my_table> by (comp_table). ``` At the same time, constructor expressions will be quite limited: it's not possible to use # in the type specification or use dynamic tables in the FILTER and other expressions which require design type information about components.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.