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: 

Internal Tables performance and memory allocation

Former Member
0 Kudos

Hi all,

1) itab with out header line and explicit work area

2) itab with header line (occurs 0)

3) itab with header line ( occurs 10(some number))

for the above

1)which one is better with respect to performance and

2)how memory is allocated for these.

Thanks in Advance.

SAI

1 ACCEPTED SOLUTION

Former Member
0 Kudos

The number <N> indicate how many lines has to have the table in initialization time: i.e. when the program is loaded in memory, the space for the table depends on the initialization numbers of the records.

AT run time if the table needs more space, this'll automatically be enhanced.

But If you know your table can have a certain numbers of records, you can indicate it in the defination, what'll improve the performance:

all the space the table needs is taken at the beginin, so it doesn't need to enhance the space at run time.

When this initial area is full, the system makes twice as much extra space available up to a limit of 8KB. Further memory areas of 12KB each are then allocated.

You can usually leave it to the system to work out the initial memory requirement. The first time you fill the table, little memory is used. The space occupied, depending on the line width, is 16 <= <n> <= 100.

It only makes sense to specify a concrete value of <n> if you can specify a precise number of table entries when you create the table and need to allocate exactly that amount of memory (exception: Appending table lines to ranked lists). This can be particularly important for deep-structured internal tables where the inner table only has a few entries (less than 5, for example).

To avoid excessive requests for memory, large values of <n> are treated as follows: The largest possible value of <n> is 8KB divided by the length of the line. If you specify a larger value of <n>, the system calculates a new value so that n times the line width is around 12KB."

7 REPLIES 7

Former Member
0 Kudos

The number <N> indicate how many lines has to have the table in initialization time: i.e. when the program is loaded in memory, the space for the table depends on the initialization numbers of the records.

AT run time if the table needs more space, this'll automatically be enhanced.

But If you know your table can have a certain numbers of records, you can indicate it in the defination, what'll improve the performance:

all the space the table needs is taken at the beginin, so it doesn't need to enhance the space at run time.

When this initial area is full, the system makes twice as much extra space available up to a limit of 8KB. Further memory areas of 12KB each are then allocated.

You can usually leave it to the system to work out the initial memory requirement. The first time you fill the table, little memory is used. The space occupied, depending on the line width, is 16 <= <n> <= 100.

It only makes sense to specify a concrete value of <n> if you can specify a precise number of table entries when you create the table and need to allocate exactly that amount of memory (exception: Appending table lines to ranked lists). This can be particularly important for deep-structured internal tables where the inner table only has a few entries (less than 5, for example).

To avoid excessive requests for memory, large values of <n> are treated as follows: The largest possible value of <n> is 8KB divided by the length of the line. If you specify a larger value of <n>, the system calculates a new value so that n times the line width is around 12KB."

Former Member
0 Kudos

Hi,

itab with header line ( occurs 10(some number))

is better one.

memory will be alloted in chunks of bytes of memory.

Ex: occurs 10 will allot memory in multiples of 10 chunks of memory.

If found useful, award points pls..

Regards,

Bharadwaj

former_member184569
Active Contributor
0 Kudos

Hi Sai,

<b>OCcurs n and Occurs 0</b>

Internal tables are a dynamic data structure. Their memory requirements are met in blocks. The initial memory allocation (called the OCCURS area), can be controlled using the " OCCURS n" or "INITIAL SIZE n " addition in the table definition (see DATA, TYPES). Once the OCCURS area is full, the next block to be created is twice as big as the OCCURS area (as long as this is not greater than 8 KB). All further blocks are then created with a constant size of 12 KB.

You can leave it to the system to determine the size of the OCCURS area by specifying n = 0. In this case, the system allocates only a "small" portion of memory at the first INSERT or APPEND statement. "OCCURS 0" or "INITIAL SIZE 0" means that 16 <= n <= 100 (depending on the line width).

