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

FREE Statement

Former Member
0 Likes
1,464

Hi friends,

i have a question for the experts here.

iam using FREE statment in my code

now what i know is this free statment wil do ie: FREE: removes the internal table from the memory by deleting data and everything.

now iam using the below code

CODE :

DATA :

BEGIN OF IT_MARA OCCURS 0,

MATNR TYPE MARA-MATNR,

MTART TYPE MARA-MTART,

WERKS type MARC-WERKS,

LGORT type MARD-LGORT,

END OF IT_MARA.

IT_MARA-MATNR = 1.

iT_MARA-WERKS = 1000.

IT_MARA-LGORT = 100.

APPEND IT_MARA.

IT_MARA-MATNR = 2.

iT_MARA-WERKS = 2000.

IT_MARA-LGORT = 200.

APPEND IT_MARA.

FREE IT_MARA.

IT_MARA-MATNR = 3.

iT_MARA-WERKS = 3000.

IT_MARA-LGORT = 300.

APPEND IT_MARA.

now free is removing the contents of the body of the internla table.

now as said earlier that free will dealocate the memory of the internal table also,

now what does this mean..? where does it dealocate the memory..?

as per my understanding is that the same 8kb of memory which is allocated for occurs 0 as default if we dont mention.

now if it dealocates the memory then there will no memory for my internal table but when iam again appending the values to the internal table after free statement , its appending the values to that particular internal table whose memory is deleted already by using free statement.

does the free statment is failing here or where exactly the memory is dealocated.

can any expert tell me

Regards

Satish.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,120

yes.. FREE dealocates the memory..

i guess after free when u are appending it reallocates the memory..

u should use refresh for your need.

8 REPLIES 8
Read only

Former Member
0 Likes
1,121

yes.. FREE dealocates the memory..

i guess after free when u are appending it reallocates the memory..

u should use refresh for your need.

Read only

0 Likes
1,120

Hi,

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.

KR Jaideep,

Read only

Former Member
0 Likes
1,120

You can use FREE to directly initialize an internal table and to release its entire memory space, including the initial memory requirement, without first using the REFRESH or CLEAR statements. Like REFRESH, FREEaccesses the table body, not the table work area. After a FREEstatement, the internal table still exists. 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.

That is why it is not a good idea to use FREE when you have an intention of refilling your internal table, you should rather use refresh or clear[] (Refresh is obsolete as well).

Use Free when you are sure not to reuse an internal table again. In a big program its going to help your program's performance.

Hope it helps!

Read only

Former Member
0 Likes
1,120

Hi Satish,

As you know you Internal Tables are Dynamically Expandable,,,!.. If you have a small amount of memory also the it will expand itself...!

Thanks & regards,

Dileep .C

Read only

0 Likes
1,120

By the above answer i got that when we are trying to append the values again to the internal table after using the free statement It still occupies the amount of memory required for its header.

ITAB

FREE ITAB

append wa to ITAB.

now WA is the work area which i have created ie: ITAB is the internal table without header.

now for this we are creating WA explicitly.

now from above i got after using the free statement It still occupies the amount of memory required for its header.

The work area is different and internal table is different.

now if i use free WA also the will the memory of the work area will also be deleted....?

or not.

If deleted there will be no memory available to it. now from where does the internal table gets the memory back.

will this work for varaible also..?

example :

data :

l_num type i.

l_num = '10'.

free l_num.

l_num = '20'.

free l_num.

its agian assigning the value back to the varaible.

can any expert jsutify this.

Regards

Satish

Read only

0 Likes
1,120

Hi,

When you refill the table, the system has to allocate new memory space to the lines.

KR Jaideep,

Read only

0 Likes
1,120

see when declaring the internal table or work area or varaible the memory will be allocated.

now we are freein the memory of those by using FREE statement.

since the memory is lost from where does it get the memory again.

as we are just appending the values into those but not declaring them again.

Regards

Satish

Read only

0 Likes
1,120

Hi,

System is intelligent enough once you access the variable once again it allocates the memory for the internal table.

KR Jaideep,