Application Development 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: 

Table deceleration

Former Member
0 Kudos
172

1. Types: begin of itab ,

…..

…..// Structure creation

End of itab.

Data: gt_itab type table of itab, // internal table

Gw_itab type itab. // work area

2. Data: begin of itab occurs 0 with header line.

….

End of itab.

Question:

1.What is the difference between this two type (memory allocation?)

2.Why prefer the first method to declare the internal table, why we r not giving priority for the second type?

3.Why we r creating separate work area in the first case. And how come it differs from the second case?

Please give the detail explanation…

6 REPLIES 6

Former Member
0 Kudos
102

hi

first method is more recommended than second one.

in the second method memory will be allocated for body and header also,

wastage of memory and in this case nesting of internal tables with header lines

is not possible. so we generally declare a separate work area as in the first case.

we are declaring work area separately because we can append that directly to

internal table.

Former Member
0 Kudos
102

In the first case, an internal table without a header line is created and in the second an internal table with a header line is created. SAP advises to use internal table without header lines for performance reasons. OO programming also does not support internal tables with header lines.

Former Member
0 Kudos
102

hi..

We are creating work area explicitly in the 1st method but in second method the first line of the internal table itself act as the work area..

<b>Reward points if useful</b>

Regards

AShu

Former Member
0 Kudos
102

OCCURS 0 is an old way of defining the table and workarea. In this the field which we declare can act as both Workarea and Table, whereas first way of defining table is recently used.

Both work the same but we use the first method as it is recommended.

Regards,

Pavan.

Former Member
0 Kudos
102

<b>Internal table declaration</b> - various ways of declaring an internal table

Declaring internal tables is an essential part of writing ABAP code as this is where most of the data retrieved from database tables will be stored. During the select statement you retrieve data from a database table into an internal table (multiple rows) or a work area or header line (single row).

 
*&---------------------------------------------------------------------*
*& 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 
 

reward points if it is usefull ...

Girish

Simha_
Advisor
Advisor
0 Kudos
102

Hi,

1) We prefer the first case always..

Bcoz.. In this case we can change the structure any number of times...and the same can be used in different places as and when required...

2) While we use second type, if we have to change the structure of the internal table, then we have to manipulate the itab and it is not a good standard, as it can effect a lot of places in the code..

3) We are creating the work area in the first case as it is not a headerline table.

and SAP recommends to use tables without headerline bcoz OOPS doesn't use tables with header line...

Cheers,

Simha.

Reward all the helpful answers..