Intro to ABAP - Chapter 05
W
Description
sap abap introduction, very specific,welcome download
Document Sample


Retrieving Data with SELECT
Statements
BC170_2.05.1
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.
BC170_2.05.2
Retrieving Information From the
Database
Data
DB
BC170_2.05.3
Open SQL
• A subset of standard SQL
• Portable across various databases
BC170_2.05.4
The Basic SELECT Statement
TABLES: <table name>.
Mary
Stiles
John Smith
SELECT <fields> FROM <table name>
Work Area […..]
ENDSELECT.
DB
BC170_2.05.5
Example Using the SELECT
Statement
TABLES: KNA1.
SELECT KUNNR
NAME1
INTO (KNA1-KUNNR,
KNA1-NAME1)
FROM KNA1.
WRITE: / KNA1-KUNNR, KNA1-NAME1.
ENDSELECT.
BC170_2.05.6
The SELECT Statement with a
WHERE Clause
TABLES: KNA1.
SELECT KUNNR
NAME1
INTO (KNA1-KUNNR,
KNA1-NAME1)
FROM KNA1
WHERE KTOKD = ‘0001’.
WRITE: / KNA1-KUNNR, KNA1-NAME1.
ENDSELECT.
BC170_2.05.7
SY-SUBRC
TABLES: KNA1.
SELECT KUNNR
NAME1
INTO (KNA1-KUNNR,
KNA1-NAME1)
FROM KNA1
WHERE KTOKD = ‘0001’.
WRITE: / KNA1-KUNNR, KNA1-NAME1.
ENDSELECT.
IF SY-SUBRC <> 0.
WRITE: / ‘No records found.’.
ENDIF.
BC170_2.05.8
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.
BC170_2.05.9
Summary
• The participants should 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
BC170_2.05.10