Entering content frame

Initializing Internal Tables Locate the document in its SAP Library structure

Like all data objects, you can initialize internal tables with the

CLEAR itab.

The memory space required for the table is released, except for the initial memory requirement.

If you are using internal tables with header lines, remember that the header line and the body of the table have the same name. If you want to address the body of the table itself, not the header line, during initialization using CLEAR, you must place two square brackets ([]) after the table name.

CLEAR itab[].

To ensure that the table itself has been initialized, you can use the statement

REFRESH itab.

This always applies to the body of the table. With REFRESH, too, the initial memory requirement fort he table remains reserved. To release this memory space, use the statement

FREE itab.

You can use FREE to directly initialize an internal table and to release its entire memory space, including the initial memory requirement, without first using the REFRESH or CLEAR statements. Like REFRESH, FREEaccesses the table body, not the table work area. After a FREEstatement, the internal table still exists. It still occupies the amount of memory required for its header (currently 256 bytes). When you refill the table, the system has to allocate new memory space to the lines.

Example

REPORT demo_int_tables_clear.

DATA: BEGIN OF line,
         col1(1) TYPE c,
         col2(1) TYPE c,
      END OF line.

DATA itab LIKE TABLE OF line.

line-col1 = 'A'. line-col2 = 'B'.

APPEND line TO itab.

REFRESH itab.

IF itab IS INITIAL.
  WRITE 'itab is empty'.
  FREE itab.
ENDIF.

The list output is:

itab is empty.

An internal table itab is filled and then initialized with REFRESH. The IF statement uses the expression itab IS INITIAL to find out whether itab is empty. If so, the memory is released.

 

 

 

Leaving content frame