Application Development and Automation 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: 
Read only

Differences

Former Member
0 Likes
1,203

Hi,

Difference between refresh and clear

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,167

clear -- to clear the data of the internal table header

clear[] -- to clear the body of the internal table

refresh -- clears the internal table data from header and body

free -- deletes the data of the internal table and also deletes the memory area allocated to the internal table

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

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

FREE <itab>.

You can use FREE to initialize an internal table and release its memory space without first using the REFRESH or CLEAR statement. Like REFRESH, FREE works on the table body, not on the table work area. After a FREE statement, you can address the internal table again. 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.

DATA: BEGIN OF LINE,

COL1,

COL2,

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 output is:

ITAB is empty.

In this program, 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.

To reset a variable var to the appropriate initial value for its type, use the statement

CLEAR var.

This statement has different effects for different data types:

&#65399; Elementary ABAP types

The CLEAR statement sets the value of elementary variables to their initial value (see the keyword documentation) not to the start value, which is set using the VALUE parameter of the DATA statement.

&#65399; References

The CLEAR statement resets a reference variable to its initial value, that is, so that it does not point to an object.

&#65399; Structures

The CLEAR statement resets the individual components of a structure to their respective initial values.

&#65399; Internal tables

The CLEAR statement deletes the entire contents of an internal table (see also Initializing Internal Tables).

You cannot use the CLEAR statement to reset a constant.

REPORT demo_data_clear.

DATA number TYPE i VALUE '10'.

WRITE number.

CLEAR number.

WRITE / number.

The output appears as follows:

10

0

The CLEAR statement resets the contents of the field number from 10 to its initial value 0.

Free - It deletes all the rows and free the associated memory i.e. free itab.

refresh - It deletes all the rows but memory remains allocated i.e. refresh itab.

Clear - It deletes all the rows and leave the memory allocated but clear the header line i.e. clear itab.To clear the Intertal Table Hearder as well Body we can use Clear ITAB [ ] statement.

chk this also

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb384e358411d1829f0000e829fbfe/frameset.htm

yntax

CLEAR dobj [ {WITH val [IN {BYTE|CHARACTER} MODE] }

| {WITH NULL} ].

Effect

Without the optional additions, the data object dobj is assigned the type-specific initial value. The following applies:

The initial values are assigned to elementary data types according to the table of built-in ABAP types.

Reference variables are assigned null references.

Structures are set to their initial values component by component.

All rows in an internal table are deleted. All the memory required for the table, except for the initial memory requirement, is released (see Declaring Internal Tables). The FREE statement is used to release the memory space occupied by the rows of internal tables.

The optional additions allow you to fill the spaces of a data object with other values than the initial value.

Note

If dobj is an internal table with a header line, you must specify dobj[] to delete the rows, otherwise only the header line will be deleted.

Addition 1

... WITH val [IN {BYTE|CHARACTER} MODE]

Effect

If you use the WITH val addition and specify BYTE or CHARACTER MODE, all spaces are replaced either with the first byte or the first character in val. If dobj is of the type string or xstring (as of Release 6.10), the string is processed in its current length.

The IN BYTE and CHARACTER MODE additions can be used as of Release 6.10 (see also Processing Byte Strings and Character Strings ). Without specification and before Release 6.10 the IN CHARACTER MODE addition applies. Depending on the addition, the data object dobj must be either byte-type or character-type and the data object val must be either byte-type or character type and have the length 1. Before Release 6.10, dobj and val must be flat. If dobj and val do not have the correct type and correct length in a non- Unicode program, they are still handled as if they do, independently of the actual type. In Unicode programs, this will cause a Syntax error or an exception that cannot be handled.

Example

The byte string hexstring as assigned a specific byte value over the entire current length.

DATA: hexstring TYPE xstring,

hex(1) TYPE x VALUE 'FF'.

...

hexstring = '00000000'.

...

CLEAR hexstring WITH hex IN BYTE MODE.

Addition 2

... WITH NULL

Effect

This addition, which is not allowed in ABAP Objects, replaces all bytes of dobj with the value hexadecimal 0. In this case, the data object dobj must be flat.

Note

