Open SQL & Internal Table - Presentation Transcript
ABAP Chapter 3
Open SQL
Internal Table
SAP System : 3 Tier Client/Server DB Server SAP Application Server SAP GUI Presentation Server SAP GUI SAP GUI
SAP SYSTEM (3 Tier Architecture) Presentation Layer (Windows based) Application Layer (Windows Server/UNIX) Database Server Database Layer (Windows Server/UNIX) M SAP Instance Oracle Informix DB2 MS SQL Server SAP DB/MaxDB G Dispatcher Request Queue D D B V S E SAP Buffer (Shared Mem) SAP GUI SAP GUI
SAP System : Dialog Processing Database Server Application Server Dispatcher Request Queue D D D D … SAP Buffer Program Table … 1 3 4 5 6 8 9 10 Report zpsm1. Tables customers. Select single * from customers where id = 1. Write: / customers-name. Execute ABAP statement Check Program in Program Buffer 7 Load&Gen Program SQL Request Send List Generate Screen(List) Send Request Request List 2 Search for free WP Store request to queue Send request to WP SAP GUI
Dialog Work Process Architecture TaskHandler DYNPRO Processor ABAP Processor Local Memory Memory Space DB Interface List buffer Database Server Dialog Work Process Result Set Memory
Open SQL
SELECT ...
INSERT ...
UPDATE ...
DELETE ...
DB Interface SAP Application Server Local Memory Dialog WP TaskHandler DB Interface Result Set Database Server ~ 32 KB in length ABAP Processor DYNPRO Memory Space List Buffer
Example Tables in DB
spfli
customers BK NY NY cityto 250 SQ 0110 SQ 540 BK 0402 LH 100 LA 0400 LH distance cityfrom connid carrid London David 3 Singapore Peter 2 New York John 1 city name id
Example Tables in DB sflight 75 20010226 0110 SQ 130 20010228 0400 LH 145 20010110 0400 LH 150 20010101 0400 LH price fldate connid carrid
Select Overview
Select < result > Which Columns?
From < table > Which Table?
Into < destination > Where to place?
Where < condition > Which Lines?
Select Statement
Select multiple records from database
Select single record from database
SELECT * FROM customers. … ENDSELECT. SELECT SINGLE * FROM customers WHERE id = 1. …
Select Multiple Records
Tables spfli.
Seclect * from spfli.
write: / spfli-carrid, spfli-connid,
spf li-cityto.
endselect.
if sy-subrc <> 0.
write: / ‘No Data’.
endif.
Dialog WP
Dialog WP
TaskHandler DYNPRO Processor ABAP Processor Database Local Memory Memory Space DB Interface Lis t b uffer Result Set
SELECT Statement Working Steps 1. Transform open SQL to DB SQL and return result set into result set work area SELECT * FROM spfli. … ENDSELECT. SELECT * FROM spfli; 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
Select … Into Table Structure
Tables spfli.
Seclect * from spfli into spfli .
write: / spfli-carrid, spfli-connid,
spfli-cityfrom, spfli-cityto.
endselect.
if sy-subrc <> 0.
write: / ‘No Data’.
endif.
Select … Into Work Area
Data wa like spfli.
Seclect * from spfli into wa .
write: / wa -carrid, wa -connid,
wa -cityfrom, wa -cityto.
endselect.
if sy-subrc <> 0.
write: / ‘No Data’.
endif.
Exercise I customers-id customers-name customers-city
SELECT with WHERE Clause
Loop Processing with Restriction
Tables spfli.
Select * from spfli
where cityfrom = ‘FRANKFURT’.
write: / spfli-carrid, spfli-cityto.
endselect.
If sy-subrc <> 0.
write / ‘no data’.
endif.
Select With Range
Tables sflight.
Select * From sflight
Where price between 100 and 1000.
Write: / sflight-carrid, sflight-connid,
sflight-price.
Endselect.
SELECT … With IN List
Tables sflight.
Select * From sflight
Where price in ( 100, 1000 ).
Write: / sflight-carrid, sflight-connid,
sflight-price.
Endselect.
Select Single Record
Select Single Record
Table s spfli.
Select single * from spfli
where carrid = ‘LH’ and
connid = ‘0400’.
if sy-subrc = 0.
write: / spfli-carrid, spfli-connid,
spfli-cityfrom, spfli-cityto.
else.
write: / ‘Data not found’.
endif.
Select Column List
Select * : Example SELECT *
Reading Selected Column
Data: id like customers - id,
name like customers-name,
city like customers-city.
Select id name city
into ( id , name, city )
from customers.
write: / id, name, city .
endselect.
if sy-subrc <> 0.
write / ‘No Data found ’.
endif.
Reading Selected Column
Data: begin of wa,
id like customers - id,
name like customers-name,
city like customers-city,
end of wa.
Select id name city
into wa
from customers.
write: / wa-id, wa-name , wa-city .
endselect.
if sy-subrc <> 0.
write / ‘No Data found ’.
endif.
Select Column : Example I
Reading Selected Column
Tables customers.
Select id name city
into (customers-id, customers-name, customers-city)
Table : A Table : B A-a B-b B-c b2 a2 b1 a1 b a c2 b2 c3 b3 c1 b1 c b
Open SQL – Inner Join Table : A Table : B Single Result Table(Result set) Select … inner join.. Endselect. Database Server Application Server 1 2 b2 a2 b1 a1 b a c2 b2 c3 b3 c1 b1 c b b2 b1 B~b c2 a2 c1 a1 B~c A~a
0 comments
Post a comment