SlideShare a Scribd company logo
1 of 20
Download to read offline
• An alternative database interface language
• NOT a database management system
• High level, simple statement formats
• A language used for:
• Data Definition (DDL)
• Data Manipulation (DML)
• Completely interchangeable data methods
• SQL tables may be accessed with native language
• DDS created files can be access with SQL
• Great for selecting and manipulating groups of data
• If you want to update/delete all the records in a file matching a certain
criteria, use SQL. SQL can change or delete a group of records in a single
statement, whereas native I/O would require you to loop through a file
and issue individual update or delete statements.
• Columnar functions allow for column/field manipulation during
the record selection phase
• SQL has many columnar functions designed to tally, total, summarize,
manipulate, and calculate columns of data. Many program features such
as substringing, averaging, and math functions can be performed
during the record selection phase. Columns can even be returned that
don't exist in the file, such as counts, calculations, literals, and dates.
• Aggregate data
• if you wanted to find a list of all the different zip codes in a mailing
address file and count how many addresses were in each zip code, SQL
can easily accomplish this in a single statement. In native I/O you would
have to loop through a file and increment counter fields or use arrays
and/or multiple-occurrence data structures to aggregate like data.
• Interactive SQL
STRSQL
Quick ad-hoc queries
• Embedded SQL
Alternative to native file I/O
Allows for SQL functionality in RPG or COBOL
• STRSQL (Green Screen)
• System i Navigator
• Most Common SQL Statements
The SELECT statement is used to select data from a database. The result is
stored in a result table, called the result-set.
The UPDATE statement is used to update existing records in a table.
The DELETE statement is used to delete rows in a table.
• SELECT *
FROM EMPLOYEE
• SELECT EMPNO, LASTNAME, BIRTHDATE, SALARY
FROM EMPLOYEE
WHERE SALARY > 30000
• SELECT LASTNAME, SALARY, BONUS, COM
FROM EMPLOYEE
WHERE SALARY > 22000 AND BONUS = 400
OR BONUS = 500 AND COM < 1900
ORDER BY LASTNAME
• UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
• Be careful when updating records !!!
If you omit the WHERE, all records get
updated
• Example:
UPDATE EMPLOYEE
SET SALARY = SALARY + 1000
WHERE WORKDEPT = 'C01'
• DELETE FROM table_name
WHERE some_column=some_value
• BE CAREFUL WHEN DELETING RECORDS!
Like the UPDATE statement, if you omit the
WHERE clause, all records get deleted.
BACK IT UP!
• Example:
DELETE FROM TESTEMP
WHERE EMPNO = '000111'
• Static SQL
The simplest form of embedding SQL in RPG or COBOL
The SQL statement is hard coded in your program
• Dynamic SQL
The SQL statement is assembled at run-time
Requires more resource at run-time for preparing the statement
Makes an application very dynamic
Can become very sophisticated
• Most variables defined in RPG or COBOL can be used in a SQL
statement
• Variables are preceded by a colon, ( : ).
• Example:
To use RPG or COBOL’s variable field name
ITMNBR in SQL use it as :ITMNBR
COST OF ON HAND INVENTORY
ITEM# DESCRIPTION COST QTY OH COST OH
20001 Telephone, one line 15.00 10 150.00
20002 Telephone, two line 89.00 5 445.00
20003 Speaker Telephone 85.00 6 510.00
20004 Telephone Extension Cord 1.10 25 27.50
20005 Dry Erase Marker Packs 2.25 428 963.00
20006 Executive Chairs 325.00 10 3,250.00
20007 Secretarial Chairs 55.00 13 715.00
20008 Desk Calendar Pads 5.00 56 280.00
20009 Diskette Mailers .20 128 25.60
20010 Address Books 6.00 1,680 10,080.00
20011 Desk lamp, brass 20.00 3 60.00
20012 Blue pens 20.00 7 140.00
20013 Red pens 100.00 14 1,400.00
20014 Black pens 150.00 25 3,750.00
20015 Number 2 pencils 2.50 150 375.00
20016 Number 3 pencils 4.50 25 112.50
20017 Two Drawer File Cabinets 5.50 15 82.50
20018 Manilla folders 4.00 50 200.00
20019 Hanging file folders 3.00 150 450.00
20020 Metal desk 125.00 2 250.00
::::: :::::::::::::::::::: :::: ::::: ::::::
20045 Blue paper, 8 1/2 X 11 2.95 75 221.25
20046 Continuous 8,5 X 11 paper 20.00 24 480.00
20047 Yellow paper, 8 1/2 X 11 2.95 199 587.05
20048 3 hole white paper 3.35 35 117.25
20049 3 hole lined paper 3.85 10 38.50
20050 Heavy duty stapler 9.15 5 45.75
TOTAL COST OF INVENTORY ON HAND: 51,755.90
• Step 1 – calculate average Item cost
• Read all item records and calculate the ITMCOST average
• Put the average result in AVGCOST
• Step 2 – Select Item cost > Average cost
• Re-Read all item records again and compare the ITMCOST to
AVGCOST
• If the ITMCOST > AVGCOST calculate the amount of
ITMCOST * ITMQTYOH to ITMCOSTOH and print the record,
if NOT read next records
• Print a total of ITMCOSTOH after all records have been
read.
• select avg(itmcost) from item_pf
0001.00 010313
0002.00 FItpCost2 O E Printer OflInd(PrtOver) 150612
0003.00 Drecend s n 150614
0004.00 DITEMDS E DS EXTNAME(ITEM_PF:ITEM_FMT) 091212
0005.00 Drata s 5 2 150612
0006.00 020125
0007.00 /Free 020125
0008.00 150614
0009.00 Write Heading; 020125
0010.00 010313
0011.00 EXEC SQL select avg(itmcost) into :rata from item_pf; 150614
0012.00 150614
0013.00 EXEC SQL DECLARE C1 CURSOR FOR SELECT itmnbr, 150614
0014.00 itmdescr, itmcost, itmqtyoh, itmcost * itmqtyoh as 150614
0015.00 OnHand from item_pf where itmcost > :rata; 150614
0016.00 150614
0017.00 EXEC SQL OPEN C1; 091212
0018.00 150614
0019.00 EXEC SQL FETCH C1 INTO :itmnbr, :itmdescr, :itmcost, :itmqtyoh, 150614
0020.00 :itmcostoh; 150614
0021.00 150612
0022.00 DoW not recend; 150327
0023.00 If PrtOver; // Check for overflow 020128
0024.00 Write Heading; 020125
0025.00 PrtOver = *Off; 020125
0026.00 Endif; 020125
0027.00 010313
0028.00 Write Detail; // Print detail record format 150614
0029.00 150612
0030.00 EXEC SQL FETCH C1 INTO :itmnbr, :itmdescr, :itmcost, :itmqtyoh, 150614
0031.00 :itmcostoh; 150614
0032.00 // *** Check whether no more recors to be processed 150614
0033.00 150327
0034.00 recend = (SQLCODE <> 0); 150614
0035.00 150327
0036.00 Enddo; 150614
0037.00 150612
0038.00 EXEC SQL select sum(itmcost * itmqtyoh) into :totcostoh from item_pf 150614
0039.00 where itmcost > :rata; 150614
0040.00 150614
0041.00 EXEC SQL CLOSE C1; 091212
0042.00 Write Total; // Print total record format 030731
0043.00 *InLR = *On; 020125
0044.00 /End-free 020125
Public Training SQL Implementation & Embedded Programming in IBM i (05-09 Juni 2017)

More Related Content

What's hot

Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005rainynovember12
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query TuningAlexander Rubin
 
Get up to Speed (Quick Guide to data.table in R and Pentaho PDI)
Get up to Speed (Quick Guide to data.table in R and Pentaho PDI)Get up to Speed (Quick Guide to data.table in R and Pentaho PDI)
Get up to Speed (Quick Guide to data.table in R and Pentaho PDI)Serban Tanasa
 
Billion Goods in Few Categories: how Histograms Save a Life?
Billion Goods in Few Categories: how Histograms Save a Life?Billion Goods in Few Categories: how Histograms Save a Life?
Billion Goods in Few Categories: how Histograms Save a Life?Sveta Smirnova
 
Billion Goods in Few Categories: How Histograms Save a Life?
Billion Goods in Few Categories: How Histograms Save a Life?Billion Goods in Few Categories: How Histograms Save a Life?
Billion Goods in Few Categories: How Histograms Save a Life?Sveta Smirnova
 
New SQL features in latest MySQL releases
New SQL features in latest MySQL releasesNew SQL features in latest MySQL releases
New SQL features in latest MySQL releasesGeorgi Sotirov
 
January 2016 Meetup: Speeding up (big) data manipulation with data.table package
January 2016 Meetup: Speeding up (big) data manipulation with data.table packageJanuary 2016 Meetup: Speeding up (big) data manipulation with data.table package
January 2016 Meetup: Speeding up (big) data manipulation with data.table packageZurich_R_User_Group
 
