Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Free, Clear and Refresh statements

Former Member
0 Kudos

What are the differences among FREE, CLEAR & REFRESH statements?

When we should use each? Please explain with example.

Regards,

Mau

1 ACCEPTED SOLUTION

Former Member
0 Kudos

CLEAR <itab>.

statement. This statement restores an internal table to the state it was in immediately after you declared it. This means that the table contains no lines. However, the memory already occupied by the memory up until you cleared it remains allocated to the table.

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 in a comparison, you must place two brackets ([ ]) after the table name.

CLEAR <itab>[].

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

REFRESH <itab>.

statement. This always applies to the body of the table. As with the CLEAR statement, the memory used by the table before you initialized it remains allocated. To release the memory space, use the statement

refresh should use only internal table,clear - you can use variables,internal table ,work areas

FREE : it is deallocating meomry

Thanks

Seshu

3 REPLIES 3

uwe_schieferstein
Active Contributor
0 Kudos

Hello Mau

That is what the ABAP keyword documentation says to FREE:

Syntax

FREE dobj.

Effect

The FREE statement has the same effect as the CLEAR

statement for any data objects except internal tables.

For internal tables, FREE has the same effect as the REFRESH statement. It releases the entire memory area occupied by the table rows. If dobj is a structure with table-like components, the memory of each table-like component is released.

Note

If dobj is an internal table with a header line , FREE has the same effect as REFRESH on the table body, and not the header line.

I personally have never used the FREE statements. Since I have banned itabs with header lines a long time ago I do not get confused using CLEAR and REFRESH:

- I use CLEAR to initialize (single) fields and structures

- I use REFRESH to initialize itabs (always WITHOUT header line)

Although it is also possible to initialize itabs using the CLEAR statement I stick to my rules for the following reasons:

- If you see a CLEAR statement in any of my programs you will know for sure the variable is either a field or structure (but NEVER an itab)

- If you see a REFRESH statement in any of my programs you will know for sure the variable is an itab

Thus, my rules enhance readability and maintainability of my programs.

Regards

Uwe

Former Member
0 Kudos

Hi Mau,

Free: Frees an internal table contents as well as its structure from the memory while a program is being executed.

Refresh: Just removes all the contents of an internal table. Keeps the structure in the memory.

Clear: Cleares the value of a work area / variable during execution of the program.

Regs,

Sameer

Former Member
0 Kudos

CLEAR <itab>.

statement. This statement restores an internal table to the state it was in immediately after you declared it. This means that the table contains no lines. However, the memory already occupied by the memory up until you cleared it remains allocated to the table.

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 in a comparison, you must place two brackets ([ ]) after the table name.

CLEAR <itab>[].

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

REFRESH <itab>.

statement. This always applies to the body of the table. As with the CLEAR statement, the memory used by the table before you initialized it remains allocated. To release the memory space, use the statement

refresh should use only internal table,clear - you can use variables,internal table ,work areas

FREE : it is deallocating meomry

Thanks

Seshu