Chapter 05 - Retrieving Data With SELECT Statements
Chapter 05 - Retrieving Data With SELECT Statements
Objectives
2 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services
Jo
Sm n
h ry
ith Ma es
l
Sti
Data
DB
3 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services
Open SQL
4 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services
SELECT *FROM
<table name>
[…..]
ENDSELECT.
Mary
Stiles
John Smith
Work Area
DB
5 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services
TABLES: KNA1.
SELECT *
FROM KNA1.
WRITE: / KNA1-KUNNR, KNA1-NAME1.
ENDSELECT.
6 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services
TABLES: KNA1.
SELECT *
FROM KNA1
WHERE KTOKD = ‘0001’.
WRITE: / KNA1-KUNNR, KNA1-NAME1.
ENDSELECT.
7 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services
SY-SUBRC
TABLES: KNA1.
SELECT *
FROM KNA1
WHERE KTOKD = ‘0001’.
WRITE: / KNA1-KUNNR, KNA1-NAME1.
ENDSELECT.
IF SY-SUBRC <> 0.
WRITE: / ‘No records found.’.
ENDIF.
8 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services
TABLES: KNA1.
SELECT KUNNR
NAME1
FROM KNA1
INTO (KNA1-KUNNR, KNA1-NAME1).
WRITE : / KNA1-KUNNR, KNA1-NAME1.
ENDSELECT.
IF SY-SUBRC <> 0.
WRITE: / ‘No records found.’.
ENDIF.
9 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services
INTO CORRESPONDING-FIELDS
TABLES: KNA1.
SELECT KUNNR
NAME1
FROM KNA1
INTO CORRESPONDING-FIELDS
OF KNA1.
WRITE : / KNA1-KUNNR, KNA1-NAME1.
ENDSELECT.
IF SY-SUBRC <> 0.
WRITE: / ‘No records found.’.
ENDIF.
10 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services
Demonstration
Selection of data from a database table, checking sy-subrc and displaying the
values in a report.
11 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services
Practice
Selection of data from a database table, checking sy-subrc and displaying the
values in a report.
12 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services
Summary
13 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services
Questions
14 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation