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

ABAP: How to create a dynamic internal table and work area
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.

ERP Avatar

7 responses to “ABAP: How to create a dynamic internal table and work area”

  1. Sebastien Avatar

    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. Sebastien Avatar

    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.

    1. sapdb_info Avatar

      Nice, thanks for your inputs. Updated the code 🙂

  3. Planning and scheduling Avatar

    I can not imagine finding this information right on time, thank you.

  4. Fatburner Avatar
    Fatburner

    Ever heard of ABAP Runtime Type Services classes that are available since 6.40? There are Object-Oriented APIs for dynamic creation and instantiation of strtuctures, internal tables and so on. For more info you can have a look at:

    http://help.sap.com/abapdocu_70/en/ABENCREATE_DAT

    Best Regards and a Happy New Year:)

  5. raj Avatar
    raj

    *&———————————————————————*
    *& 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 to Sebastien Cancel reply

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