The WITH NULL addition should only be used for byte-type data objects and therefore be replaced with the CLEAR WITH val addition, which - in this context - at least ensures a higher level of security in Unicode programs.

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.

FORMAT RESET.

This addition sets all formatting settings for which the corresponding addition is not specified in the same FORMAT statement to the state OFF, apart from the setting of the FRAMES addition, which is set to ON. For settings whose addition is also specified, the RESET addition has no effect,

But if you need regarding REFRESH

REFRESH itab.

Effect

This statement sets an internal table itab to its initial value, meaning that it deletes all rows of the internal table. The memory space required for the table is freed up to the initial memory size INITIAL SIZE. For itab, you must specify an internal table.

To delete all rows and free the entire memory space occupied by rows, you can use the statement FREE.

Reward Points for useful answers

12 REPLIES 12
Read only

Former Member
0 Likes
1,167

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

Read only

Former Member
0 Likes
1,167

clear is used to clear the header values of itab...

refresh is used to clear the itab contents.. with refresh itab header contents remain unchanged

Read only

former_member194152
Contributor
0 Likes
1,167

Hi,

refresh will delete all content from internal table while using CLEAR it will delete content of work area or fields only.

Regards

Gagan

Read only

former_member188770
Active Participant
0 Likes
1,167

Refresh : Complete table gets reset

Clear : Only header is reset

Read only

Former Member
0 Likes
1,167

hi,,

shyam

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

Read only

Former Member
0 Likes
1,167

Hi,

CLEAR resets to its initial values..

1.

For structure it will clear all the fields in the structure..

EX:

DATA: S_MARA LIKE MARA.

CLEAR: S_MARA.

2. For internal tables if it is declared with header line then it clear the header line otherwise it will clear the whole internal table..

EX:

DATA: ITAB TYPE STANDARD TABLE OF MARA WITH HEADER LINE.

CLEAR: ITAB.. " THis will clear the header line..

DATA: ITAB TYPE STANDARD TABLE OF MARA.

CLEAR: ITAB.. " THis will clear the whole internal table..

3. Refresh clear the internal tables irrespective of with or without header line.

4. Clear can be used for variables, work areas and internal tables..

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.

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

Read only

Former Member
0 Likes
1,167

Hi,

refresh clears the whole internal table and clear will clear the variables and we clear internal tables also.

Read only

Former Member
0 Likes
1,167

Hi,

Refresh : This statement is use to clear all the contents of the table. But if the table has a header line also and both contain some data, then only the table contents are cleared and the header line is left untouched.

Clear : Clear can be used to clear the contents of the header line as well as the table.

e.g. Clear : itab will clear the header line

Clear itab[] will clear the contents of the table

Regards,

Himanshu

Read only

Former Member
0 Likes
1,168

clear -- to clear the data of the internal table header

clear[] -- to clear the body of the internal table

refresh -- clears the internal table data from header and body

free -- deletes the data of the internal table and also deletes the memory area allocated to the internal table

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

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

FREE <itab>.

You can use FREE to initialize an internal table and release its memory space without first using the REFRESH or CLEAR statement. Like REFRESH, FREE works on the table body, not on the table work area. After a FREE statement, you can address the internal table again. 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.

DATA: BEGIN OF LINE,

COL1,

COL2,

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 output is:

ITAB is empty.

In this program, 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.

To reset a variable var to the appropriate initial value for its type, use the statement

CLEAR var.

This statement has different effects for different data types:

&#65399; Elementary ABAP types

The CLEAR statement sets the value of elementary variables to their initial value (see the keyword documentation) not to the start value, which is set using the VALUE parameter of the DATA statement.

&#65399; References

The CLEAR statement resets a reference variable to its initial value, that is, so that it does not point to an object.

&#65399; Structures

The CLEAR statement resets the individual components of a structure to their respective initial values.

&#65399; Internal tables

The CLEAR statement deletes the entire contents of an internal table (see also Initializing Internal Tables).

You cannot use the CLEAR statement to reset a constant.

REPORT demo_data_clear.

DATA number TYPE i VALUE '10'.

WRITE number.

CLEAR number.

WRITE / number.

The output appears as follows:

10

0

The CLEAR statement resets the contents of the field number from 10 to its initial value 0.

