Clear , Free and Refresh Statement in SAP ABAP | Memory clean up statements in SAP ABAP programming


ABAP Statement - Clear 

CLEAR statement in ABAP programming is used for resetting the variables values to their initial values depending on the data types.

For example CLEAR statement with an integer variable will reset its value as 0.
For an Internal table it will clear all the contents of that internal table. For structures it will CLEAR each components of the structure.
Reference variables are assigned the null reference.
In the case of CLEAR, the initial memory requirements of an internal table are not released, which can have a performance issue when inserting new rows in the internal table.
INITIAL SIZE  get allocated - when declaring an internal table – Declared by the system.
If an internal table is having a header line, itab [] must be specified to delete the rows including the header line.
Syntax  –
Clear XXX.    /// CLEAR itab. / CLEAR ITAB [].
DATA it_data TYPE STANDARD TABLE OF ty_data WITH HEADER LINE.


ABAP Statement - Free

Mainly used for internal table used in ABAP CODE.
The statement FREE deletes all rows from an internal table and releases the memory area that the rows occupied.
For structure with table like component - the memory of all the table-like components is released.
In general, FREE should be used only if the entire memory is to be released in full and the internal table is no longer needed (or at the least not filled again right away)

Syntax –
FREE itab.

ABAP Statement - Refresh

Mainly used to internal table in ABAP code.
This statement deletes all rows in an internal table itab. This frees up the memory space required for the table, except for the initial memory requirement (see INITIAL SIZE). 
If the internal table itab has a header line --------------
The statement REFRESH itab will initialize the table body and not the header line. But using Clear itab [] , it removes the header line as well.
If the internal table itab does not have a header line, REFRESH itab has the same effect as CLEAR itab. 
DATA it_data TYPE STANDARD TABLE OF ty_data WITH HEADER LINE.


Watch the video for the explanation -





No comments:

Post a Comment