ABAP: How to create a dynamic internal table and work area

7
ABAP Structure
FIELD-SYMBOLS:<fs_table> TYPE STANDARD TABLE,  <fs_table_wa> TYPE ANY.
DATA:  table_ref TYPE REF TO data, wa_ref TYPE REF TO data.
DATA: l_structure TYPE dd02l-tabname value 'VBAP'.
 
CREATE DATA table_ref TYPE STANDARD TABLE OF (l_structure).
ASSIGN table_ref->* TO <fs_table>.
CREATE DATA wa_ref LIKE LINE OF <fs_table>.
ASSIGN wa_ref->* TO <fs_table_wa>.

Now you have the table <fs_table> and the work area for it <fs_table_wa>.

To know more about Internal tables, check this post on Internal tables.

7 thoughts on “ABAP: How to create a dynamic internal table and work area

  1. Hi,

    Sorry but it is a very crappy method. SAP use generated form to declare data, so you are limited by the stack size for the number of call of this method. (approx. 20 times for my current sap system)

    It's better to use create data with a declared ddic structure (when possible)

  2. This instruction :
    generate subroutine pool lt_source[] name l_name
    message l_message line l_line word l_word.
    is used by the function "ALV_TABLE_CREATE" which is called by the method cl_alv_table_create=>create_dynamic_table (or perhaps called by a function called by the method 😉 )

    And in sap documentation you can read :
    Up to 36 temporary subroutine pools can currently be managed for each roll area. (not 20 as i said previously)

    So, this method is not usable in case of recurrent call. That's why a create data with ddic structure is betten, when possible.

  3. *&———————————————————————*
    *& Report ZDYN_INT_TABLES
    *&
    *&———————————————————————*
    *&
    *&
    *&———————————————————————*
    *dynamic hashed internal table
    REPORT zdyn_int_tables.

    FIELD-SYMBOLS: TYPE HASHED TABLE, TYPE any.
    DATA: table_ref TYPE REF TO data, wa_ref TYPE REF TO data.
    DATA: l_structure TYPE dd02l-tabname VALUE ‘RSRREPDIR’.

    CREATE DATA table_ref TYPE HASHED TABLE OF (l_structure) WITH UNIQUE KEY compuid objvers infocube.
    ASSIGN table_ref->* TO .
    SELECT * FROM (l_structure) INTO TABLE .
    CREATE DATA wa_ref LIKE LINE OF .
    ASSIGN wa_ref->* TO .

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: