Your SlideShare is downloading. ×
0
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
03 abap3-090715081232-phpapp01
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

03 abap3-090715081232-phpapp01

2,090

Published on

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,090
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
137
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. ABAP Chapter 3 <ul><li>Open SQL </li></ul><ul><li>Internal Table </li></ul>
  • 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&amp;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 <ul><li>SELECT ... </li></ul><ul><li>INSERT ... </li></ul><ul><li>UPDATE ... </li></ul><ul><li>DELETE ... </li></ul>
  • 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 <ul><li>spfli </li></ul>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 <ul><li>Select &lt; result &gt; Which Columns? </li></ul><ul><li>From &lt; table &gt; Which Table? </li></ul><ul><li>Into &lt; destination &gt; Where to place? </li></ul><ul><li>Where &lt; condition &gt; Which Lines? </li></ul>
  • 11. Select Statement <ul><li>Select multiple records from database </li></ul><ul><li>Select single record from database </li></ul>SELECT * FROM customers. … ENDSELECT. SELECT SINGLE * FROM customers WHERE id = 1. …
  • 12. Select Multiple Records <ul><li>Tables spfli. </li></ul><ul><li>Seclect * from spfli. </li></ul><ul><li>write: / spfli-carrid, spfli-connid, </li></ul><ul><li>spf li-cityto. </li></ul><ul><li>endselect. </li></ul><ul><li>if sy-subrc &lt;&gt; 0. </li></ul><ul><li>write: / ‘No Data’. </li></ul><ul><li>endif. </li></ul>
  • 13. Dialog WP <ul><ul><ul><ul><li>Dialog WP </li></ul></ul></ul></ul>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 <ul><li>Tables spfli. </li></ul><ul><li>Seclect * from spfli into spfli . </li></ul><ul><li>write: / spfli-carrid, spfli-connid, </li></ul><ul><li>spfli-cityfrom, spfli-cityto. </li></ul><ul><li>endselect. </li></ul><ul><li>if sy-subrc &lt;&gt; 0. </li></ul><ul><li>write: / ‘No Data’. </li></ul><ul><li>endif. </li></ul>
  • 16. Select … Into Work Area <ul><li>Data wa like spfli. </li></ul><ul><li>Seclect * from spfli into wa . </li></ul><ul><li>write: / wa -carrid, wa -connid, </li></ul><ul><li>wa -cityfrom, wa -cityto. </li></ul><ul><li>endselect. </li></ul><ul><li>if sy-subrc &lt;&gt; 0. </li></ul><ul><li>write: / ‘No Data’. </li></ul><ul><li>endif. </li></ul>
  • 17. Exercise I customers-id customers-name customers-city
  • 18. SELECT with WHERE Clause
  • 19. Loop Processing with Restriction <ul><li>Tables spfli. </li></ul><ul><li>Select * from spfli </li></ul><ul><li>where cityfrom = ‘FRANKFURT’. </li></ul><ul><li>write: / spfli-carrid, spfli-cityto. </li></ul><ul><li>endselect. </li></ul><ul><li>If sy-subrc &lt;&gt; 0. </li></ul><ul><li>write / ‘no data’. </li></ul><ul><li>endif. </li></ul>
  • 20. Select With Range <ul><li>Tables sflight. </li></ul><ul><li>Select * From sflight </li></ul><ul><li>Where price between 100 and 1000. </li></ul><ul><li>Write: / sflight-carrid, sflight-connid, </li></ul><ul><li>sflight-price. </li></ul><ul><li>Endselect. </li></ul>
  • 21. SELECT … With IN List <ul><li>Tables sflight. </li></ul><ul><li>Select * From sflight </li></ul><ul><li>Where price in ( 100, 1000 ). </li></ul><ul><li>Write: / sflight-carrid, sflight-connid, </li></ul><ul><li>sflight-price. </li></ul><ul><li>Endselect. </li></ul>
  • 22. Select Single Record
  • 23. Select Single Record <ul><li>Table s spfli. </li></ul><ul><li>Select single * from spfli </li></ul><ul><li>where carrid = ‘LH’ and </li></ul><ul><li> connid = ‘0400’. </li></ul><ul><li>if sy-subrc = 0. </li></ul><ul><li>write: / spfli-carrid, spfli-connid, </li></ul><ul><li> spfli-cityfrom, spfli-cityto. </li></ul><ul><li>else. </li></ul><ul><li>write: / ‘Data not found’. </li></ul><ul><li>endif. </li></ul>
  • 24. Select Column List
  • 25. Select * : Example SELECT *
  • 26. Reading Selected Column <ul><li>Data: id like customers - id, </li></ul><ul><li>name like customers-name, </li></ul><ul><li>city like customers-city. </li></ul><ul><li>Select id name city </li></ul><ul><li>into ( id , name, city ) </li></ul><ul><li>from customers. </li></ul><ul><li>write: / id, name, city . </li></ul><ul><li>endselect. </li></ul><ul><li>if sy-subrc &lt;&gt; 0. </li></ul><ul><li>write / ‘No Data found ’. </li></ul><ul><li>endif. </li></ul>
  • 27. Reading Selected Column <ul><li>Data: begin of wa, </li></ul><ul><li>id like customers - id, </li></ul><ul><li>name like customers-name, </li></ul><ul><li>city like customers-city, </li></ul><ul><li>end of wa. </li></ul><ul><li>Select id name city </li></ul><ul><li>into wa </li></ul><ul><li>from customers. </li></ul><ul><li>write: / wa-id, wa-name , wa-city . </li></ul><ul><li>endselect. </li></ul><ul><li>if sy-subrc &lt;&gt; 0. </li></ul><ul><li>write / ‘No Data found ’. </li></ul><ul><li>endif. </li></ul>
  • 28. Select Column : Example I
  • 29. Reading Selected Column <ul><li>Tables customers. </li></ul><ul><li>Select id name city </li></ul><ul><li>into (customers-id, customers-name, customers-city) </li></ul><ul><li>from customers. </li></ul><ul><li>write: / customers-id, customers-name, customers-city . </li></ul><ul><li>endselect. </li></ul><ul><li>if sy-subrc &lt;&gt; 0. </li></ul><ul><li>write / ‘No Data found ’. </li></ul><ul><li>endif. </li></ul>
  • 30. Select Column : Example II
  • 31. Corresponding Fields of... <ul><li>Tables: customers. </li></ul><ul><li>Select id name city </li></ul><ul><li>into corresponding fields of customers </li></ul><ul><li>from customers. </li></ul><ul><li>Write: / customers-id, customers-name, </li></ul><ul><li>customers-city. </li></ul><ul><li>Endselect. </li></ul>
  • 32. Select Statement : Special Topics
  • 33. DB Count : SY-DBCNT <ul><li>Tables customers. </li></ul><ul><li>Select * from customers. </li></ul><ul><li>write: / sy-dbcnt , customers-id, customers-name . </li></ul><ul><li>endselect. </li></ul><ul><li>if sy-subrc &lt;&gt; 0. </li></ul><ul><li>write : / ‘No Data found ’. </li></ul><ul><li>else. </li></ul><ul><li>write: / sy-dbcnt, ‘Record found’. </li></ul><ul><li>endif. </li></ul>
  • 34. SELECT … ORDER BY ... <ul><li>Tables: spfli. </li></ul><ul><li>Select * from spfli </li></ul><ul><li>Order by cityfrom . </li></ul><ul><li>Write: / spfli-carrid, spfli-connid, </li></ul><ul><li>spfli-cityfrom. </li></ul><ul><li>Endselect. </li></ul>
  • 35. SELECT … With Template <ul><li>Tables customers. </li></ul><ul><li>Select * From customers </li></ul><ul><li>Where name Like ‘_ r %’. </li></ul><ul><li>Write: / customers-id,customers-name. </li></ul><ul><li>Endselect. </li></ul>
  • 36. Aggregate Functions <ul><li>Data: maxdat like sflight-distance, </li></ul><ul><li>mindat like sflight-distance, </li></ul><ul><li>counter type I. </li></ul><ul><li>Select C OUNT ( * ) M IN ( distance ) M AX ( distance ) </li></ul><ul><li>into (counter , m in dat, m ax dat) </li></ul><ul><li> from spfli. </li></ul><ul><li>Write: / ‘Count :’ , counter , </li></ul><ul><li>/ ‘Min :’ , mindat, </li></ul><ul><li>/ ‘Max :’ , maxdat . </li></ul>Aggregate Functions : COUNT,MIN,MAX,AVG and SUM
  • 37. SELECT … GROUP BY ... <ul><li>Data: carrid like sflight-carrid, </li></ul><ul><li>mindat Type P Decimals 2, </li></ul><ul><li>maxdat Type P Decimals 2. </li></ul><ul><li>Select carrid Min( price ) Max( price ) </li></ul><ul><li>Into (carrid, mindat, maxdat) </li></ul><ul><li>From sflight </li></ul><ul><li>Group by carrid. </li></ul><ul><li>Write: / carrid, mindat, maxdat. </li></ul><ul><li>Endselect. </li></ul>อยากทราบว่า ในแต่ละสายการบิน มีราคาตั๋วต่ำสุดและสูงสุดเท่าไร sflight 75 20010226 0110 SQ 130 20010228 0400 LH 145 20010110 0400 LH 150 20010101 0400 LH Price fldate connid carrid
  • 38. Sub Query <ul><li>tables customers. </li></ul><ul><li>select * </li></ul><ul><li>from customers </li></ul><ul><li>where id &lt;&gt; 1 and </li></ul><ul><li>city = </li></ul><ul><li>( select city </li></ul><ul><li>from customers </li></ul><ul><li>where id = 1 ). </li></ul><ul><li>write: / customers-id, customers-name. </li></ul><ul><li>endselect. </li></ul>ลูกค้าคนใดที่อยู่เมืองเดียวกับลูกค้ารหัส 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 <ul><li>spfli </li></ul>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 <ul><li>Question: Select carrid, connid and cityto from spfli </li></ul><ul><li>and fldate,price from sflight where carrid = ‘LH’ </li></ul><ul><li>spfli-carrid spfli-connid sflight-fldate spfli-cityto sflight-price </li></ul><ul><li>เงื่อนไข : ให้แสดงข้อมูลเฉพาะสายการบิน ‘ LH’ เท่านั้น </li></ul>
  • 44. Standard SQL <ul><li>Select spfli.carrid, spfli.connid, sflight.fldate, </li></ul><ul><li>sflight.price </li></ul><ul><li>From spfli, sflight </li></ul><ul><li>Where spfli.carrid = sflight.carrid and </li></ul><ul><li>spfli.connid = sflight.connid and </li></ul><ul><li> spfli.carrid = ‘LH’; </li></ul>
  • 45. Tables Join Methods <ul><li>Nested select statement </li></ul><ul><li>Internal table </li></ul><ul><li>View </li></ul><ul><li>Inner join of Select statement </li></ul>
  • 46. Nested Select Statement <ul><li>Tables: spfli,sflight. </li></ul><ul><li>Select * from spfli where carrid = ‘LH’. </li></ul><ul><li>Select * from sflight </li></ul><ul><li>where carrid = spfli-carrid and </li></ul><ul><li>connid = spfli-connid. </li></ul><ul><li>Write: / spfli-carrid, spfli-connid, sflight-fldate, </li></ul><ul><li>sflight-price. </li></ul><ul><li>Endselect. </li></ul><ul><li>Endselect. </li></ul>
  • 47. Open SQL – Inner Join <ul><li>Tables: spfli,sflight. </li></ul><ul><li>Select spfli~carrid spfli~connid sflight~fldate spfli~cityto sflight~price </li></ul><ul><li>into (spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price) </li></ul><ul><li>from spfli inner join sflight </li></ul><ul><li>on spfli~carrid = sflight~carrid and </li></ul><ul><li>spfli~connid = sflight~connid </li></ul><ul><li>where spfli~carrid = ‘LH’. </li></ul><ul><li>Write: / spfli-carrid, spfli-connid, sflight-fldate, </li></ul><ul><li>spfli-cityto, sflight-price. </li></ul><ul><li>Endselect. </li></ul>
  • 48. Open SQL – Inner Join <ul><li>Tables: A,B. </li></ul><ul><li>Select A~a B~b B~c </li></ul><ul><li>into (A-a,B-b,B-c) </li></ul><ul><li>from A inner join B </li></ul><ul><li>on A~b = B~b. </li></ul><ul><li>Write: / A-a,B-b,B-c. </li></ul><ul><li>Endselect. </li></ul>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 <ul><li>Tables: spfli,sflight. </li></ul><ul><li>Select a~carrid a~connid b~fldate a~cityto b~price </li></ul><ul><li>into (spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price) </li></ul><ul><li>from spfli as a inner join sflight as b </li></ul><ul><li>on a~carrid = b~carrid and </li></ul><ul><li>a~connid = b~connid </li></ul><ul><li>where a~carrid = ‘LH’. </li></ul><ul><li>Write: / spfli-carrid, spfli-connid, sflight-fldate, spfli-cityto, sflight-price. </li></ul><ul><li>Endselect. </li></ul>
  • 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 <ul><li>REPORT ZINNERJOIN01 . </li></ul><ul><li>TABLES: ZCUSTOMERS,ZSALES. </li></ul><ul><li>SELECT A~NAME B~PROD_ID </li></ul><ul><li>INTO (ZCUSTOMERS-NAME,ZSALES-PROD_ID) </li></ul><ul><li>FROM ZSALES AS B INNER JOIN ZCUSTOMERS AS A </li></ul><ul><li>ON B~CUST_ID = A~ID. </li></ul><ul><li>WRITE: / ZCUSTOMERS-NAME,ZSALES-PROD_ID. </li></ul><ul><li>ENDSELECT. </li></ul>
  • 53. Open SQL – Inner Join &gt; 2 Tables <ul><li>Tables: A,B,C. </li></ul><ul><li>Select A~a B~c C~y </li></ul><ul><li>into (A-a,B-c,C-y) </li></ul><ul><li>from A inner join B </li></ul><ul><li>on A~b = B~b </li></ul><ul><li>inner join C </li></ul><ul><li>on C~x = B~c. </li></ul><ul><li>Write: / A-a,B-c,C-y. </li></ul><ul><li>Endselect. </li></ul>Table : A Table : B Table : C A-a B-c C-y … … b a ... … … … ... … c b ... … y x
  • 54. Open SQL – Inner Join &gt; 2 Tables <ul><li>REPORT ZINNERJOIN02 . </li></ul><ul><li>TABLES: ZCUSTOMERS,ZPRODUCTS,ZSALES. </li></ul><ul><li>SELECT A~NAME C~PROD_NAME B~QTY </li></ul><ul><li>INTO (ZCUSTOMERS-NAME, ZPRODUCTS-PROD_NAME, ZSALES-QTY) </li></ul><ul><li>FROM ZSALES AS B INNER JOIN ZCUSTOMERS AS A </li></ul><ul><li>ON B~CUST_ID = A~ID </li></ul><ul><li>INNER JOIN ZPRODUCTS AS C </li></ul><ul><li>ON C~P_ID = B~PROD_ID. </li></ul><ul><li>WRITE: / ZCUSTOMERS-NAME,ZPRODUCTS-PROD_NAME,ZSALES-QTY. </li></ul><ul><li>ENDSELECT. </li></ul>
  • 55. Exercise <ul><li>List customers who buy product from company as following fields: </li></ul><ul><li>zcustomers-id </li></ul><ul><li>zcustomers-name </li></ul><ul><li>zsales-sale_date </li></ul><ul><li>zproducts-prod_name </li></ul><ul><li>zsales-qty </li></ul><ul><li>zsalereps-name </li></ul>
  • 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 <ul><li>REPORT ZOUTERJOIN . </li></ul><ul><li>TABLES: ZCUSTOMERS,ZSALES. </li></ul><ul><li>SELECT A~NAME B~PROD_ID </li></ul><ul><li>INTO (ZCUSTOMERS-NAME,ZSALES-PROD_ID) </li></ul><ul><li>FROM ZCUSTOMERS AS A LEFT OUTER JOIN ZSALES AS B </li></ul><ul><li>ON A~ID = B~CUST_ID. </li></ul><ul><li>WRITE: / ZCUSTOMERS-NAME,ZSALES-PROD_ID. </li></ul><ul><li>ENDSELECT. </li></ul>Single Result Table B~PROD_ID A~NAME X1 David Micheal Peter A2 John A1 John
  • 59. Exercise <ul><li>List customers name who do not buy any product from company </li></ul>
  • 60. Sub Query <ul><li>REPORT ZSUBQUERY . </li></ul><ul><li>tables: zcustomers. </li></ul><ul><li>select * from zcustomers as a </li></ul><ul><li>where not exists </li></ul><ul><li>( select * </li></ul><ul><li>from zsales as b </li></ul><ul><li>where b~cust_id = a~id ). </li></ul><ul><li>write: / zcustomers-name. </li></ul><ul><li>endselect. </li></ul>ลูกค้าชื่ออะไรที่ไม่ได้ซื้อสินค้าจากเรา มีใครบ้าง
  • 61. Internal Table
  • 62. Data Objects in ABAP <ul><li>Memory Space </li></ul>Structure Table Structure Internal Table Variable Constants &lt;Field-symbols&gt;
  • 63. INTERNAL TABLE <ul><li>Flight (Structure) </li></ul>Carrid Connid Date Price Internal Table Flight (Internal Table) Carrid Connid Date Price Header Line
  • 64. Structure <ul><li>Data: Begin of flight, </li></ul><ul><li>carrid like sflight-carrid, </li></ul><ul><li>connid like sflight-connid, </li></ul><ul><li>date like sflight-fldate, </li></ul><ul><li>price like sflight-price. </li></ul><ul><li>Data: End of flight. </li></ul><ul><li>flight-carrid = ‘LH’. </li></ul><ul><li>Write: / flight-carrid. </li></ul>
  • 65. INTERNAL TABLE <ul><li>Data: begin of tab occurs 10, </li></ul><ul><li>carrid like sflight-carrid, </li></ul><ul><li>connid like sflight-connid, </li></ul><ul><li>fldate like sflight-fldate, </li></ul><ul><li>price like sflight-price. </li></ul><ul><li>Data end of tab. </li></ul>
  • 66. USING ABAP DICTIONARY STRUCTURE <ul><li>Data: begin of tab occurs 0 . </li></ul><ul><li>Include structure sflight. </li></ul><ul><li>Data end of tab. </li></ul>
  • 67. INTERNAL TABLE USING LIKE <ul><li>Data tab LIKE sflight OCCURS 0 WITH HEADER LINE . </li></ul>
  • 68. FILLING INTERNAL TABLE (APPEND) <ul><li>Tables sflight. </li></ul><ul><li>Data flight like sflight occurs 0 with header line. </li></ul><ul><li>Select * from sflight. </li></ul><ul><li>Move sflight to flight. </li></ul><ul><li>Append flight. </li></ul><ul><li>Endselect. </li></ul>
  • 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 <ul><li>Data tab like sflight occurs 0 with header line. </li></ul><ul><li>Select * from sflight into table tab . </li></ul><ul><li>If sy-subrc = 0. </li></ul><ul><li>Loop at tab. </li></ul><ul><li>Write: / tab-carrid, tab-price. </li></ul><ul><li>Endloop. </li></ul><ul><li>Else. </li></ul><ul><li>Write: / ‘No Data’. </li></ul><ul><li>Endif. </li></ul>
  • 71. Access Database Without Internal Table
  • 72. Access Database Using Internal Table
  • 73. Reading Data From Internal Table <ul><li>Data : begin of tab occurs 0 , </li></ul><ul><li>id like customers-id, </li></ul><ul><li>name like customers-name, </li></ul><ul><li>end of tab. </li></ul><ul><li>Select id name from customers into table tab . </li></ul><ul><li>If sy-subrc = 0. </li></ul><ul><li>Loop at tab. </li></ul><ul><li>Write: / tab-id, tab -name . </li></ul><ul><li>Endloop. </li></ul><ul><li>else . </li></ul><ul><li>Write : / ‘No Data’. </li></ul><ul><li>Endif. </li></ul>
  • 74. Exercise I : Change Using Internal Table
  • 75. SORTING INTERNAL TABLE (SORT) <ul><li>Sort flight. </li></ul><ul><li>Sort flight by price fldate. </li></ul><ul><li>Sort flight by price ascending </li></ul><ul><li>fldate descending. </li></ul>
  • 76. <ul><li>Data tab like spfli occurs 0 with header line. </li></ul><ul><li>Select * from spfli into table tab. </li></ul><ul><li>Sort tab by cityfrom. </li></ul><ul><li>… </li></ul><ul><li>Loop at tab. </li></ul><ul><li>write: / tab-carrid, tab-connid,tab-cityfrom. </li></ul><ul><li>Endloop. </li></ul>SORTING INTERNAL TABLE
  • 77. PROCESSING INTERNAL TABLE <ul><ul><li>... </li></ul></ul><ul><li>Loop at flight. </li></ul><ul><li>Write: / flight-carrid, flight-connid. </li></ul><ul><li>Endloop. </li></ul><ul><li>Loop at flight where carrid = ‘LH’. </li></ul><ul><li>Write: / flight-carrid , flight-connid. </li></ul><ul><li>Endloop. </li></ul><ul><li>Loop at flight from 1 to 10. </li></ul><ul><li>Write: / sy-tabix , flight-carrid , flight-connid. </li></ul><ul><li>Endloop. </li></ul>
  • 78. Internal Table Template Condition <ul><li>... </li></ul><ul><li>loop at tab where name cp ‘+r*’. </li></ul><ul><li>... </li></ul>
  • 79. Reading Single Record <ul><li>... </li></ul><ul><li>Sort flight by carrid connid fldate . </li></ul><ul><li>Read table flight </li></ul><ul><li>with key c arrid = ‘LH’ </li></ul><ul><li>c onnid = ‘0400’ </li></ul><ul><li>fldate = ‘19990201’ </li></ul><ul><li>Binary Search. </li></ul><ul><li>if sy-subrc = 0 . </li></ul><ul><li>write : / flight-carrid,flight-connid, </li></ul><ul><li>flight-fldate, flight-price. </li></ul><ul><li>endif. </li></ul>
  • 80. Reading Single Record using Index <ul><ul><li>... </li></ul></ul><ul><li>Read table flight index 3. </li></ul><ul><li>If sy-subrc = 0. </li></ul><ul><li>write: / flight-carrid , flight-connid . </li></ul><ul><li>Endif. </li></ul>
  • 81. CHANGING INTERNAL TABLE <ul><ul><li>... </li></ul></ul><ul><li>Delete flight index 5. </li></ul><ul><li>Delete flight where carrid = ‘LH’. </li></ul><ul><li>flight-carrid = ‘XX’. </li></ul><ul><li>flight-price = 100. </li></ul><ul><li>… </li></ul><ul><li>Insert flight index 1. </li></ul>
  • 82. DELETING INTERNAL TABLE <ul><li>Clear flight. </li></ul><ul><li>Refresh flight. </li></ul><ul><li>Free flight. </li></ul>DATA flight LIKE sflight occurs 0 with header line.
  • 83. Total Record of Internal Table <ul><li>Data: line_count type i. </li></ul><ul><li>Data tab like sflight occurs 0 with header line. </li></ul><ul><li>Select * from sflight into table tab. </li></ul><ul><li>Describe table tab lines line_count. </li></ul><ul><li>Write: / line_count. </li></ul>
  • 84. Exercise I
  • 85. Internal Table Processing <ul><li>Data tab like spfli occurs 0 with Header line. </li></ul><ul><li>… </li></ul><ul><li>Select * from spfli </li></ul><ul><li>appending table tab </li></ul><ul><li>where carrid = ‘LH’. </li></ul>
  • 86. SELECT … INNER JOIN <ul><li>REPORT ZINNERJOIN01 . </li></ul><ul><li>TABLES: ZCUSTOMERS,ZSALES. </li></ul><ul><li>SELECT A~NAME B~PROD_ID </li></ul><ul><li>INTO (ZCUSTOMERS-NAME,ZSALES-PROD_ID) </li></ul><ul><li>FROM ZSALES AS B INNER JOIN ZCUSTOMERS AS A </li></ul><ul><li>ON B~CUST_ID = A~ID. </li></ul><ul><li>WRITE: / ZCUSTOMERS-NAME,ZSALES-PROD_ID. </li></ul><ul><li>ENDSELECT. </li></ul>
  • 87. Inner Join into Internal Table <ul><li>REPORT ZJOIN01 . </li></ul><ul><li>DATA: begin of tab occurs 0, </li></ul><ul><li>name like zcustomers-name, </li></ul><ul><li>prod_id like zsales-prod_id, </li></ul><ul><li>end of tab. </li></ul><ul><li>SELECT A~NAME B~PROD_ID </li></ul><ul><li>INTO TABLE tab </li></ul><ul><li>FROM ZSALES AS B INNER JOIN ZCUSTOMERS AS A </li></ul><ul><li>ON B~CUST_ID = A~ID. </li></ul><ul><li>… </li></ul><ul><li>LOOP AT tab. </li></ul><ul><li>WRITE: / TAB-NAME,TAB-PROD_ID. </li></ul><ul><li>ENDLOOP. </li></ul>
  • 88. Internal Table Without Header Line <ul><li>DATA tab LIKE customers OCCURS 0. </li></ul><ul><li>DATA wa LIKE customers. </li></ul><ul><li>… </li></ul><ul><li>LOOP AT tab INTO wa . </li></ul><ul><li>WRITE: / wa-id, wa-name. </li></ul><ul><li>ENDLOOP. </li></ul>
  • 89. Internal Table Declaration <ul><li>DATA tab TYPE TABLE OF customers. </li></ul><ul><li>DATA wa LIKE LINE OF customers. </li></ul><ul><li>… </li></ul>
  • 90. ABAP Practice
  • 91. Database Table Processing <ul><li>INSERT </li></ul><ul><li>UPDATE </li></ul><ul><li>MODIFY </li></ul><ul><li>DELETE </li></ul>Database
  • 92. Insert (Table) <ul><li>Tables customers. </li></ul><ul><li>customers-id = ‘999’. </li></ul><ul><li>customers-name = ‘Test’. </li></ul><ul><li>Insert customers. </li></ul><ul><li>if sy-subrc &lt;&gt; 0. </li></ul><ul><li>write: / ‘Data Already Exists’. </li></ul><ul><li>endif. </li></ul>
  • 93. Update Statement <ul><li>Tables customers. </li></ul><ul><li>Select single * from customers where id = 1. </li></ul><ul><li>If sy-subrc = 0. </li></ul><ul><li>customers-name = ‘John’. </li></ul><ul><li>update customers. </li></ul><ul><li>Endif. </li></ul>Update customers set name = ‘John’ where id = 1.
  • 94. Update Statement <ul><li>Data wa like customers. </li></ul><ul><li>wa -id = ‘1’. </li></ul><ul><li>wa-nam e = ‘Test No 1’. </li></ul><ul><li>wa-city = ‘Bangkok’. </li></ul><ul><li>update customers from wa . </li></ul><ul><li>If sy-subrc &lt;&gt; 0. </li></ul><ul><li>write: / ‘Data not found’. </li></ul><ul><li>Endif. </li></ul>
  • 95. Modify Statement <ul><li>Tables customers. </li></ul><ul><li>customers-id = ‘1’. </li></ul><ul><li>customers-name = ‘Test No 1’. </li></ul><ul><li>Modify customers. </li></ul>
  • 96. Deleting Database Table Entries <ul><li>Tables customers. </li></ul><ul><li>customers-id = ‘1’. </li></ul><ul><li>Delete customers. </li></ul><ul><li>Delete customers From Table delcustomers. </li></ul><ul><li>Delete From customers Where city = ‘ Bangkok ’. </li></ul>
  • 97. Exercise II
  • 98. Exercise II usr02-ltime usr02-trdat usr02-bname 1. ห้ามใช้ SELECT * 2. ใช้ Internal Table
  • 99. Exercise III
  • 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

×