abap tables

22
1 ABAP Tables Northern Arizona University College of Business

Upload: eugene

Post on 21-Jan-2016

61 views

Category:

Documents


1 download

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 Presentation

TRANSCRIPT

Page 1: ABAP Tables

1

ABAP Tables

Northern Arizona University

College of Business

Page 2: ABAP Tables

2

Database tables

To reference a database table inside an ABAP program the Tables identifier must be used.

Tables:

Sflight .

Page 3: ABAP Tables

3

Records - Revisited

Data:

Begin of Flight_Record ,

Carrid Like Sflight-Carrid ,

Connid Like Sflight-Connid ,

End of Flight_Record .

Page 4: ABAP Tables

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

5

Internal Tables

Data:

Begin of INT_Demo Occurs 100 ,

Include Structure Sflight ,

End of INT_Demo .

Page 6: ABAP Tables

6

Internal Table Structure

Header

Items

Header

Items

Page 7: ABAP Tables

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

8

Item Records

The item records are the internal table.

All usage of the items are via the header record.

Page 9: ABAP Tables

9

Selecting from an External Table

Select * from Sflight into Flight_Record.

Select Carrid Connid from Sflight into Flight_Record.

Page 10: ABAP Tables

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

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

12

Clearing the Header

Clear INT_Demo.

The Clear statement clears the header only, not the items.

Page 13: ABAP Tables

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

14

Sorting the Internal Table

Sort INT_Demo by Carrid Ascending SeatsOcc Descending .

Up to 50 fields can be sorted .

Page 15: ABAP Tables

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

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

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

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

19

Loop At

Loop At INT_Demo .

whatever .

EndLoop .

Page 20: ABAP Tables

20

Loop At Where

Loop At INT_Demo Where condition .

whatever .

EndLoop .

Page 21: ABAP Tables

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

22

Deleting an item

Loop At INT_Demo .

If whatever .

Delete INT_Demo Index sy-tabix .

EndIf .

Clear INT_Demo.

EndLoop .