‎2007 Apr 02 6:06 AM
Hi friends,
can anyone tell me the purpose of zero in the itab declaration.
ex: begin of itab occurs 0,
-
end of itab.
i have seen different numbers used in place of zero in the itab declaration.
What is the purpose of mentioning different numbers there?? is the memory allocation the reason why we have to declare numbers there other than zero??
‎2007 Apr 02 6:13 AM
Hi Raghu,
The number specified in occurs clause depicts how much space to be allocated once the itab runs out of space.
Like -
begin of itab occurs 10.
size of element - 0.5 kb,
end of itab.
initial capacity 10 elements.
at insertion of 11 element, capacity rises to 20 elements.
This capacity increment is either no of elements you specify in occurs clause or 8 kb whichever is lesser.
Regards,
Manish Joshi
Don't tell me, you don't know how to award points.
‎2007 Apr 02 6:09 AM
Occurs statament mean the structure is a internal table:
DATA: BEGIN OF LT_ITAB,
END OF LT_ITAB.
This is a flat structure
DATA: BEGIN OF LT_ITAB OCCURS <n>,
END OF LT_ITAB.
This is an internal table
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, that'll improve the performance:
all the space the table needs is taken at the begining, so it doesn't need to enhance the space at run time.
Regards,
Santosh
Message was edited by:
Santosh Kumar Patha
‎2007 Apr 02 6:11 AM
hi raghu
OCCURS 0 specifies that it is an internal table which as 0 lines allocated to memory, and the HEADER LINE, means that there is an implicit header line or work area, so you do not need to create a separate explicit workarea in which to read the data into.
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.
regards,
navjot
reward all helpfull answers
‎2007 Apr 02 6:12 AM
Hi Raghu,
Occurs 0 ---> By default No Memory Allocation to the Itab. The Allocation will be Dynamically done at Run time.
Occurs N ---> By Default it will be allocated of Size N. this is not Good Practice in case of performance.
for Better Performance Use Occurs 0.
OCCURS 0 will create a page of 8kb.
System itself assigns more memory automatically when it exceeds the limit with OCCURS 0 usage.
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.
Regards,
Priyanka.
‎2007 Apr 02 6:12 AM
Hi..,
occurs 0..
it specifies the initial approx records that this internal table would hold... i.e initial memory...
If this memory is filled, then it allocates a chunks of 12kb memory each time...
The real difference u can see when u use this in case of APPEND SORTED BY statement...
<b><i>Observe the difference in output between these two programs...</i></b>
<b>*************************************************
data :
begin of itab occurs 4,
field type i,
end of itab.
do 10 times.
itab-field = sy-index.
append itab.
enddo.
loop at itab.
write : / itab-field.
endloop.</b>
*******************************************************
<b> data :
begin of itab occurs 4,
field type i,
end of itab.
do 10 times.
itab-field = sy-index.
append itab sorted by field.
enddo.
loop at itab.
write : / itab-field.
endloop.</b>
*************************************************
regards,
sai ramesh
‎2007 Apr 02 6:13 AM
Hi Raghu,
The number specified in occurs clause depicts how much space to be allocated once the itab runs out of space.
Like -
begin of itab occurs 10.
size of element - 0.5 kb,
end of itab.
initial capacity 10 elements.
at insertion of 11 element, capacity rises to 20 elements.
This capacity increment is either no of elements you specify in occurs clause or 8 kb whichever is lesser.
Regards,
Manish Joshi
Don't tell me, you don't know how to award points.
‎2007 Apr 02 6:13 AM
Hi Raghu,
Before Release 3.0, internal tables all had header lines and a flat-structured line type. There were no independent table types. You could only create a table object using the OCCURS addition in the DATA statement, followed by a declaration of a flat structure:
DATA: BEGIN OF <itab> OCCURS <n>,
...
<fi> ...,
...
END OF <itab>.
This statement declared an internal table <itab> with the line type defined following the OCCURS addition. Furthermore, all internal tables had header lines.
The number <n> in the OCCURS addition had the same meaning as in the INITIAL SIZE addition from Release 4.0. Entering 0 had the same effect as omitting the INITIAL SIZE addition. In this case, the initial size of the table is determined by the system.
The above statement is still possible in Release 4.0, and has roughly the same function as the following statements:
TYPES: BEGIN OF <itab>,
...
<fi> ...,
...
END OF <itab>.
DATA <itab> TYPE STANDARD TABLE OF <itab>
WITH NON-UNIQUE DEFAULT KEY
INITIAL SIZE <n>
WITH HEADER LINE.
In the original statement, no independent data type <itab> is created. Instead, the line type only exists as an attribute of the data object <itab>.
Standard Tables From Release 3.0
Since Release 3.0, it has been possible to create table types using
TYPES <t> TYPE|LIKE <linetype> OCCURS <n>.
and table objects using
DATA <itab> TYPE|LIKE <linetype> OCCURS <n> [WITH HEADER LINE].
The effect of the OCCURS addition is to construct a standard table with the data type <linetype>. The line type can be any data type. The number <n> in the OCCURS addition has the same meaning as before Release 3.0. Before Release 4.0, the key of an internal table was always the default key, that is, all non-numeric fields that were not themselves internal tables.
The above statements are still possible in Release 4.0, and have the same function as the following statements:
TYPES|DATA <itab> TYPE|LIKE STANDARD TABLE OF <linetype>
WITH NON-UNIQUE DEFAULT KEY
INITIAL SIZE <n>
[WITH HEADER LINE].
regards,
keerthi
‎2007 Apr 02 6:13 AM
hi,
<b> occurs </b> clause reallly comes into picture when we use append sorted by .
when we use occurs n the number records that can be entered to internal table using append sorted by is only n records . its sorted the recordes in decending order . its gives only top most n records.
regards,
ananth
‎2007 Apr 02 7:47 AM
Hi friends,
thank you all for your responces. My doubt is clarified. I have awarded points to you all.
Cheers