SAP ABAP: Internal table

Andrew Yong Zheng Dao
2 min readApr 23, 2023

--

This post will illustrate the method to declare and implement an internal table in the SAP ABAP program.

What is the internal table?

In ABAP, internal tables are dynamic data and they fulfill the function of arrays. Internal tables provide a form of fixed structure and store it in working memory which is used to process a dataset from a database table with a fixed structure within a program. The data is stored and formatted line by line in memory, and each line has the same structure.

Declare the structure of an internal table.

TYPES: BEGIN OF i_tab,
EBELN TYPE EKKO-EBEL,
BUKRS TYPE EKKO-BURKS,
BSTYP TYPE EKKO-BSTYP,
BSART TYPE EKKO-BASRT,
LOEKZ TYPE EKKO-LOEKZ,
LIFNR TYPE EKKO-LIFNR,
END OF i_tab.

TYPES statement declares the structure lines as defined above. The TYPE keyword is used to refer to the datatype of the field in a database table. Use the commands below to create an internal table and work area of the internal table.

DATA: it_tab TYPE TABLE OF i_tab,
wa_tab TYPE it_tab.

TYPE TABLE OF is used for defining the variable of the internal table whereas TYPE is used for the work area of the internal table.

Populating internal table.

Write to internal table

SELECT EBELN BUKRS BSTYP BSART LOEKZ LIFNR
FROM EKKO INTO TABLE it_tab
WHERE EBELN EQ "<THE PURCHASE ORDER NUMBER>".

Append to internal table

APPEND wa_tab TO it_tab. 

Insert to internal table

INSERT wa_tab INTO it_tab [index <idx>].

Collect to internal table

COLLECT wa_tab INTO it_tab.

Read internal table

LOOP AT it_tab INTO wa_tab.
ENDLOOP.

.
.
.

OR

.
.
.

READ it_tab INTO wa_tab WITH KEY ebeln = "<THE PURCHASE ORDER NUMBER>" .

Delete internal table

DELETE it_tab.

Delete internal table by index

DELETE it_tab INDEX <IDX>.

--

--

No responses yet