0% found this document useful (0 votes)
13 views6 pages

Internal Tables 9

The document discusses various operations that can be performed on internal tables in ABAP such as appending, inserting, collecting, reading, modifying, deleting, sorting, and transferring data. Append adds data to the end of a table, insert adds based on a key, and collect checks for a key and adds or updates data accordingly. Reading can be done by index, condition, or loop. Data can be modified or deleted using keywords and sorted or transferred between tables.

Uploaded by

mohan b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

Internal Tables 9

The document discusses various operations that can be performed on internal tables in ABAP such as appending, inserting, collecting, reading, modifying, deleting, sorting, and transferring data. Append adds data to the end of a table, insert adds based on a key, and collect checks for a key and adds or updates data accordingly. Reading can be done by index, condition, or loop. Data can be modified or deleted using keywords and sorted or transferred between tables.

Uploaded by

mohan b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Operations on Internal Table: -

1. Pushing data from work area to internal table by using


a. Append  Standard table
b. Insert  Sorted table
c. Collect  Hashed table

2. Reading the data from internal table

Single Record Multiple Records (Loop at)


3. Modify the data in an internal table by using modify keyword.
4. Delete the data in an internal table by using delete keyword.
5. Sort the data in an internal table by using sort keyword.
6. Delete the duplicate records from the internal table by using Delete adjacent duplicates.
7. Transfer for the data from one internal table to another internal table

Append: - Append is the keyword to transfer the data from work area to at the last record of internal table.

Syntax: -
Append <work area> to <internal table>.

Ex: - Append WA_t001 to IT_t001.

Example on append

REPORT YSP_7PM_OITAB_OPERATIONS.

TYPES : BEGIN OF TY_T001,


BUKRS TYPE T001-BUKRS,
BUTXT TYPE T001-BUTXT,
ORT01 TYPE T001-ORT01,
END OF TY_T001.

DATA : WA_T001 TYPE TY_T001,


IT_T001 TYPE TABLE OF TY_T001.

SELECT BUKRS BUTXT ORT01 FROM T001 INTO TABLE IT_T001 UP TO 5 ROWS.

LOOP AT IT_T001 INTO WA_T001.


WRITE :/ WA_T001-BUKRS,WA_T001-BUTXT,WA_T001-ORT01.
ENDLOOP.
ULINE.
*Append
WA_T001-BUKRS = '0004'.
WA_T001-BUTXT = 'SPRAO Technologies'.
WA_T001-ORT01 = 'HYD'.
APPEND WA_T001 TO IT_T001.

LOOP AT IT_T001 INTO WA_T001.


WRITE :/ WA_T001-BUKRS,WA_T001-BUTXT,WA_T001-ORT01.
ENDLOOP.

Insert: - Insert is the keyword to transfer the data from work area to internal table based on the key
field.

Syntax: -
Insert <work area> into table <internal table>.

Ex: -
Insert WA_t001 into table IT_t001.

Note: - If we use insert keyword to standard internal table then it acts like append.

Example on insert

REPORT YSP_7PM_OITAB_OPERATIONS.

TYPES : BEGIN OF TY_T001,


BUKRS TYPE T001-BUKRS,
BUTXT TYPE T001-BUTXT,
ORT01 TYPE T001-ORT01,
END OF TY_T001.

DATA : WA_T001 TYPE TY_T001,


IT_T001 TYPE SORTED TABLE OF TY_T001 WITH UNIQUE KEY BUKRS.

SELECT BUKRS BUTXT ORT01 FROM T001 INTO TABLE IT_T001 UP TO 5 ROWS.

LOOP AT IT_T001 INTO WA_T001.


WRITE :/ WA_T001-BUKRS,WA_T001-BUTXT,WA_T001-ORT01.
ENDLOOP.
ULINE.
*Insert
WA_T001-BUKRS = '0004'.
WA_T001-BUTXT = 'SPRAO Technologies'.
WA_T001-ORT01 = 'HYD'.
INSERT WA_T001 INTO TABLE IT_T001.

LOOP AT IT_T001 INTO WA_T001.


WRITE :/ WA_T001-BUKRS,WA_T001-BUTXT,WA_T001-ORT01.
ENDLOOP.