Migration from mysql to elasticsearch
Migration from mysql to elasticsearchMigration from mysql to elasticsearch
Migration from mysql to elasticsearchRyosuke Nakamura
 
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)Sergey Petrunya
 

What's hot (13)

Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query Tuning
 
Lab
LabLab
Lab
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
 
Get up to Speed (Quick Guide to data.table in R and Pentaho PDI)
Get up to Speed (Quick Guide to data.table in R and Pentaho PDI)Get up to Speed (Quick Guide to data.table in R and Pentaho PDI)
Get up to Speed (Quick Guide to data.table in R and Pentaho PDI)
 
Ddl commands
Ddl commandsDdl commands
Ddl commands
 
Billion Goods in Few Categories: how Histograms Save a Life?
Billion Goods in Few Categories: how Histograms Save a Life?Billion Goods in Few Categories: how Histograms Save a Life?
Billion Goods in Few Categories: how Histograms Save a Life?
 
Billion Goods in Few Categories: How Histograms Save a Life?
Billion Goods in Few Categories: How Histograms Save a Life?Billion Goods in Few Categories: How Histograms Save a Life?
Billion Goods in Few Categories: How Histograms Save a Life?
 
New SQL features in latest MySQL releases
New SQL features in latest MySQL releasesNew SQL features in latest MySQL releases
New SQL features in latest MySQL releases
 
January 2016 Meetup: Speeding up (big) data manipulation with data.table package
January 2016 Meetup: Speeding up (big) data manipulation with data.table packageJanuary 2016 Meetup: Speeding up (big) data manipulation with data.table package
January 2016 Meetup: Speeding up (big) data manipulation with data.table package
 
Sql
SqlSql
Sql
 
Migration from mysql to elasticsearch
Migration from mysql to elasticsearchMigration from mysql to elasticsearch
Migration from mysql to elasticsearch
 
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
Common Table Expressions in MariaDB 10.2 (Percona Live Amsterdam 2016)
 

Similar to Public Training SQL Implementation & Embedded Programming in IBM i (05-09 Juni 2017)

Vendor session myFMbutler DoSQL 2
Vendor session myFMbutler DoSQL 2Vendor session myFMbutler DoSQL 2
Vendor session myFMbutler DoSQL 2Koen Van Hulle
 
In memory databases presentation
In memory databases presentationIn memory databases presentation
In memory databases presentationMichael Keane
 
Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...
Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...
Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...InSync2011
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.pptMARasheed3
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)Dave Stokes
 
Oracle sql tutorial
Oracle sql tutorialOracle sql tutorial
Oracle sql tutorialMohd Tousif
 
