ibm-information-center/dist/eclipse/plugins/i5OS.ic.sqlp_5.4.0.1/rbafyce.htm

269 lines
11 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?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="Example 1: ILE C and PL/I procedures called from ILE C applications" />
<meta name="DC.subject" content="examples, stored procedures, returning completion status ILE C and PL/I, stored procedure, returning completion status, ILE C and PL/I" />
<meta name="keywords" content="examples, stored procedures, returning completion status ILE C and PL/I, stored procedure, returning completion status, ILE C and PL/I" />
<meta name="DC.Relation" scheme="URI" content="rbafyexamplecall.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rbafyce" />
<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>Example 1: ILE C and PL/I procedures called from ILE C applications</title>
</head>
<body id="rbafyce"><a name="rbafyce"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example 1: ILE C and PL/I procedures called from ILE C applications</h1>
<div><div class="section"> <div class="note"><span class="notetitle">Note:</span> By using the code examples, you agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
</div>
<div class="example"> <p><strong>Sample of CREATE PROCEDURE and CALL</strong></p>
<pre>/**************************************************************/
/*********** START OF SQL C Application ***********************/
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;decimal.h&gt;
main()
{
EXEC SQL INCLUDE SQLCA;
char PARM1[10];
signed long int PARM2;
signed short int PARM3;
float PARM4;
double PARM5;
decimal(10,5) PARM6;
struct { signed short int parm7l;
char parm7c[10];
} PARM7;
char PARM8[10]; /* FOR DATE */
char PARM9[8]; /* FOR TIME */
char PARM10[26]; /* FOR TIMESTAMP */
</pre>
<pre>/*******************************************************/
/* Initialize variables for the call to the procedures */
/*******************************************************/
strcpy(PARM1,"PARM1");
PARM2 = 7000;
PARM3 = -1;
PARM4 = 1.2;
PARM5 = 1.0;
PARM6 = 10.555;
PARM7.parm7l = 5;
strcpy(PARM7.parm7c,"PARM7");
strncpy(PARM8,"1994-12-31",10); /* FOR DATE */
strncpy(PARM9,"12.00.00",8); /* FOR TIME */
strncpy(PARM10,"1994-12-31-12.00.00.000000",26);
/* FOR TIMESTAMP */
/***********************************************/
/* Call the C procedure */
/* */
/* */
/***********************************************/
EXEC SQL CALL P1 (:PARM1, :PARM2, :PARM3,
:PARM4, :PARM5, :PARM6,
:PARM7, :PARM8, :PARM9,
:PARM10 );
if (strncmp(SQLSTATE,"00000",5))
{
/* Handle error or warning returned on CALL statement */
}
/* Process return values from the CALL. */
:
/***********************************************/
/* Call the PLI procedure */
/* */
/* */
/***********************************************/
/* Reset the host variables before making the CALL */
/* */
:
EXEC SQL CALL P2 (:PARM1, :PARM2, :PARM3,
:PARM4, :PARM5, :PARM6,
:PARM7, :PARM8, :PARM9,
:PARM10 );
if (strncmp(SQLSTATE,"00000",5))
{
/* Handle error or warning returned on CALL statement */
}
/* Process return values from the CALL. */
:
}
/******** END OF C APPLICATION **********************************/
/****************************************************************/</pre>
</div>
<div class="example"> <p><strong>Sample procedure P1</strong></p>
<pre>/******** START OF C PROCEDURE P1 *******************************/
/* PROGRAM TEST12/CALLPROC2 */
/****************************************************************/
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;decimal.h&gt;
main(argc,argv)
int argc;
char *argv[];
{
char parm1[11];
long int parm2;
short int parm3,i,j,*ind,ind1,ind2,ind3,ind4,ind5,ind6,ind7,
ind8,ind9,ind10;
float parm4;
double parm5;
decimal(10,5) parm6;
char parm7[11];
char parm8[10];
char parm9[8];
char parm10[26];
/* *********************************************************/
/* Receive the parameters into the local variables - */
/* Character, date, time, and timestamp are passed as */
/* NUL terminated strings - cast the argument vector to */
/* the proper data type for each variable. Note that */
/* the argument vector can be used directly instead of */
/* copying the parameters into local variables - the copy */
/* is done here just to illustrate the method. */
/* *********************************************************/
/* Copy 10 byte character string into local variable */
strcpy(parm1,argv[1]);
/* Copy 4 byte integer into local variable */
parm2 = *(int *) argv[2];
/* Copy 2 byte integer into local variable */
parm3 = *(short int *) argv[3];
/* Copy floating point number into local variable */
parm4 = *(float *) argv[4];
/* Copy double precision number into local variable */
parm5 = *(double *) argv[5];
/* Copy decimal number into local variable */
parm6 = *(decimal(10,5) *) argv[6];</pre>
<pre>/**********************************************************/
/* Copy NUL terminated string into local variable. */
/* Note that the parameter in the CREATE PROCEDURE was */
/* declared as varying length character. For C, varying */
/* length are passed as NUL terminated strings unless */
/* FOR BIT DATA is specified in the CREATE PROCEDURE */
/**********************************************************/
strcpy(parm7,argv[7]);
/**********************************************************/
/* Copy date into local variable. */
/* Note that date and time variables are always passed in */
/* ISO format so that the lengths of the strings are */
/* known. strcpy works here just as well. */
/**********************************************************/
strncpy(parm8,argv[8],10);
/* Copy time into local variable */
strncpy(parm9,argv[9],8);
/**********************************************************/
/* Copy timestamp into local variable. */
/* IBM SQL timestamp format is always passed so the length*/
/* of the string is known. */
/**********************************************************/
strncpy(parm10,argv[10],26);
/**********************************************************/
/* The indicator array is passed as an array of short */
/* integers. There is one entry for each parameter passed */
/* on the CREATE PROCEDURE (10 for this example). */
/* Below is one way to set each indicator into separate */
/* variables. */
/**********************************************************/
ind = (short int *) argv[11];
ind1 = *(ind++);
ind2 = *(ind++);
ind3 = *(ind++);
ind4 = *(ind++);
ind5 = *(ind++);
ind6 = *(ind++);
ind7 = *(ind++);
ind8 = *(ind++);
ind9 = *(ind++);
ind10 = *(ind++);
:
/* Perform any additional processing here */
:
return;
}
/******** END OF C PROCEDURE P1 *******************************/</pre>
</div>
<div class="example"> <p><strong>Sample procedure P2</strong></p>
<pre>/******** START OF PL/I PROCEDURE P2 **************************/
/******** PROGRAM TEST12/CALLPROC *****************************/
/**************************************************************/
CALLPROC :PROC( PARM1,PARM2,PARM3,PARM4,PARM5,PARM6,PARM7,
PARM8,PARM9,PARM10,PARM11);
DCL SYSPRINT FILE STREAM OUTPUT EXTERNAL;
OPEN FILE(SYSPRINT);
DCL PARM1 CHAR(10);
DCL PARM2 FIXED BIN(31);
DCL PARM3 FIXED BIN(15);
DCL PARM4 BIN FLOAT(22);
DCL PARM5 BIN FLOAT(53);
DCL PARM6 FIXED DEC(10,5);
DCL PARM7 CHARACTER(10) VARYING;
DCL PARM8 CHAR(10); /* FOR DATE */
DCL PARM9 CHAR(8); /* FOR TIME */
DCL PARM10 CHAR(26); /* FOR TIMESTAMP */
DCL PARM11(10) FIXED BIN(15); /* Indicators */
/* PERFORM LOGIC - Variables can be set to other values for */
/* return to the calling program. */
:
END CALLPROC;
</pre>
</div>
<div class="section"><p>The next example shows a REXX procedure called from an ILE C program.</p>
</div>
<div class="section"><p>Assume a procedure is defined as follows:</p>
</div>
<div class="example"> <pre> EXEC SQL <strong>CREATE PROCEDURE</strong> REXXPROC
(IN PARM1 <strong>CHARACTER(</strong>20<strong>),</strong>
IN PARM2 <strong>INTEGER,</strong>
IN PARM3 <strong>DECIMAL(</strong>10,5<strong>),</strong>
IN PARM4 <strong>DOUBLE PRECISION,</strong>
IN PARM5 <strong>VARCHAR(</strong>10<strong>),</strong>
IN PARM6 <strong>GRAPHIC(</strong>4<strong>),</strong>
IN PARM7 <strong>VARGRAPHIC(</strong>10<strong>),</strong>
IN PARM8 <strong>DATE,</strong>
IN PARM9 <strong>TIME,</strong>
IN PARM10 <strong>TIMESTAMP)</strong>
<strong>EXTERNAL NAME</strong> 'TEST.CALLSRC(CALLREXX)'
<strong>LANGUAGE REXX GENERAL WITH NULLS</strong></pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafyexamplecall.htm" title="These examples show how the arguments of the CALL statement are passed to the procedure for several languages. They also show how to receive the arguments into local variables in the procedure.">Examples of CALL statements</a></div>
</div>
</div>
</body>
</html>