abap tables
DESCRIPTION
ABAP Tables. Northern Arizona University College of Business. Database tables. To reference a database table inside an ABAP program the Tables identifier must be used. Tables: Sflight. Records - Revisited. Data: Begin of Flight_Record , CarridLike Sflight-Carrid , - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/1.jpg)
1
ABAP Tables
Northern Arizona University
College of Business
![Page 2: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/2.jpg)
2
Database tables
To reference a database table inside an ABAP program the Tables identifier must be used.
Tables:
Sflight .
![Page 3: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/3.jpg)
3
Records - Revisited
Data:
Begin of Flight_Record ,
Carrid Like Sflight-Carrid ,
Connid Like Sflight-Connid ,
End of Flight_Record .
![Page 4: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/4.jpg)
4
Internal Tables
Data:
Begin of INT_Demo Occurs 100 ,
Carrid Like Sflight-Carrid ,
Connid Like Sflight-Connid ,
End of INT_Demo .
![Page 5: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/5.jpg)
5
Internal Tables
Data:
Begin of INT_Demo Occurs 100 ,
Include Structure Sflight ,
End of INT_Demo .
![Page 6: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/6.jpg)
6
Internal Table Structure
Header
Items
Header
Items
![Page 7: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/7.jpg)
7
Header Record
The header record is a temporary holding area.
The header contains data before it is written to the internal table (append).
The header contains data after an item has been read.
![Page 8: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/8.jpg)
8
Item Records
The item records are the internal table.
All usage of the items are via the header record.
![Page 9: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/9.jpg)
9
Selecting from an External Table
Select * from Sflight into Flight_Record.
Select Carrid Connid from Sflight into Flight_Record.
![Page 10: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/10.jpg)
10
Moving from the record to the header of the internal table.
Move:
Flight_Record-Carrid to INT_Demo-Carrid ,
Flight_Record-Connid to INT_Demo-Connid .
![Page 11: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/11.jpg)
11
Appending records from the header to the items.
Append INT_Demo.
The contents of the header record are added to the end of the items.
![Page 12: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/12.jpg)
12
Clearing the Header
Clear INT_Demo.
The Clear statement clears the header only, not the items.
![Page 13: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/13.jpg)
13
Clearing the Items
Refresh INT_Demo.
The Refresh statement purges the internal table of all data, but not the header.
![Page 14: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/14.jpg)
14
Sorting the Internal Table
Sort INT_Demo by Carrid Ascending SeatsOcc Descending .
Up to 50 fields can be sorted .
![Page 15: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/15.jpg)
15
Determining the number of items
Data: W_Lines type I ,
W_Cnt type I .
Describe INT_Demo Lines W_Lines .
![Page 16: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/16.jpg)
16
Looping through the table
While W_Cnt < W_Lines .
W_Cnt = W_Cnt + 1 .
Read Table INT_Demo Index W_Cnt .
. . . . . . .
EndWhile .
![Page 17: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/17.jpg)
17
Field Strings (Record)
Data:
Begin of INT_Key ,
City(10) type C ,
State(2) type C ,
End of INT_Key .
![Page 18: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/18.jpg)
18
Read with Key
Move ‘Flagstaff’ to City .
Move ‘AZ’ to State .
Read Table INT_Demo
with Key INT_Key .
Read Table INT_Demo
with Key INT_Key Binary Search .
![Page 19: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/19.jpg)
19
Loop At
Loop At INT_Demo .
whatever .
EndLoop .
![Page 20: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/20.jpg)
20
Loop At Where
Loop At INT_Demo Where condition .
whatever .
EndLoop .
![Page 21: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/21.jpg)
21
Modifying an item
Loop At INT_Demo .
(modify the header field(s)).
Modify INT_Demo Index sy-tabix .
Clear INT_Demo .
EndLoop .
![Page 22: ABAP Tables](https://reader036.vdocuments.us/reader036/viewer/2022062309/568150be550346895dbedde1/html5/thumbnails/22.jpg)
22
Deleting an item
Loop At INT_Demo .
If whatever .
Delete INT_Demo Index sy-tabix .
EndIf .
Clear INT_Demo.
EndLoop .