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:

[pastacode lang=”markup” manual=”TYPES%20%3A%20begin%20of%20line%2C%20empno%20type%20I%2C%20empname(20)%20type%20c%20%2C%20end%20of%20line.” message=”” highlight=”” provider=”manual”/]

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

[pastacode lang=”markup” manual=”Data%20%5Bwith%20header%20line%5D.” message=”” highlight=”” provider=”manual”/]

Example

[pastacode lang=”markup” manual=”DATA%20itab%20TYPE%20line%20OCCURS%2010%20with%20header%20line.” message=”” highlight=”” provider=”manual”/]

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
[pastacode lang=”markup” manual=”LIKE%20occurs%20n%20%5Bwith%20header%20line%5D.” message=”” highlight=”” provider=”manual”/]

Example

[pastacode lang=”markup” manual=”DATA%20itab%20LIKE%20sline%20OCCURS%2010.” message=”” highlight=”” provider=”manual”/]

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

[pastacode lang=”markup” manual=”Data%20%3A%20Begin%20of%20occurs%20%2C%20%2C%20……………………………%2C%20End%20of%20.” message=”” highlight=”” provider=”manual”/]

Example –

Data :
[pastacode lang=”markup” manual=”Begin%20of%20itab%20occurs%2010%2C%20column1%20type%20I%2C%20column2(4)%20type%20C%2C%20column3%20like%20mara-ernam%2C%20End%20of%20itab.” message=”” highlight=”” provider=”manual”/]

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:
[pastacode lang=”markup” manual=”Begin%20of%20itab%20occurs%2010%2C%20col1%20type%20C%2C%20col2%20type%20I%2C%20end%20of%20itab.%20Append%20initial%20line%20to%20itab.” message=”” highlight=”” provider=”manual”/]

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