Chapter 07 - Data Structures & Internal Tables
Chapter 07 - Data Structures & Internal Tables
Objectives
Data Structures
LN FN City ST.
LN FN City ST.
1 REPORT YN1C0008.
2
3 DATA: BEGIN OF ADDRESS, Basic Syntax:
4 FLAG TYPE C, DATA: BEGIN OF <name>
5 ID TYPE TABNA-ID,
6 NAME1 TYPE TABNA-NAME1, <field1> . . .
7 CITY TYPE TABNA-CITY, <field2> . . .
8 END OF ADDRESS.
9 MOVE ‘X’ TO ADDRESS-FLAG. ...
10 MOVE ‘0001’ TO ADDRESS-ID. END OF <name>.
11 MOVE ‘Smith’ TO ADDRESS-NAME1.
12 MOVE ‘Philadelphia’ TO
13 ADDRESS- CITY.
14 WRITE: ADDRESS-FLAG,ADDRESS-ID. Address Structure
15 ADDRESS-NAME1,ADDRESS-CITY Flag ID Name1 City
‘Philadelphia’ TO ADDRESS-CITY.
WRITE: ADDRESS-ID, ADDRESS-NAME1,
ADDRESS-CITY.
Demonstration
Declaring a structure and populating the structure with values inside a program.
Practice
Declaring a structure and populating the structure with values inside a program.
Standard
Sorted
Hashed
ID NAME1 COUNTRY
DATA: EMPTAB TYPE STANDARD TABLE
OF EMP,
EMPTAB_WA TYPE EMP.
Work Area
Performance Issues
EMPLOYEE
A
COUNTRY ID FORMA NAME1 SORTL . . .
ID NAME1 COUNTRY
B Work Area
2 ID NAME1 COUNTRY
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
REPORT Y170DM41.
DATA: EMPTAB TYPE STANDARD TABLE OF The internal table EMPTAB
EMPLOYEE, will have the exact same
WA_EMP TYPE EMPLOYEE. structure as the dictionary
table EMPLOYEE.
REPORT Y170DM69.
SELECT * FROM <table> . . .
1. INTO TABLE <EMPTAB>.
DATA: EMPTAB TYPE STANDARD TABLE OF 2. APPENDING TABLE
EMPLOYEE.
<EMPTAB>.
Screen output
SELECT * FROM EMPLOYEE INTO WA_EMP.
A 371,065.00
MOVE WA_EMP TO EMPTAB. CH 45,305.00
COLLECT WA_EMP INTO EMPTAB. D 8,200,000.00
ENDSELECT. F 0.00
LOOP AT EMPTAB INTO WA_EMP.
GB 500,000.00
NL 577,000.00
WRITE: / WA_EMP-COUNTRY, WA_EMP- NO 234.00
SALES.
USA 1,000,000.00
ENDLOOP. HK 0.00
20 Data Structure & Internal Tables | Dec-2008 © 2005 IBM Corporation
IBM Global Services
Implicit Key
All character fields
Explicit Key
User-defined
e.g. WITH [ UNIQUE/NON-UNIQUE ] KEY FIELD1 FIELD2 ...
AT FIRST
AT NEW < field >
AT END < field >
AT LAST
REPORT Y170DM47.
TYPES: BEGIN OF EMP,
COUNTRY TYPE COUNTRY,
NAME1 TYPE NAME1,
END OF EMP.
READ TABLE ….
screen output
Demonstration
Declaring an internal table, populating it by selecting data from the table and then
looping into it and displaying the data fetched.
Practice
Declaring an internal table, populating it by selecting data from the table and then
looping into it and displaying the data fetched.
Summary
Summary (Contd.)
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.