ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzaik_5.4.0.1/callsp.htm

116 lines
5.0 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="Example: Call an iSeries stored procedure by using Visual Basic" />
<meta name="abstract" content="The Visual Basic programming examples listed below show a stored procedure call being prepared." />
<meta name="description" content="The Visual Basic programming examples listed below show a stored procedure call being prepared." />
<meta name="DC.Relation" scheme="URI" content="rzaikspex.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="callsp" />
<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: Call an iSeries stored procedure by using Visual Basic</title>
</head>
<body id="callsp"><a name="callsp"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Call an iSeries™ stored procedure by using Visual Basic</h1>
<div><p>The Visual Basic programming examples listed below show a stored
procedure call being prepared.</p>
<div class="section"><p>Two statements are shown:</p>
</div>
<div class="section"> <ol><li>A statement for the creation of the stored procedure</li>
<li>A statement to prepare the call</li>
</ol>
</div>
<div class="section"><p>Create the stored procedure only once. The definition that it
provides is available to ODBC applications, as well as to integrated <span class="keyword">i5/OS™</span> applications.</p>
</div>
<div class="section"><p>Because of the way Visual Basic stores and manages the String
data type, using an array of Byte data type instead of a String variable is
recommended for the following parameter types: </p>
<ul><li>Input/output parameters</li>
<li>Output parameters</li>
<li>Any parameter that contains binary data (rather then standard ANSI characters)</li>
<li>Any input parameter that has a variable address which is set once, but
referred to many times</li>
</ul>
<p>The last case would be true for the if the application made multiple
calls to <strong>SQLExecute</strong>, while modifying <strong>Parm1</strong> between each call.
The following Visual Basic functions assist in converting strings and arrays
of byte:</p>
</div>
<div class="example"> <pre>Public Sub Byte2String(InByte() As Byte, OutString As String)
'Convert array of byte to string
OutString = StrConv(InByte(), vbUnicode)
End Sub
Public Function String2Byte(InString As String, OutByte() As Byte) As Boolean
'vb byte-array / string coercion assumes Unicode string
'so must convert String to Byte one character at a time
'or by direct memory access
'This function assumes Lower Bound of array is 0
Dim I As Integer
Dim SizeOutByte As Integer
Dim SizeInString As Integer
SizeOutByte = UBound(OutByte) + 1
SizeInString = Len(InString)
'Verify sizes if desired
'Convert the string
For I = 0 To SizeInString - 1
OutByte(I) = AscB(Mid(InString, I + 1, 1))
Next I
'If size byte array &gt; len of string pad with Nulls for szString
If SizeOutByte &gt; SizeInString Then 'Pad with Nulls
For I = SizeInString To UBound(OutByte)
OutByte(I) = 0
Next I
End If
String2Byte = True
End Function
Public Sub ViewByteArray(Data() As Byte, Title As String)
'Display message box showing hex values of byte array
Dim S As String
Dim I As Integer
On Error GoTo VBANext
S = "Length: " &amp; Str(UBound(Data) - LBound(Data) + 1) &amp; " Data (in hex):"
For I = LBound(Data) To UBound(Data)
If (I Mod 8) = 0 Then
S = S &amp; " " 'add extra space every 8th byte
End If
S = S &amp; Hex(Data(I)) &amp; " "
VBANext:
Next I
MsgBox S, , Title
End Sub</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzaikspex.htm" title="View examples of stored procedures.">Examples: Stored procedures</a></div>
</div>
</div>
</body>
</html>