AWS December 2015 Webinar Series - Design Patterns using Amazon DynamoDB
AWS December 2015 Webinar Series - Design Patterns using Amazon DynamoDBAWS December 2015 Webinar Series - Design Patterns using Amazon DynamoDB
AWS December 2015 Webinar Series - Design Patterns using Amazon DynamoDBAmazon Web Services
 
about-SQL AND ETC.pptx
about-SQL AND ETC.pptxabout-SQL AND ETC.pptx
about-SQL AND ETC.pptxjwhuqyqtayaw
 
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-KompatibilitätMariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-KompatibilitätMariaDB plc
 

Similar to Public Training SQL Implementation & Embedded Programming in IBM i (05-09 Juni 2017) (20)

SQL NAD DB.pptx
SQL NAD DB.pptxSQL NAD DB.pptx
SQL NAD DB.pptx
 
Vendor session myFMbutler DoSQL 2
Vendor session myFMbutler DoSQL 2Vendor session myFMbutler DoSQL 2
Vendor session myFMbutler DoSQL 2
 
In memory databases presentation
In memory databases presentationIn memory databases presentation
In memory databases presentation
 
Etl2
Etl2Etl2
Etl2
 
Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...
Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...
Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.ppt
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
 
8. sql
8. sql8. sql
8. sql
 
Sql 2006
Sql 2006Sql 2006
Sql 2006
 
Erik_van_Roon.pdf
Erik_van_Roon.pdfErik_van_Roon.pdf
Erik_van_Roon.pdf
 
Oracle sql tutorial
Oracle sql tutorialOracle sql tutorial
Oracle sql tutorial
 
SQL
SQLSQL
SQL
 
SQL Notes
SQL NotesSQL Notes
SQL Notes
 
DBMS Chapter-3.ppsx
DBMS Chapter-3.ppsxDBMS Chapter-3.ppsx
DBMS Chapter-3.ppsx
 
AWS December 2015 Webinar Series - Design Patterns using Amazon DynamoDB
AWS December 2015 Webinar Series - Design Patterns using Amazon DynamoDBAWS December 2015 Webinar Series - Design Patterns using Amazon DynamoDB
AWS December 2015 Webinar Series - Design Patterns using Amazon DynamoDB
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
 
about-SQL AND ETC.pptx
about-SQL AND ETC.pptxabout-SQL AND ETC.pptx
about-SQL AND ETC.pptx
 
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-KompatibilitätMariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
 
Triggers n Cursors.ppt
Triggers n Cursors.pptTriggers n Cursors.ppt
Triggers n Cursors.ppt
 
Mssql
MssqlMssql
Mssql
 

More from Hany Paulina

