Tables

ABAP INTERNAL TABLES ABAP Internal Table - Internal table is data object to store identically structured data records

Views 119 Downloads 4 File size 233KB

Report DMCA / Copyright

DOWNLOAD FILE

Recommend stories

Citation preview

ABAP INTERNAL TABLES

ABAP Internal Table - Internal table is data object to store identically structured data records at runtime and no memory allocated , ABAP runtime dynamically manages the size of internal table -It is used for processing large data set in structured manner and can be used • For fetching data from database table • Preparing data for output • •

Properties of internal tables • • • • • • • • • • • • • •

Line Type :- structure of table row Primary key :- can be unique and non unique depending on access type Table kind :- Standard , Hash , Sorted dependent on access type

ABAP Internal Table Types Choose table type (and access method) by most frequently performed operation There are 3 ABAP Internal Table Types: 1) Standard Tables • •

Access by linear table index or key Response time proportional to table size

2) Sorted Tables

Filled in sorted order • Access by linear index or sort key Response time logarithmically proportional to table size •

3) Hashed TablesDirect access (only) by table key • • •

• • • • • • • • • • • • • • • • • •

Constant, fast response time Most appropriate when access to rows is by a key. (Cannot access hashed tables via the table index)response time remains constant regardless of the number of rows in the table.

Further to type of declaration there are

There are two types of internal tables. Internal tables with HEADER line Internal tables without HEADER line. Internal Tables with Header Line Here the system automatically creates the work area. This work area is called the HEADER line. Internal Tables without Header Line : Here there is no work area associated with the table. Work area is to be explicitly specified when we need to access such tables. With Header line is now obsolete and not used as it create work area with same name as internal table which sometimes create hindrance. Creating Internal Tables There are many ways to create an Internal Table. Lets look at them one by one1.By Using the Type Statement TYPES : begin of line, empno empname(20) end of line.

type I, type c

,

2.By referring to another Table You can  create an internal table by referring to an existing table. The existing table could be a standard SAP table, a Z table or another internal table. 3.By referring to existing Structure SyntaxData

LIKE occurs n [with header line].

4.By creating a new Structure Let us now create an internal table with a structure of our own. Here the table is created with an Header line, by default. Syntax Data : Begin of occurs , , ................................., End of . • • • •

Generic Key Operations

For

processing single records of an internal table a structure variable that has the same type as the line type of internal table is required.The structure variable is known as work area. Eg inserting a row in worktable DATA: gt_flightinfo TYPE bc400_t_flights, gs_flightinfo LIKE LINE OF gt_flightinfo gs_flightinfo-carrid = ‘’. gs_flightinfo-connid = ‘’ …. INSERT gs_flightinfo ITO TABLE gt_flightinfo. Standard Table :- append Sorted Table :- record inserted in correct place to keep table sorted Hash Table inserted according to hash algorithm For every operation we have to define the work area READ ROWS

Data Transfer & Internal Tables Filling line by line • Append, Collect, Insert Copying the contents of another table • Append, insert, move Reading line by line • Loop, read, search Determining the attributes of an internal table • Describe • • •

1) Append APPEND [ TO | INITIAL LINE TO] itab type standard table of spfli , itab_wa like spfli. Select * into itab_wa From spfli. Append itab_wa to itab. endselect.

System Fields Used in Table Processing SY-TABIX • Holds the index of the current line in the table SY-SUBRC • Return code for operation SY-SUBRC = 0 • Operation was sucessful SY-SUBRC 0 • Operation failed SY-DBCNT • Number of lines that were affected by the operation • How many lines have already been processed • • •