ABAP - T05-001 - ABAP Internal Table
ABAP - T05-001 - ABAP Internal Table
Report Output
MOVE WA_EMPL1 TO WA_EMPL2.
WRITE: / WA_EMPL2-LASTNAME,
Salm
/ WA_EMPL2-PERSNBR. 546259
SKIP.
*GS_SPFLI-CARRID = GS_SPFLI_TBL-CARRID.
MOVE-CORRESPONDING GS_SPFLI_TBL TO GS_SPFLI.
WRITE: / GS_SPFLI.
• HEADER LINE is a special work area that have the same name as
the internal table.
• It is created when we declare WITH HEADER LINE.
• It can be used to access internal table data without the need to create a
separate Work Area.
• HEADER LINE not working with ABAP OOP.
• HEADER LINE is obsolete.
• DO NOT use HEADER LINE in your new program.
Internal Table Attributes
PROGRAM ZEXAMPLE.
TYPE: BEGIN OF TY_EMPLOYEE,
PERSNBR(6) TYPE N, Line Type
LASTNAME(20) TYPE C,
END OF TY_EMPLOYEE.
Table
DATA: ITAB_EMPLTAB TYPE STANDARD TABLE Type
OF TY_EMPLOYEE WITH KEY UNIQUE PERSNBR
INITIAL SIZE 10,
WA_EMPLTAB TYPE T_TAB.
Key
* All of the above syntax will be explained in detail later in this section!
Declaring an Internal Table
I_EMPLTAB WA_EMPLTAB
546259 SALM 578110 MIDDLEMARK
163927 COSTIGAN
578110 MIDDLEMARK In order to manipulate a row in an
803124 SIEBER internal table, that row must first be put in
804320 SIFFERMAN the work area (commands that put the
. . contents of a table row into the work area
. . will be discussed later on!)
Filling an Internal Table
TAB-INDEX = SY-TABIX + 1.
READ TABLE I_TAB INDEX TAB_INDEX.
ABAP Internal Table
Part 3 - Internal Table Types: Standard
Outline
» 3 types of Internal Table
1. Creating every types of Internal Table
2. Adding data records to Internal Table using APPEND
3. Adding data records to Internal Table using INSERT
4. Single data accessing: READ TABLE
5. Data accessing: LOOP
6. Single data accessing: LOOP … EXIT …
7. Modifying data records using MODIFY
8. Modifying data records using FIELD-SYMBOL
9. Delete data from Internal Table
10. Clear all data of an Internal Table
Terms
» KEY field: a field to help identify one line of data in table.
» PRIMARY KEY: every table must has at least 1 primary key. A
Primary Key can include one or many KEY fields
» SECONDARY KEY: help increase search performance.
» UNIQUE: not allow duplication of data (E.g. Không thể tồn tại 2
số CCCD trùng nhau)
» NON-UNIQUE: allow duplication of data.
» HASH: https://en.wikipedia.org/wiki/Hash_function
» BINARY SEARCH / LINEAR SEARCH
Internal Table Types
Prior to SAP 4.0, the standard table was the only table type.
STANDARD TABLE
ABAP Internal Table
Part 4 - Internal Table Types: Sorted
Internal Table Types
Prior to SAP 4.0, the standard table was the only table type.
SORTED TABLE
ABAP Internal Table
Part 5 - Internal Table Types: Hashed
Internal Table Types
Prior to SAP 4.0, the standard table was the only table type.
HASHED TABLE
Internal Table Types and Keys
Changing an Internal Table
INSERT <wa> INTO <itab> INDEX <i>.
MODIFY <itab> FROM <wa> INDEX <i>.
DELETE <wa> FROM <itab> INDEX <i>.
REPORT ZEXAMPLE.
TABLES: TABNA.
TYPES: BEGIN OF T_REC,
COUNTRY LIKE TABNA-COUNTRY,
ID LIKE TABNA-ID,
NAME1 LIKE TABNA-NAME1,
END OF T_REC.
DATA: I_TAB TYPE STANDARD TABLE OF T_REC,
WA_TAB TYPE T_REC.
.
.
READ TABLE I_TAB WITH KEY ‘USA’ BINARY SEARCH INTO WA_TAB.
MOVE ’US of A' TO I_TAB-NAME1.
MODIFY I_TAB FROM WA_TAB INDEX SY-TABIX.
READ TABLE I_TAB WITH KEY ‘CAN’ BINARY SEARCH INTO WA_TAB.
MOVE ‘MEX’ TO WA_TAB-COUNTRY.
INSERT WA_TAB INTO I_TAB.
READ TABLE I_TAB WITH KEY ‘IRE’ BINARY SEARCH INTO WA_TAB.
DELETE I_TAB INDEX SY-TABIX.
Deleting an Internal Table
CLEAR <itab>.
REFRESH <itab>.
FREE <itab>.
REPORT <name>.
.
.
.
LOOP AT TAB.
WRITE: / SY-TABIX, TAB-COUNTRY, ... .
ENDLOOP.
REPORT <name>.
.
.
.
PARAMETERS: START LIKE SY-TABIX DEFAULT '10',
END LIKE SY-TABIX DEFAULT '20'.
LOOP AT TAB FROM START TO END.
WRITE: / SY-TABIX, TAB-COUNTRY, ... .
ENDLOOP.
ABAP Internal Table
Part 6 - Some techniques for Internal Tables:
SORT, COLLECT, etc.
Outline Part 6
» Compressing Data using COLLECT
» Sorting an Internal Table using SORT
» Delete duplicated data in an Internal Table
» Copy an Internal Table to another Internal Table
» Get information of an Internal Table: Number of line, etc.
Compressing Data with an Internal Table
COLLECT <itab>. Country Sales (Type P)
REPORT <name>.
TABLES: ADRC.
TYPES: BEGIN OF TY_MAT,
COUNTRY LIKE ADRC-COUNTRY,
ID LIKE ADRC-ID,
NAME1 LIKE ADRC-NAME1
SALES LIKE ADRC-SALES,
END OF TY_MAT.
DATA: ITAB_ADRC TYPE STANDARD TABLE OF TY_MAT
WITH KEY NON-UNIQUE COUNTRY
INITIAL SIZE 5,
WA_TAB TYPE TY_MAT.
SORT ITAB_ADRC.
REPORT <name>.
TABLES: TABNA.
REPORT <name>.
.
.
.
LOOP AT <itab> INTO <wa>.
.
.
.
MODIFY <itab> FROM <wa>.
.
.
.
INSERT <wa> INTO <itab>.
.
.
.
DELETE <itab>.
.
.
.
ENDLOOP.
Thank you
Q&A