Professional Documents
Culture Documents
Internal table operations are most important for a ABAP developer, below are some of the most
important internal table operations
APPEND
INSERT
SORT
DESCRIBE TABLE
READ TABLE WITH KEY
READ TABLE WITH INDEX
LOOP....ENDLOOP.
MODIFY
DELETE
DELETE ADJACENT DUPLICATES
CLEAR, REFRESH, FREE
APPEND LINES OF
INSERT LINES OF
MOVE
COLLECT
Using APPEND in SAP ABAP
1. This statement is used to append a single record from work area to Internal Table.
2. The record is always added at the bottom.
This statement is used to INSERT a single record from work area to Internal Table at a specified
location.
INSERT WA_MARA INTO IT_MARA INDEX 2. "The record will be inserted into internal
Table at 2nd position.
SORT is used to sort an internal table data in ascending order or descending order, by default it will
sort data in ascending order. By default it sorts based on field1, field2, field3...etc.
.
Syntax1: SORT <ITAB>. "Default sorts data in ascending order.
Syntax2: SORT <ITAB> DESCENDING. Sort in descending order.
Syntax3: SORT <ITAB> BY <FIELD1> <FIELD2>... ASCENDING/DESCENDING
This statement is used to find the total number of records in an Internal Table.
Syntax:
READ TABLE WITH KEY... BINARY SEARCH is used to read a single record from an internal
table into work area specified by field name and field value.
BINARY SEARCH is a search mechanism which is used to read a record from internal table into
work area very fastly, the functionality of binary search it divides the into parts and searches, for full
details Binary Search mechanism in SAP ABAP /recourse/binary search.html. The internal table
must be sorted in ascending order before using binary search.
Read Table:
This statement is used to read a record from Internal Table into work area specified by either index
Number or key.
Syntax:
READ TABLE <ITAB> INTO <WA> WITH KEY <FIELD1> = <FIELD1 VALUE>
<FIELD1> =
<FIELD1 VALUE>
BINARY SEARCH
." Read a record into work area where some field = some value
READ TABLE IT_MARA INTO WA_MARA WITH KEY MATNR = '0001' BINARY SEARCH.
"Read a record into work area where MATNE is '0001'
READ TABLE WITH INDEX is used to read a single record from an internal table into work area
specified by index.
Syntax:
Save->Act->test
Read table i_kna1 into wa_kna1 with key kunnr = 0000001011 Binary search.
Save->Act->test
Using LOOP....ENDLOOP. In SAP ABAP
Loop...End loop. Is also used to read data from an internal table into work area, this is used to
read multiple records serially one after one.
ENDLOOP.
ENDLOOP.
ENDLOOP.
MODIFY is used to modify single or multiple internal table records based on condition
TRANSPORTING is a keyword which is used to specify list pf fields to be modified
instead of all fields. [OR]
This statement is used to MODIFY the Internal Table records based on Condition [OR]
From work area.
Syntax 1: MODIFY <ITAB> FROM <WA> INDEX <INDEX NO> TRANSPORTING
<FIELD1> <FIELD2>
SYTABIX is a key word which stores the index no of currently processed record. For full
Details read using sy tabix in sap abap programs /resourses/sytabis.html.
It is a system variable which stores the index number of the internal table records which is currently
being processed in work area.
TRANSPORTING: It specifies the list of the fields to be modified from work area to internal table.
DATA: IT_MARA TYPE TABLE OF MARA.
DATA: WA_MARA TYPE MARA.
SELECT * FROM MARA INTO TABLE IT_MARA. GET DATA INTO ITAB IT_MARA.
WA_MARAMTART = 'FERT';
"ASSIGN A VALUE TO WORKAREA TO MODIFY INTERNAL TABLE.
MODIFY IT_MARA FROM WA_MARA INDEX SYTABIX TRANSPORTING MTART.
"NOW THE VALUE OF.
FIELD MTART WILL BE MODIFIED FOR CURRENT RECORD IN IT_MARA
SELECT * FROM MARA INTO TABLE IT_MARA. GET DATA INTO ITAB IT_MARA.
WA_MARAMTART = 'FERT';
"ASSIGN A VALUE TO WORKAREA TO MODIFY INTERNAL TABLE .
MODIFY IT_MARA FROM WA_MARA TRANSPORTING MTART WHERE MATNR = '0001'.
NOW THE VALUE OF.
FIELD MTART WILL BE MODIFIED WHERE MATNR = '0001' IN ITAB
DELETE is used to delete single or multiple records from an internal table from work area
based on some condition.
This statement is used to DELETE a single record or multiple records based on Condition.
Ex on Delete:
DELETE ADJACENT DUPLICATES is used to delete duplicate records which are adjacent to
eachother. Pre requisite for this is the internal table must be sorted in ascending order
CLEAR WA_MARA.
REFRESH IT_MARA.
FREE IT_MARA.
Using APPEND LINES OF in SAP ABAP
APPEND LINES OF is used to append multiple records to an internal table from another internal
table.
Syntax:
INSERT LINES OF is used to INSERT multiple records to an internal table from another internal
table at specified Location.
Syntax:
COLLECT is similar to APPEND, the difference is it COLLECT will check whether the work
area record already exists with the same key only C, D, N, T, if exists it will add numerical fields
sum to the existing record, if work area record doesnt exists it will append a new record .
COLLECT:
This statement checks whether the WA record already exists in the internal table with the
same key.
If YES, it will just add the numerical fields.
If NO, A new record is appended.
1. This statement is used to DELETE the Duplicate records which are adjacent or side by side to
each other.
2. The prerequisite for this statement is, the ITAB should be sorted in ascending order.
SYNTAX:
CLEAR:
1. This statement is used to CLEAR or Delete the data from work area.
2. In older version this clear statement was used to delete the data from ITAB also.
SYNTAX:
Clear <wa>.
Clear <ITAB>[ ]---- IN older version.
REFRESH:
FREE:
1. This statement is used to DELETE the Data from work area and ITAB.
3. The difference is, the free statement delete the data as well as memory Occupied by ITAB or
work area, where as clear and refresh will delete only the data not the memory.
This statement is used to APPEND multiple records one internal table to another internal table.
SYNTAX:
Append lines of ITAB1 to ITAB2.
Append lines of ITAB1 from 3 to 7 to ITAB2.
This statement is used to INSERT multiple records one internal table to another internal table at a
specified location.
SYNTAX:
Insert lines of ITAB1 to ITAB2 index <N>.
Insert lines of ITAB1 from 3 to 7 to ITAB2.
This statement is used to move entire internal table records from one ITAB to another.