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: 

Difference between INITIAL SIZE and OCCURS

gopalkrishna_baliga
Participant
0 Kudos

Hi ABAP Gurus,

I am new to ABAP. I am facing a confusion whether to use INITIAL SIZE option while defining my internal table. Some existing codes use OCCURS. So my questions are:

1. Difference between INITIAL SIZE and OCCURS?

2. When should I use INITIAL size. Are there any specific cases?

3. Is there any performance issue if I use INITIAL SIZE?

4. Why OCCURS is not recommended?

5. Is it true that if I use OCCURS then the internal table is created with header line? With INITIAL SIZE header line is not created?

6. What is the difference between INITIAL SIZE 0 and INITIAL SIZE 10?

Thanks

Gopal

4 REPLIES 4

Vinod_Chandran
Active Contributor
0 Kudos

Hi,

Both are for the same purpose. i.e. for defining the initial size of the internal table. But the OCCURS statement cannot be used inside object oriented programming.

INITIAL SIZE specifies how many table lines are to be created initially. The number of table lines can then be increased as needed.

You can read about the performance issues regarding internal tables by going to the help of DATA statment. Press F1 key on the 'DATA' and then

Defining an Internal Table -> 4. DATA itab {TYPE RANGE OF type|DATA itab LIKE RANGE OF f}. (Variant 4)

Here you can find the link "Performance: Notes for Internal Tables.".

Thanks

Vinod

Former Member
0 Kudos

Hi Gopal

1. There isn't really a different beetween INITIAL SIZE and OCCURS, because these stataments have the same function in different way to declare an internal table: area size for memory allocation.

So i can declare an internal table like VBRK in these ways (for example):

A) DATA: BEGIN OF T_VBRK OCCURS 10.

INCLUDE STRUCTURE VBRK.

DATA: END OF T_VBRK.

or

B) DATA: T_VBRK TYPE STANDARD TABLE OF VBRK INITIAL SIZE 10.

Anyway the option OCCURS always needs to declare an internal table when you use a statament like A, infact:

DATA: BEGIN OF T_VBRK.

INCLUDE STRUCTURE VBRK.

DATA: END OF T_VBRK.

That statament indicates that T_VBRK is flat structure.

If you want the system automatically allocate an initial portion of memory:

A) DATA: BEGIN OF T_VBRK OCCURS 0.

INCLUDE STRUCTURE VBRK.

DATA: END OF T_VBRK.

or

B) DATA: T_VBRK TYPE STANDARD TABLE OF VBRK.

2/3/4/6

As I wrote above, the use of INITIAL SIZE or OCCURS is depend on the way to declare an internal table.

When a program start, the system allocates an initial portion of memory for each table, these portion can automatically be calculated by system or we can define it (OCCURS 10 or INITIAL SIZE 10).

So the performance are improved because the system haven't to decide memory size for allocation, but to define initial memroy size makes sense if it knows exactly how many records a table will have.

- If you know your table will have more 10 entries, it

should be better to use: OCCURS 10 or INTIAL SIZE 10.

- if you don't know that, use: OCCURS 0 or INITIAL SIZE 0 (in this case don't write option INITIAL SIZE);

5. No! It isn't true. Depend on how to declare a table:

DATA: BEGIN OF T_VBRK OCCURS 0.

INCLUDE STRUCTURE VBRK.

DATA: END OF T_VBRK.

This statament creates an internal table with header line.

DATA T_VBRK LIKE VBRK OCCURS 0.

This statament creates an internal table without header line.

You could note there some way to define a table are the same to define a flat structure: only difference is the use of OCCURS.

So when you use OCCURS, it means: this variable is a table;

when you don't use OCCURS, it means: this variable is a flat structure.

When you use a statament doesn't create the header line, you can directly specife it:

DATA T_VBRK LIKE VBRK OCCURS 0 WITH HEADER LINE.

The stataments use INITIAL SIZE doesn't create the header line, so if you want it, you have to specify it:

DATA: T_VBRK TYPE STANDARD TABLE OF VBRK INITIAL SIZE 10

with header line.

Max

Message was edited by: max bianchi

Former Member
0 Kudos

Hi

Initial Size 0 will always allocate 8 Kb of memory area to the internal table. Further memory allocations will be dynamic i.e. as you add entries into internal table system will assign next blocks in chunks of 12kb each.

Initial size 10 will allocate the memory depending on the line wodth of your internal table . If your table line

Is 80 Bytes Long - Intial Memory allocated would be

8 kb as ( 80 X 10 = 800 b is less than 8 Kb and system will not allocate less than 8 kb. )

Is 900 bytes long then Initial memory allocation would be 20 kb ( 900 X 10 = 9000 Bytes , is greater than 8 kb so the next block of memory is released ).

In nutshell occurs or initial size only affect the initial memory space allocation of int. table. All subsequent memory blocks are 12 Kb.

For custom programs occurs 0 or initial size 0 is good as system will take care of memory allocation. In any case you can only change the initial memory allocation by these two key words.

Cheers

Former Member
0 Kudos

Hi Gopal,

<i>1. Difference between INITIAL SIZE and OCCURS?</i>

OCCURS is obsolete and is no longer valid in OO ABAP. It defines an internal table with memory allocated to store a specified number of rows of the internal table in the main memory. <b>It also provides you with a header line by default.

INITIAL SIZE will also allocate the initial memory but will not define your header line. The only thing is that it cannot be used with generic table types like ANY TABLE or INDEX TABLE.

<i>2. When should I use INITIAL size. Are there any specific cases?</i>

If you are in newer versions, it may be advisable to start using it in every case.

<i>3. Is there any performance issue if I use INITIAL SIZE?</i>

Using initial sze you are telling the system to allocate a certain portion of the available memory for this internal table. Unless you are very confident about the size of your internal table, it is not advisable to reserve this memory. This will be useful only if you know that you will have a specific number of records in your internal table, like preloading all the material types into the table.

<i>4. Why OCCURS is not recommended? </i>

We only know that it is not allowed in ABAP objects, why I don't know. May be any implicit header work area is not in line with object oriented programming.

<i>5. Is it true that if I use OCCURS then the internal table is created with header line? With INITIAL SIZE header line is not created?</i>

As explained above, YES.

<i>6. What is the difference between INITIAL SIZE 0 and INITIAL SIZE 10?</i>

Exaplained above in 3.

If these answers helped you, please reward and close the post.

Srinivas