2007 Oct 10 11:06 AM
Hi all,
I have small confusion on occurs 1, occurs 2, ...... etc, i don't know how much memeory is allocated those, so that is why every time iam taking only occurs 0.
thanks & regds.
srinivas
Hi all,
I have small confusion on occurs 1, occurs 2, ...... etc, i don't know how much memeory is allocated those, so that is why every time iam taking only occurs 0.
thanks & regds.
srinivas
2007 Oct 10 11:08 AM
Hi,
Coming to performance: If you know that you will store only one single value in the Internal table If you use OCCURS 1. It would perform well than OCCURS 0.
Occurs 0 keeps on incrementing when there is a value. But Occurs 1 will assign a single space even though there is no value.
Lets suppose you did not get any values from the DB after a select, in this case if you write Occurs 0 it will not allocate any single space in the memory. If you write OCCURS1 it will pre allocates some memory.
occurs 0 means initially it will allocate 8kb of memory.later it will increment in terms of <b>8kbs</b>
occurs n means initially it will allocate memory for n rows.later it will increment in terms of n rows
Thanks.
2007 Oct 10 11:10 AM
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."
*********************************
OCCURS Value or INITIAL SIZE Specification
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. 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.
2007 Oct 10 11:41 AM
Hi Vasu,
Still my doubt is not cleared can u explain me briefly about occurs 1,
occurs 2..........................................., how memory will take these.
2007 Oct 10 11:44 AM
Hi Srinivas,
occurs clause is only for guidlines to determine how much memory to allocate ..
whether is occurs 1 or occurs 2.
the first time a row is added to the internal table ,enough memory is allocaed to hold the number of rows sppecified on the occus clause.
in occurs 0,the system will allocate 8KB pages of memory at a time.however there is no adavntage of using occurs 0
Thanks.
2007 Oct 10 11:57 AM
if u declare as occurs 1 ....in runtime only one record would be loaded to the internal table...........if u declare it as occurs 10 , 10 records would be compatiable for u r internal table..............
2007 Oct 10 11:15 AM
Hi
<b>occurs 0</b>
in the data definition, occurs 0 will indicate that a memory of 8 kbytes is allocated to the internal table which was declared by you of the data base table type which was specified. Here, if u dont give with heade line option, it will create only the body area and there will not be any header. The internal table can have the header line with the extention ' with header line ' .
For more detailed explanation, go through the following.
data: wa like kna1. --> wa is a structure of the type kna1 table. it can store only
one record of data.
data: itab like kna1 occurs 0. --> Here itab is the internal table which has 8 kb of
memory allocated for the body area. Here it
doesnt have header. if the data loaded in the itab
exceeds 8 kb, another 8 kb of memory is
allocated and the process continues.
we can also give 1, 2, .... in place of 0. Here the
memory allocated will be that required to store
one record of data, 2 records of data .....
respectively. If more records are to be
populated, extra memory of 1, 2, ..... records
will be generated. Thus, the memory allocated
will be generic and not constant.
data: itab like kna1 occurs 0 with header line --> Everything is same as earlier
except that header line is also generated and
it will be in addition to the actual memory
located to body.
Note: to populate data into itab without header line we have to define a work area of the structure of the itab.
data: itab like kna1 occurs 0.
data: wa like line of itab.
Then populate data into wa and append to itab ( append wa to itab ). Where as in case of an internal table with header line, we can populate data directly to header of itab and append it to its body. ( append itab. )
hope this will give a clear picture of the way in which data is allocated based on our statement.
<b>occurs 0, the memory allocation is done by system,
in case of occurs 100 memory of 100 records allocated initially ,then if records</b> exceeds then system ll allocate memory,
memory allocation here is known as extent and depend upon basis administrator...
You can use the above addition to reserve memory space for <n> table lines when you declare the table object.
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."
OCCURS 0 is betten than OCCURS 100 because
OCCURS 100.
*****************
if you use occurs 100, the ABAP memory will allocate for 100 records memory location, some time you have only 20 records at that time the remaining 80 records memory space will waste.
REAL TIME EXAMPLE: BUS
***************************
In bus total seat is 57, some time only 20 people only will come at that time also bus should go so remaining seats will waste.
OCCURS 0:
**************
OCCURS 0, the memory is not allocated previously, that is optimistic.if you have 20 records the memory will take for only 20 records.
<b>Reward if usefull</b>
2007 Oct 10 11:42 AM
Hi Naresh,
Still my doubt is not cleared can u explain me briefly about occurs 1,
occurs 2..........................................., how memory will take these.
2007 Oct 10 12:11 PM
Hi Srinivas,
OCCURS 0 means that system will allocate 8KB pages of memory even though
there are few records in the table.
So if there are only 100 records in the table and the internal table's occurs value 0 then that leads wastage of memory.
Ex: suppose your database table contains morethan 10000 records
then you can go for OCCURS 0.
suppose your database table contains below 1000 records
then you can go for OCCURS 100.
After you fill your internal table with 100 records and you are trying to fill further then system will allocate 100 records space at one shot.
You can use OCCURS 1 also.
But here if you try to fill the internal table with 5 records. For each record system has to allocate 1 records space at one shot.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |