220 likes | 548 Views
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 , Carrid Like Sflight-Carrid ,
E N D
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 , Carrid Like Sflight-Carrid , Connid Like Sflight-Connid , End of Flight_Record .
Internal Tables Data: Begin of INT_Demo Occurs 100 , Carrid Like Sflight-Carrid , Connid Like Sflight-Connid , End of INT_Demo .
Internal Tables Data: Begin of INT_Demo Occurs 100 , Include Structure Sflight , End of INT_Demo .
Internal Table Structure Header Header Items Items
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.
Item Records • The item records are the internal table. • All usage of the items are via the header record.
Selecting from an External Table Select * from Sflight into Flight_Record. Select Carrid Connid from Sflight into Flight_Record.
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 .
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.
Clearing the Header Clear INT_Demo. • The Clear statement clears the header only, not the items.
Clearing the Items Refresh INT_Demo. • The Refresh statement purges the internal table of all data, but not the header.
Sorting the Internal Table Sort INT_Demo by Carrid Ascending SeatsOcc Descending . • Up to 50 fields can be sorted .
Determining the number of items Data: W_Lines type I , W_Cnt type I . Describe INT_Demo Lines W_Lines .
Looping through the table While W_Cnt < W_Lines . W_Cnt = W_Cnt + 1 . Read Table INT_Demo Index W_Cnt . . . . . . . . EndWhile .
Field Strings (Record) Data: Begin of INT_Key , City(10) type C , State(2) type C , End of INT_Key .
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 .
Loop At Loop At INT_Demo . whatever . EndLoop .
Loop At Where Loop At INT_Demo Where condition . whatever . EndLoop .
Modifying an item Loop At INT_Demo . (modify the header field(s)). Modify INT_Demo Index sy-tabix . Clear INT_Demo . EndLoop .
Deleting an item Loop At INT_Demo . If whatever . Delete INT_Demo Index sy-tabix . EndIf . Clear INT_Demo. EndLoop .