Академический Документы
Профессиональный Документы
Культура Документы
Open SQL
Internal Table
SAP GUI
SAP GUI
Presentation
Server
SAP
Application
Server
DB Server
SAP GUI
Presentation Layer
(Windows based)
SAP Instance
Application Layer
Dispatcher
(Windows Server/UNIX)
Request
Queue
SAP Buffer
(Shared Mem)
E
G
Oracle
Database Layer
Informix
(Windows Server/UNIX)
Database Server
DB2
MS SQL Server
SAP DB/MaxDB
Request
Application Server
Store request to
queue 3
Tables customers.
List
Generate
1
10
Screen(List)
Send Request
Send List
Write: / customersname.
Dispatcher
2
Request
Queue Send request to
WP4
customers where id =
1.
Search for
free WP
Check Program in
Program
Buffer
5
SAP Buffer
Program
Table
Database Server
SQL
Request
Load&Gen
Program
Execute
ABAP
statement
Local Memory
TaskHandler
Memory Space
ABAP Processor
List buffer
DYNPRO Processor
DB Interface
Database Server
Open SQL
SELECT ...
INSERT ...
UPDATE ...
DELETE ...
DB Interface
SAP Application Server
Dialog WP
Local Memory
TaskHandler
Memory Space
ABAP Processor
DYNPRO
DB Interface
List Buffer
Result Set
~ 32 KB in length
Database Server
Data
Data
Data
Data
Data
Example Tables in DB
customers
spfli
id
name
city
New
York
carrid
connid
cityfrom
cityto
distance
John
LH
0400
LA
NY
100
LH
0402
BK
NY
540
Peter Singapor
e
SQ
0110
SQ
BK
250
Davi
d
London
Example Tables in DB
sflight
carrid
connid
fldate
price
LH
0400 2001010
1
150
LH
0400 2001011
0
145
LH
0400 2001022
8
130
SQ
0110 2001022
6
75
Select Overview
Select <result>
Columns?
From <table>
Into <destination>
place?
Where <condition>
Lines?
Which
Which Table?
Where to
Which
Select Statement
ENDSELECT.
Dialog WP
Dialog WP
Local Memory
TaskHandler
Memory Space
ABAP Processor
DYNPRO Processor
DB Interface
Result Set
Database
List buffer
ENDSELECT.
ENDSELECT.
Exercise I
customers-id
customersname
customerscity
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.
Tables customers.
Select * From customers
Where name Like _r%.
Write: /
customers-id,customers-nam
Endselect.
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.
Price
150
145
130
75
Sub Query
ID 1
tables customers.
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
customersname
customerscity
Exercise II
SELECT *
usr02-bname
usr02-trdat
usr02-ltime
Tables Join
sflight
spfli
carrid
carrid
connid
cityfrom
cityto
distance
LH
0400
NY
BK
100
LH
0402
BK
NY
540
SQ
0110
SQ
BK
250
connid
fldate
price
LH
0400 2001010
1
150
LH
0400 2001011
0
145
LH
0400 2001022
8
130
SQ
0110 2001022
6
75
Tables Join
Question: Select carrid, connid and cityto from spfli
and fldate,price from sflight where carrid = LH
spfli-carrid
spfli-connid
: 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;
c
c1
b2
c2
a1
b1
b3
c3
a2
b2
Table : A
Databas
e
Server
a1
b1
a2
b2
Application
Server
Select
inner join..
Endselect.
b1
c1
b2
c2
b3
c3
A~a
B~b
B~c
a1
b1
c1
a2
b2
c2
ZCUSTOMERS
i
d
name
city
John
New York
111111
Peter
London
222222
David
Singapor
e
432555
Micheal
Bangkok
234111cust_id
ZPRODUCTS
tel
p_id
prod_name
on_hand
A1
Pen
100
A2
Pencil
125
B1
Ruler
80
X1
Tape
120
Y1
CD
99
sale_id
name
01
Somchai
02
Pipop
ZSALES
prod_id
sale_dat
e
qty
sale_id
A1
2002031
8
10
01
A2
2002031
8
50
01
X1
2002032
1
90
02
...
Table : B
...
...
REPORT ZINNERJOIN02 .
TABLES: ZCUSTOMERS,ZPRODUCTS,ZSALES.
SELECT A~NAME C~PROD_NAME B~QTY
INTO (ZCUSTOMERS-NAME, ZPRODUCTS-PROD_NAME, ZSALES-QTY
FROM ZSALES AS B INNER JOIN ZCUSTOMERS AS A
ON B~CUST_ID = A~ID
INNER JOIN ZPRODUCTS AS C
ON C~P_ID = B~PROD_ID.
WRITE: / ZCUSTOMERS-NAME,ZPRODUCTS-PROD_NAME,ZSALESQTY.
ENDSELECT.
Exercise
USR02-TRDAT
ADCP-TEL_NUMBER
Tables Relationship
USR02
BNAME
USR21
PERSNUMBER
ADDRNUMBER
ADCP
B~PROD_ID
John
A1
John
A2
Peter
David
Micheal
X1
Exercise
Sub Query
REPORT ZSUBQUERY .
tables: zcustomers.
Internal Table
Structure
Internal Table
Table Structure
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:
End of flight.
flight-carrid = LH.
Write:
/ flight-carrid.
INTERNAL TABLE
Data:
Data
Tables sflight.
Data flight like sflight occurs 0 with header lin
Select * from sflight.
Move sflight to flight.
Append flight.
Endselect.
f2
f3
f4
Exercise I : Change
Using Internal Table
flight.
flight by price fldate.
flight by price ascending
fldate descending.
Loop at tab.
write: / tab-carrid, tab-connid,tab-cityfrom.
Endloop.
PROCESSING INTERNAL
TABLE
...
Loop at flight.
Write: / flight-carrid, flight-connid.
Endloop.
Loop at flight where carrid = LH.
Write: / flight-carrid, flight-connid.
Endloop.
Loop at flight from 1 to 10.
Write: / sy-tabix ,flight-carrid, flight-connid.
Endloop.
CHANGING INTERNAL
TABLE
...
Delete
Delete
flight index 5.
flight where carrid = LH.
flight-carrid = XX.
flight-price = 100.
Clear flight.
Refresh flight.
Free flight.
Exercise I
LOOP AT tab.
WRITE: / TAB-NAME,TAB-PROD_ID.
ENDLOOP.
ABAP Practice
INSERT
UPDATE
MODIFY
DELETE
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.
Update customers
Endif.
set name = John
where id = 1.
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.
From
From
customers
Table
Where
city =
Exercise II
Exercise II
1. SELECT * 2. Internal Table
usr02-bname
usr02-trdat
usr02-ltime
Exercise III
USR02-TRDAT
ADCP-TEL_NUMBER
Tables Relationship
USR02
BNAME
USR21
PERSNUMBER
ADDRNUMBER
ADCP
Internal Table