Collect: - Collect checks the internal table whether the record is available or not based on the key field.
If not it acts like append (record adds first). Other wise it adds the numeric fields from work area to
number field in the internal table.

Syntax: -
Collect <Workarea> into <Internal table>.

Ex: - Collect WA into IT.


Whether we are working with collect keyword then we
must declare other than numeric (data types) files are unique.

Example on collect

REPORT YSP_7PM_OITAB_OPERATIONS.

TYPES : BEGIN OF TY,


EID(10) TYPE C,
EBO TYPE I,
END OF TY.

DATA : WA TYPE TY,


IT TYPE HASHED TABLE OF TY WITH UNIQUE KEY EID.

WA-EID = '1'.
WA-EBO = '5000'.
COLLECT WA INTO IT.

WA-EID = '2'.
WA-EBO = '9000'.
COLLECT WA INTO IT.

WA-EID = '4'.
WA-EBO = '2000'.
COLLECT WA INTO IT.
LOOP AT IT INTO WA.
WRITE :/ WA-EID,WA-EBO.
ENDLOOP.
ULINE.

*Collect
WA-EID = '3'.
WA-EBO = '7000'.
COLLECT WA INTO IT.

WA-EID = '2'.
WA-EBO = '6000'.
COLLECT WA INTO IT.

LOOP AT IT INTO WA.


WRITE :/ WA-EID,WA-EBO.
ENDLOOP.

Example on reading data from internal table

REPORT YSP_7PM_OITAB_OPERATIONS.

TYPES : BEGIN OF TY_T001,


BUKRS TYPE T001-BUKRS,
BUTXT TYPE T001-BUTXT,
ORT01 TYPE T001-ORT01,
END OF TY_T001.

DATA : WA_T001 TYPE TY_T001,


IT_T001 TYPE TABLE OF TY_T001 .

SELECT BUKRS BUTXT ORT01 FROM T001 INTO TABLE


IT_T001 UP TO 5 ROWS.

LOOP AT IT_T001 INTO WA_T001.


WRITE :/ WA_T001-BUKRS,WA_T001-BUTXT,WA_T001-ORT01.
ENDLOOP.
ULINE.

Reading a single record from internal table based on index:-


Syntax: -
Read table <internal table> into <work area> index <number>.
Ex: -
Read table IT_t001 into WA_t001 index 2.
We never use this condition in real time.
Reading a single record for the internal table based on condition:-
Syntax: -
Read table <internal table> into <work area> with key condition.

Ex: -
Read table IT_t001 into WA_t001 with key BUKRS = ‘2000’.
OP: - 1000 IBM Chennair
Ex:-
Read table IT_t001 into WA_t001 with key ort01 = ‘Hyd’.

Reading multiple records from the internal table based on index.


Syntax: -
Loop at <internal table> into <work area> from <index no> to <index no>.
-------
------- optional
-------
Endloop.
Ex: -
Loop at IT_t001 into WA_t001 from 2 to 3.
Write: / WA_t001-BUKRS, WA_t001-BUTXT, WA_t001-ORT01.
Endloop.
OP: - 200 IBM Chennai
300 HCL Hyderabad

Reading multiple records from the internal table based on condition :-


Syntax: -
Loop at <internal table> into <work area> where <condition>.
--------
--------
--------
Endloop.

Ex: -
Loop at IT_t001 into WA_t001 where ORT01 = ‘Hyderabad’.
Write: / WA_t001-BUKRS, WA_t001-BUTXT, WA_t001-ORT01.
Endloop.
OP: - 1000 TCS Hyderabad
3000 HCL Hyderabad

Modify the data in internal table by using modify keyword:-

This is 2 step procedure.


1. Fill the latest information into the work area.
2. Modify the index table based on work area.
Syntax:-
Modify <internal table> from <work area> transporting <field1> <field2> where <condition>.
Ex: -
WA_t001-ORT01 = ‘BAN’.
Modify IT_t001 from WA_t001 transporting ORT01 where BUKRS = ‘2000’.

LOOP AT IT_T001 INTO WA_T001.


WRITE :/ WA_T001-BUKRS,WA_T001-BUTXT,WA_T001-ORT01.
ENDLOOP.

You might also like