ABAP Internal table declaration - Various methods of creating internal data structures and tablesDeclaring 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).
data: it_ekpo TYPE STANDARD TABLE OF EKKO INITIAL SIZE 0. This creates an internal table called it_data with the same structure as EKKO. The initial size 0 simple tells the program not to reserve any space for it upfront and allocate it as and when filled. Also if you wanted an internal 1 line work area with this structure you could also reference the dictionary object using the following statement: data: wa_ekpo TYPE EKPO. “Creates a local work area called wa_ekpo or wa_ekpo1 like line of it_ekko EKPO. “Creates a local work based on an existing itab or TABLES: EKPO. “Also creates a local work area called ekpo
TYPES: BEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
“more fields can be added here
END OF t_ekpo.
The 'TYPES: BEGIN OF' statement defines the start of this declaration and the t_ekpo is the name of the structure and can be anything you want. The 'END OF t_ekpo.' statement defines the end of the structure definition. You now have a structure called t_ekpo that can be used in the same way as the dictionary object EKKO was used above: data: it_ekpo TYPE STANDARD TABLE OF t_ekpo,
wa_ekpo TYPE t_ekpo.
TYPES: BEGIN OF t_repdata.
INCLUDE STRUCTURE ekko.
TYPES: ebelp TYPE ekpo-ebelp,
werks TYPE ekpo-werks.
TYPES: END OF t_repdata.
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)
DATA: BEGIN OF tab_ekpo, "Work area declaration / Header line
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
END OF tab_ekpo.
DATA: BEGIN OF tab_ekpo OCCURS 0, "Table declaration with header line
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
END OF tab_ekpo.
If you wanted to reference a dictionary object (SE11) such as EKPO then you would use the following syntax: Data: it_tabekpo LIKE ekpo OCCURS 0, "Table with header line wa_tabekpo LIKE ekpo. “Work area Example report showing full ABAP syntax and use of table declarations described above *&-------------------------------------------------------------*
*& Report ZTYPES *
*& *
*&-------------------------------------------------------------*
REPORT ZTYPES .
*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)
wa_ekpo1 LIKE LINE OF it_ekpo.
* Build internal table and work area from existing table with
* additional fields
TYPES: BEGIN OF t_repdata.
INCLUDE STRUCTURE ekko. "could be an itab such as tab_ekpo
TYPES: ebelp TYPE ekpo-ebelp,
werks TYPE ekpo-werks.
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)
* 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.
Data: it_tabekpo LIKE ekpo OCCURS 0, "Table with header line
wa_tabekpo LIKE ekpo. "Work area
* Build internal table from existing dictionary structure (old method)
DATA: it_datatab LIKE ekko OCCURS 0.
**************************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
*Select data in itab
SELECT ebeln
ebelp
from EKPO
into table it_ekpo.
*Process data within itab using LOOP statement
Loop at it_ekpo into wa_ekpo.
write: wa_ekpo-ebeln.
* processing......
endloop.
*Select data in itab declared the old way
SELECT ebeln
ebelp
from EKPO
into table tab_ekpo.
Loop at tab_ekpo.
write: tab_ekpo-ebeln.
* processing......
endloop.
|
||||