Preface – This post is part of the Differences in ABAP for Interviews series.
Table of Contents
Introduction
Before discussing the differences between REFRESH and CLEAR statement, we will have a short introduction of the two. Both of these Statements are part of SAP ABAP Reports/Editors and are mainly used to clear out the used variables and save memory or reuse the variables.
REFRESH
REFRESH statement sets the internal table to its initial size by deleting all the rows of the internal table. This frees up the allocated memory for the internal table. A FREE statement is used to delete entire rows and free all the memory(used when the internal table is no longer needed).
Syntax of REFRESH statement:
REFRESH <itab>.
For an itab, an internal table has to be specified.
If an internal table itab has a header line, then the table body is initialized, not the table header. If itab has no header, it acts as a CLEAR itab statement. Hence, it is recommended to always use CLEAR statement instead of REFRESH.
The use of a table with a header line is forbidden in classes, which makes the use of the REFRESH statement obsolete.
CLEAR
CLEAR statement clears the header line as well as the rows of the internal table and work area. This frees up the allocated memory required for the internal table and sets it to its initial size.
Syntax of CLEAR statement:
CLEAR <dobj>.
For a dobj, itab or itab[] has to be specified.
CLEAR itab is used to clear only the header line and the table rows i.e. clear the content of the structure. If the table header line is not defined, CLEAR itab clears the table content.
CLEAR itab[] is used to clear the internal table contents.
Differences between REFRESH and CLEAR
Now, let’s have a look at their difference.
REFRESH statement | CLEAR statement |
It always refers to an internal table. | It refers to an internal table as well as a work area. |
Header line cannot be cleared using this statement. | Header line can be cleared using the CLEAR itab statement. |
0 Comments