What Is The Purpose of Giving OCCURS 0

When ever we declare internal tables or variables or constants system will allocate memory to each one based on the size of the object while runtime. For variables and constants we can determine the size from the definition. For internal tables size will be equal to sum of sizes of all fields. i.e. size of one row equal to sum of sizes of all fields. Size of table equal to Size of each row * Number of rows.

OCCURS statement is used to define an implicit work area called header line while defining internal table. 
OCCURS 0 is used to allocate initial memory of 8KB to the internal table.

OCCURS n, The value specified in n identifies number of expected records in the internal table. If the number of records exceeds then the system will allocate memory for next n records. If the value of n is zero then it means that you don't know how many records you are going to get. So the system will allocate default memory of 8KB. Use OCCURS 0 only if you are sure that your table contents crosses 8KB at some point. Otherwise it will be simply waste of resource (Memory) while executing the program.

My sugesstion is don't go for OCCURS addition as it is already obsolete in OOPS concepts. Also If we use OCCURS then name of the internal table and header line will be same. So there will be confusion in which is work area and which is header line. So always go for explicit work areas.

Check below the effective way of defining internal tables.

TYPES: BEGIN OF t_vbap, "Structure
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
END OF t_vbap.

DATA: i_vbak TYPE STANDARD TABLE OF t_vbak, "Internal table 
wa_vbak TYPE t_vbak. "Explicit Work area


Occurs statement is used to allocate the initial space to the internal table records in the program area.

Basic terms : 

Roll Area : area in the virtual memory. usually RAM Area. the access on this area is fast. 

Paging Area : This is the memory allocated in the page division of hard disk. the accesses to this area is slow.

When we declare Occurs 0.  The system will allocate initially space for 0 records in the roll area but increases the memory by record by record.  The maximum limit is 8kb in roll area, after that it will allocate in the paging area.

When we declare occurs 2.  The system will allocate space for initial 2 records and increases 2 records by 2 records. The maximum limit in the roll area is 8kb only and after that allocates i the paging area.

When we declare occurs 100.  The number that will take more space for the allocation of records than 8kb., first it will allocate the space for all this records i.e., 8kb from the roll area and other area in paging area.

For performance:

If we don't know how much average fields are there.
Calculate the number of records that can be inserted in the 8 kb of space. i.e.,  let it be N.  Declare occurs  N.  If we know how much average fields are there.
Declare Occcurs M.   Where M ., average number of records expected in the internal table.

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.