Beruflich Dokumente
Kultur Dokumente
Dec-2008
Objectives
The participants will be able to:
Describe how to use the following in an ABAP Program:
SELECT DISTINCT Statement
Dynamic WHERE Clause
Concatenate Statement
Join (Inner vs. Left Outer)
Aliases
Dec-2008
Using SELECT
DISTINCT, it
is possible
to eliminate duplicate
rows from the
result set.
Dec-2008
Dec-2008
The parameters
entered make up the
contents of the
WHERE clause. The
user has the option of
changing the
conditions and
dynamically effecting
which way the
program will execute.
Dec-2008
CONCATENATE Statement
REPORT YAP00010.
PARAMETERS:
WHERECL1(72) DEFAULT COUNTRY = USA ,
WHERECL2(3) DEFAULT OR,
WHERECL3(72) DEFAULT COUNTRY = GB .
TYPE: BEGIN OF ITAB_RECORD,
TEXT(72),
END OF ITAB_RECORD.
Dec-2008
Dec-2008
REPORT YAP00012.
PARAMETERS: TAB_NAME(6) DEFAULT TABNA'.
DATA: TABLE_LINE(240).
SELECT * FROM (TAB_NAME) INTO TABLE_LINE.
WRITE: / TABLE_LINE.
ENDSELECT.
Dec-2008
Demonstration
Using a dynamic select statement in a custom ABAP program.
Dec-2008
Practice
Using a dynamic select statement in a custom ABAP program.
10
Dec-2008
CURSOR Processing
OPEN CURSOR [WITH HOLD] <cursor name>
FOR <SELECT statement>.
11
Dec-2008
12
Dec-2008
DO.
FETCH NEXT CURSOR TABCUR INTO YTABNA_WA.
IF SY-SUBRC <> 0.
CLOSE CURSOR TABCUR.
After the FETCH is executed, the SY-SUBRC is
EXIT.
tested. Zero indicates a successful retrieval;
ELSE.
indicates there are no more rows.
WRITE: / YTABNA_WA-COUNTRY, Four
ytabna-NAME1.
ENDIF.
ENDDO.
13
Dec-2008
DO.
FETCH NEXT CURSOR TABCUR INTO YTABNA_WA.
IF SY-SUBRC <> 0.
CLOSE CURSOR TABCUR.
EXIT.
ELSE.
WRITE: / YTABNA_WA-COUNTRY, ytabna-NAME1.
ENDIF.
ENDDO.
14
Dec-2008
Demonstration
Using cursor in a program to retrieve data from a database table .
15
Dec-2008
Practice
Using cursor in a program to retrieve data from a database table .
16
Dec-2008
Joins are more efficient than logical databases and nested selects.
They access multiple tables with one select statement.
17
Dec-2008
Inner Joins
SCARR
18
SFLIGHT
Dec-2008
19
Dec-2008
20
Dec-2008
21
SFLIGHT
Dec-2008
22
Dec-2008
23
Dec-2008
Redundancy
LFA1
24
BSIK
Dec-2008
25
Dec-2008
Aliases
SELECT A~carrname
B~carrid
B~connid
B~fldate
INTO (carrid, connid, date, carrname)
FROM scarr AS A INNER JOIN sflight AS B
ON scarr~carrid = sflight~carrid.
WRITE: / carrid, connid, date, carrname.
ENDSELECT.
26
Dec-2008
Subquery
SFLIGHT
SCARR
27
Dec-2008
Subquery Syntax/Example
28
Dec-2008
Having Clause
29
Dec-2008
30
Dec-2008
Demonstration
Using JOIN in select statement of a custom ABAP program retrieve data from
two or more related database tables.
31
Dec-2008
Practice
Using JOIN in select statement of a custom ABAP program retrieve data from
two or more related database tables.
32
Dec-2008
Summary
SELECT DISTINCT option is used to return only one record for each unique
occurrence of data in a column based on a field name.
Aggregate functions MIN, MAX, AVG, SUM, and COUNT are a valuable tool for
accumulating values across the entire table or a subset of the table rows based
on the conditions in the WHERE clause.
WHERE clause can be created at runtime and can be created by the user using
parameters.
It is possible to use the ORDER BY PRIMARY KEY, but not ORDER BY any other
field.
CURSOR processing enables the programmer to execute SELECT statements
that produce multiple row result sets then read/process each row of the result set
sequentially.
33
Dec-2008
Summary (Contd.)
The CURSOR data type is then associated with a SELECT from a database table
in the OPEN statement.
Individual rows of the result set are processed using a FETCH statement
sequentially until the end of the table is reached.
CURSOR processing is terminated using the CLOSE CURSOR statement. At
that point the result set is destroyed.
Joins have the advantage of accessing multiple tables with one Select statement,
thereby reducing the amount of server overhead.
Sub queries are a more efficient method of performing complex select
statements.
HAVING must be used with aggregate expressions.
34
Dec-2008
Questions
What are the aggregate functions? And why these are used in the select
statement?
What is the purpose of using CONCATENATE statement?
What are the different steps of cursor processing?
How data can be retrieved from two or multiple related database table in single
select?
35
Dec-2008