Application Development and Automation 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: 
Read only

internal tables

Former Member
0 Likes
1,921

Hi,

can any one explain mewhat is occurs 0 in internal tables?

what is the use with header line in internal tables?

19 REPLIES 19
Read only

Former Member
0 Likes
1,840

Basically occurs 0 indicates the initial size of the internal table ...SAP would allocate memory space for the specified records in SAP memory and if it exceeds the same it would put the store records in auxillary memory area.

As for header line..when you read the internal table either via read or loop the record read from the internal table is fetched and stored in the header..but as SAP standard they now specify to use work-areas instead of header line.

Regards

Anurag

Read only

Bharathi_j
Explorer
0 Likes
1,840

Hi,

Occurs '0' addition will not allocate memory area at first instance but at runtime it picks up all data.

Whenever u loop /read data from internal table either it will be read in hader area or workarea for tables without header line.

Regards,

Bharathi.

Read only

former_member758419
Active Participant
0 Likes
1,840

Hi,

Header line is a implicit work area for the internal table. The header line is a field string with the same structure as a row of the body, but it can only hold a single row , whereas internal table can have more than one record.

Data : itab like mara occurs 0 with header line.

will create internal table with header line.

Data: itab like mara occurs 0.

will create internal table without header line. For this u need to create work area explicitly.

data: wa_itab like itab.

for more info,,

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb367a358411d1829f0000e829fbfe/frameset.htm

Hope this helps,

Regards,

Sachidanand.B

Pls award helpful answers

Read only

anversha_s
Active Contributor
0 Likes
1,840

hi,

pls go thru this.

u will get good idea.

*&---------------------------------------------------------------------*
*& Report  ZTYPES                                                      *
*&                                                                     *
*&---------------------------------------------------------------------*
REPORT  ZTYPES                                                  .

* Table declaration (old method)
DATA: BEGIN OF tab_ekpo OCCURS 0,             "itab with header line
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
 END OF tab_ekpo.

*Table declaration (new method)     "USE THIS WAY!!!
TYPES: BEGIN OF t_ekpo,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
 END OF t_ekpo.

DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,      "itab
      wa_ekpo TYPE t_ekpo.                    "work area (header line)

* Build internal table and work area from existing internal table
DATA: it_datatab LIKE tab_ekpo OCCURS 0,      "old method
      wa_datatab LIKE LINE OF tab_ekpo.

* Build internal table and work area from existing internal table,
* adding additional fields
TYPES: BEGIN OF t_repdata.
        INCLUDE STRUCTURE tab_ekpo.  "could include EKKO table itself!!

TYPES: bukrs  TYPE ekpo-werks,
       bstyp  TYPE ekpo-bukrs.
TYPES: END OF t_repdata.

DATA: it_repdata TYPE STANDARD TABLE OF t_repdata INITIAL SIZE 0,   "itab
      wa_repdata TYPE t_repdata.                 "work area (header line)

rgds

Anver

Read only

srinivas_akiri
Active Participant
0 Likes
1,840

Hi,

occurs statement is used to specify the body of the internal table. if you specify occurs 0, then the system inially allocates 8 bytes of memory to the internal table body and as the records filled the size of the table will be increased.

if you know the exact size of the internal table then you can specify that in the defination of the internal table itself through OCCURS clause to improve the performance.

Read only

Former Member
0 Likes
1,840

Hi Kan,

When you give Occurs addition it will try to allocate that much memory

initially, when ever more data comes it will extend it.

for example if you give occurs 0 , it will not allocate any memory initially but at

run time it will allocate.

if you say occurs 5, it will allocate memory for 5 records and

accordingly it will allocate at runtime.

Header line is like work area, when you process records in your itab to store

current record we use it. When you give this addition automatically it will have

work area explicit work area is not required.

Thanks & Regards,

Siri.

Read only

Former Member
0 Likes
1,840

Hi kan ath,

i'll put it in my words

wid d occurs statement u can reserve d memory space before d program runs

for eg: itab like table occurs 5

this will reserve memory space for 5 rows of the object itab...

the length of 1 row will be equal to the lenght of the structure table

wid header line wil create a workarea for the table object of d table name

wen u want to access d tables' data, u cant directly access it like in an array

i.e itab(2)-field and so on is not possible.

wat u need is a seperate data element which will hold the data from d table temprorarily

this is d use of a workarea...

Every int table has a workarea where d table data can be modified and accessed from

if u specify with header line while creating the table object....a workarea will be created wid d same name as that of d table

d following r d differrences while workin wid tables wid and widout header lines

Header line No header line

loop at itab loop at itab into workarea

endloop endloop

