Abap Table
Abap Table
Abap Table
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)
Oracle Informix
Database Server
Application Server
Store request to queue 3 Send List 9
Reque st
Tables customers.
List
Dispatcher
2
SAP Buffer
Program Table
D
8
D
SQL Reques t
D
6
Database Server
Load&Gen Program
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
Database Server
Data
Example Tables in DB
spfli
carrid connid cityfrom cityto distance
customers
id name city
1 2 3
LH LH SQ
LA BK SQ
NY NY BK
Example Tables in DB
sflight
carrid connid fldate price
LH LH LH SQ
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. select * from customers where id <> 1 and city = ( select city from customers where id = 1 ). write: / customers-id, customers-name. endselect. ID 1
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
Tables Join
Question: Select carrid, connid and cityto from spfli and fldate,price from sflight where carrid = LH spfli-carrid spfli-connid sflight-fldate spfli-cityto sflight-price
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
b1
c
c1 c2 c3
a
a1 a2
b
b1 b2
b2 b3
Table : B
a
a1 a2
b
b1 b2
b
b1 b2 b3
c
c1 c2 c3
1
Application Server 2
A~a
a1 a2
B~b
b1 b2
B~c
c1 c2
ZSALEREPS
city tel
111111 222222 432555 234111
name
John Peter David Micheal
sale_id
01 02
name
Somchai Pipop
ZSALES
cust_id 1 prod_id A1 A2 X1 sale_date 20020318 20020318 20020321 qty 10 50 90 sale_id 01 01 02
ZPRODUCTS
p_id
A1 A2 B1 X1 Y1 prod_name Pen Pencil Ruler Tape CD on_hand 100 125 80 120 99
1 3
Table : B
y
...
c
... ...
Exercise
Tables Relationship
USR02
BNAME
USR21
PERSNUMBER ADDRNUMBER
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:
End of flight.
flight-carrid = LH . / flight-carrid.
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: Data begin of tab occurs 0. Include structure sflight. end of tab.
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
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. 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.
Exercise II
Exercise II
1. SELECT *2. Internal Table
usr02-bname
usr02-trdat
usr02-ltime
Exercise III
Tables Relationship
USR02
BNAME
USR21
PERSNUMBER ADDRNUMBER
ADCP
Internal Table