Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125

How to create internal table dynamically ?

Internal tables are a core concept for storing structured data. You can create them dynamically at runtime using RTTS (Runtime Type Services).

DATA: lo_descr TYPE REF TO cl_abap_structdescr,
lo_table TYPE REF TO cl_abap_tabledescr,
lr_data TYPE REF TO data,
lr_line TYPE REF TO data.

“— Step 1: Define a structure dynamically
lo_descr = cl_abap_structdescr=>create(
VALUE #( ( name = ‘FIELD1’ type = cl_abap_elemdescr=>get_c( 10 ) )
( name = ‘FIELD2’ type = cl_abap_elemdescr=>get_i( ) ) )
).

“— Step 2: Create internal table description
lo_table = cl_abap_tabledescr=>create( lo_descr ).

“— Step 3: Create actual data object (the table)
CREATE DATA lr_data TYPE HANDLE lo_table.
ASSIGN lr_data->* TO FIELD-SYMBOL(<itab>).

“— Step 4: Create a line type and assign
CREATE DATA lr_line TYPE HANDLE lo_descr.
ASSIGN lr_line->* TO FIELD-SYMBOL(<wa>).

“— Step 5: Fill dynamically created table
<wa>-field1 = ‘Hello’.
<wa>-field2 = 123.
APPEND <wa> TO <itab>.

<wa>-field1 = ‘World’.
<wa>-field2 = 456.
APPEND <wa> TO <itab>.

“— Step 6: Loop through the dynamic internal table
LOOP AT <itab> ASSIGNING <wa>.
WRITE: / <wa>-field1, <wa>-field2.
ENDLOOP.

Key Points:
  1. Use RTTS (Runtime Type Services) → cl_abap_structdescr, cl_abap_tabledescr, cl_abap_elemdescr.
  2. Create data objects at runtime with CREATE DATA ... TYPE HANDLE.
  3. Use field symbols (<itab>, <wa>) to access the data.

 

Related Questions

Leave an answer

Leave an answer