Beruflich Dokumente
Kultur Dokumente
Presentation Server
DB Server
Presentation Layer
(Windows based)
SAP Instance
Application Layer
(Windows Server/UNIX)
Request Queue
Dispatcher
M
SAP Buffer (Shared Mem)
E G
Database Layer
(Windows Server/UNIX)
Database Server
Request
Tables customers.
Application Server
Store request to queue
3
Send Request
Generate Screen(List)
10
List
Dispatcher
Send List
2 9
SAP Buffer
Program Table
D
8
D
SQL Request
D
6
Load&Gen Program
Database Server
ABAP Processor
List buffer
Database Server
Open SQL
DB Interface
SAP Application Server Dialog WP
TaskHandler ABAP Processor DYNPRO
List Buffer
Local Memory
Memory Space
DB Interface
Result Set
~ 32 KB in length
Database Server
Data
Data
Data
Data
Data
Example Tables in DB
spfli
carrid connid cityfrom cityto distance
customers
id name city
John
New York
LH LH SQ
LA BK SQ
NY NY BK
2 3
Peter David
Singapore London
Example Tables in DB
sflight
carrid connid fldate price
LH
0400
20010101
150
LH LH
SQ
0400 0400
0110
20010110 20010228
20010226
145 130
75
Select Overview
Select <result> From <table> Into <destination> Where <condition> Which Columns? Which Table? Where to place? Which Lines?
Select Statement
Dialog WP
Dialog WP TaskHandler
ABAP Processor
List buffer
Local Memory
Memory Space
DYNPRO Processor
DB Interface
Result Set
Database
2. Loop with data in result set and transfer each record to work area in memory space
SELECT * FROM spfli. ENDSELECT. Table Structure in Memory Space
Exercise I
customers-id
customers-name
customers-city
Select * : Example
SELECT *
DB Count : SY-DBCNT
Tables customers. Select * from customers. write: / sy-dbcnt, customers-id, customers-name. endselect. if sy-subrc <> 0. write: / No Data found. else. write: / sy-dbcnt, Record found. endif.
Aggregate Functions
Data: maxdat like sflight-distance, mindat like sflight-distance, counter type I.
Select COUNT( * ) MIN( distance ) MAX( distance ) into (counter ,mindat, maxdat) from spfli. Write: / Count : , counter, / Min : , mindat, / Max : , maxdat.
Sub Query
tables customers. ID 1 select * from customers where id <> 1 and city = ( select city from customers where id = 1 ). write: / customers-id, customers-name. endselect.
Exercise I
SELECT *
customers-id
customers-name
customers-city
Exercise II
SELECT *
usr02-bname
usr02-trdat
usr02-ltime
Tables Join
spfli
carrid connid cityfrom cityto distance
sflight
carrid connid fldate price
LH LH SQ
NY BK SQ
BK NY BK
LH LH LH SQ
Tables Join
Question: Select carrid, connid and cityto from spfli and fldate,price from sflight where carrid = LH
spfli-carrid
: LH
Standard SQL
Select spfli.carrid, spfli.connid, sflight.fldate, sflight.price From spfli, sflight Where spfli.carrid = sflight.carrid and spfli.connid = sflight.connid and spfli.carrid = LH;
Nested select statement Internal table View Inner join of Select statement
Table : B
b b
b1 b2
b1 b2 b3
c
c1 c2 c3
a
a1 a2
Table : B
a
a1 a2
b
b1 b2
b
b1 b2 b3
1
c
c1 c2 c3
Application Server
2
A~a
a1 a2
B~b
b1 b2
B~c
c1 c2
ZSALEREPS
city tel
111111 222222
name
John Peter
sale_id
01 02
name
Somchai Pipop
3
4
David
Micheal
Singapore
Bangkok
432555
234111
ZSALES
cust_id prod_id A1 A2 X1 sale_date 20020318 20020318 20020321 qty 10 50 90 sale_id 01 01 02 1 1 3
ZPRODUCTS
p_id
A1 A2 prod_name Pen Pencil on_hand 100 125
B1
X1 Y1
Ruler
Tape CD
80
120 99
Table : B
y
...
c
... ...
Exercise
Tables Relationship
ADCP
Exercise
List customers name who do not buy any product from company
Sub Query
REPORT ZSUBQUERY . tables: zcustomers. select * from zcustomers as a where not exists ( select * from zsales as b where b~cust_id = a~id ). write: / zcustomers-name. endselect.
Internal Table
Table Structure
Internal Table
Constants
<Field-symbols>
INTERNAL TABLE
Flight (Structure)
Carrid Connid Date Price
Internal Table
Flight (Internal Table)
Carrid Connid Date
Header Line
Price
Structure
Data: Begin of carrid connid date price flight, like sflight-carrid, like sflight-connid, like sflight-fldate, like sflight-price.
Data: Write:
flight-carrid = LH.
INTERNAL TABLE
Data: begin of tab occurs 10, carrid like sflight-carrid, connid like sflight-connid, fldate like sflight-fldate, price like sflight-price. end of tab.
Data
USING ABAP DICTIONARY STRUCTURE Data: begin of tab occurs 0. Include structure sflight. end of tab.
Data
Data: begin of tab occurs 0, f1 type C, f2 type I, f3 type N, f4 type P, end of tab.
f1
f2
f3
f4
Exercise I : Change
Using Internal Table
Exercise I
ABAP Practice
Database
Insert (Table)
Tables customers. customers-id = 999. customers-name = Test. Insert customers. if sy-subrc <> 0. write: / Data Already Exists. endif.
Update Statement
Tables customers. Select single * from customers where id = 1. If sy-subrc = 0. customers-name = John. update customers. Endif.
Update Statement
Data wa like customers. wa-id = 1. wa-name = Test No 1. wa-city = Bangkok. update customers from wa. If sy-subrc <> 0. write: / Data not found. Endif.
Modify Statement
Tables customers. customers-id = 1. customers-name = Test No 1. Modify customers.
Exercise II
Exercise II
1. SELECT * 2. Internal Table
usr02-bname
usr02-trdat
usr02-ltime
Exercise III
Tables Relationship
ADCP
Internal Table