modify itab modify itab from workarea

append itab append workarea to itab

and more.......

here the name of the table refers to both the workarea and the table

to access the int table u can use the sqr brackets---> itab[]

u can any points if this is helpful

Regds,

Vs

Read only

Former Member
0 Likes
1,840

The occurs clause addition or Initial size addition while declaring an internal table refers to the size of the memory area getting allocated at ruin time for the internal table.

The header line of an internal table is similar to that of a work area and with which the lineitems of the internal table can be processed according to your needs.

Object oriented programming approach in ABAP doesn't support internal tables with header lines. So other than the internal table, a work area has to be declared explicitly.

Regards,

Radhu

Read only

Former Member
0 Likes
1,840

1). Allocating the extra memory for the structure is the concept of Internal table.

By default a structure can hold one record data. To make it to handle multiple records data, we use ‘occurs 0’ statement.

‘Occurs 0’ statement allocates 8 kb (8*1024 bytes) of memory to the given table.

When we enter the data into the internal table. The records uses this memory. Even we entered 2 or 3 records, It consumes all the 8kb data. If we enters the records that exceeds to have more than 8kb memory, The ‘occurs 0’ statement again allocates 8kb of memory.

So… if we use ‘occurs 0’ statement, each time 8kb of memory will be allocated to the internal table.

If we use ‘occurs 1’ statement rather than ‘occurs 0’ it allocates memory for only one record. If we continue to enter the data into the ITAB. This statement passes the required memory dynamically. So, It is a good programming practice to use ‘occurs 1’ as for as memory is considered.

2). Internal table have two parts. One is header area and another one is body area.

When ever we enter a record into the ITAB. First it enters into the body area. When we use append statement. It populates the data in to the body area. Then 2nd record enters into the header. The same process continues.

While reading also, We cant read the data of an ITAB directly from the body area. We need to bring a record into header and use it.

Read only

Former Member
0 Likes
1,840

Hi,

Occurs 0 specifies the initial size of your internal table.

The memory of any internal table is assigned in the form of blocks.. suppose you write occurs 10 initial size of the internal table will be 10 and as soon as you append the 11th record another block of memory of double the size of previous one that is 20 will be created this time.

Occurs 0 is used when you dont have the idea of number of records, it automatically gets adjusted to the number of records you are appending.

Regards,

-pankaj singh

Read only

Former Member
0 Likes
1,840

HI

An internal table is one of two structured data types in ABAP. It can contain any number of identically structured rows, with or without a header line.

The header line is similar to a structure and serves as the work area of the internal table. The data type of individual rows can be either elementary or structured.

When defining internal tables before release 6.40, you could not specify a start value with addition VALUE. As of release 6.40, you can specify IS INITIAL as a start value.

The initial memory requirement defined during the creation of the internal table with the addition INITIAL SIZE or the obsolete addition OCCURS is determined and assigned to the data object n.

So occurs 0 is nothing but intial size is 0 for the internal table.

Regards,

gunasree.

Read only

Former Member
0 Likes
1,840

Hi kan ath

By definition, Internal tables and Field strings

are user defined structured data types.

These internal tables can be created as a

replica of data base table, using some or all

fields of one table or more tables.

These internal tables are created only during

run time. No memory is reserved.

Long Life data is stored in database tables.

When we are directly modifying data, there is

every possibility that we may loose data by

accident, which we can not afford to do so.

As such we need some intermediate tables to

do some operations. Up on satisfactory

results, we can modify database table.

Basically there are 2 types of Internal tables.

Internal tables with header line.

Internal tables without header line

When you create internal table with header

line, a default work area is created.

In this case, we need to create explicit work

area to work with it.

When we need to nest the tables with in

tables, we need to use this type of internal

table.

There are 3 steps involved in creating Internal

tables.

Declaration of Internal table.

Populating Internal table.

Processing Internal table.

1) data : itab like <table name> occurs 0 with header line.

Itab : name of internal table.

<table name> : name of data base table.

Occurs 0 : performance factor.

By default internal table created is without

header line.

2) data : begin of itab occurs 0.

include structure <table name>.

data : end of itab.

3) data : begin of itab occurs 0,

carrid like sflight-carrid,

connid like sflight-connid,

fldate like sflight-fldate,

end of itab.

4) data : begin of itab occurs 0,

carrdid like sflight-carrid,

connid like sflight-connid,

bookid like sbook-bookid,

fldate like sbook-fldate,

end of itab.

( In this case we are using fields from more than one table)

1) itab-name = ‘abcd’.

Append itab.

Internal table can be declared in the following ways:

• Data : Itab like sflight occurs 0 with header line

