0% found this document useful (0 votes)
11 views14 pages

Chapter 05 - Retrieving Data With SELECT Statements

This document discusses using SELECT statements in ABAP to retrieve data from database tables. It introduces SQL and its components like DML, DDL, and DCL. It then explains the basic SELECT statement and how to retrieve fields into a work area or structure using the INTO and CORRESPONDING FIELDS clauses. It also emphasizes the importance of checking the SY-SUBRC system field to determine if a SELECT statement was successful. Examples are provided and a demonstration and practice are outlined to apply these concepts.

Uploaded by

Mostafa Hassanin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views14 pages

Chapter 05 - Retrieving Data With SELECT Statements

This document discusses using SELECT statements in ABAP to retrieve data from database tables. It introduces SQL and its components like DML, DDL, and DCL. It then explains the basic SELECT statement and how to retrieve fields into a work area or structure using the INTO and CORRESPONDING FIELDS clauses. It also emphasizes the importance of checking the SY-SUBRC system field to determine if a SELECT statement was successful. Examples are provided and a demonstration and practice are outlined to apply these concepts.

Uploaded by

Mostafa Hassanin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

IBM Global Services

Retrieving Data with SELECT Statements

Retrieving Data with the SELECT St March-2005 © 2005 IBM Corporation


atement | 3.05
IBM Global Services

Objectives

 The participants will be able to:


 Retrieve information from the database using Open SQL.
 Create basic Select statements for use in ABAP Code.
 Describe the system field SY-SUBRC and properly use it in an ABAP Program.

2 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services

Retrieving Information From the Database


Structured Query Language (SQL)
----------------------------------------
1. Data Manipulation Language (DML)
2. Data Definition Language (DDL)
3. Data Control Language (DCL)

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

Open SQL - a subset of standard SQL

Portable across various databases

4 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services

The Basic SELECT Statement

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

Example Using the SELECT Statement

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

The SELECT Statement with a WHERE Clause

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

The INTO Clause

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

 SQL has three main components:


 Data Manipulation Language (DML):
 Data Definition Language (DDL):
 Data Control Language (DCL):
 The DML provides the four basic data operations:
 Select (retrieve)
 Insert
 Update
 Delete
 Open SQL is a subset of standard SQL with a specific syntax recognised by
ABAP.

13 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation
IBM Global Services

Questions

 What is SQL ? And What are different types of SQL ?


 How values can be retrieved from a database table ?
 Why SY-SUBRC check is required in the program ?

14 Retrieving Data with the SELECT Statement | 3.05 March-2005 © 2005 IBM Corporation

You might also like