PELATIHAN SYSTEM zSERIES
PELATIHAN SYSTEM zSERIESPELATIHAN SYSTEM zSERIES
PELATIHAN SYSTEM zSERIESHany Paulina
 
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (13-17...
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (13-17...Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (13-17...
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (13-17...Hany Paulina
 
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (24-28...
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (24-28...Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (24-28...
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (24-28...Hany Paulina
 
Ikuti Public Training Structure,Tailoring & Performance Analysis (03-06 Septe...
Ikuti Public Training Structure,Tailoring & Performance Analysis (03-06 Septe...Ikuti Public Training Structure,Tailoring & Performance Analysis (03-06 Septe...
Ikuti Public Training Structure,Tailoring & Performance Analysis (03-06 Septe...Hany Paulina
 
Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...
Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...
Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...Hany Paulina
 
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (17-21...
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (17-21...Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (17-21...
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (17-21...Hany Paulina
 
Ikuti Public Training AS/400 Managing Jobs,Database & Security (03-07 Septemb...
Ikuti Public Training AS/400 Managing Jobs,Database & Security (03-07 Septemb...Ikuti Public Training AS/400 Managing Jobs,Database & Security (03-07 Septemb...
Ikuti Public Training AS/400 Managing Jobs,Database & Security (03-07 Septemb...Hany Paulina
 
Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...
Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...
Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...Hany Paulina
 
Ikuti Public Training AS/400 Control Language Programming (26-29 Maret 2018)
Ikuti Public Training AS/400 Control Language Programming (26-29 Maret 2018)Ikuti Public Training AS/400 Control Language Programming (26-29 Maret 2018)
Ikuti Public Training AS/400 Control Language Programming (26-29 Maret 2018)Hany Paulina
 
Ikuti Public Training AS/400 System Administration & Control (12-16 Maret 2018)
Ikuti Public Training AS/400 System Administration & Control (12-16 Maret 2018)Ikuti Public Training AS/400 System Administration & Control (12-16 Maret 2018)
Ikuti Public Training AS/400 System Administration & Control (12-16 Maret 2018)Hany Paulina
 
Ikuti Public Training AS/400 Query for Data Processing (19-21 Februari 2018)
Ikuti Public Training AS/400 Query for Data Processing (19-21 Februari 2018)Ikuti Public Training AS/400 Query for Data Processing (19-21 Februari 2018)
Ikuti Public Training AS/400 Query for Data Processing (19-21 Februari 2018)Hany Paulina
 
Ingin Belajar System AS/400, Security, Back Up Recovery & Problem Determintat...
Ingin Belajar System AS/400, Security, Back Up Recovery & Problem Determintat...Ingin Belajar System AS/400, Security, Back Up Recovery & Problem Determintat...
Ingin Belajar System AS/400, Security, Back Up Recovery & Problem Determintat...Hany Paulina
 
Ikuti Public Training AS/400 System Administration & Control (29 Januari - 02...
Ikuti Public Training AS/400 System Administration & Control (29 Januari - 02...Ikuti Public Training AS/400 System Administration & Control (29 Januari - 02...
Ikuti Public Training AS/400 System Administration & Control (29 Januari - 02...Hany Paulina
 
Public Training AS/400 Structure, Tailoring & Performance Analysis (22-25 Jan...
Public Training AS/400 Structure, Tailoring & Performance Analysis (22-25 Jan...Public Training AS/400 Structure, Tailoring & Performance Analysis (22-25 Jan...
Public Training AS/400 Structure, Tailoring & Performance Analysis (22-25 Jan...Hany Paulina
 
Public Training AS/400 System Administration & Control (06-10 November 2017)
Public Training AS/400 System Administration & Control (06-10 November 2017)Public Training AS/400 System Administration & Control (06-10 November 2017)
Public Training AS/400 System Administration & Control (06-10 November 2017)Hany Paulina
 
Public Training AS/400 Structure,Tailoring & Performance Analysis (23-26 Okto...
Public Training AS/400 Structure,Tailoring & Performance Analysis (23-26 Okto...Public Training AS/400 Structure,Tailoring & Performance Analysis (23-26 Okto...
Public Training AS/400 Structure,Tailoring & Performance Analysis (23-26 Okto...Hany Paulina
 
Ingin Belajar AS/400 System Tuning & Performance Tips & Techniques
Ingin Belajar AS/400 System Tuning & Performance Tips & TechniquesIngin Belajar AS/400 System Tuning & Performance Tips & Techniques
Ingin Belajar AS/400 System Tuning & Performance Tips & TechniquesHany Paulina
 
Program Oktober Ceria untuk Public Training AS/400 Programming
Program Oktober Ceria untuk Public Training  AS/400 Programming Program Oktober Ceria untuk Public Training  AS/400 Programming
Program Oktober Ceria untuk Public Training AS/400 Programming Hany Paulina
 

More from Hany Paulina (20)

PELATIHAN SYSTEM zSERIES
PELATIHAN SYSTEM zSERIESPELATIHAN SYSTEM zSERIES
PELATIHAN SYSTEM zSERIES
 
Pelatihan AS/400
Pelatihan AS/400Pelatihan AS/400
Pelatihan AS/400
 
Register Now
Register NowRegister Now
Register Now
 
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (13-17...
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (13-17...Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (13-17...
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (13-17...
 
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (24-28...
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (24-28...Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (24-28...
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (24-28...
 
Ikuti Public Training Structure,Tailoring & Performance Analysis (03-06 Septe...
Ikuti Public Training Structure,Tailoring & Performance Analysis (03-06 Septe...Ikuti Public Training Structure,Tailoring & Performance Analysis (03-06 Septe...
Ikuti Public Training Structure,Tailoring & Performance Analysis (03-06 Septe...
 
Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...
Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...
Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...
 
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (17-21...
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (17-21...Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (17-21...
Ikuti Public Training AS/400 SQL Implementation & Embedded Programming (17-21...
 
Ikuti Public Training AS/400 Managing Jobs,Database & Security (03-07 Septemb...
Ikuti Public Training AS/400 Managing Jobs,Database & Security (03-07 Septemb...Ikuti Public Training AS/400 Managing Jobs,Database & Security (03-07 Septemb...
Ikuti Public Training AS/400 Managing Jobs,Database & Security (03-07 Septemb...
 
Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...
Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...
Ikuti Public Training AS/400 System Administration & Control (27-31 Augustus ...
 
Ikuti Public Training AS/400 Control Language Programming (26-29 Maret 2018)
Ikuti Public Training AS/400 Control Language Programming (26-29 Maret 2018)Ikuti Public Training AS/400 Control Language Programming (26-29 Maret 2018)
Ikuti Public Training AS/400 Control Language Programming (26-29 Maret 2018)
 
Ikuti Public Training AS/400 System Administration & Control (12-16 Maret 2018)
Ikuti Public Training AS/400 System Administration & Control (12-16 Maret 2018)Ikuti Public Training AS/400 System Administration & Control (12-16 Maret 2018)
Ikuti Public Training AS/400 System Administration & Control (12-16 Maret 2018)
 
Ikuti Public Training AS/400 Query for Data Processing (19-21 Februari 2018)
Ikuti Public Training AS/400 Query for Data Processing (19-21 Februari 2018)Ikuti Public Training AS/400 Query for Data Processing (19-21 Februari 2018)
Ikuti Public Training AS/400 Query for Data Processing (19-21 Februari 2018)
 
Ingin Belajar System AS/400, Security, Back Up Recovery & Problem Determintat...
Ingin Belajar System AS/400, Security, Back Up Recovery & Problem Determintat...Ingin Belajar System AS/400, Security, Back Up Recovery & Problem Determintat...
Ingin Belajar System AS/400, Security, Back Up Recovery & Problem Determintat...
 
Ikuti Public Training AS/400 System Administration & Control (29 Januari - 02...
Ikuti Public Training AS/400 System Administration & Control (29 Januari - 02...Ikuti Public Training AS/400 System Administration & Control (29 Januari - 02...
Ikuti Public Training AS/400 System Administration & Control (29 Januari - 02...
 
Public Training AS/400 Structure, Tailoring & Performance Analysis (22-25 Jan...
Public Training AS/400 Structure, Tailoring & Performance Analysis (22-25 Jan...Public Training AS/400 Structure, Tailoring & Performance Analysis (22-25 Jan...
Public Training AS/400 Structure, Tailoring & Performance Analysis (22-25 Jan...
 
Public Training AS/400 System Administration & Control (06-10 November 2017)
Public Training AS/400 System Administration & Control (06-10 November 2017)Public Training AS/400 System Administration & Control (06-10 November 2017)
Public Training AS/400 System Administration & Control (06-10 November 2017)
 
Public Training AS/400 Structure,Tailoring & Performance Analysis (23-26 Okto...
Public Training AS/400 Structure,Tailoring & Performance Analysis (23-26 Okto...Public Training AS/400 Structure,Tailoring & Performance Analysis (23-26 Okto...
Public Training AS/400 Structure,Tailoring & Performance Analysis (23-26 Okto...
 
Ingin Belajar AS/400 System Tuning & Performance Tips & Techniques
Ingin Belajar AS/400 System Tuning & Performance Tips & TechniquesIngin Belajar AS/400 System Tuning & Performance Tips & Techniques
Ingin Belajar AS/400 System Tuning & Performance Tips & Techniques
 
Program Oktober Ceria untuk Public Training AS/400 Programming
Program Oktober Ceria untuk Public Training  AS/400 Programming Program Oktober Ceria untuk Public Training  AS/400 Programming
Program Oktober Ceria untuk Public Training AS/400 Programming
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 

Public Training SQL Implementation & Embedded Programming in IBM i (05-09 Juni 2017)

  • 1.
  • 2. • An alternative database interface language • NOT a database management system • High level, simple statement formats • A language used for: • Data Definition (DDL) • Data Manipulation (DML) • Completely interchangeable data methods • SQL tables may be accessed with native language • DDS created files can be access with SQL
  • 3. • Great for selecting and manipulating groups of data • If you want to update/delete all the records in a file matching a certain criteria, use SQL. SQL can change or delete a group of records in a single statement, whereas native I/O would require you to loop through a file and issue individual update or delete statements. • Columnar functions allow for column/field manipulation during the record selection phase • SQL has many columnar functions designed to tally, total, summarize, manipulate, and calculate columns of data. Many program features such as substringing, averaging, and math functions can be performed during the record selection phase. Columns can even be returned that don't exist in the file, such as counts, calculations, literals, and dates. • Aggregate data • if you wanted to find a list of all the different zip codes in a mailing address file and count how many addresses were in each zip code, SQL can easily accomplish this in a single statement. In native I/O you would have to loop through a file and increment counter fields or use arrays and/or multiple-occurrence data structures to aggregate like data.
  • 4. • Interactive SQL STRSQL Quick ad-hoc queries • Embedded SQL Alternative to native file I/O Allows for SQL functionality in RPG or COBOL
  • 5. • STRSQL (Green Screen) • System i Navigator • Most Common SQL Statements The SELECT statement is used to select data from a database. The result is stored in a result table, called the result-set. The UPDATE statement is used to update existing records in a table. The DELETE statement is used to delete rows in a table.
  • 6. • SELECT * FROM EMPLOYEE • SELECT EMPNO, LASTNAME, BIRTHDATE, SALARY FROM EMPLOYEE WHERE SALARY > 30000 • SELECT LASTNAME, SALARY, BONUS, COM FROM EMPLOYEE WHERE SALARY > 22000 AND BONUS = 400 OR BONUS = 500 AND COM < 1900 ORDER BY LASTNAME
  • 7.
  • 8.
  • 9.
  • 10. • UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value • Be careful when updating records !!! If you omit the WHERE, all records get updated • Example: UPDATE EMPLOYEE SET SALARY = SALARY + 1000 WHERE WORKDEPT = 'C01'
  • 11. • DELETE FROM table_name WHERE some_column=some_value • BE CAREFUL WHEN DELETING RECORDS! Like the UPDATE statement, if you omit the WHERE clause, all records get deleted. BACK IT UP! • Example: DELETE FROM TESTEMP WHERE EMPNO = '000111'
  • 12. • Static SQL The simplest form of embedding SQL in RPG or COBOL The SQL statement is hard coded in your program • Dynamic SQL The SQL statement is assembled at run-time Requires more resource at run-time for preparing the statement Makes an application very dynamic Can become very sophisticated
  • 13. • Most variables defined in RPG or COBOL can be used in a SQL statement • Variables are preceded by a colon, ( : ). • Example: To use RPG or COBOL’s variable field name ITMNBR in SQL use it as :ITMNBR
  • 14. COST OF ON HAND INVENTORY ITEM# DESCRIPTION COST QTY OH COST OH 20001 Telephone, one line 15.00 10 150.00 20002 Telephone, two line 89.00 5 445.00 20003 Speaker Telephone 85.00 6 510.00 20004 Telephone Extension Cord 1.10 25 27.50 20005 Dry Erase Marker Packs 2.25 428 963.00 20006 Executive Chairs 325.00 10 3,250.00 20007 Secretarial Chairs 55.00 13 715.00 20008 Desk Calendar Pads 5.00 56 280.00 20009 Diskette Mailers .20 128 25.60 20010 Address Books 6.00 1,680 10,080.00 20011 Desk lamp, brass 20.00 3 60.00 20012 Blue pens 20.00 7 140.00 20013 Red pens 100.00 14 1,400.00 20014 Black pens 150.00 25 3,750.00 20015 Number 2 pencils 2.50 150 375.00 20016 Number 3 pencils 4.50 25 112.50 20017 Two Drawer File Cabinets 5.50 15 82.50 20018 Manilla folders 4.00 50 200.00 20019 Hanging file folders 3.00 150 450.00 20020 Metal desk 125.00 2 250.00 ::::: :::::::::::::::::::: :::: ::::: :::::: 20045 Blue paper, 8 1/2 X 11 2.95 75 221.25 20046 Continuous 8,5 X 11 paper 20.00 24 480.00 20047 Yellow paper, 8 1/2 X 11 2.95 199 587.05 20048 3 hole white paper 3.35 35 117.25 20049 3 hole lined paper 3.85 10 38.50 20050 Heavy duty stapler 9.15 5 45.75 TOTAL COST OF INVENTORY ON HAND: 51,755.90
  • 15. • Step 1 – calculate average Item cost • Read all item records and calculate the ITMCOST average • Put the average result in AVGCOST • Step 2 – Select Item cost > Average cost • Re-Read all item records again and compare the ITMCOST to AVGCOST • If the ITMCOST > AVGCOST calculate the amount of ITMCOST * ITMQTYOH to ITMCOSTOH and print the record, if NOT read next records • Print a total of ITMCOSTOH after all records have been read.
  • 16. • select avg(itmcost) from item_pf
  • 17.
  • 18.
  • 19. 0001.00 010313 0002.00 FItpCost2 O E Printer OflInd(PrtOver) 150612 0003.00 Drecend s n 150614 0004.00 DITEMDS E DS EXTNAME(ITEM_PF:ITEM_FMT) 091212 0005.00 Drata s 5 2 150612 0006.00 020125 0007.00 /Free 020125 0008.00 150614 0009.00 Write Heading; 020125 0010.00 010313 0011.00 EXEC SQL select avg(itmcost) into :rata from item_pf; 150614 0012.00 150614 0013.00 EXEC SQL DECLARE C1 CURSOR FOR SELECT itmnbr, 150614 0014.00 itmdescr, itmcost, itmqtyoh, itmcost * itmqtyoh as 150614 0015.00 OnHand from item_pf where itmcost > :rata; 150614 0016.00 150614 0017.00 EXEC SQL OPEN C1; 091212 0018.00 150614 0019.00 EXEC SQL FETCH C1 INTO :itmnbr, :itmdescr, :itmcost, :itmqtyoh, 150614 0020.00 :itmcostoh; 150614 0021.00 150612 0022.00 DoW not recend; 150327 0023.00 If PrtOver; // Check for overflow 020128 0024.00 Write Heading; 020125 0025.00 PrtOver = *Off; 020125 0026.00 Endif; 020125 0027.00 010313 0028.00 Write Detail; // Print detail record format 150614 0029.00 150612 0030.00 EXEC SQL FETCH C1 INTO :itmnbr, :itmdescr, :itmcost, :itmqtyoh, 150614 0031.00 :itmcostoh; 150614 0032.00 // *** Check whether no more recors to be processed 150614 0033.00 150327 0034.00 recend = (SQLCODE <> 0); 150614 0035.00 150327 0036.00 Enddo; 150614 0037.00 150612 0038.00 EXEC SQL select sum(itmcost * itmqtyoh) into :totcostoh from item_pf 150614 0039.00 where itmcost > :rata; 150614 0040.00 150614 0041.00 EXEC SQL CLOSE C1; 091212 0042.00 Write Total; // Print total record format 030731 0043.00 *InLR = *On; 020125 0044.00 /End-free 020125