Here you are declaring internal table, which is similar to sflight i.e., itab like sflight i.e., you are referring to existing table (like).

(By default internal table created with this declaration is without header line).

• Data : Begin of itab occurs 0.

Include structure sflight

Data : End of itab

(Internal Table created with this type of declaration is similar to declaration done in ‘a’ type the only difference is by default internal table created by this type is with header line)

• Data : Begin of itab occurs 0

carrid like sflight-carrid,

connid like sflight-connid,

fldate like sflight-f1date

End of itab.

By default internal table created by this type of declaration is with header line. In this type of declaration, you are using only those fields from database table, which you require for processing.

• Data : Begin of itab occurs 0

carrid like sflight-carrid,

connid like sflight-connid,

bookid like sbook-bookid

id like scustom-id,

End of itab.

Here you are combining fields from three different tables in one internal table.

• Data : Begin of itab occurs 0

Carrid1 like sflight-carrid,

End of itab.

Here you are specifying different field names.

Read only

Former Member
0 Likes
1,840

Occurs 0 indicates the initial size of the internal table ...SAP would allocate memory space for the specified records in SAP memory and if it exceeds the same it would put the store records in auxillary memory area.

Header line is an implicit work area for the internal table..when you read the internal table either via read or loop the record read from the internal table is fetched and stored in the header..but now we use work area instead of headerl line..its obsolete as per sap standards..

Read only

Former Member
0 Likes
1,840

Hi ,

If you are using occurs 0 you need not use work area .This itself acts as work area .It defaultly reserves a memory space for you to manipulate the data .

Internal table declared as

data : itab type table of <tablename>.

does not have field names hence by using ' with header line ' the line type

( field name ) is included.

But ' occurs ' and ' with header line ' are obsolete statements .

Read only

Former Member
0 Likes
1,840

HI,

Using ' occurs ' in internal table will allocate memory for the internal table at runtime .

example ;

data : it_makt type makt occurs 2 with header line.

Generally in internal table the field names are not included ie.,

data : itab type table of <table name> . does not contain line type (field name).

' with header line ' includes line type to the internal table.

but ' occurs ' and ' with header line ' are obsolete .

Read only

Former Member
0 Likes
1,840

while declaring internal tables we need to give occurs 0.occurs is used to reserve the memory space.if we do not give occurs then it is not treated as internal table.

there r two types with header line and without header line.

with header line is to include the work area.if we use with header line then it includes both header and the body or else it will include only the body of the internal table.

Read only

Former Member
0 Likes
1,840

hi kan,

the internal tables can be defined in 2 ways:

1) internal tables with header line

2) internal table without header line

First let me tell u about occurs 0 in internal table:

Whenever we define an internal table with occurs 0...it will allocate an 8Kb of memory size to that internal table. also when we define an internal table with occurs 0 it will be with header line...Also work area (body) will be assigned to that internal table...

define:

Data : begin of itab occurs 0,

field1 like Databasetable-field,

end of itab.

or

data : itab like Databasetable occurs 0 with header line.

here the internal table ITAB will have a memory size of 8Kb intially...also it will be with header line...

Now internal table without header line will not have the work area (body). we will have to define the work area for that internal table...

Regards,

Prashant

Read only

Former Member
0 Likes
1,840

hi kan

Occurs 0-allocates 8kb of default memory

there are 2 types of internal table

1.internal table with header line

2.internal table without header line

---If you use Occurs 0 then it is Internal table with header line,so default work area will be automatically created.so the records that you need to append into internal table first goes into work area and then into internal table.so records are appended one by one..

---But if you do not use Occurs 0 then it is internal table without header line,so you have to create default work area.This is always recommended since if you create your own work area then it will be effiecient since you are decalaring it.

REWARD IT PLEASE....!!!

Read only

Preetha33
Explorer
0 Likes
1,840

Hi,

Internal table with Header line: By default with header line creates one work area with the name of internal table. That means the name of the work area as well as name of the internal table as similarly.

Types:   begin of <type_name>
--------------
---------------
End of <type_name> .
Data: it_tab type table of <type_name> with header line.

Occurs 0 in internal table : occurs 0 indicates the initial size of the internal table... occurs 0 by default allocates 8 kb of memory for the internal table. If the data in the internal table exceeds 8 kb, then it’ll provide one more 8 kb of memory … up to 2 GB.

Syntax: -
Data: begin of <type_name> occurs 0, 
-------------------
-----------------
End of <type_name>.

Occurs ‘n’: - By default it allocates ‘n’ records of memory for internal table. If the data in the internal table exceeds 10 records. Then it’ll be allocates one more ‘n’ records of memory ---- up to 2 GB.