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

Doubt with Clear and Refresh

Former Member
0 Likes
1,459

Hi All,

I have a doubt with Clear and Refresh with Internal Tables.

Clear Internal Table with Header Line clears the Header Line only.

Clear Internal Table without Header Line clears the body of the table.

Refresh with or without the Header Line clears the body of the table.

Now,if I have to first clear the Header line of an Internal table and then clear the body of the same Internal table, I guess I have 2 options as mentioned below :

1.First use clear Internal table with header line and it clears the Header line of the table and then use Clear the same Internal table and its body would be cleared as there is no header line left.

2.First use clear Internal table with header line and it clears the Header line of the table and then use Refresh the same internal table and it will clear the body of the internal table.

What are the differences between these 2 options???

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,420

suppose itab is ur table with 5 entries ..

1.

itab[ ] = 5 entries " option 1 .

2.

loop at itab

clear itab.

endloop.

will fetch the first record into the header .

clear itab will clear the header line .

means the contents in the table are present but none in the header line .

refresh itab --> effect is the contents itab[5] are cleared from the table .

execute the code with case 1 and case 2 independently .

data : begin of itab occurs 0 ,
       f1(5) type c ,
       end of itab .


      itab-f1 = '001'.
      APPEND ITAB.

      itab-f1 = '002'.
      APPEND ITAB.

      itab-f1 = '003'.
      APPEND ITAB.
*CASE 1.
      LOOP AT ITAB .
      CLEAR ITAB.
      WRITE:/ ITAB-F1.
      ENDLOOP.
*EFFECT --> NO OUTPUT 
*CASE 2.
      REFRESH ITAB.
      LOOP AT ITAB.
      WRITE:/ ITAB-F1.
      ENDLOOP.
*EFFECT --> NO OUTPUT .

play around commenting clear and refersh and u ;'ll have an idea .

regards,

vijay

Hi All,

I have a doubt with Clear and Refresh with Internal Tables.

Clear Internal Table with Header Line clears the Header Line only.

Clear Internal Table without Header Line clears the body of the table.

Refresh with or without the Header Line clears the body of the table.

Now,if I have to first clear the Header line of an Internal table and then clear the body of the same Internal table, I guess I have 2 options as mentioned below :

1.First use clear Internal table with header line and it clears the Header line of the table and then use Clear the same Internal table and its body would be cleared as there is no header line left.

2.First use clear Internal table with header line and it clears the Header line of the table and then use Refresh the same internal table and it will clear the body of the internal table.

What are the differences between these 2 options???

11 REPLIES 11
Read only

Former Member
0 Likes
1,420

Hi

CLEAR ITAB-----WILL CLEAR ONLY HEADER LINE OF ITAB BUT NO EFFECT ON BODY OF ITAB

CLEAR ITAB[]---CLEAR THE BODY OF ITAB BUT HEADER LINE WILL NOT BE AFFECTED

REFRESH ITAB---BOTH HEADER AND BODY WILL BE CLEARED but memory for itab will be there.

REFRESH can be used only for internal tables but not for variables whereas CLEAR can be used for variables to store the default values for variables.

Regs

Manas Ranjan Panda

Message was edited by:

MANAS PANDA

Read only

0 Likes
1,420

Hi,

Thanks for the reply.

But Refresh itab does not clear the header line.It just clears the body of the internal table irrespective of the table with or without header line,i.e

Clear itab[] = refresh itab.

Just try it in the debug mode.

Read only

0 Likes
1,420

hi puneet,

you are right.

refresh itab = clear itab[].

there is no performance issue.

<b><i>but refresh will not relaese the memory .</i></b>

clear : wa_area,itab[].

or

clear wa_area.

refresh itab.

rgds

anver

pls mark all helpful answers

Read only

Former Member
0 Likes
1,420

clear : itab , itab[].

and

clear itab.

refresh itab.

are same

Read only

0 Likes
1,420

Hey,

Thanks for the reply.

But my question was that both the options mentioned by me work in the same manner,then why do we have refresh?

We can use clear in both the cases.

Is there any performance issue related to it?

Read only

0 Likes
1,420

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

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

Read only

Former Member
0 Likes
1,420

clear is used to clear contents of header line or variables etc....

refresh is used to clear contents of internal table...
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..

Message was edited by:

Ramesh Babu Chirumamilla

Read only

Former Member
0 Likes
1,420

Hi puneet,

1. I usually prefer this simple statement.

*----


internal table with header line

REFRESH ITAB.

CLEAR ITAB.

2.

*----


internal table WITHOUT header line

CLEAR ITAB.

regards,

amit m.

Read only

Former Member
0 Likes
1,421

suppose itab is ur table with 5 entries ..

1.

itab[ ] = 5 entries " option 1 .

2.

loop at itab

clear itab.

endloop.

will fetch the first record into the header .

clear itab will clear the header line .

means the contents in the table are present but none in the header line .

refresh itab --> effect is the contents itab[5] are cleared from the table .

execute the code with case 1 and case 2 independently .

data : begin of itab occurs 0 ,
       f1(5) type c ,
       end of itab .


      itab-f1 = '001'.
      APPEND ITAB.

      itab-f1 = '002'.
      APPEND ITAB.

      itab-f1 = '003'.
      APPEND ITAB.
*CASE 1.
      LOOP AT ITAB .
      CLEAR ITAB.
      WRITE:/ ITAB-F1.
      ENDLOOP.
*EFFECT --> NO OUTPUT 
*CASE 2.
      REFRESH ITAB.
      LOOP AT ITAB.
      WRITE:/ ITAB-F1.
      ENDLOOP.
*EFFECT --> NO OUTPUT .

play around commenting clear and refersh and u ;'ll have an idea .

regards,

vijay

Read only

Former Member
0 Likes
1,420

Hi,

What you said is right?

As per your Question, If you want to Clear the internal table header first , You use, CLEAR <ITAB>, Which clears, only the header.

Then use CLEAR <itab>[] , This will clears, only the body.

This is the right options. As use said, no need to use REFRESH again.

If you feel satisfied reward me points

Thanks

Manju Nagendra

Read only

Former Member
0 Likes
1,420

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.

hope this clears you doubts