Declaration of internal tables ABAP
There are many options for defining internal tables. I'm going to consider each of them in detail. We’ll also take a look at the new definition option, inline declaration, introduced in version 7.4.
Definition based on structure, database table or dictionary item
Having determined the structure or element of the desired type in the dictionary, based on it we create an internal table as follows:
DATA: lt_text TYPE STANDARD TABLE OF tline. " tline - this is a dictionary structure DATA: lt_vbak TYPE STANDARD TABLE OF vbak. " vbak - this is a db table DATA: lt_vkorg TYPE STANDARD TABLE OF vkorg. " vkorg - this is an element of the dictionary
The example shows standard types, we can also use custom data types. I want to highlight that when accessing a column of an internal table, defined through an element, the name of this column will not be vkorg, but table_line (the standard name) for tables defined in this way.
Local structure declaration
Using this method, a local structure is defined, in a program, method, or subprogram, after which the table is defined similarly.
TYPES: BEGIN OF ts_data, vkorg TYPE vkorg, werks TYPE werks_d, matnr TYPE matnr, END OF ts_data. DATA: lt_text TYPE STANDARD TABLE OF ts_data. " ts_data - this is a local structure
Dictionary based table type definition
When determining the type of a table in a dictionary, it is possible to set additional properties of a table, defined using this type, for example, a key, etc. A table type simplifies the declaration of an internal table.
DATA: lt_text TYPE tline_tab. " tline_tab - this is a table type from a dictionary
Inline declaration of internal tables
This method of definition has been available since version 7.4. Using this method an internal table is defined without specifying a type in advance.
That means, the program understands what type is needed and forms a table according to this type.
You can read more about the inline declaration including internal tables in the article Inline declaration.
Here are some examples:
" Definition of the table and its filling in one line DATA(lt_ekpo) = VALUE ekpo( ( ebeln = '1000000091' ebelp = '00010' ) ). " Declaration of the table inline, with the necessary columns SELECT ebeln, ebelp INTO TABLE @DATA(lt_ekpo) FROM ekpo UP TO 5 ROWS. " We pass the table inline to the input and to the output we also get zcl_proc_table=>factory( EXPORTING t_table = VALUE #( ( day = '22' year = 2020 ) ) IMPORTING t_res_table = DATA(lt_result) ).
Defining a table with a title bar (outdated)
This design is outdated, but you still need to know it, because sometimes it occurs, for example, on older systems or in standard code.
DATA: lt_text TYPE STANDARD TABLE OF tline WITH HEADER LINE. " tline - this is the structure of the dictionary (other options are possible)
In the near future there will be an article with a detailed description of working with internal tables, writing and reading data from them.