195 lines
6.8 KiB
HTML
195 lines
6.8 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="reference" />
|
||
|
<meta name="DC.Title" content="Examples: RPG - Host code for ODBC stored procedures" />
|
||
|
<meta name="abstract" content="In this example, the program, SPROC2, is called from the client as a stored procedure via ODBC. It returns data to the client from the PARTS database file." />
|
||
|
<meta name="description" content="In this example, the program, SPROC2, is called from the client as a stored procedure via ODBC. It returns data to the client from the PARTS database file." />
|
||
|
<meta name="DC.Relation" scheme="URI" content="rzaikodbcprogexamples.htm" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 1999, 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1999, 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="odbcrpghostex" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>Examples: RPG - Host code for ODBC stored procedures</title>
|
||
|
</head>
|
||
|
<body id="odbcrpghostex"><a name="odbcrpghostex"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Examples: RPG - Host code for ODBC stored procedures</h1>
|
||
|
<div><p>In this example, the program, <strong>SPROC2</strong>, is called from the
|
||
|
client as a stored procedure via ODBC. It returns data to the client from
|
||
|
the PARTS database file.</p>
|
||
|
<div class="section"><h4 class="sectiontitle">RPG/400<sup>®</sup> (non-ILE)
|
||
|
example:</h4><pre> * THIS EXAMPLE IS WRITTEN IN RPG/400 (NON-ILE)
|
||
|
*
|
||
|
* DEFINES PART AS AN INTEGER (BINARY 4.0)
|
||
|
*
|
||
|
I#OPTDS DS
|
||
|
I B 1 40#OPT
|
||
|
I#PRTDS DS
|
||
|
I B 1 40#PART
|
||
|
C *ENTRY PLIST
|
||
|
C PARM #OPTDS
|
||
|
C PARM #PRTDS
|
||
|
* COPY PART NUMBER TO RPG NATIVE VARIABLE WITH SAME
|
||
|
* ATTRIBUTES OF FIELD IN PARTS MASTER FILE (PACKED DECIMAL 5,0)
|
||
|
C Z-ADD#PART PART 50
|
||
|
C #OPT CASEQ1 ONEREC
|
||
|
C #OPT CASEQ2 ALLREC
|
||
|
C ENDCS
|
||
|
C SETON LR
|
||
|
C RETRN
|
||
|
*
|
||
|
****************************
|
||
|
C ONEREC BEGSR
|
||
|
****************************
|
||
|
* PROCESS REQUEST FOR A SINGLE RECORD.
|
||
|
C/EXEC SQL DECLARE C1 CURSOR FOR
|
||
|
C+ SELECT
|
||
|
C+ PARTNO,
|
||
|
C+ PARTDS,
|
||
|
C+ PARTQY,
|
||
|
C+ PARTPR,
|
||
|
C+ PARTDT
|
||
|
C+
|
||
|
C+ FROM PARTS -- FROM PART MASTER FILE
|
||
|
C+
|
||
|
C+ WHERE PARTNO = :PART
|
||
|
C+
|
||
|
C+
|
||
|
C+ FOR FETCH ONLY -- READ ONLY CURSOR
|
||
|
C/END-EXEC
|
||
|
C*
|
||
|
C/EXEC SQL
|
||
|
C+ OPEN C1
|
||
|
C/END-EXEC
|
||
|
C*
|
||
|
C/EXEC SQL
|
||
|
C+ SET RESULT SETS CURSOR C1
|
||
|
C/END-EXEC
|
||
|
C ENDSR
|
||
|
****************************
|
||
|
C ALLREC BEGSR
|
||
|
****************************
|
||
|
* PROCESS REQUEST TO RETURN ALL RECORDS
|
||
|
C/EXEC SQL DECLARE C2 CURSOR FOR
|
||
|
C+ SELECT
|
||
|
C+ PARTNO,
|
||
|
C+ PARTDS,
|
||
|
C+ PARTQY,
|
||
|
C+ PARTPR,
|
||
|
C+ PARTDT
|
||
|
C+
|
||
|
C+ FROM PARTS -- FROM PART MASTER FILE
|
||
|
C+
|
||
|
C+
|
||
|
C+ ORDER BY PARTNO -- SORT BY PARTNO
|
||
|
C+
|
||
|
C+ FOR FETCH ONLY -- READ ONLY CURSOR
|
||
|
C/END-EXEC
|
||
|
C*
|
||
|
C/EXEC SQL
|
||
|
C+ OPEN C2
|
||
|
C/END-EXEC
|
||
|
C*
|
||
|
C/EXEC SQL
|
||
|
C+ SET RESULT SETS CURSOR C2
|
||
|
C/END-EXEC
|
||
|
C ENDSR</pre>
|
||
|
</div>
|
||
|
<div class="section"><h4 class="sectiontitle">ILE-RPG example:</h4><pre> * This example is written in ILE-RPG
|
||
|
*
|
||
|
* Define option and part as integer
|
||
|
D#opt s 10i 0
|
||
|
D#part s 10i 0
|
||
|
* Define part as packed 5/0
|
||
|
Dpart s 5p 0
|
||
|
|
||
|
C *entry plist
|
||
|
C parm #opt
|
||
|
C part parm #part
|
||
|
|
||
|
C #opt caseq 1 onerec
|
||
|
C #opt caseq 2 allrec
|
||
|
C endcs
|
||
|
|
||
|
C eval *inlr = *on
|
||
|
C return
|
||
|
*
|
||
|
****************************
|
||
|
C onerec begsr
|
||
|
****************************
|
||
|
* Process request for a single record.
|
||
|
C/EXEC SQL DECLARE C1 CURSOR FOR
|
||
|
C+ SELECT
|
||
|
C+ PARTNO,
|
||
|
C+ PARTDS,
|
||
|
C+ PARTQY,
|
||
|
C+ PARTPR,
|
||
|
C+ PARTDT
|
||
|
C+
|
||
|
C+ FROM PARTS -- FROM PART MASTER FILE
|
||
|
C+
|
||
|
C+ WHERE PARTNO = :PART
|
||
|
C+
|
||
|
C+
|
||
|
C+ FOR FETCH ONLY -- READ ONLY CURSOR
|
||
|
C/END-EXEC
|
||
|
C*
|
||
|
C/EXEC SQL
|
||
|
C+ OPEN C1
|
||
|
C/END-EXEC
|
||
|
C*
|
||
|
C/EXEC SQL
|
||
|
C+ SET RESULT SETS CURSOR C1
|
||
|
C/END-EXEC
|
||
|
C endsr
|
||
|
****************************
|
||
|
C allrec begsr
|
||
|
****************************
|
||
|
* Process request to return all records
|
||
|
C/EXEC SQL DECLARE C2 CURSOR FOR
|
||
|
C+ SELECT
|
||
|
C+ PARTNO,
|
||
|
C+ PARTDS,
|
||
|
C+ PARTQY,
|
||
|
C+ PARTPR,
|
||
|
C+ PARTDT
|
||
|
C+
|
||
|
C+ FROM PARTS -- FROM PART MASTER FILE
|
||
|
C+
|
||
|
C+
|
||
|
C+ ORDER BY PARTNO -- SORT BY PARTNO
|
||
|
C+
|
||
|
C+ FOR FETCH ONLY -- READ ONLY CURSOR
|
||
|
C/END-EXEC
|
||
|
C*
|
||
|
C/EXEC SQL
|
||
|
C+ OPEN C2
|
||
|
C/END-EXEC
|
||
|
C*
|
||
|
C/EXEC SQL
|
||
|
C+ SET RESULT SETS CURSOR C2
|
||
|
C/END-EXEC
|
||
|
C endsr</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzaikodbcprogexamples.htm" title="The following ODBC programming examples demonstrate simple queries, and accessing and returning data by calling stored procedures. C/C++, Visual Basic and RPG programming language versions are provided.">ODBC program examples</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|