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

159 lines
8.5 KiB
HTML
Raw Permalink 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="Indicator variables and stored procedures" />
<meta name="abstract" content="Indicator variables can be used with the CALL statement, provided host variables are used for the parameters, to pass additional information to and from the procedure." />
<meta name="description" content="Indicator variables can be used with the CALL statement, provided host variables are used for the parameters, to pass additional information to and from the procedure." />
<meta name="DC.subject" content="stored procedures, parameter passing, indicator variables, stored procedures, indicator variables" />
<meta name="keywords" content="stored procedures, parameter passing, indicator variables, stored procedures, indicator variables" />
<meta name="DC.Relation" scheme="URI" content="rbafysproeg.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="rbafyindicator" />
<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>Indicator variables and stored procedures</title>
</head>
<body id="rbafyindicator"><a name="rbafyindicator"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Indicator variables and stored procedures</h1>
<div><p>Indicator variables can be used with the CALL statement, provided
host variables are used for the parameters, to pass additional information
to and from the procedure. </p>
<div class="section"><p>Indicator variables are the SQL standard means of denoting that
the associated host variable should be interpreted as containing the null
value, and this is their primary use.</p>
</div>
<div class="section"><p>To indicate that an associated host variable contains the null
value, the indicator variable, which is a two-byte integer, is set to a negative
value. A CALL statement with indicator variables is processed as follows:
</p>
<ul><li>If the indicator variable is negative, this denotes the null value. A
default value is passed for the associated host variable on the CALL and the
indicator variable is passed unchanged.</li>
<li>If the indicator variable is not negative, this denotes that the host
variable contains a non-null value. In this case, the host variable and the
indicator variable are passed unchanged.</li>
</ul>
</div>
<div class="section"><p>These rules of processing are the same for input parameters to
the procedure as well as output parameters returned from the procedure. When
indicator variables are used with stored procedures, the correct method of
coding their handling is to check the value of the indicator variable first
before using the associated host variable.</p>
</div>
<div class="section"><p>The following example illustrates the handling of indicator variables
in CALL statements. Notice that the logic checks the value of the indicator
variable before using the associated variable. Also note the method that the
indicator variables are passed into procedure PROC1 (as a third argument consisting
of an array of two-byte values).</p>
</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>
<p>Assume a procedure was defined
as follows:</p>
</div>
<div class="example"> <pre> <strong>CREATE PROCEDURE</strong> PROC1
(<strong>INOUT</strong> DECIMALOUT <strong>DECIMAL</strong>(7,2), <strong>INOUT</strong> DECOUT2 <strong>DECIMAL</strong>(7,2))
<strong>EXTERNAL NAME</strong> LIB1.PROC1 <strong>LANGUAGE RPGLE</strong>
<strong>GENERAL WITH NULLS</strong>)
</pre>
</div>
<div class="example"> <p><strong>Handling of indicator variables in CALL statements</strong></p>
<pre>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Program CRPG
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
D INOUT1 S 7P 2
D INOUT1IND S 4B 0
D INOUT2 S 7P 2
D INOUT2IND S 4B 0
C EVAL INOUT1 = 1
C EVAL INOUT1IND = 0
C EVAL INOUT2 = 1
C EVAL INOUT2IND = -2
C/EXEC SQL CALL PROC1 (:INOUT1 :INOUT1IND , :INOUT2
C+ :INOUT2IND)
C/END-EXEC
C EVAL INOUT1 = 1
C EVAL INOUT1IND = 0
C EVAL INOUT2 = 1
C EVAL INOUT2IND = -2
C/EXEC SQL CALL PROC1 (:INOUT1 :INOUT1IND , :INOUT2
C+ :INOUT2IND)
C/END-EXEC
C INOUT1IND IFLT 0
C* :
C* HANDLE NULL INDICATOR
C* :
C ELSE
C* :
C* INOUT1 CONTAINS VALID DATA
C* :
C ENDIF
C* :
C* HANDLE ALL OTHER PARAMETERS
C* IN A SIMILAR FASHION
C* :
C RETURN
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
End of PROGRAM CRPG
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</pre>
<pre>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Program PROC1
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
D INOUTP S 7P 2
D INOUTP2 S 7P 2
D NULLARRAY S 4B 0 DIM(2)
C *ENTRY PLIST
C PARM INOUTP
C PARM INOUTP2
C PARM NULLARRAY
C NULLARRAY(1) IFLT 0
C* :
C* INOUTP DOES NOT CONTAIN MEANINGFUL DATA
C*
C ELSE
C* :
C* INOUTP CONTAINS MEANINGFUL DATA
C* :
C ENDIF
C* PROCESS ALL REMAINING VARIABLES
C*
C* BEFORE RETURNING, SET OUTPUT VALUE FOR FIRST
C* PARAMETER AND SET THE INDICATOR TO A NON-NEGATIV
C* VALUE SO THAT THE DATA IS RETURNED TO THE CALLING
C* PROGRAM
C*
C EVAL INOUTP2 = 20.5
C EVAL NULLARRAY(2) = 0
C*
C* INDICATE THAT THE SECOND PARAMETER IS TO CONTAIN
C* THE NULL VALUE UPON RETURN. THERE IS NO POINT
C* IN SETTING THE VALUE IN INOUTP SINCE IT WON'T BE
C* PASSED BACK TO THE CALLER.
C EVAL NULLARRAY(1) = -5
C RETURN
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
End of PROGRAM PROC1
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafysproeg.htm" title="A procedure (often called a stored procedure) is a program that can be called to perform operations that can include both host language statements and SQL statements. Procedures in SQL provide the same benefits as procedures in a host language.">Stored procedures</a></div>
</div>
</div>
</body>
</html>