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

Internal Table : occurs statement

Former Member
0 Likes
15,032

What is the meaning of using "occurs" statement in Internal Table. What does it imply?

DATA: BEGIN OF ITAB OCCURS 10,

.

.

.

.

END OF ITAB.

What difference it will make if suppose I use "OCCURS 0" or "OCCURS 10" ?

1 ACCEPTED SOLUTION
Read only

Former Member
6,392

occurs 0 means it won't allocate any memory for the itab, but it allows n no of records,

occurs 10 means , first it allocates 10 records memory to the itab, but still it allows n no of records.

only diff is that it allocate the memory based on occurs..

13 REPLIES 13
Read only

Former Member
6,393

occurs 0 means it won't allocate any memory for the itab, but it allows n no of records,

occurs 10 means , first it allocates 10 records memory to the itab, but still it allows n no of records.

only diff is that it allocate the memory based on occurs..

Read only

Former Member
0 Likes
6,392

difference it will make if suppose I use "OCCURS 0" or "OCCURS 10"

after the internal table is full for the next record OCCURS 10 will allocate memeory for 10 records whether it will be used completely or not while OCCURS 0 will allocate meory record by record .

ANd both of them make a internal table with header line

reward if helpful

Read only

0 Likes
6,392

So what will be better to use considering performance? 'OCCURS 0' OR 'OCCURS 10'?

Read only

0 Likes
6,392

Hi,

if you are sure u'll have 10 records, u can specify 10. it is better to use occurs 0 because, as and when the internal table expands, the size also expands.

regards,

madhumitha

Read only

0 Likes
6,392

Hi yogesh for more clearification

difference b/w occurs 0 & occurs n

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."

and it is better to use occus 0 inplace of occurs n because of above specified reasons

while it is not recommended to use occurs for internal table declaration and it has become obselete

reward if helpful

Read only

0 Likes
6,392

Thank you Ashish for the exhaustive explanation. Since the occurs statement has become obsolete I should use "TYPE STANDARD TABLE" statement to make an internal table?

Read only

0 Likes
6,392

Hi Yogesh ,

Yes now you need to declare types seperately using

types : begin of type ,

end of type .

and then

declare table like

data : it_tab type standard table of type .

and also don't declare it with header line instead declare a separate work area like

data : wa_tab type type.

reward if helpful

Read only

0 Likes
6,392

Will there be any difference if I declare with a default work area or it will be better to declare a work area separately?

Read only

Former Member
6,392

Hi Yogesh,

Occurs specifies the memory allocation for the internal table records.If you specify occurs 0 then 8kb space will be allocated,If you specify 10 then 10*8kb will be allocated.

Occurs 0 is better than Occurs 10.Because once that 8kb space is filled ,the system again allocates another 8 kb space.

Thanks & Regards,

Khan.

Read only

0 Likes
6,392

Hello Khan,

But is it not heavy in terms of performance to allocate memory everytime?

Read only

0 Likes
6,392

hi,

No, it is not a performance bottleneck.It automatically allocates the memory based on the volume of data. If u specify the memory using OCCURS and less number of records are fetched, unnecessary memory is blocked.

this is an excerpt from SAP Help file:

Internal tables are a dynamic data structure. Their memory requirements are met in blocks. The initial memory allocation (hereafter 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.

regards,

madhu

Read only

0 Likes
6,392

Hi,

No not at all.It is best thing when you dont know how many records you can fetch.

the best thing it is better to declare internal table using types and create separate workarea as shown below for reference.

  • Structure for Internal Table

Types:Begin of ty_mara,

matnr type matnr,

mtart type mtart,

end of ty_mara.

  • Internal Table Body

Data i_mara type table of ty_mara.

  • Work Area for internal Table

Data wa_mara type ty_mara.

thanks & Regards,

Khan

Read only

Former Member
0 Likes
6,392

Hi Yogesh,

I write Occurs 10 ,then it wud mean whenever an internal table is falling short of rows , 10 new rows will get added to it.

but there is one problem, suppose I have 5 records..then 4 will get stored in one go and next time 4 more rows will be added however there is a requirement of only one extra row, so our memory is wasted.

This is the reason we always write OCCURS 0 which means whenever internal table is falling short of rows add only the rows required and hence this saves memory..

Please reward points if helpful

Regards,

S.Suresh.