cancel
Showing results for 
Search instead for 
Did you mean: 

report

Former Member
0 Kudos

hi gurus i am new in abap plz tell me the some ques. answer.

wht is diff b/w occurs 0 and occurs 1.why we use it.

why we use read statements.

why we use loop statement.

thankx. jay

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

if we define internal table with occurs 0 then intially it will allocate 8kb memory latter on it will increase the size depending on the records.

if we define itab with occurs 1 i will allocate memory required for one record.

read is used to read the particular record in the internal table depending on the condition or index. better to use binary search in case of read. to use binary search we have to sort the internal table first.

loop will loop through all the records in the internal table.

we can also where condition for loops.

below is the document regarding memory allocation.

You can specify the initial amount of main memory assigned to an internal table object when you define the data type using the following addition:

INITIAL SIZE <n>

This size does not belong to the data type of the internal table, and does not affect the type check. 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.

Former Member
0 Kudos

HI

occurs 0

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.

occurs 0, the memory allocation is done by system,

in case of occurs 100 memory of 100 records allocated initially ,then if records 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.

Former Member
0 Kudos

Hi,

read statement is for reading a record from the internal table.

loop...endloop is for accessing all the internal table contents one by one

rgds,

bharat.

Former Member
0 Kudos

occurs 0 It alooactes 8K memory to itab

occurs 1 It alooactes memory equal to 1 row of itab

READ to read a single line from iTAB

loop to read all lines from iTAB

Award points if useful

abdulazeez12
Active Contributor
0 Kudos

Hi Jayant-

The OCCURS parameter n specifies how many table lines of storage is required. This storage reservation process does not happen until the first line is inserted in the table. The value n of the OCCURS specification has no effect on type checking, i.e. data objects which have types with different OCCURS specifications are type-compatible.

if are specifying 10 then initially 10 lines of storage is reserved. once 10 lines completed then again 10 lines will be reserved.

0 means no specific reservation of lines. depends on the requirement the storage will be reserved.

Refer to the following links

READ statement is used to read a internal table entry based on the KEY u put in the READ syntax..For more details on READ statement, you can enter keyword as "READ" in ABAPDOCU transaction code and look for documentation!

LOOP is used to loop the inernal table and do the processing for each and every table entry. You can refer to LOOP statement in ABAPDOCU tcode..

Award points,

Shakir