Internal Table with and Without Header

What is a Work Area ? Work areas are single rows of data. They  should have the same format as any of the internal tables. It is used to process the data in an internal table one line at a time. Difference Between Internal Table and a Work Area ? A picture says a thousand […]

What is a Work Area ? Work areas are single rows of data. They  should have the same format as any of the internal tables. It is used to process the data in an internal table one line at a time. Difference Between Internal Table and a Work Area ? A picture says a thousand […]

What is a Work Area ?

Work areas are single rows of data. They  should have the same format as any of the internal tables. It is used to process the data in an internal table one line at a time.

Difference Between Internal Table and a Work Area ?

A picture says a thousand words SAP ABAP Internal Table: Create, Read, Populate, Copy & Delete

Types of Internal Tables

There are two types of internal tables.

  1. Internal tables with HEADER line
  2. Internal tables without HEADER line.

Internal Tables with Header Line

  • Here the system automatically creates the work area.
  • The work area has the same data type as internal table.
  • This work area is called the HEADER line.
  • It is here that all the changes or any of the action on the contents of the table are done. As a result of this, records can be directly inserted into the table or accessed from the internal table directly.

Internal Tables without Header Line :

  • Here there is no work area associated with the table.
  • Work area is to be explicitly specified when we need to access such tables.
  • Hence these tables cannot be accessed directly.

Creating Internal Tables

There are many ways to create an Internal Table. Lets look at them one by one-

1.By Using the Type Statement

Let us now create a Internal table itab using the TYPE statement.

The syntax is –

Example:

TYPES : begin of line, empno type I, empname(20) type c , end of line.

The TYPES statement creates a structure line as defined. To actually create an Internal Table itab use the following command. Data itab type line occurs 10.

An internal table itab is created with the structure of line.Besides declaring the structure of an internal table, the OCCURS clause also defines how many table entries are maintained in main storage(in this case 10). Extra records are written out to paging area and can effect performance.
.
2.By referring to another Table.

You can  create an internal table by referring to an existing table. The existing table could be a standard SAP table, a Z table or another internal table.

Syntax

Data [with header line].

Example

DATA itab TYPE line OCCURS 10 with header line.

Here an internal table itab is created of the type line with a header line. Please note “with header line” is optional
3.By referring to existing Structure
Syntax

Data
LIKE occurs n [with header line].

Example

DATA itab LIKE sline OCCURS 10.

Here  a table itab is created having a structure same as that of sline

4.By creating a new Structure

Let us now create an internal table with a structure of our own. Here the table is created with an Header line, by default. Syntax

Data : Begin of occurs , , ................................., End of .

Example –

Data :
Begin of itab occurs 10, column1 type I, column2(4) type C, column3 like mara-ernam, End of itab.

Internal table itab is created

Populating Internal Tables

Now that we have successfully created some internal tables, let us see how do we populate them with some records. There are various methods available to populate tables
1.Append Data line by line

The first method available is the use of the APPEND statement.

Using the APPEND statement we can either add one line from another work area to the internal table or we can add one initial line to the internal table..

Syntax –

APPEND [ TO / INITIAL LINE TO] .

Here work area or the Initial Line is appended to the internal table .

The system variable SY-TABIX contains the index of the appended line.

Example:

Data:
Begin of itab occurs 10, col1 type C, col2 type I, end of itab. Append initial line to itab.

Source: https://www.guru99.com/all-about-sap-internal-tables.html

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments