SlideShare a Scribd company logo
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) from  customers. write: /  customers-id, customers-name, customers-city . endselect. if  sy-subrc  <>  0. write  /  ‘No Data  found ’. endif.
Select Column : Example II
Corresponding Fields of... Tables:  customers. Select  id name city into corresponding fields of customers from customers.  Write: / customers-id, customers-name, customers-city. Endselect.
Select Statement : Special Topics
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.
SELECT  … ORDER BY ... Tables: spfli. Select  * from spfli Order by  cityfrom . Write:  /  spfli-carrid, spfli-connid, spfli-cityfrom. Endselect.
SELECT … With  Template Tables customers. Select  *  From customers  Where  name  Like   ‘_ r %’. Write: / customers-id,customers-name. Endselect.
Aggregate Functions Data: maxdat   like sflight-distance, mindat   like sflight-distance, counter type I. Select C OUNT ( * ) M IN ( distance )   M AX ( distance )  into (counter  , m in dat, m ax dat)   from  spfli. Write: /  ‘Count :’ , counter , /  ‘Min :’  , mindat, /  ‘Max :’  , maxdat . Aggregate Functions : COUNT,MIN,MAX,AVG and SUM
SELECT  … GROUP BY ... Data:  carrid like sflight-carrid, mindat  Type P  Decimals 2, maxdat Type P  Decimals 2. Select  carrid  Min( price )  Max( price ) Into (carrid, mindat, maxdat) From sflight Group by carrid. Write:  /  carrid, mindat, maxdat. Endselect. อยากทราบว่า ในแต่ละสายการบิน มีราคาตั๋วต่ำสุดและสูงสุดเท่าไร sflight 75 20010226 0110 SQ 130 20010228 0400 LH 145 20010110 0400 LH 150 20010101 0400 LH Price fldate connid carrid
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 customers-id customers-name customers-city ห้ามใช้  SELECT *
Exercise II usr02-ltime usr02-trdat usr02-bname ห้ามใช้  SELECT *
ABAP : Inner Join
Tables Join spfli sflight BK NY BK cityto 250 SQ 0110 SQ 540  BK 0402 LH 100 NY 0400 LH distance cityfrom connid carrid 75 20010226 0110 SQ 130 20010228 0400 LH 145 20010110 0400 LH 150 20010101 0400 LH price fldate connid carrid
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’;
Tables Join Methods Nested select statement Internal table View Inner join  of Select statement
Nested Select Statement Tables:  spfli,sflight. Select  *  from spfli where carrid = ‘LH’. Select  *  from  sflight  where  carrid = spfli-carrid and connid = spfli-connid. Write: / spfli-carrid, spfli-connid, sflight-fldate, sflight-price. Endselect. Endselect.
Open SQL – Inner Join Tables:  spfli,sflight. Select  spfli~carrid  spfli~connid  sflight~fldate  spfli~cityto  sflight~price  into  (spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price) from spfli inner join sflight on  spfli~carrid  = sflight~carrid and spfli~connid = sflight~connid where spfli~carrid = ‘LH’. Write: / spfli-carrid, spfli-connid, sflight-fldate,  spfli-cityto, sflight-price. Endselect.
Open SQL – Inner Join Tables:  A,B. Select  A~a B~b B~c into (A-a,B-b,B-c) from A inner join B on  A~b  = B~b.  Write: / A-a,B-b,B-c. Endselect. 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
Open SQL – Alias Table Name Tables:  spfli,sflight. Select  a~carrid  a~connid  b~fldate  a~cityto  b~price into  (spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price) from spfli  as a  inner join sflight  as b on  a~carrid  = b~carrid and a~connid = b~connid where a~carrid = ‘LH’. Write: / spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price. Endselect.
Inner Join/Outer Join Example ZPRODUCTS  ZSALES ZSALEREPS  ZCUSTOMERS 432555 Singapore David 3 234111 Bangkok Micheal 4 222222 London Peter 2 111111 New York John 1 tel city name id CD Tape Ruler Pencil Pen prod_name 120 X1 80 B1 99 Y1 125 A2 100 A1 on_hand p_id 90 50 10 qty 02 20020321 X1 3 01 20020318 A2 1 01 20020318 A1 1 sale_id sale_date prod_id cust_id Pipop 02 Somchai 01 name sale_id
Open SQL – Inner Join REPORT ZINNERJOIN01 . TABLES: ZCUSTOMERS,ZSALES. SELECT  A~NAME B~PROD_ID INTO  (ZCUSTOMERS-NAME,ZSALES-PROD_ID) FROM ZSALES  AS B INNER JOIN ZCUSTOMERS AS A ON B~CUST_ID = A~ID. WRITE: / ZCUSTOMERS-NAME,ZSALES-PROD_ID. ENDSELECT.
Open SQL – Inner Join > 2 Tables Tables:  A,B,C. Select  A~a B~c C~y into (A-a,B-c,C-y) from A inner join B on  A~b  = B~b inner join C on C~x = B~c.  Write: / A-a,B-c,C-y. Endselect. Table : A Table : B Table : C A-a  B-c  C-y …  …  b a ... … … … ... … c b ... … y x
Open SQL – Inner Join > 2 Tables  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,ZSALES-QTY. ENDSELECT.
Exercise List customers who buy product from company as following fields: zcustomers-id  zcustomers-name  zsales-sale_date  zproducts-prod_name  zsales-qty  zsalereps-name
Exercise : User Master USR02-BNAME  USR02-TRDAT  ADCP-TEL_NUMBER USR02 USR21 ADCP BNAME PERSNUMBER ADDRNUMBER Tables Relationship
ABAP : Outer Join
Open SQL – Outer Join REPORT ZOUTERJOIN . TABLES: ZCUSTOMERS,ZSALES. SELECT  A~NAME B~PROD_ID INTO (ZCUSTOMERS-NAME,ZSALES-PROD_ID) FROM ZCUSTOMERS AS A  LEFT OUTER JOIN  ZSALES AS B ON  A~ID = B~CUST_ID. WRITE: / ZCUSTOMERS-NAME,ZSALES-PROD_ID. ENDSELECT. Single Result Table B~PROD_ID A~NAME X1 David Micheal Peter A2 John A1 John
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
Data Objects in ABAP Memory Space Structure Table Structure Internal Table Variable Constants <Field-symbols>
INTERNAL TABLE Flight (Structure) Carrid Connid Date Price Internal Table Flight (Internal Table) Carrid Connid Date Price Header Line
Structure Data: Begin of flight, carrid like sflight-carrid, connid like sflight-connid, date like sflight-fldate, price like sflight-price. Data: End of flight. flight-carrid = ‘LH’. Write: /  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. Data  end of tab.
USING ABAP DICTIONARY STRUCTURE Data: begin of tab  occurs 0 . Include structure sflight. Data end of tab.
INTERNAL TABLE USING LIKE Data tab LIKE sflight  OCCURS 0 WITH HEADER LINE .
FILLING INTERNAL TABLE (APPEND) Tables sflight. Data flight like sflight occurs 0 with header line. Select  *  from sflight. Move sflight to flight. Append flight. Endselect.
Standard Key of Internal Table Data: begin of tab occurs 0, f1 type  C , f2 type I, f3 type  N , f4 type P, end of tab. tab f4 f3 f2 f1
Reading Data From Internal Table Data  tab like sflight occurs 0 with header line. Select  *   from sflight  into  table  tab . If  sy-subrc  =   0. Loop at tab. Write:  /  tab-carrid, tab-price. Endloop. Else. Write:  /  ‘No Data’. Endif.
Access Database Without Internal Table
Access Database Using Internal Table
Reading Data From Internal Table Data : begin of  tab occurs 0 , id like customers-id, name like customers-name, end of tab. Select  id name  from  customers   into  table  tab . If sy-subrc = 0. Loop at tab. Write:  /  tab-id, tab -name . Endloop. else . Write :  /  ‘No Data’. Endif.
Exercise I : Change Using Internal Table
SORTING INTERNAL TABLE (SORT) Sort flight. Sort flight by price fldate. Sort flight by price ascending fldate descending.
Data tab like spfli occurs 0 with header line. Select * from spfli into table tab. Sort tab by cityfrom. … Loop at tab. write: / tab-carrid, tab-connid,tab-cityfrom. Endloop. SORTING INTERNAL TABLE
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.
Internal Table Template Condition ... loop at  tab where name cp ‘+r*’. ...
Reading Single Record ... Sort flight by carrid connid  fldate . Read table flight with key  c arrid  = ‘LH’ c onnid  = ‘0400’ fldate  = ‘19990201’ Binary Search. if sy-subrc = 0 . write : /  flight-carrid,flight-connid, flight-fldate,  flight-price. endif.
Reading Single Record using Index ... Read table flight index 3. If  sy-subrc  =  0. write:  /  flight-carrid , flight-connid . Endif.
CHANGING INTERNAL TABLE ... Delete flight index 5. Delete flight where carrid  =  ‘LH’. flight-carrid  =  ‘XX’. flight-price  = 100. … Insert  flight  index 1.
DELETING INTERNAL TABLE Clear  flight. Refresh  flight. Free  flight. DATA flight LIKE sflight occurs 0 with header line.
Total Record of  Internal Table Data: line_count  type i. Data tab like sflight occurs 0  with header line. Select * from sflight into table tab. Describe table tab lines line_count. Write: / line_count.
Exercise I
Internal Table Processing Data tab like spfli occurs 0 with Header line. … Select  *  from spfli  appending   table tab where carrid = ‘LH’.
SELECT … INNER JOIN REPORT ZINNERJOIN01 . TABLES: ZCUSTOMERS,ZSALES. SELECT  A~NAME B~PROD_ID INTO  (ZCUSTOMERS-NAME,ZSALES-PROD_ID) FROM ZSALES  AS B INNER JOIN ZCUSTOMERS AS A ON B~CUST_ID = A~ID. WRITE: / ZCUSTOMERS-NAME,ZSALES-PROD_ID. ENDSELECT.
Inner Join   into Internal Table REPORT ZJOIN01 . DATA: begin of tab occurs 0, name like zcustomers-name, prod_id like zsales-prod_id, end of tab.  SELECT  A~NAME B~PROD_ID  INTO TABLE tab FROM ZSALES AS B INNER JOIN ZCUSTOMERS AS A ON B~CUST_ID = A~ID. … LOOP AT tab.  WRITE: / TAB-NAME,TAB-PROD_ID. ENDLOOP.
Internal Table Without Header Line DATA tab LIKE customers OCCURS 0. DATA wa LIKE customers. … LOOP AT tab  INTO wa . WRITE: / wa-id, wa-name. ENDLOOP.
Internal Table Declaration DATA tab TYPE TABLE OF customers. DATA wa LIKE LINE OF customers. …
ABAP Practice
Database Table Processing 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. Endif. Update customers set name = ‘John’ where id = 1.
Update Statement Data wa like  customers. wa -id  =  ‘1’. wa-nam e  = ‘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.
Deleting Database Table Entries Tables customers. customers-id  =  ‘1’. Delete  customers. Delete  customers  From  Table  delcustomers. Delete  From  customers  Where  city   =  ‘ Bangkok ’.
Exercise II
Exercise II usr02-ltime usr02-trdat usr02-bname 1.  ห้ามใช้  SELECT * 2.  ใช้  Internal Table
Exercise III
Tables Relationship for User Master USR02-BNAME  USR02-TRDAT  ADCP-TEL_NUMBER USR02 USR21 ADCP BNAME PERSNUMBER ADDRNUMBER Tables Relationship
Exercise III : User Master usr02-bname usr02-trdat adcp-tel_number ใช้  Internal Table

More Related Content

What's hot (20)

PPT
0104 abap dictionary
vkyecc1
 
PDF
SAP ABAP data dictionary
Revanth Nagaraju
 
PPT
Ab1011 module pool programming
Satheesh Kanna
 
PPTX
SAP Smart forms
Jugul Crasta
 
PPTX
Abap dictionary 1
venkata karthik
 
DOC
Badi document
hamisha_malik
 
PPT
List Processing in ABAP
sapdocs. info
 
PPTX
Abap data dictionary
SmartGokul4
 
PPT
SAP ABAP - Needed Notes
Akash Bhavsar
 
PPT
SAP ABAP HR TRAINING
JoshiRavin
 
DOCX
Field symbols
skumar_sap
 
PPT
Module pool programming
Subhojit- Opekkhay
 
DOCX
Abap performance tunning tips
Jay Dalwadi
 
PPTX
Reports
Jugul Crasta
 
PPT
07.Advanced Abap
sapdocs. info
 
PPTX
smartforms training | SAP SMART FORMS online training
Global Online Trainings
 
DOCX
Badis
Rajesh Kumar
 
PPTX
SAP ALE Idoc
Jugul Crasta
 
DOCX
OOPS ABAP.docx
JayantaPatra16
 
PPT
Maximizing SAP ABAP Performance
PeterHBrown
 
0104 abap dictionary
vkyecc1
 
SAP ABAP data dictionary
Revanth Nagaraju
 
Ab1011 module pool programming
Satheesh Kanna
 
SAP Smart forms
Jugul Crasta
 
Abap dictionary 1
venkata karthik
 
Badi document
hamisha_malik
 
List Processing in ABAP
sapdocs. info
 
Abap data dictionary
SmartGokul4
 
SAP ABAP - Needed Notes
Akash Bhavsar
 
SAP ABAP HR TRAINING
JoshiRavin
 
Field symbols
skumar_sap
 
Module pool programming
Subhojit- Opekkhay
 
Abap performance tunning tips
Jay Dalwadi
 
Reports
Jugul Crasta
 
07.Advanced Abap
sapdocs. info
 
smartforms training | SAP SMART FORMS online training
Global Online Trainings
 
Badis
Rajesh Kumar
 
SAP ALE Idoc
Jugul Crasta
 
OOPS ABAP.docx
JayantaPatra16
 
Maximizing SAP ABAP Performance
PeterHBrown
 

Viewers also liked (11)

PPT
ABAP Open SQL & Internal Table
sapdocs. info
 
PPT
Introduction to ABAP
sapdocs. info
 
PPT
ABAP Message, Debugging, File Transfer and Type Group
sapdocs. info
 
PPT
08.Abap Dialog Programming Overview
sapdocs. info
 
PPT
Dialog Programming Overview
sapdocs. info
 
PPT
SAP Accounts Reveivable Functions | http://sapdocs.info
sapdocs. info
 
PPT
SAP Accounts Reveivable Customer Master | http://sapdocs.info
sapdocs. info
 
PPT
SAP Accounts Reveivable Introduction | http://sapdocs.info
sapdocs. info
 
PPT
HR ABAP Technical Overview | http://sapdocs.info/
sapdocs. info
 
PDF
Beginner’s guide to sap abap 1
Panduka Bandara
 
PDF
ABAP for Beginners - www.sapdocs.info
sapdocs. info
 
ABAP Open SQL & Internal Table
sapdocs. info
 
Introduction to ABAP
sapdocs. info
 
ABAP Message, Debugging, File Transfer and Type Group
sapdocs. info
 
08.Abap Dialog Programming Overview
sapdocs. info
 
Dialog Programming Overview
sapdocs. info
 
SAP Accounts Reveivable Functions | http://sapdocs.info
sapdocs. info
 
SAP Accounts Reveivable Customer Master | http://sapdocs.info
sapdocs. info
 
SAP Accounts Reveivable Introduction | http://sapdocs.info
sapdocs. info
 
HR ABAP Technical Overview | http://sapdocs.info/
sapdocs. info
 
Beginner’s guide to sap abap 1
Panduka Bandara
 
ABAP for Beginners - www.sapdocs.info
sapdocs. info
 
Ad

Similar to Open SQL & Internal Table (20)

DOCX
Query
Raj Devaraj
 
PDF
Sql wksht-6
Mukesh Tekwani
 
PPT
dbs class 7.ppt
MARasheed3
 
PPTX
DOAG: Visual SQL Tuning
Kyle Hailey
 
PPT
INTRODUCTION TO SQL QUERIES REALTED BRIEF
VADAPALLYPRAVEENKUMA1
 
PPTX
SQL Server Learning Drive
TechandMate
 
PPTX
Sql
pratik201289
 
PDF
Master SQL from Scratch_ Beginners to Advanced 📝.pdf
gobilgobil
 
PDF
sql ppt for students who preparing for sql
bharatjanadharwarud
 
PPTX
Joins in SQL
Pooja Dixit
 
PPTX
Data Access Basics and Introduction to SQL
Nogalis Inc
 
DOCX
the following SPOOL command will capture the results of .docx
MARRY7
 
PDF
kscope2013vst-130627142814-phpapp02.pdf
TricantinoLopezPerez
 
PPT
Sql
tech4us
 
ODT
Sql Tags
Sutharsan nagarajan
 
PPTX
Sql server
Fajar Baskoro
 
PPTX
Sql for biggner
Arvind Kumar
 
PPT
SQL200.2 Module 2
Dan D'Urso
 
PPTX
Server Query Language – Getting Started.pptx
auzee32
 
DOC
Complete Sql Server querries
Ibrahim Jutt
 
Sql wksht-6
Mukesh Tekwani
 
dbs class 7.ppt
MARasheed3
 
DOAG: Visual SQL Tuning
Kyle Hailey
 
INTRODUCTION TO SQL QUERIES REALTED BRIEF
VADAPALLYPRAVEENKUMA1
 
SQL Server Learning Drive
TechandMate
 
Master SQL from Scratch_ Beginners to Advanced 📝.pdf
gobilgobil
 
sql ppt for students who preparing for sql
bharatjanadharwarud
 
Joins in SQL
Pooja Dixit
 
Data Access Basics and Introduction to SQL
Nogalis Inc
 
the following SPOOL command will capture the results of .docx
MARRY7
 
kscope2013vst-130627142814-phpapp02.pdf
TricantinoLopezPerez
 
Sql
tech4us
 
Sql server
Fajar Baskoro
 
Sql for biggner
Arvind Kumar
 
SQL200.2 Module 2
Dan D'Urso
 
Server Query Language – Getting Started.pptx
auzee32
 
Complete Sql Server querries
Ibrahim Jutt
 
Ad

More from sapdocs. info (20)

PDF
SAP PM Master Data Training Guide
sapdocs. info
 
DOCX
SAP SD Certification (C_TSCM62_66) Preparation Training Notes
sapdocs. info
 
DOCX
Variant Configuration in SAP PP: Beginner's Guide
sapdocs. info
 
PDF
SAP FICO BBP Sample Document PDF NEW!
sapdocs. info
 
PDF
SAP PP MRP Guide for Beginners
sapdocs. info
 
PDF
SAP ECC 6.0 PM Configuration Manual - www.sapdocs.info
sapdocs. info
 
PDF
SAP PM Training Manual - www.sapdocs.info
sapdocs. info
 
PDF
ABAP Basico para Consultores Funcionales
sapdocs. info
 
PDF
SAP Configuration Guide for Functional Modules (Based on IDES)
sapdocs. info
 
PDF
SAP FI-AP TCODES & MENU PATHS
sapdocs. info
 
PDF
SAP FI-AR TCODES & MENU PATHS
sapdocs. info
 
DOC
SAP CO Configuration Guide - Exclusive Document
sapdocs. info
 
DOC
SAP PP End User Document - www.sapdocs.info
sapdocs. info
 
PDF
SAP MM Configuration - Real Project Documentation
sapdocs. info
 
PDF
SAP FI AP: Configuration & End User Guide
sapdocs. info
 
PDF
SAP FI AR: End User Guide for Beginners
sapdocs. info
 
PDF
SAP FI AP: End User Guide for Beginners
sapdocs. info
 
PDF
SAP FI Asset Accounting: End User Guide for Beginners
sapdocs. info
 
PDF
Variant Configurition in SAP: Beginners Guide | www.sapdocs.info
sapdocs. info
 
PDF
Exclusive SAP Basis Training Book | www.sapdocs.info
sapdocs. info
 
SAP PM Master Data Training Guide
sapdocs. info
 
SAP SD Certification (C_TSCM62_66) Preparation Training Notes
sapdocs. info
 
Variant Configuration in SAP PP: Beginner's Guide
sapdocs. info
 
SAP FICO BBP Sample Document PDF NEW!
sapdocs. info
 
SAP PP MRP Guide for Beginners
sapdocs. info
 
SAP ECC 6.0 PM Configuration Manual - www.sapdocs.info
sapdocs. info
 
SAP PM Training Manual - www.sapdocs.info
sapdocs. info
 
ABAP Basico para Consultores Funcionales
sapdocs. info
 
SAP Configuration Guide for Functional Modules (Based on IDES)
sapdocs. info
 
SAP FI-AP TCODES & MENU PATHS
sapdocs. info
 
SAP FI-AR TCODES & MENU PATHS
sapdocs. info
 
SAP CO Configuration Guide - Exclusive Document
sapdocs. info
 
SAP PP End User Document - www.sapdocs.info
sapdocs. info
 
SAP MM Configuration - Real Project Documentation
sapdocs. info
 
SAP FI AP: Configuration & End User Guide
sapdocs. info
 
SAP FI AR: End User Guide for Beginners
sapdocs. info
 
SAP FI AP: End User Guide for Beginners
sapdocs. info
 
SAP FI Asset Accounting: End User Guide for Beginners
sapdocs. info
 
Variant Configurition in SAP: Beginners Guide | www.sapdocs.info
sapdocs. info
 
Exclusive SAP Basis Training Book | www.sapdocs.info
sapdocs. info
 

Recently uploaded (20)

PDF
How do we fix the Messed Up Corporation’s System diagram?
YukoSoma
 
PDF
Why Unipac Equipment Leads the Way Among Gantry Crane Manufacturers in Singap...
UnipacEquipment
 
PDF
LDM Recording for Yogi Goddess Projects Summer 2025
LDMMia GrandMaster
 
PDF
_How Freshers Can Find the Best IT Companies in Jaipur with Salarite.pdf
SALARITE
 
PDF
HOW TO RECOVER LOST CRYPTOCURRENCY - VISIT iBOLT CYBER HACKER COMPANY
diegovalentin771
 
PPTX
Technical Analysis of 1st Generation Biofuel Feedstocks - 25th June 2025
TOFPIK
 
PDF
Smart Lead Magnet Review: Effortless Email List Growth with Automated Funnels...
Larry888358
 
PDF
Buy Facebook Accounts Buy Facebook Accounts
darlaknowles49
 
PPTX
Smarter call Reporting with Callation.pptx
Callation us
 
PPTX
World First Cardiovascular & Thoracic CT Scanner
arineta37
 
DOCX
DiscoveryBit The 21st century seen.docx
seomehk
 
PPTX
Hackathon - Technology - Idea Submission Template -HackerEarth.pptx
nanster236
 
PDF
Agriculture Machinery PartsAgriculture Machinery Parts
mizhanw168
 
PPTX
25 Future Mega Trends Reshaping the World in 2025 and Beyond
presentifyai
 
PPTX
Oil and Gas EPC Market Size & Share | Growth - 2034
Aman Bansal
 
PDF
Choosing the Right Packaging for Your Products – Sriram Enterprises, Tirunelveli
SRIRAM ENTERPRISES, TIRUNELVELI
 
PDF
Top Supply Chain Management Tools Transforming Global Logistics.pdf
Enterprise Wired
 
PDF
3rd Edition of Human Resources Management Awards
resources7371
 
PDF
2018 - Building a Culture By Design PPTX
Cheryl M
 
PDF
20250703_A. Stotz All Weather Strategy - Performance review July
FINNOMENAMarketing
 
How do we fix the Messed Up Corporation’s System diagram?
YukoSoma
 
Why Unipac Equipment Leads the Way Among Gantry Crane Manufacturers in Singap...
UnipacEquipment
 
LDM Recording for Yogi Goddess Projects Summer 2025
LDMMia GrandMaster
 
_How Freshers Can Find the Best IT Companies in Jaipur with Salarite.pdf
SALARITE
 
HOW TO RECOVER LOST CRYPTOCURRENCY - VISIT iBOLT CYBER HACKER COMPANY
diegovalentin771
 
Technical Analysis of 1st Generation Biofuel Feedstocks - 25th June 2025
TOFPIK
 
Smart Lead Magnet Review: Effortless Email List Growth with Automated Funnels...
Larry888358
 
Buy Facebook Accounts Buy Facebook Accounts
darlaknowles49
 
Smarter call Reporting with Callation.pptx
Callation us
 
World First Cardiovascular & Thoracic CT Scanner
arineta37
 
DiscoveryBit The 21st century seen.docx
seomehk
 
Hackathon - Technology - Idea Submission Template -HackerEarth.pptx
nanster236
 
Agriculture Machinery PartsAgriculture Machinery Parts
mizhanw168
 
25 Future Mega Trends Reshaping the World in 2025 and Beyond
presentifyai
 
Oil and Gas EPC Market Size & Share | Growth - 2034
Aman Bansal
 
Choosing the Right Packaging for Your Products – Sriram Enterprises, Tirunelveli
SRIRAM ENTERPRISES, TIRUNELVELI
 
Top Supply Chain Management Tools Transforming Global Logistics.pdf
Enterprise Wired
 
3rd Edition of Human Resources Management Awards
resources7371
 
2018 - Building a Culture By Design PPTX
Cheryl M
 
20250703_A. Stotz All Weather Strategy - Performance review July
FINNOMENAMarketing
 

Open SQL & Internal Table

  • 1. ABAP Chapter 3 Open SQL Internal Table
  • 2. SAP System : 3 Tier Client/Server DB Server SAP Application Server SAP GUI Presentation Server SAP GUI SAP GUI
  • 3. 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
  • 4. 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
  • 5. 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
  • 6. Open SQL SELECT ... INSERT ... UPDATE ... DELETE ...
  • 7. 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
  • 8. 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
  • 9. 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
  • 10. Select Overview Select < result > Which Columns? From < table > Which Table? Into < destination > Where to place? Where < condition > Which Lines?
  • 11. Select Statement Select multiple records from database Select single record from database SELECT * FROM customers. … ENDSELECT. SELECT SINGLE * FROM customers WHERE id = 1. …
  • 12. 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.
  • 13. Dialog WP Dialog WP TaskHandler DYNPRO Processor ABAP Processor Database Local Memory Memory Space DB Interface Lis t b uffer Result Set
  • 14. 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
  • 15. 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.
  • 16. 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.
  • 17. Exercise I customers-id customers-name customers-city
  • 19. 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.
  • 20. Select With Range Tables sflight. Select * From sflight Where price between 100 and 1000. Write: / sflight-carrid, sflight-connid, sflight-price. Endselect.
  • 21. SELECT … With IN List Tables sflight. Select * From sflight Where price in ( 100, 1000 ). Write: / sflight-carrid, sflight-connid, sflight-price. Endselect.
  • 23. 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.
  • 25. Select * : Example SELECT *
  • 26. 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.
  • 27. 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.
  • 28. Select Column : Example I
  • 29. Reading Selected Column Tables customers. Select id name city into (customers-id, customers-name, customers-city) from customers. write: / customers-id, customers-name, customers-city . endselect. if sy-subrc <> 0. write / ‘No Data found ’. endif.
  • 30. Select Column : Example II
  • 31. Corresponding Fields of... Tables: customers. Select id name city into corresponding fields of customers from customers. Write: / customers-id, customers-name, customers-city. Endselect.
  • 32. Select Statement : Special Topics
  • 33. 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.
  • 34. SELECT … ORDER BY ... Tables: spfli. Select * from spfli Order by cityfrom . Write: / spfli-carrid, spfli-connid, spfli-cityfrom. Endselect.
  • 35. SELECT … With Template Tables customers. Select * From customers Where name Like ‘_ r %’. Write: / customers-id,customers-name. Endselect.
  • 36. Aggregate Functions Data: maxdat like sflight-distance, mindat like sflight-distance, counter type I. Select C OUNT ( * ) M IN ( distance ) M AX ( distance ) into (counter , m in dat, m ax dat) from spfli. Write: / ‘Count :’ , counter , / ‘Min :’ , mindat, / ‘Max :’ , maxdat . Aggregate Functions : COUNT,MIN,MAX,AVG and SUM
  • 37. SELECT … GROUP BY ... Data: carrid like sflight-carrid, mindat Type P Decimals 2, maxdat Type P Decimals 2. Select carrid Min( price ) Max( price ) Into (carrid, mindat, maxdat) From sflight Group by carrid. Write: / carrid, mindat, maxdat. Endselect. อยากทราบว่า ในแต่ละสายการบิน มีราคาตั๋วต่ำสุดและสูงสุดเท่าไร sflight 75 20010226 0110 SQ 130 20010228 0400 LH 145 20010110 0400 LH 150 20010101 0400 LH Price fldate connid carrid
  • 38. 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
  • 39. Exercise I customers-id customers-name customers-city ห้ามใช้ SELECT *
  • 40. Exercise II usr02-ltime usr02-trdat usr02-bname ห้ามใช้ SELECT *
  • 41. ABAP : Inner Join
  • 42. Tables Join spfli sflight BK NY BK cityto 250 SQ 0110 SQ 540 BK 0402 LH 100 NY 0400 LH distance cityfrom connid carrid 75 20010226 0110 SQ 130 20010228 0400 LH 145 20010110 0400 LH 150 20010101 0400 LH price fldate connid carrid
  • 43. 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’ เท่านั้น
  • 44. 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’;
  • 45. Tables Join Methods Nested select statement Internal table View Inner join of Select statement
  • 46. Nested Select Statement Tables: spfli,sflight. Select * from spfli where carrid = ‘LH’. Select * from sflight where carrid = spfli-carrid and connid = spfli-connid. Write: / spfli-carrid, spfli-connid, sflight-fldate, sflight-price. Endselect. Endselect.
  • 47. Open SQL – Inner Join Tables: spfli,sflight. Select spfli~carrid spfli~connid sflight~fldate spfli~cityto sflight~price into (spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price) from spfli inner join sflight on spfli~carrid = sflight~carrid and spfli~connid = sflight~connid where spfli~carrid = ‘LH’. Write: / spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price. Endselect.
  • 48. Open SQL – Inner Join Tables: A,B. Select A~a B~b B~c into (A-a,B-b,B-c) from A inner join B on A~b = B~b. Write: / A-a,B-b,B-c. Endselect. Table : A Table : B A-a B-b B-c b2 a2 b1 a1 b a c2 b2 c3 b3 c1 b1 c b
  • 49. 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
  • 50. Open SQL – Alias Table Name Tables: spfli,sflight. Select a~carrid a~connid b~fldate a~cityto b~price into (spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price) from spfli as a inner join sflight as b on a~carrid = b~carrid and a~connid = b~connid where a~carrid = ‘LH’. Write: / spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price. Endselect.
  • 51. Inner Join/Outer Join Example ZPRODUCTS ZSALES ZSALEREPS ZCUSTOMERS 432555 Singapore David 3 234111 Bangkok Micheal 4 222222 London Peter 2 111111 New York John 1 tel city name id CD Tape Ruler Pencil Pen prod_name 120 X1 80 B1 99 Y1 125 A2 100 A1 on_hand p_id 90 50 10 qty 02 20020321 X1 3 01 20020318 A2 1 01 20020318 A1 1 sale_id sale_date prod_id cust_id Pipop 02 Somchai 01 name sale_id
  • 52. Open SQL – Inner Join REPORT ZINNERJOIN01 . TABLES: ZCUSTOMERS,ZSALES. SELECT A~NAME B~PROD_ID INTO (ZCUSTOMERS-NAME,ZSALES-PROD_ID) FROM ZSALES AS B INNER JOIN ZCUSTOMERS AS A ON B~CUST_ID = A~ID. WRITE: / ZCUSTOMERS-NAME,ZSALES-PROD_ID. ENDSELECT.
  • 53. Open SQL – Inner Join > 2 Tables Tables: A,B,C. Select A~a B~c C~y into (A-a,B-c,C-y) from A inner join B on A~b = B~b inner join C on C~x = B~c. Write: / A-a,B-c,C-y. Endselect. Table : A Table : B Table : C A-a B-c C-y … … b a ... … … … ... … c b ... … y x
  • 54. Open SQL – Inner Join > 2 Tables 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,ZSALES-QTY. ENDSELECT.
  • 55. Exercise List customers who buy product from company as following fields: zcustomers-id zcustomers-name zsales-sale_date zproducts-prod_name zsales-qty zsalereps-name
  • 56. Exercise : User Master USR02-BNAME USR02-TRDAT ADCP-TEL_NUMBER USR02 USR21 ADCP BNAME PERSNUMBER ADDRNUMBER Tables Relationship
  • 57. ABAP : Outer Join
  • 58. Open SQL – Outer Join REPORT ZOUTERJOIN . TABLES: ZCUSTOMERS,ZSALES. SELECT A~NAME B~PROD_ID INTO (ZCUSTOMERS-NAME,ZSALES-PROD_ID) FROM ZCUSTOMERS AS A LEFT OUTER JOIN ZSALES AS B ON A~ID = B~CUST_ID. WRITE: / ZCUSTOMERS-NAME,ZSALES-PROD_ID. ENDSELECT. Single Result Table B~PROD_ID A~NAME X1 David Micheal Peter A2 John A1 John
  • 59. Exercise List customers name who do not buy any product from company
  • 60. 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. ลูกค้าชื่ออะไรที่ไม่ได้ซื้อสินค้าจากเรา มีใครบ้าง
  • 62. Data Objects in ABAP Memory Space Structure Table Structure Internal Table Variable Constants <Field-symbols>
  • 63. INTERNAL TABLE Flight (Structure) Carrid Connid Date Price Internal Table Flight (Internal Table) Carrid Connid Date Price Header Line
  • 64. Structure Data: Begin of flight, carrid like sflight-carrid, connid like sflight-connid, date like sflight-fldate, price like sflight-price. Data: End of flight. flight-carrid = ‘LH’. Write: / flight-carrid.
  • 65. INTERNAL TABLE Data: begin of tab occurs 10, carrid like sflight-carrid, connid like sflight-connid, fldate like sflight-fldate, price like sflight-price. Data end of tab.
  • 66. USING ABAP DICTIONARY STRUCTURE Data: begin of tab occurs 0 . Include structure sflight. Data end of tab.
  • 67. INTERNAL TABLE USING LIKE Data tab LIKE sflight OCCURS 0 WITH HEADER LINE .
  • 68. FILLING INTERNAL TABLE (APPEND) Tables sflight. Data flight like sflight occurs 0 with header line. Select * from sflight. Move sflight to flight. Append flight. Endselect.
  • 69. Standard Key of Internal Table Data: begin of tab occurs 0, f1 type C , f2 type I, f3 type N , f4 type P, end of tab. tab f4 f3 f2 f1
  • 70. Reading Data From Internal Table Data tab like sflight occurs 0 with header line. Select * from sflight into table tab . If sy-subrc = 0. Loop at tab. Write: / tab-carrid, tab-price. Endloop. Else. Write: / ‘No Data’. Endif.
  • 71. Access Database Without Internal Table
  • 72. Access Database Using Internal Table
  • 73. Reading Data From Internal Table Data : begin of tab occurs 0 , id like customers-id, name like customers-name, end of tab. Select id name from customers into table tab . If sy-subrc = 0. Loop at tab. Write: / tab-id, tab -name . Endloop. else . Write : / ‘No Data’. Endif.
  • 74. Exercise I : Change Using Internal Table
  • 75. SORTING INTERNAL TABLE (SORT) Sort flight. Sort flight by price fldate. Sort flight by price ascending fldate descending.
  • 76. Data tab like spfli occurs 0 with header line. Select * from spfli into table tab. Sort tab by cityfrom. … Loop at tab. write: / tab-carrid, tab-connid,tab-cityfrom. Endloop. SORTING INTERNAL TABLE
  • 77. 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.
  • 78. Internal Table Template Condition ... loop at tab where name cp ‘+r*’. ...
  • 79. Reading Single Record ... Sort flight by carrid connid fldate . Read table flight with key c arrid = ‘LH’ c onnid = ‘0400’ fldate = ‘19990201’ Binary Search. if sy-subrc = 0 . write : / flight-carrid,flight-connid, flight-fldate, flight-price. endif.
  • 80. Reading Single Record using Index ... Read table flight index 3. If sy-subrc = 0. write: / flight-carrid , flight-connid . Endif.
  • 81. CHANGING INTERNAL TABLE ... Delete flight index 5. Delete flight where carrid = ‘LH’. flight-carrid = ‘XX’. flight-price = 100. … Insert flight index 1.
  • 82. DELETING INTERNAL TABLE Clear flight. Refresh flight. Free flight. DATA flight LIKE sflight occurs 0 with header line.
  • 83. Total Record of Internal Table Data: line_count type i. Data tab like sflight occurs 0 with header line. Select * from sflight into table tab. Describe table tab lines line_count. Write: / line_count.
  • 85. Internal Table Processing Data tab like spfli occurs 0 with Header line. … Select * from spfli appending table tab where carrid = ‘LH’.
  • 86. SELECT … INNER JOIN REPORT ZINNERJOIN01 . TABLES: ZCUSTOMERS,ZSALES. SELECT A~NAME B~PROD_ID INTO (ZCUSTOMERS-NAME,ZSALES-PROD_ID) FROM ZSALES AS B INNER JOIN ZCUSTOMERS AS A ON B~CUST_ID = A~ID. WRITE: / ZCUSTOMERS-NAME,ZSALES-PROD_ID. ENDSELECT.
  • 87. Inner Join into Internal Table REPORT ZJOIN01 . DATA: begin of tab occurs 0, name like zcustomers-name, prod_id like zsales-prod_id, end of tab. SELECT A~NAME B~PROD_ID INTO TABLE tab FROM ZSALES AS B INNER JOIN ZCUSTOMERS AS A ON B~CUST_ID = A~ID. … LOOP AT tab. WRITE: / TAB-NAME,TAB-PROD_ID. ENDLOOP.
  • 88. Internal Table Without Header Line DATA tab LIKE customers OCCURS 0. DATA wa LIKE customers. … LOOP AT tab INTO wa . WRITE: / wa-id, wa-name. ENDLOOP.
  • 89. Internal Table Declaration DATA tab TYPE TABLE OF customers. DATA wa LIKE LINE OF customers. …
  • 91. Database Table Processing INSERT UPDATE MODIFY DELETE Database
  • 92. Insert (Table) Tables customers. customers-id = ‘999’. customers-name = ‘Test’. Insert customers. if sy-subrc <> 0. write: / ‘Data Already Exists’. endif.
  • 93. Update Statement Tables customers. Select single * from customers where id = 1. If sy-subrc = 0. customers-name = ‘John’. update customers. Endif. Update customers set name = ‘John’ where id = 1.
  • 94. Update Statement Data wa like customers. wa -id = ‘1’. wa-nam e = ‘Test No 1’. wa-city = ‘Bangkok’. update customers from wa . If sy-subrc <> 0. write: / ‘Data not found’. Endif.
  • 95. Modify Statement Tables customers. customers-id = ‘1’. customers-name = ‘Test No 1’. Modify customers.
  • 96. Deleting Database Table Entries Tables customers. customers-id = ‘1’. Delete customers. Delete customers From Table delcustomers. Delete From customers Where city = ‘ Bangkok ’.
  • 98. Exercise II usr02-ltime usr02-trdat usr02-bname 1. ห้ามใช้ SELECT * 2. ใช้ Internal Table
  • 100. Tables Relationship for User Master USR02-BNAME USR02-TRDAT ADCP-TEL_NUMBER USR02 USR21 ADCP BNAME PERSNUMBER ADDRNUMBER Tables Relationship
  • 101. Exercise III : User Master usr02-bname usr02-trdat adcp-tel_number ใช้ Internal Table