It only makes sense to specify a concrete value of n > 0 when you know exactly how many entries the table will have, and you want to set up the OCCURS area exactly. This can be particularly important if you want to nest internal tables (where an "outer" internal table contains one or more other internal tables in each line, and the "inner" tables only have a few entries (no more than 5, for example).

To avoid excessive memory requirements, the system handles large values of n as follows: The largest possible value of n is n_max = 8 KB divided by the line width. For larger values, n is set such that n multiplied by the line width is around 12 KB.

<b>WIth and without header line</b>

Avoid unnecessary assignments to the header line when using internal tables with a header line. Whenever possible, use statements that have an explicit work area.

For example, "APPEND wa TO itab." is approximately twice as fast as "itab = wa. APPEND itab.". The same applies to COLLECT and INSERT.

It is better to create internal table without header, and then perform all operations using the workarea.

Former Member
0 Kudos

HI

GOOD

IN THREE OF THEM THERE IS NOT MUCH DIFFERENCE.

IF YOU KNOW THE EXACT AMOUNT OF DATA COMING FROM DATABASE THAN YOU CAN GO FOR 3RD WHICH WILL GIVE YOU GOOD PERFORMANCE.

IF YOU DOESN'T KNOW THE AMOUNT OF VALUE RETURN FROM DATABASE THAN YOU CAN GO FOR THE SECOND ONE.

AND LIKE THAT YOU CAN USE THE 1ST ONE ALSO AS PER YOUR REQUIRMENT.

ACCORDING TO THE ABOVE POSITIONS IT WILL GIVE YOU THE PERFORMANCE.

THANKS

MRUTYUN

Former Member
0 Kudos

Hi,

Always go for internal table without headerline. Go for explicit workarea. This would definitely improve the performance.

Also if you are looping larger internal tables, declare that work area as field symbol and loop the table in to field symbol. So that the performance will increase.

regs,

Venkat Ramanan N

Former Member
0 Kudos

Hi sai,

1. For all the three cases,

i have written one code,

which will give the perfomance

time

start time, end time,

and we can diagnose for ourselves,

which is faster.

2. Just copy paste in new program.

3.

report abc.

*----


data : begin of itab occurs 0,

myline(10) type c,

end of itab.

types : begin of titab,

myline(10) type c,

end of titab.

data : wa type itab.

data : pitab type table of titab.

*----


data : begin of mtab occurs 10,

myline(10) type c,

end of mtab.

*----


get time.

write 😕 'With Header Line : ' , sy-uzeit.

do 100 times.

do 100000 times.

itab-myline = 'ABCDE'.

append itab.

enddo.

enddo.

get time.

write : ' ' , sy-uzeit.

*----


get time.

write 😕 'Without Header Line : ' , sy-uzeit.

do 100 times.

do 100000 times.

wa = 'ABCDE'.

append wa to pitab.

enddo.

enddo.

get time.

write : ' ' , sy-uzeit.

*----


get time.

write 😕 'With Header Line Occurs 10 : ' , sy-uzeit.

do 100 times.

do 100000 times.

mtab-myline = 'ABCDE'.

append mtab.

enddo.

enddo.

get time.

write : ' ' , sy-uzeit.

regards,

amit m.

Former Member
0 Kudos

Hi again,

1. time in seconds.

2. the same program (a little bit enhanced)

will show the time taken

in seconds, for all 3 cases.

3. just copy paste in new program.

4.

report abc.

*----


data : begin of itab occurs 0,

myline(10) type c,

end of itab.

types : begin of titab,

myline(10) type c,

end of titab.

data : wa type itab.

data : pitab type table of titab.

data : st type sy-uzeit.

data : et type sy-uzeit.

data : diff type i.

*----


data : begin of mtab occurs 10,

myline(10) type c,

end of mtab.

*----


get time.

st = sy-uzeit.

do 100 times.

do 100000 times.

itab-myline = 'ABCDE'.

append itab.

enddo.

enddo.

get time.

et = sy-uzeit.

diff = et - st.

write 😕 'With Header Line : ' , diff.

*----


get time.

st = sy-uzeit.

do 100 times.

do 100000 times.

wa = 'ABCDE'.

append wa to pitab.

enddo.

enddo.

get time.

et = sy-uzeit.

diff = et - st.

write 😕 'Without Header Line : ' , diff.

*----


get time.

st = sy-uzeit.

do 100 times.

do 100000 times.

mtab-myline = 'ABCDE'.

append mtab.

enddo.

enddo.

get time.

et = sy-uzeit.

diff = et - st.

write 😕 'With Header Line Occurs 10 : ' , diff.

regards,

amit m.