Skip to Content

Introduction

Dynamic Internal tables concept comes into existence when the developer is not sure of the structure of the internal table. This concept creates the structure and internal table during run time.

This document will explain the process of creating and processing dynamic internal tables.

Steps to be followed

Ø Create a reference variable.

DATA : wa_dref TYPE REF TO DATA.

Ø Create two field symbols; one for the internal table and other for the work area.

FIELD-SYMBOLS : <t_itab> TYPE ANY TABLE,
                <wa_itab>.

Ø Create a reference to the Structure for which you need to create a Dynamic Internal Table.

CREATE DATA wa_dref TYPE TABLE OF (s_tables-low).

Ø Assign this reference to the field symbol created for the Dynamic Internal Table.

ASSIGN wa_dref->* TO <t_itab>.

Now, <t_itab> will take the structure of the contents of the field s_tables-low.

Ø Create a reference to the internal table for which you need to create a Dynamic Work Area.

CREATE DATA wa_dref LIKE LINE OF <t_itab>.

Ø Assign this reference to the field symbol created for the Work Area.

ASSIGN wa_dref->* TO <wa_itab>.

Now, <wa_itab> will take the structure of the internal Table <t_itab>.

Ø Selecting data from the table whose name is held by s_tables-low is as follows.

    SELECT * FROM (s_tables-low)
     
INTO TABLE <t_itab>.

Note: The variable which holds the name of the table from which data has to be fetched should be mentioned within brackets.

Ø Processing Dynamic Internal Tables and Work Areas is the same as normal Internal Tables and Work Areas.

LOOP AT <t_itab> INTO <wa_itab>.

ENDLOOP.

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Former Member

    Thanks by the post.

    Could you, please, examplify how to access values from workarea’s field?

    Let’s say the (s_tables-low) refers to MARA table. How can I get value from MATNR field?

    (0) 
    1. Former Member

      you have to use the following syntax . suppose the table is <fs_tab> of type mara.

      <fs_tab> is a field symbol.

      define field-symbols : <matnr> type mara-matnr.

      loop at <fs_tab> assigning <fs_wa>.

      assign component ‘MATNR’ of structure <fs_wa> into <fs_matnr>.

      endloop.

      whatever value you change in <fs_matnr> automatically refers to the <fs_tab> table. no need to modify.

      (0) 

Leave a Reply