Chapter 07 - Data Structures & Internal Tables
Chapter 07 - Data Structures & Internal Tables
Objectives
2 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
Data Structures
LN FN City ST.
LN FN City ST.
3 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
4 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
5 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
REPORT Y170DM37.
TABLES: EMPLOYEE. EMPLOYEE
ID Name1 City
DATA: BEGIN OF ADDRESS,
000000001 Electronics Inc. Waldorf
FLAG,
Address MOVE-CORRESPONDING EMPLOYEE
ID LIKE EMPLOYEE-ID, TO ADDRESS.
NAME LIKE EMPLOYEE-NAME1,
Flag ID Name City
CITY LIKE EMPLOYEE-CITY,
END OF ADDRESS. 000000001 Waldorf
6 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
Demonstration
Declaring a structure and populating the structure with values inside a program.
7 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
Practice
Declaring a structure and populating the structure with values inside a program.
8 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
Standard
Sorted
Hashed
9 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
10 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
Implicit Key
All character fields
Explicit Key
User-defined
e.g. WITH [ UNIQUE/NON-UNIQUE ] KEY FIELD1 FIELD2 ...
11 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
12 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
13 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
EMPLOYEE
A
COUNTRY ID FORMA NAME1 SORTL . . .
ID NAME1 COUNTRY
B Header Line
15 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
1 EMPLOYEE
ID NAME1 COUNTRY
Header Line
16 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
1 EMPLOYEE
2
ID NAME1 COUNTRY
00000001 Baker Distributors USA Header Line
17 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
1 EMPLOYEE
2
ID NAME1 COUNTRY
00000001 Baker Distributors USA Header Line
18 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
4 EMPLOYEE
5
ID NAME1 COUNTRY
00000002 Diversified Indust... USA Header Line
6 2
00000002 Diversified Indust... USA
3
. .
. .
. .
10
19 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
20 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
Performance Issues
21 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
EMPLOYEE
A
COUNTRY ID FORMA NAME1 SORTL . . .
ID NAME1 COUNTRY
B Work Area
22 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
ID NAME1 COUNTRY
2
00000001 Baker Distributors USA Work Area
ID NAME1 COUNTRY
00000001 Baker Distributors USA 1
3 This work area
2 is not attached
to the body of
the internal
3
. table.
.
.
10
23 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
REPORT Y170DM41.
TABLES: EMPLOYEE.
DATA: EMPTAB LIKE STANDARD TABLE OF
EMPLOYEE INITIAL SIZE 10 WITH HEADER LINE.
The internal table EMPTAB
will have the exact same
SELECT * FROM EMPLOYEE. structure as the dictionary
MOVE EMPLOYEE TO EMPTAB. table EMPLOYEE.
APPEND EMPTAB.
ENDSELECT.
24 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
25 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
REPORT Y170DM69.
SELECT * FROM <table> . . .
TABLES: EMPLOYEE. 1. INTO TABLE <EMPTAB>.
2. APPENDING TABLE
DATA: EMPTAB LIKE STANDARD TABLE <EMPTAB>.
EMPLOYEE INITIAL SIZE 10 WITH HEADER LINE.
26 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
30 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
AT FIRST
AT NEW < field >
AT END < field >
AT LAST
31 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
REPORT Y170DM47.
TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
COUNTRY LIKE EMPLOYEE-COUNTRY,
NAME1 LIKE EMPLOYEE-NAME1,
END OF EMPTAB.
READ TABLE ….
32 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
33 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
34 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
35 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
36 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
37 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
REPORT Y170DM50.
TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
COUNTRY LIKE EMPLOYEE-COUNTRY,
NAME1 LIKE EMPLOYEE-NAME1,
END OF EMP,
DATA: EMPTAB TYPE STANDARD TABLE OF EMP
INITIAL SIZE 10 WITH HEADER LINE,
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB.
APPEND EMPTAB.
ENDSELECT.
EDITOR-CALL FOR EMPTAB.
CHECK SY-SUBRC EQ 0.
LOOP AT EMPTAB WHERE NAME1 EQ ‘Maurice Cheeks’.
WRITE: / EMPTAB-COUNTRY, EMPTAB-NAME1.
ENDLOOP.
IF SY-SUBRC NE 0. WRITE: / ‘No records.’. ENDIF.
screen output
38 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
Demonstration
Declaring an internal table, populating it by selecting data from the table and then
looping into it and displaying the data fetched.
39 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
Practice
Declaring an internal table, populating it by selecting data from the table and then
looping into it and displaying the data fetched.
40 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
Summary
41 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
Summary (Contd.)
42 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation
IBM Global Services
Questions
What is a Structure?
What is an internal table?
What are the different types of internal tables are there?
Explain the following statements :
Move corresponding
Append
Clear
Refresh
Free.
43 Data Structure & Internal Tables | 3.07 March-2005 © 2005 IBM Corporation