Www.PrismaTech.net Jump-Start Embedded SQL into RPG Presented by: Robert Arce.

Slides:



Advertisements
Similar presentations
BD05/06 PL/SQL  Introduction  Structure of a block  Variables and types  Accessing the database  Control flow  Cursors  Exceptions  Procedures.
Advertisements

AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
PL/SQL. Introduction to PL/SQL PL/SQL is the procedure extension to Oracle SQL. It is used to access an Oracle database from various environments (e.g.
Embedded SQL (Cont.) Pertemuan 10 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
CSC343 – Introduction to databases – A. Vaisman1 Database Application Development.
Chapter 8 Embedded SQL.
Embedded SQL John Ortiz. Lecture 15Embedded SQL2 Why Isn’t Interactive SQL Enough?  How to do this using interactive SQL?  Print a well-formatted transcript.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
Chapter 4B: More Advanced PL/SQL Programming
1 Minggu 6, Pertemuan 11 Programmatic SQL Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
SPRING 2004CENG 3521 SQL: Constraints, Triggers, Embedded SQL Chapters: 5, 6.
A Guide to SQL, Seventh Edition. Objectives Embed SQL commands in PL/SQL programs Retrieve single rows using embedded SQL Update a table using embedded.
Chapter 5 Data Manipulation and Transaction Control Oracle 10g: SQL
SEMESTER 1, 2013/2014 DB2 APPLICATION DEVELOPMENT OVERVIEW.
DB2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/DB01/003 Version No:2.0a Session Plan SPUFI Hands On Introduction to Embedded SQL DCLGEN.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
Agenda Journalling More Embedded SQL. Journalling.
Overview of JDBC and Pro*C 1 Overview of JDBC,Pro*C and Oracle connectivity on Omega CSE 5330 – Database Systems.
1 No class Thurs. Oct. 2 E-day Exam 1 Thurs. Oct. 9 HW3 Oct. 2 to –Available Oct 2 only until 2 pm.
Dinamic SQL & Cursor. Why Dinamic SQL ? Sometimes there is a need to dynamically create a SQL statement on the fly and then run that command. This can.
Stored Procedures, Transactions, and Error-Handling
3rd Annual Plex/2E Worldwide Users Conference 5D – Advanced Search for Plex RPG Using SQL Mark Murphy STAR Base Consulting, Inc.
Overview of JDBC and Pro*C 1 CSE 5330 – Database Systems.
Converting To Anthony Tichonoff Florida Hospital MIS January 2007 With Ease Multi-Row Fetch.
Dr Gordon Russell, Napier University Unit Embedded SQL - V3.0 1 Embedded SQL Unit 5.1.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
An Introduction to SQL Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.
Stored Procedures Week 9. Test Details Stored Procedures SQL can call code written in iSeries High Level Languages –Called stored procedures SQL has.
ICS 321 Fall 2009 DBMS Application Programming Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 10/06/20091Lipyeow.
ICS 321 Fall 2010 SQL in a Server Environment (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 11/1/20101Lipyeow.
Programmatic SQL Shaista Khan CS 157B. Topic Embedded SQL statements in high-level programming languages.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
1 CS 430 Database Theory Winter 2005 Lecture 14: Additional SQL Topics.
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Chapter 4: SQL Complex Queries Complex Queries Views Views Modification of the Database Modification of the Database Joined Relations Joined Relations.
Dr Gordon Russell, Napier University Unit Embedde SQL - V2.0 1 Embedded SQL Unit 5.1.
Chapter 4 An Introduction to SQL. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.4-2 Topics in this Chapter SQL: History and Overview The.
Oracle10g Developer: PL/SQL Programming1 Objectives SQL queries within PL/SQL Host or bind variables The %TYPE attribute Include queries and control structures.
1 Pertemuan > > Matakuliah: >/ > Tahun: > Versi: >
A Guide to SQL, Eighth Edition Chapter Eight SQL Functions and Procedures.
Chapter 8 Embedded SQL.
Retrieving Data in PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Recognize the SQL statements that can.
Oracle11g: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
In this module, we will design a program to work with the PROJECT table, learning to insert a new project into the table, to delete one or more projects.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Lu Wei1 Outline Introduction Basic SQL Setting Up and Using PostgreSQL Advanced SQL Embeded SQL.
RETRIEVE A NO. OF ROWS ¦ Declare a cursor ¦ Open the cursor ¦ Fetch rows of data ¦ Stop fetching rows ¦ Close the cursor.
Be “GUI ready” developing in RPG by Robert Arce from PrismaTech. Be “GUI ready” developing in RPG-ILE Presented by: Robert Arce.
A Guide to MySQL 6. 2 Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT command.
1 Section 10 - Embedded SQL u Many computer languages allow you to embed SQL statements within the code (e.g. COBOL, PowerBuilder, C++, PL/SQL, etc.) u.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Application Development Chapter 6.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Chapter 4 An Introduction to SQL.
SQL Environment.
A Guide to SQL, Seventh Edition
CPSC-310 Database Systems
Database Application Development
Chapter 2 Handling Data in PL/SQL Blocks Oracle9i Developer:
Unit I-2.
Chapter 8 Advanced SQL.
Appendix D: Network Model
Dynamic SQL The dynamic SQL component of SQL allows programs to construct and submit SQL queries at run time. In contrast, embedded SQL statements must.
Chapter 11 Managing Databases with SQL Server 2000
Handling Data in PL/SQL Blocks
Presentation transcript:

Jump-Start Embedded SQL into RPG Presented by: Robert Arce

Jump-Start embedded SQL into RPG by Robert Arce Why SQL in RPG? Useful for ad hoc retrieval and update Easy manipulation of data SQL alone may not provide logic capabilities to perform required operations SQL has no user interface ad hoc statements can be complex sorting possibilities are enhanced by SQL

Jump-Start embedded SQL into RPG by Robert Arce SQL embedded types Static statements – structure of the statement does NOT change Static “select into” statements Dynamic Statements Cursors – to handle multiple retrieves

Jump-Start embedded SQL into RPG by Robert Arce SQL source type SQLRPG DB2/400 Query Manager RPG SQLRPGLE DB2 Query Manager RPG/400 Integrated Language Environment

Jump-Start embedded SQL into RPG by Robert Arce Create SQL ILE RPG Object CRTSQLRPGI Precompiles SQL statements creates RPGLE source file in QTEMP/QSQLTEMP1 (ToSrcFile option) Create Bound RPG program CRTBNDRPG Voila! you have a program

Jump-Start embedded SQL into RPG by Robert Arce Precompiler Directives Only one SQL statement C /exec sql --open sql code C+ update CUSMS C+ set CMREPS=233 C+ where CMREPS=5 C/ end-exec -- close sql code

Jump-Start embedded SQL into RPG by Robert Arce Host Variables RPG program variables are use within the SQL statements C /exec sql --open sql code C+ update CUSMS C+ set CMREPS= : newslsrep C+ where CMREPS= : oldslsrep C/ end-exec -- close sql code

Jump-Start embedded SQL into RPG by Robert Arce Indicator Variable ~ Null Indicator variable can optionally be coded after the host variable Two ways to declare Indicator variable: Dindnul_1 s 5i 0 Dindnul_2 s 4b 0 Assign negative (-1) as null or positive (0) as not null

Jump-Start embedded SQL into RPG by Robert Arce Indicator Variable C+ set SHIPTO=:newshipto :indship Same as: if indship = -1 SHIPTO = null else SHIPTO = newshipto endif

Jump-Start embedded SQL into RPG by Robert Arce Select Into ONLY retrieve ONE row or NADA! Into clause must list one host variable for each column in the select list Optionally and is suggested to use an indicator variable per each row Can select all fields “*” and assign them into the proper Data structure sqlstt = '21000‘  more than one row

Jump-Start embedded SQL into RPG by Robert Arce Select Into * Set host variables C customer= * C/exec sql C+ select CMCSNO, --customer number C+ CMCSNM, --customer name C+ CMDFSH --default shipto C+ into :csCMCSNO, C+ :csCMCSNM, C+ :csCMDFSH :inCMDFSH C+ from CUSMS C+ where CMCSNO=:customer C/end-exec

Jump-Start embedded SQL into RPG by Robert Arce Dynamic SQL Construct in string variables on the fly Execute immediate vs Prepare and execute Prepare takes extra time building statement but execution runs faster Parameter markers ‘?’  define in the Using clause with one host variable per marker

Jump-Start embedded SQL into RPG by Robert Arce Dynamic execute immediate * Assign SQL statement dynsqlstm='delete from CUSMS where '+ 'CMCSNM LIKE '+'''%CAR%''‘ * default when create pgm COMMIT =*CHG C/exec sql set option commit=*none C/end-exec C/exec sql C+ execute immediate :dynsqlstm C/end-exec

Jump-Start embedded SQL into RPG by Robert Arce Dynamic Prepare-execute Prepare Statement-Name from :host-variable C/exec sql --Part 1 C+ prepare dltcuscar C+ from :dynsqlstm C/end-exec * C if sqlstt = '00000' C/exec sql -- Part 2 C+ execute dltcuscar C/end-exec

Jump-Start embedded SQL into RPG by Robert Arce Dynamic Prepare-Parameter Marker dynsqlstm='delete from CUSMS where CMCSNM like ?' C/exec sql C+ prepare dltcustcar C+ from :dynsqlstm C/end-exec C if sqlstt = '00000' C eval namelike ='%CAR%‘ * C/exec sql C+ execute dltcustcar C+ using :namelike C/end-exec

Jump-Start embedded SQL into RPG by Robert Arce Cursors Cursors open more than one row Is based on Select statements Allow you to do data manipulation Sorts Sums Use Host Variable for sorts and selections Declare as read-only or updatable

Jump-Start embedded SQL into RPG by Robert Arce Cursors Declare cursor Open the cursor Fetch – like read records (rows) from cursor (optionally update or delete the most recently fetched record) Close cursor (cursor must be open)

Jump-Start embedded SQL into RPG by Robert Arce Cursor - Declare C/exec sql C+ declare custcursor cursor C+ for select CMCSNO, CMCSNM, CMDFSH C+ from CUSMS C+ where CMCSNM like :namelike C+ order by :custsort C+ for read only C/end-exec

Jump-Start embedded SQL into RPG by Robert Arce Cursor - Open Host variables are evaluated only when the cursor is open * sets values for the host variables C eval namelike = '%CAR%' C eval custsort = 'CMCSNO' C/exec sql C+ open custcursor C/end-exec

Jump-Start embedded SQL into RPG by Robert Arce Cursor - Fetch C dow morerows C/exec sql C+ Fetch Next C+ from custcursor C+ into :csCMCSNO, C+ :csCMCSNM, C+ :csCMDFSH C/end-exec

Jump-Start embedded SQL into RPG by Robert Arce Cursors - Update In the declare cursor statement replace: “for read only” by “for update of CMREPS” After the fetch do the update: C/exec sql C+ update CUSMS C+ set CMREPS=:newslsrep C+ where current of custcursor --name of the cursor C/end-exec

Jump-Start embedded SQL into RPG by Robert Arce Cursor - Dynamic C/exec sql C+ declare custcursor cursor C+ for selcustcar C/end-exec * Asssign sql to host variable: sqlstm='select CMCSNO,CMCSNM,CMDFSH '+ 'from CUSMS ' + 'where CMCSNM like ? ' + 'order by CMCSNO'

Jump-Start embedded SQL into RPG by Robert Arce Cursor - Dynamic C/exec sql C+ prepare selcustcar C+ from :dynsqlstm C/end-exec C if sqlstt ='00000' * sets parameter marker value C eval namelike='%CAR%' C/exec sql C+ open custcursor C+ using :namelike C/end-exec

Jump-Start embedded SQL into RPG by Robert Arce Fetch Position Next - Prior First - Last Before  before the first row After  after the last row Current  no change in position Relative n   negative ~ previous  positive ~ next

Jump-Start embedded SQL into RPG by Robert Arce references DB2 UDB for iSeries SQL programming c2924/index.htm?info/sqlp/rbafymst02.htm SQL/400 developer’s guide by Paul Conte and Mike Cravitz