ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzajp_5.4.0.1/rzajpsqlcacobol.htm

113 lines
6.5 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="Define the SQL communications area in COBOL applications that use SQL" />
<meta name="abstract" content="A COBOL program can be written to use the SQLCA to check return status for embedded SQL statements, or the program can use the SQL diagnostics area to check return status." />
<meta name="description" content="A COBOL program can be written to use the SQLCA to check return status for embedded SQL statements, or the program can use the SQL diagnostics area to check return status." />
<meta name="DC.subject" content="application program, SQLCA (SQL communication area), COBOL, SQLCA (SQL communication area), COBOL program, SQLCA, declaring, SQLCODE, declaring, SQLSTATE, declaring, SQLCODE, SQLSTATE" />
<meta name="keywords" content="application program, SQLCA (SQL communication area), COBOL, SQLCA (SQL communication area), COBOL program, SQLCA, declaring, SQLCODE, declaring, SQLSTATE, declaring, SQLCODE, SQLSTATE" />
<meta name="DC.Relation" scheme="URI" content="rzajpcob.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajpdiagnostics.htm" />
<meta name="DC.Relation" scheme="URI" content="../db2/rbafzmstsqlcca.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="rzajpsqlcacobol" />
<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>Define the SQL communications area in COBOL applications
that use SQL</title>
</head>
<body id="rzajpsqlcacobol"><a name="rzajpsqlcacobol"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Define the SQL communications area in COBOL applications
that use SQL</h1>
<div><p>A COBOL program can be written to use the SQLCA to check return
status for embedded SQL statements, or the program can use the SQL diagnostics
area to check return status.</p>
<div class="section"><p>To use the SQL diagnostics area instead of the SQLCA, use the
SET OPTION SQL statement with the option SQLCA = *NO. </p>
</div>
<div class="section"><p>When using the SQLCA, a COBOL program that contains SQL statements
must include one or both of the following: </p>
<ul><li>An SQLCODE variable declared as PICTURE S9(9) BINARY, PICTURE S9(9) COMP-4,
or PICTURE S9(9) COMP.</li>
<li>An SQLSTATE variable declared as PICTURE X(5)</li>
</ul>
</div>
<div class="section"><p>Or, </p>
<ul><li>An SQLCA (which contains an SQLCODE and SQLSTATE variable).</li>
</ul>
</div>
<div class="section"><p>The SQLCODE and SQLSTATE values are set by the database manager
after each SQL statement is run. An application can check the SQLCODE or SQLSTATE
value to determine whether the last SQL statement was successful.</p>
</div>
<div class="section"><p>The SQLCA can be coded in a COBOL program either
directly or by using the SQL INCLUDE statement. When coding it directly, make
sure it is initialized. Using the SQL INCLUDE statement requests the inclusion
of a standard declaration: </p>
<pre> EXEC SQL <strong>INCLUDE SQLCA</strong> END-EXEC.</pre>
</div>
<div class="section"><p>The SQLCODE, SQLSTATE, and SQLCA variable declarations must appear
in the WORKING-STORAGE SECTION or LINKAGE SECTION of your program and can
be placed wherever a record description entry can be specified in those sections.</p>
</div>
<div class="section"><p>When you use the INCLUDE statement, the SQL COBOL precompiler
includes COBOL source statements for the SQLCA: </p>
<pre>01 SQLCA.
05 SQLCAID PIC X(8). VALUE X"0000000000000000".
05 SQLCABC PIC S9(9) BINARY.
05 SQLCODE PIC S9(9) BINARY.
05 SQLERRM.
49 SQLERRML PIC S9(4) BINARY.
49 SQLERRMC PIC X(70).
05 SQLERRP PIC X(8).
05 SQLERRD OCCURS 6 TIMES
PIC S9(9) BINARY.
05 SQLWARN.
10 SQLWARN0 PIC X.
10 SQLWARN1 PIC X.
10 SQLWARN2 PIC X.
10 SQLWARN3 PIC X.
10 SQLWARN4 PIC X.
10 SQLWARN5 PIC X.
10 SQLWARN6 PIC X.
10 SQLWARN7 PIC X.
10 SQLWARN8 PIC X.
10 SQLWARN9 PIC X.
10 SQLWARNA PIC X.
05 SQLSTATE PIC X(5).</pre>
</div>
<div class="section"><p>For ILE COBOL for <span class="keyword">iSeries™</span>,
the SQLCA is declared using the GLOBAL clause. SQLCODE is replaced with SQLCADE
when a declare for SQLCODE is found in the program and the SQLCA is provided
by the precompiler. SQLSTATE is replaced with SQLSTOTE when a declare for
SQLSTATE is found in the program and the SQLCA is provided by the precompiler.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzajpcob.htm" title="This topic describes the unique application and coding requirements for embedding SQL statements in a COBOL program. Requirements for host structures and host variables are defined.">Code SQL statements in COBOL applications</a></div>
</div>
<div class="relconcepts"><strong>Related concepts</strong><br />
<div><a href="rzajpdiagnostics.htm" title="The SQL diagnostics area is used to keep the returned information for an SQL statement that has been run in a program. It contains all the information that is available to you as an application programmer through the SQLCA.">Use the SQL diagnostics area</a></div>
</div>
<div class="relinfo"><strong>Related information</strong><br />
<div><a href="../db2/rbafzmstsqlcca.htm">SQL communication area</a></div>
</div>
</div>
</body>
</html>