Free - It deletes all the rows and free the associated memory i.e. free itab.

refresh - It deletes all the rows but memory remains allocated i.e. refresh itab.

Clear - It deletes all the rows and leave the memory allocated but clear the header line i.e. clear itab.To clear the Intertal Table Hearder as well Body we can use Clear ITAB [ ] statement.

chk this also

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb384e358411d1829f0000e829fbfe/frameset.htm

yntax

CLEAR dobj [ {WITH val [IN {BYTE|CHARACTER} MODE] }

| {WITH NULL} ].

Effect

Without the optional additions, the data object dobj is assigned the type-specific initial value. The following applies:

The initial values are assigned to elementary data types according to the table of built-in ABAP types.

Reference variables are assigned null references.

Structures are set to their initial values component by component.

All rows in an internal table are deleted. All the memory required for the table, except for the initial memory requirement, is released (see Declaring Internal Tables). The FREE statement is used to release the memory space occupied by the rows of internal tables.

The optional additions allow you to fill the spaces of a data object with other values than the initial value.

Note

If dobj is an internal table with a header line, you must specify dobj[] to delete the rows, otherwise only the header line will be deleted.

Addition 1

... WITH val [IN {BYTE|CHARACTER} MODE]

Effect

If you use the WITH val addition and specify BYTE or CHARACTER MODE, all spaces are replaced either with the first byte or the first character in val. If dobj is of the type string or xstring (as of Release 6.10), the string is processed in its current length.

The IN BYTE and CHARACTER MODE additions can be used as of Release 6.10 (see also Processing Byte Strings and Character Strings ). Without specification and before Release 6.10 the IN CHARACTER MODE addition applies. Depending on the addition, the data object dobj must be either byte-type or character-type and the data object val must be either byte-type or character type and have the length 1. Before Release 6.10, dobj and val must be flat. If dobj and val do not have the correct type and correct length in a non- Unicode program, they are still handled as if they do, independently of the actual type. In Unicode programs, this will cause a Syntax error or an exception that cannot be handled.

Example

The byte string hexstring as assigned a specific byte value over the entire current length.

DATA: hexstring TYPE xstring,

hex(1) TYPE x VALUE 'FF'.

...

hexstring = '00000000'.

...

CLEAR hexstring WITH hex IN BYTE MODE.

Addition 2

... WITH NULL

Effect

This addition, which is not allowed in ABAP Objects, replaces all bytes of dobj with the value hexadecimal 0. In this case, the data object dobj must be flat.

Note

The WITH NULL addition should only be used for byte-type data objects and therefore be replaced with the CLEAR WITH val addition, which - in this context - at least ensures a higher level of security in Unicode programs.

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.

FORMAT RESET.

This addition sets all formatting settings for which the corresponding addition is not specified in the same FORMAT statement to the state OFF, apart from the setting of the FRAMES addition, which is set to ON. For settings whose addition is also specified, the RESET addition has no effect,

But if you need regarding REFRESH

REFRESH itab.

Effect

This statement sets an internal table itab to its initial value, meaning that it deletes all rows of the internal table. The memory space required for the table is freed up to the initial memory size INITIAL SIZE. For itab, you must specify an internal table.

To delete all rows and free the entire memory space occupied by rows, you can use the statement FREE.

Reward Points for useful answers

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,167

CLEAR initialize a record, field, structure

REFRESH initialize an internal table, all records are deleted

<i>Confusion may arise due to fact that CLEAR itab[] has the same effect as REFRESH itab.</i>

Also, don't forget FREE to release the memory used by the internal table (or other objects)

Regards

Read only

Former Member
0 Likes
1,167

Hi,

<b>Refresh</b> used to clear the internal table.

<b>clear</b> works on the work area.

refresh itab. (itab internal table)

clear wa_itab (wa_itab work area of itab)

hope this works.

Read only

aris_hidalgo
Contributor
0 Likes
1,167

Hi,

The REFRESH statement deletes the contents of your internal table while CLEAR statement

only delete the contents of your header line or variables.

*This will delete all records from your internal tables gt_vbak.

REFRESH gt_vbak.

*This will delete the records from your header line or variable

CLEAR gt_vbak.

clear: gv_flag.

P.S. Please award points if it helps...