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


SELECT Statements
BC170_2.10.1
Objectives
• The participants will be able to:
– Select data from a database using a restrictive WHERE
clause
– Describe how the following ABAP commands effect a
Select Statement: SELECT SINGLE, LIKE, IN, ORDER
BY, BYPASSING BUFFER
– Describe when to use a WHERE clause vs. a CHECK
statement in an ABAP Program
– Describe when to use SELECT <field list> vs. SELECT *
in an ABAP Program
– Use Aggregate Functions in an ABAP Program
BC170_2.10.2
Database Access I
Physical
Database
Logical
Database
REPORT: ZRACER01.
TABLES: LFA1, LFB1,
LFC3.
No
SELECT * FROM LFA1. Authorization
WRITE: LFA1-LIFNR. Checking
ENDSELECT.
ABAP Open SQL
ABAP Native SQL
BC170_2.10.3
SQL (SELECT)
ABAP Programs
REPORT: YNEWAPPL. Database
TABLES...
LFA1
SELECT <f1 f2 fn> FROM LFA1.
LFB1 LFC1
ENDSELECT.
Data
ABAP
Reports
BC170_2.10.4
WHERE Clause: Single Access
The SELECT SINGLE * statement
requires the full primary key of
the table in the WHERE clause.
Expected Results
In the return-code field
(SY-SUBRC),
0 = successful and
4 = entry does not exist.
BC170_2.10.5
Syntax: Restricted Loop Processing
SELECT * FROM <table>
WHERE <table field 1> <relational operator> <field 1>
AND <table field 2> <relational operator> <field 2>
OR <table field 3> <relational operator> <field 3>
AND <table field 4> <relational operator> <field 4>
:
:
OR<table field n> <relational operator> <field n>.
ENDSELECT.
EQ =
GE >= =>
LE <= =<
NE <> >< Relational
GT > Operators
LT <
BC170_2.10.6
Syntax: Between Values, Templates
and Lists
SELECT * FROM <table> WHERE <table field>...
BETWEEN <field 1> AND <field 2>
LIKE <with ‘%’ and ‘_’ masked literal>
IN (<field 1, field 2,......field n>)
BC170_2.10.7
WHERE Clause: Loop Processing
with Restricted Selection
Expected Results
The result set is limited by
the conditions in the
WHERE clause.
BC170_2.10.8
LIKE: Example of a Template (%_)
Expected Results
The ‘_’ is an any character
positional parameter.
The ‘%’ allows for any string of
BC170_2.10.9
any length.
IN: Example of a Comparison
Value List
Expected Results
BC170_2.10.10
IN: Example of a Range
This internal table is the same one
that is created automatically when
a selection screen is processed.
The RANGES statement builds the
structure of this internal table
RANGES <name> FOR <field>. automatically.
BC170_2.10.11
The ORDER BY Clause
SELECT * FROM <table>
WHERE <condition>
ORDER BY <table field 1>
<table field 2>
<table field 3>
:
:
<table field n>.
ENDSELECT.
BC170_2.10.12
BYPASSING BUFFER
SELECT * FROM <table>
BYPASSING BUFFER
WHERE <condition>.
:
:
:
ENDSELECT.
BC170_2.10.13
INTO TABLE <itab>
Array Operations
EMPLOYEE
COUNTRY ID FORMA NAME1 SORTL . . .
Table Work Area
ID NAME1 COUNTRY
Header Line
1 00000001 Baker Distributors USA 1
00000002 Diversified Indust... USA 2
3
.
. .
. .
.
10
BC170_2.10.14
WHERE Vs CHECK in a SELECT
Statement
BC170_2.10.15
SELECT <field list> vs.. SELECT *
Which
ones?
MANDT
MATNR
ERSDA
ERNAM
LAEDA
.....
BC170_2.10.16
Aggregate Functions
12
15 4 SUM = 61
9 7 14
BC170_2.10.17
Summary
• The participants should be able to:
– Select data from a database using a restrictive WHERE
clause
– Describe how the following ABAP commands effect a
Select Statement: SELECT SINGLE, LIKE, IN, ORDER
BY, BYPASSING BUFFER
– Describe when to use a WHERE clause vs. a CHECK
statement in an ABAP Program
– Describe when to use SELECT <field list> vs. SELECT *
in an ABAP Program
– Use Aggregate Functions in an ABAP Program
BC170_2.10.18
BC170_2.10.19