Internal Tables
- Internal table is a temporary table created in RAM in Application Server
- It is created & filled with data during run time (execution time)
- Once execution is performed it is rolled out (or) discarded
Note:We Use Internal table for storing multiple records during run time
Difference between Database table & Internal table:
Database Table Internal Table
1. It is created in Database Server 1. It is created in Application Server
2. It holds data permanently 2. It holds data temporarily
3. It holds only specific type of data 3. It holds data of different tables of at one place
Question: What is exact purpose of Internal table. Do you think should be created in ABAP
programming?
Answer: In real time we are creating Internal table for storing different types of application data
from different tables at one place.
Every Internal table is having 2 parts
They are:
1. Internal Table Body
2. Header Line
1. Internal Table Body:
The name Internal table itself specifies body of Internal table & it holds multiple records
2. Header Line:
It is a default Work Area & holds single record
Note: Header Line is system defined Work Area & Work Area is user defined Header Line
Syntax:
DATA: BEGIN OF it_kna1 OCCURS 0,
customer(20) TYPE C,
name(20) TYPE C,
city(20) TYPE C,
END OF it_kna1.
Note:
1. With above syntax an Internal table it_kna1 is crated in Application Server
2. You can provide any name. But in real time Internal table should always begins with it_ (or) i_ followed by table name
3. With BEGIN option Header Line is created & OCCURS option Body is created
4. 0, 1, 2, 3, …..9 is called Size Category
5. Both Header Line & Body name is same (it_kna1)
Flow of Data in Internal Table:
1. Database Table ----> Body---> Header Line--->Virtual Page --->Presentation Server
2. Database Table ---> Body---> Presentation Server
Reading Data from Body to Work Area (or) Header Line:
1. LOOP ……….. ENDLOOP
2. READ keywords
1. LOOP ……… ENDLOOP:
It reads multiple records (record by record) from Body to Header Line (or) Work Area
Syntax:
LOOP AT it[INTO wa]
[FROM m][TO n]
[where condition].
…………
…………
ENDLOOP.
LOOP AT it: Reads multiple records (record by record) from Body to Header Line
Note:Internally system converts LOOP AT it as LOOP AT it INTO it.
Working:
- Go to SE38
- Program: ZSD_LOOPENDLOOP
- Select Create option
- Title; Internal Table
- Type: Executable Program
- Select Save option
- Leave Package:__________ blank
- Select Local Object option
Program: REPORT ZSD_LOOPENDLOOP.
* provide internal table
DATA: BEGIN OF it_kna1 OCCURS 0,
customer(20) TYPE C,
name(20) TYPE C,
city(20) TYPE C,
END OF it_kna1.
* provide extraction logic
SELECT kunnr name1 ort01 FROM kna1 INTO TABLE it_kna1.
* Appling processing logic
LOOP AT it_kna1 INTO it_kna1.
WRITE:/10 it_kna1-customer,
30 it_kna1-name,
60 it_kna1-city.
ENDLOOP.
Note; Activate the program then select F8 to execute the program
- Debugging: Internal Table
- Go to SE38
- Program: ______ which you want to debug
- Select Debugging button
- Select Tables tab (starting from 6th option)
- Table: it_kna1 & press Enter
Note:
You will find a Cap symbol which indicates Header Line (holds only single record)
Select F5 for single step debugging
Note:
1. Table keyword will transfer the data directly to Internal Table to Body
2. Always use Table keyword in select statement if you are working with Internal Tables
3. As long as you are in loop system will read next record in-line in an Internal Table. Once the loop is terminated again the loop starts reading from 1st line
LOOP AT it INTO wa:
Reads multiple records (record by record) from Body to Work Area
Working:
- Go to SE38
- Program: ZSD_INTERNAL_WORKAREA
- Select Create option
- Title: Internal Table & Work Area
- Type: Executable Program
- Select Save option
- Leave Package:__________ blank
- Select Local Object option
Program: REPORT ZSD_ INTERNAL_WORKAREA.
* provide internal table & work area
TYPES: BEGIN OF ty_kna1,
customer (20) TYPE C,
name(20) TYPE C,
city(20) TYPE C,
END OF ty_kna1.
DATA: wa_kna1 TYPE ty_kna1,
it_kna1 TYPE TABLE OF ty_kna1.
* provide extraction logic
SELECT kunnr name1 ort01 FROM kna1 INTO TABLE it_kna1.
* Appling processing logic
LOOP AT it_kna1 INTO wa_kna1.
WRITE:/10 wa_kna1-customer,
30 wa_kna1-name,
60 wa_kna1-city.
ENDLOOP.
Note:
1. Using TABLE OF you can create your own body
2. Using TYPES keyword Structures are created in ABAP programming
3. In ABAP programming always create Object (Work Area & Body) based on Structures
4. Avoid creating Internal Table with OCCURS clause
LOOP AT it INTO wa FROM m TO n:
Reads multiple records from Body to Work Area based on given condition
Example:
1. LOOP AT it INTO wa FROM 100.
2. LOOP AT it INTO wa FROM TO 50.
3. LOOP AT it INTO wa FROM 100 TO 200.
No comments:
Post a Comment