Operations on Internal Tables

 

Processing an Internal table

To perform an operation on each and every record of an internal table

LOOP AT <itab>.          Each record will be transferred to Implicit 
                         Header Line
:
:
ENDLOOP.
LOOP AT <itab> INTO <wa>.  Each record will be transferred to an Explicit 
                           Header Line
:
:
ENDLOOP.
LOOP AT <itab> INTO <wa> FROM n1 TO n2.          to process a range of records

:

ENDLOOP.
Inserting Lines into Tables

Adding records either at the end or at the specified position. If index is not specified records will be added at the end of the table.

To add a line to an internal table

INSERT <line> INTO TABLE <itab> INDEX n.

INTO addition is not required if inserting is done through implicit header line.

To add several lines to an internal table.

INSERT LINES OF <itab1> [FROM <n1>] [TO <n2>] INTO TABLE <itab2>.
Appending Lines to Tables

Adding records at the end of the table,

To add a line to an internal table.

APPEND <line> INTO TABLE <itab>.

To add several lines to an internal table.

APPEND LINES OF <itab1> [FROM <n1>] [TO <n2>] INTO TABLE <itab2>.
Changing Lines

To change a single line of any internal table, use the MODIFY statement.

To change a single line

MODIFY TABLE <itab> FROM <wa> [TRANSPORTING <f1> <f2> ...].

Changing Several Lines

MODIFY <itab> FROM <wa> TRANSPORTING <f1> <f2>....WHERE <cond>.
Deleting Lines

To delete a single line of any internal table, use the DELETE statement.

DELETE TABLE <itab> FROM <wa>.

or

DELETE TABLE <itab> WITH TABLE KEY <k1> = <f1> ... <kn> = <fn>.

To delete more than one line using a condition-

DELETE <itab> WHERE <cond>.
Reading Lines of Tables

To read a single line of any table

READ TABLE <itab> INTO <wa> WITH KEY <k1> = <f1> ...<kn> = <fn>.

Or

READ TABLE <itab> INTO <wa> INDEX n.
Clearing Tables

To make internal tables empty

CLEAR <itab>.   Clears only implicit header line.
CLEAR <itab>[].   Clears only body records.
REFRESH <itab>.    Clears only body records.
FREE <itab>.     Clears only body records and frees the memory.
Counting number of records

To know the number of records contained in an internal table

DESCRIBE TABLE <itab> LINES n.

'n' is a variable that holds the count.

Sorting the records

To arrange the records of an internal table in an order

SORT <itab> BY Ascending/Descending <f1> Ascending/Descending <f2>..

Default order is Ascending.

Other Operations
  • An internal table can be assigned to another internal table.
  • Two internal tables can be compared with relational operators.

Both tables must be type compatible.

Comments

Popular posts from this blog

Domains and Data Elements

Sample ABAP program for Updating notepad file data to Internal table and Sending it to Application server

OPEN SQL EXAMPLES IN ABAP – PART 2