Programación SQL Integrada en Bases de Datos
Programación SQL Integrada en Bases de Datos
7.5
Database
Embedded SQL programming
IBM
Note
Before using this information and the product it supports, read the information in “Notices” on page
199.
This edition applies to IBM i 7.5 (product number 5770-SS1) and to all subsequent releases and modifications until
otherwise indicated in new editions. This version does not run on all reduced instruction set computer (RISC) models nor
does it run on CISC models.
This document may contain references to Licensed Internal Code. Licensed Internal Code is Machine Code and is
licensed to you under the terms of the IBM License Agreement for Machine Code.
© Copyright International Business Machines Corporation 1998, 2022.
US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
IBM Corp.
Contents
iii
Using ILE C compiler external file descriptions in C and C++ applications that use SQL.................. 41
Determining equivalent SQL and C or C++ data types........................................................................ 42
Notes on C and C++ variable declaration and usage..................................................................... 45
Using indicator variables in C and C++ applications that use SQL......................................................45
Coding SQL statements in COBOL applications........................................................................................ 45
Defining the SQL communication area in COBOL applications that use SQL..................................... 46
Defining SQL descriptor areas in COBOL applications that use SQL.................................................. 47
Embedding SQL statements in COBOL applications that use SQL..................................................... 48
Comments in COBOL applications that use SQL............................................................................49
Continuation for SQL statements in COBOL applications that use SQL........................................ 49
Including code in COBOL applications that use SQL..................................................................... 49
Margins in COBOL applications that use SQL.................................................................................50
Sequence numbers in COBOL applications that use SQL..............................................................50
Names in COBOL applications that use SQL.................................................................................. 50
COBOL compile-time options in COBOL applications that use SQL..............................................50
Statement labels in COBOL applications that use SQL..................................................................50
WHENEVER statement in COBOL applications that use SQL........................................................ 50
Multiple source COBOL programs and the SQL COBOL precompiler............................................ 50
Using host variables in COBOL applications that use SQL.................................................................. 50
Declaring host variables in COBOL applications that use SQL...................................................... 51
Numeric host variables in COBOL applications that use SQL.................................................. 51
Floating-point host variables in COBOL applications that use SQL......................................... 53
Character host variables in COBOL applications that use SQL................................................ 53
Graphic host variables in COBOL applications that use SQL................................................... 54
Binary host variables in COBOL applications that use SQL......................................................56
LOB host variables in COBOL applications that use SQL..........................................................57
XML host variables in COBOL applications that use SQL......................................................... 59
Datetime host variables in COBOL applications that use SQL................................................. 61
Boolean host variables in COBOL applications that use SQL...................................................61
ROWID host variables in COBOL applications that use SQL.................................................... 61
Result set locator host variables in COBOL applications that use SQL................................... 62
Using host structures in COBOL applications that use SQL................................................................ 62
Host structure in COBOL applications that use SQL...................................................................... 63
Host structure indicator array in COBOL applications that use SQL............................................. 67
Using host structure arrays in COBOL applications that use SQL................................................. 68
Host structure array in COBOL applications that use SQL.............................................................69
Host array indicator structure in COBOL applications that use SQL............................................. 73
Using external file descriptions in COBOL applications that use SQL................................................ 73
Using external file descriptions for host structure arrays in COBOL applications that use SQL.. 74
Determining equivalent SQL and COBOL data types...........................................................................74
Notes on COBOL variable declaration and usage.......................................................................... 77
Using indicator variables in COBOL applications that use SQL...........................................................77
Coding SQL statements in PL/I applications.............................................................................................78
Defining the SQL communication area in PL/I applications that use SQL.......................................... 78
Defining SQL descriptor areas in PL/I applications that use SQL....................................................... 79
Embedding SQL statements in PL/I applications that use SQL.......................................................... 80
Example: Embedding SQL statements in PL/I applications that use SQL.................................... 80
Comments in PL/I applications that use SQL................................................................................ 80
Continuation for SQL statements in PL/I applications that use SQL.............................................80
Including code in PL/I applications that use SQL..........................................................................81
Margins in PL/I applications that use SQL..................................................................................... 81
Names in PL/I applications that use SQL.......................................................................................81
Statement labels in PL/I applications that use SQL...................................................................... 81
WHENEVER statement in PL/I applications that use SQL............................................................. 81
Using host variables in PL/I applications that use SQL.......................................................................81
Declaring host variables in PL/I applications that use SQL........................................................... 81
Numeric-host variables in PL/I applications that use SQL...................................................... 82
Character-host variables in PL/I applications that use SQL.................................................... 83
iv
Binary host variables in PL/I applications that use SQL.......................................................... 83
LOB host variables in PL/I applications that use SQL.............................................................. 84
ROWID host variables in PL/I applications that use SQL.........................................................86
Using host structures in PL/I applications that use SQL.....................................................................86
Host structures in PL/I applications that use SQL......................................................................... 87
Host structure indicator arrays in PL/I applications that use SQL................................................ 89
Using host structure arrays in PL/I applications that use SQL............................................................89
Host structure array in PL/I applications that use SQL................................................................. 90
Host structure array indicator in PL/I applications that use SQL............................................ 91
Using external file descriptions in PL/I applications that use SQL..................................................... 91
Determining equivalent SQL and PL/I data types............................................................................... 92
Using indicator variables in PL/I applications that use SQL............................................................... 94
Differences in PL/I because of structure parameter passing techniques.......................................... 94
Coding SQL statements in RPG/400 applications.....................................................................................95
Defining the SQL communication area in RPG/400 applications that use SQL..................................95
Defining SQL descriptor areas in RPG/400 applications that use SQL............................................... 96
Embedding SQL statements in RPG/400 applications that use SQL.................................................. 96
Example: Embedding SQL statements in RPG/400 applications that use SQL............................ 97
Comments in RPG/400 applications that use SQL........................................................................ 97
Continuation for SQL statements in RPG/400 applications that use SQL.....................................97
Including code in RPG/400 applications that use SQL..................................................................97
Sequence numbers in RPG/400 applications that use SQL.......................................................... 97
Names in RPG/400 applications that use SQL...............................................................................98
Statement labels in RPG/400 applications that use SQL.............................................................. 98
WHENEVER statement in RPG/400 applications that use SQL..................................................... 98
Using host variables in RPG/400 applications that use SQL...............................................................98
Declaring host variables in RPG/400 applications that use SQL...................................................98
Using host structures in RPG/400 applications that use SQL.............................................................98
Using host structure arrays in RPG/400 applications that use SQL................................................... 99
Using external file descriptions in RPG/400 applications that use SQL...........................................100
External file description considerations for host structure arrays in RPG/400 applications
that use SQL.............................................................................................................................100
Determining equivalent SQL and RPG/400 data types..................................................................... 101
Assignment rules in RPG/400 applications that use SQL........................................................... 104
Using indicator variables in RPG/400 applications that use SQL..................................................... 104
Example: Using indicator variables in RPG/400 applications that use SQL............................... 104
Differences in RPG/400 because of structure parameter passing techniques................................104
Correctly ending a called RPG/400 program that uses SQL............................................................. 105
Coding SQL statements in ILE RPG applications.................................................................................... 105
Defining the SQL communication area in ILE RPG applications that use SQL................................. 106
Defining SQL descriptor areas in ILE RPG applications that use SQL...............................................106
Embedding SQL statements in ILE RPG applications that use SQL................................................. 108
Comments in ILE RPG applications that use SQL........................................................................108
Continuation for SQL statements in ILE RPG applications that use SQL.................................... 109
Including code in ILE RPG applications that use SQL................................................................. 109
Using directives in ILE RPG applications that use SQL................................................................109
Sequence numbers in ILE RPG applications that use SQL..........................................................110
Names in ILE RPG applications that use SQL.............................................................................. 110
Statement labels in ILE RPG applications that use SQL..............................................................110
WHENEVER statement in ILE RPG applications that use SQL.................................................... 110
Using host variables in ILE RPG applications that use SQL.............................................................. 110
Declaring host variables in ILE RPG applications that use SQL.................................................. 111
Declaring binary host variables in ILE RPG applications that use SQL..................................112
Declaring LOB host variables in ILE RPG applications that use SQL..................................... 113
Declaring XML host variables in ILE RPG applications that use SQL.....................................116
Declaring ROWID variables in ILE RPG applications that use SQL........................................119
Declaring result set locator variables in ILE RPG applications that use SQL........................ 119
Using host structures in ILE RPG applications that use SQL............................................................ 120
v
Using host structure arrays in ILE RPG applications that use SQL................................................... 122
Using external file descriptions in ILE RPG applications that use SQL............................................ 123
External file description considerations for host structure arrays in ILE RPG applications
that use SQL.............................................................................................................................123
Determining equivalent SQL and ILE RPG data types.......................................................................124
Notes on ILE RPG variable declaration and usage...................................................................... 135
Using indicator variables in ILE RPG applications that use SQL.......................................................135
Example: Using indicator variables in ILE RPG applications that use SQL................................. 135
Example: SQLDA for a multiple row-area fetch in ILE RPG applications that use SQL....................135
Example: Dynamic SQL in an ILE RPG application that uses SQL.................................................... 136
Coding SQL statements in REXX applications........................................................................................ 137
Using the SQL communication area in REXX applications................................................................ 137
Using SQL descriptor areas in REXX applications............................................................................. 138
Embedding SQL statements in REXX applications............................................................................140
Comments in REXX applications that use SQL............................................................................ 142
Continuation of SQL statements in REXX applications that use SQL.......................................... 142
Including code in REXX applications that use SQL......................................................................142
Margins in REXX applications that use SQL................................................................................. 142
Names in REXX applications that use SQL...................................................................................142
Nulls in REXX applications that use SQL......................................................................................142
Statement labels in REXX applications that use SQL.................................................................. 142
Handling errors and warnings in REXX applications that use SQL..............................................142
Using host variables in REXX applications that use SQL...................................................................143
Determining data types of input host variables in REXX applications that use SQL.................. 143
The format of output host variables in REXX applications that use SQL.................................... 145
Avoiding REXX conversion in REXX applications that use SQL................................................... 145
Using indicator variables in REXX applications that use SQL........................................................... 145
Preparing and running a program with SQL statements.........................................................................145
Basic processes of the SQL precompiler........................................................................................... 146
Input to the SQL precompiler.......................................................................................................146
Source file CCSIDs in the SQL precompiler................................................................................. 147
Output from the SQL precompiler................................................................................................ 148
Listing...................................................................................................................................... 148
Temporary source file members created by the SQL precompiler........................................ 148
Sample SQL precompiler output.............................................................................................149
Non-ILE SQL precompiler commands............................................................................................... 152
Compiling a non-ILE application program that uses SQL............................................................153
ILE SQL precompiler commands....................................................................................................... 153
Compiling an ILE application program that uses SQL................................................................. 153
Setting compiler options using the precompiler commands............................................................ 155
Interpreting compile errors in applications that use SQL.................................................................155
Binding an application that uses SQL................................................................................................ 155
Program references in applications that use SQL........................................................................156
Displaying SQL precompiler options..................................................................................................156
Running a program with embedded SQL...........................................................................................157
Running a program with embedded SQL: DDM considerations.................................................. 157
Running a program with embedded SQL: Override considerations............................................ 157
Running a program with embedded SQL: SQL return codes....................................................... 157
Example programs: Using Db2 for i statements..................................................................................... 158
Example: SQL statements in ILE C and C++ programs..................................................................... 159
Example: SQL statements in COBOL and ILE COBOL programs.......................................................165
Example: SQL statements in PL/I programs..................................................................................... 173
Example: SQL statements in RPG/400 programs............................................................................. 179
Example: SQL statements in ILE RPG programs...............................................................................185
Example: SQL statements in REXX programs................................................................................... 191
Report produced by example programs that use SQL...................................................................... 195
CL command descriptions for host language precompilers................................................................... 196
Create SQL COBOL Program command............................................................................................. 196
vi
Create SQL ILE COBOL Object command..........................................................................................197
Create SQL ILE C Object command................................................................................................... 197
Create SQL ILE C++ Object command...............................................................................................197
Create SQL PL/I Program command..................................................................................................197
Create SQL RPG Program command..................................................................................................197
Create SQL ILE RPG Object command.............................................................................................. 197
Related information................................................................................................................................. 197
Notices..............................................................................................................199
Programming interface information........................................................................................................ 200
Trademarks.............................................................................................................................................. 200
Terms and conditions.............................................................................................................................. 201
vii
viii
Embedded SQL programming
This topic collection explains how to create database applications in host languages that use Db2® for i
SQL statements and functions.
Note: By using the code examples, you agree to the terms of the “Code license and disclaimer
information” on page 198.
• As a receiving area for column values (named in an INTO clause): You can use a host variable
to specify a program data area that is to contain the column values of a retrieved row. The INTO
clause names one or more host variables that you want to contain column values returned by SQL.
For example, suppose you are retrieving the EMPNO, LASTNAME, and WORKDEPT column values from
rows in the CORPDATA.EMPLOYEE table. You could define a host variable in your program to hold each
column, then name the host variables with an INTO clause. For example:
EXEC SQL
SELECT EMPNO, LASTNAME, WORKDEPT
INTO :CBLEMPNO, :CBLNAME, :CBLDEPT
FROM CORPDATA.EMPLOYEE
WHERE EMPNO = :EMPID
END-EXEC.
In this example, the host variable CBLEMPNO receives the value from EMPNO, CBLNAME receives the
value from LASTNAME, and CBLDEPT receives the value from WORKDEPT.
• As a value in a SELECT clause: When specifying a list of items in the SELECT clause, you are not
restricted to the column names of tables and views. Your program can return a set of column values
intermixed with host variable values and literal constants. For example:
EXEC SQL
SELECT COUNT(*), AVG(SALARY)
INTO :PLICNT, :PLISAL:INDNULL
FROM CORPDATA.EMPLOYEE
WHERE EDLEVEL < 18
END-EXEC.
You can then test INDNULL in your program to see if it contains a negative value. If it does, you know SQL
returned a null value (if its value is -1) or a data mapping error (if its value is -2). If the indicator value is
not negative, the value returned in PLISAL can be used.
01 SAL-REC.
10 MIN-SAL PIC S9(6)V99 USAGE COMP-3.
10 AVG-SAL PIC S9(6)V99 USAGE COMP-3.
10 MAX-SAL PIC S9(6)V99 USAGE COMP-3.
01 SALTABLE.
02 SALIND PIC S9999 USAGE COMP-4 OCCURS 3 TIMES.
01 EDUC-LEVEL PIC S9999 COMP-4.
…
MOVE 20 TO EDUC-LEVEL.
…
EXEC SQL
SELECT MIN(SALARY), AVG(SALARY), MAX(SALARY)
INTO :SAL-REC:SALIND
FROM CORPDATA.EMPLOYEE
WHERE EDLEVEL>:EDUC-LEVEL
END-EXEC.
In this example, SALIND is an array that contains three values, each of which can be tested for a negative
value. SQL selects the values for the result row and puts them into the host structure. If MIN-SAL is to
return a null value, the corresponding indicator variable, SALIND(1), is set to -1. Your program must check
the corresponding indicator variables first to determine which, if any, selected result variables contain the
null value.
EXEC SQL
UPDATE CORPDATA.EMPLOYEE
SET PHONENO = :NEWPHONE:PHONEIND
WHERE EMPNO = :EMPID
END-EXEC.
When NEWPHONE contains a non-null value, set PHONEIND to zero; otherwise, to tell SQL that
NEWPHONE contains a null value, set PHONEIND to a negative value.
EXEC SQL
UPDATE CORPDATA.EMPLOYEE
SET PHONENO = :NEWPHONE:PHONEIND,
LASTNAME = :LASTNAME:LASTNAMEIND,
WORKDEPT = :WORKDEPT:WORKDEPTIND,
EDLEVEL = :EDLEVEL:EDLEVELIND
WHERE EMPNO = :EMPID
END-EXEC.
With this one UPDATE statement, you can update any or all of the columns listed in the SET clause.
For example, if you only want to update the EDLEVEL column, set the EDLEVEL variable to the new
value and the EDLEVELIND indicator to 0. Set the other three indicators (PHONEIND, LASTNAMEIND, and
WORKDEPTIND) to -7. This causes the statement to be processed as though you had written it this way.
EXEC SQL
UPDATE CORPDATA.EMPLOYEE
SET EDLEVEL = :EDLEVEL:EDLEVELIND
WHERE EMPNO = :EMPID
END-EXEC.
You can use extended indicators for INSERT, UPDATE, and MERGE statements only if they are explicitly
enabled for your program. To specify that your program supports extended indicators, use *EXTIND on
the OPTION parameter of the precompiler command or EXTIND(*YES) on the SET OPTION statement.
EXEC SQL
OPEN EMPLOYEE_CURSOR
USING SUBSET :EMPID, :HIREDATE:HIREDATEIND, :WORKDEPT:WORKDEPTIND, :PHONE:PHONEIND
END-EXEC.
If the statement that was built dynamically for an instance of this cursor only contains parameter markers
for the employee ID and work department, the HIREDATEIND and PHONEIND indicator variables should
be set to -7. This would be run as if it were written as the following OPEN statement.
EXEC SQL
OPEN EMPLOYEE_CURSOR
USING :EMPID, :WORKDEPT:WORKDEPTIND
END-EXEC.
With the conversion to using the SQL diagnostics area, the application would first declare a stand-alone
SQLSTATE variable:
The completion status of the SQL statement is verified by checking the stand-alone SQLSTATE variable.
If upon the completion of the current SQL statement, the application chooses to retrieve diagnostics, the
application would run the SQL GET DIAGNOSTICS statement:
char hv1[256];
long int hv2;
The calling application checks for a failure and retrieves the information about the failure from the SQL
diagnostics area:
hv1 = -1;
EXEC SQL CALL check_input(:hv1);
if (strncmp(SQLSTATE, "99999", 5) == 0)
{
EXEC SQL GET DIAGNOSTICS CONDITION 1
:hv2 = RETURNED_SQLSTATE,
:hv3 = MESSAGE_TEXT;
}
else
{
}
char stmt_command[256];
long int error_count;
long int condition_number;
char auth_id[256];
char error_state[6];
char msgid[128];
char msgtext[1024];
(application code)
error:
EXEC SQL GET DIAGNOSTICS :stmt_command = COMMAND_FUNCTION,
:error_count = NUMBER;
for (condition_number=1;condition_number<=error_count;++condition_number)
{
EXEC SQL GET DIAGNOSTICS CONDITION :condition_number
:auth_id = DB2_AUTHORIZATION_ID,
:error_state = RETURNED_SQLSTATE,
:msgid = DB2_MESSAGE_ID,
:msgtext = DB2_MESSAGE_TEXT;
Related reference
GET DIAGNOSTICS
EXEC SQL
WHENEVER condition action
END-EXEC.
Defining the SQL communication area in C and C++ applications that use SQL
A C or C++ 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.
When using the SQLCA, a C or C++ program that contains SQL statements must include one or both of the
following:
• An SQLCODE variable declared as long SQLCODE
• An SQLSTATE variable declared as char SQLSTATE[6]
Using the SQL INCLUDE statement requests the inclusion of a standard declaration:
A standard declaration includes a structure definition and a data area that are named sqlca.
The SQLCODE, SQLSTATE, and SQLCA variables must appear before any executable statements. The
scope of the declaration must include the scope of all SQL statements in the program.
The included C and C++ source statements for the SQLCA are:
struct sqlca {
unsigned char sqlcaid[8];
long sqlcabc;
long sqlcode;
short sqlerrml;
unsigned char sqlerrmc[70];
unsigned char sqlerrp[8];
long sqlerrd[6];
unsigned char sqlwarn[11];
unsigned char sqlstate[5];
};
#define SQLCODE sqlca.sqlcode
#define SQLWARN0 sqlca.sqlwarn[0]
#define SQLWARN1 sqlca.sqlwarn[1]
#define SQLWARN2 sqlca.sqlwarn[2]
#define SQLWARN3 sqlca.sqlwarn[3]
#define SQLWARN4 sqlca.sqlwarn[4]
#define SQLWARN5 sqlca.sqlwarn[5]
#define SQLWARN6 sqlca.sqlwarn[6]
#define SQLWARN7 sqlca.sqlwarn[7]
#define SQLWARN8 sqlca.sqlwarn[8]
#define SQLWARN9 sqlca.sqlwarn[9]
#define SQLWARNA sqlca.sqlwarn[10]
#define SQLSTATE sqlca.sqlstate
struct sqlca sqlca = {0x0000000000000000};
When a declare for SQLCODE is found in the program and the precompiler provides the SQLCA, SQLCADE
replaces SQLCODE. When a declare for SQLSTATE is found in the program and the precompiler provides
the SQLCA, SQLSTOTE replaces SQLSTATE.
Note: Many SQL error messages contain message data that is of varying length. The lengths of these data
fields are embedded in the value of the SQLCA sqlerrmc field. Because of these lengths, printing the
value of sqlerrmc from a C or C++ program might give unpredictable results.
Related concepts
Using the SQL diagnostics area
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.
Related reference
SQL communication area
GET DIAGNOSTICS
A standard declaration includes only a structure definition with the name 'sqlda'.
C and C++ declarations that are included for the SQLDA are:
struct sqlda {
unsigned char sqldaid[8];
long sqldabc;
short sqln;
short sqld;
struct sqlvar {
short sqltype;
short sqllen;
union {
unsigned char *sqldata;
long long sqld_result_set_locator; };
union {
short *sqlind;
long sqld_row_change;
long sqld_result_set_rows; ];
struct sqlname {
short length;
unsigned char data[30];
} sqlname;
} sqlvar[1];
};
One benefit from using the INCLUDE SQLDA SQL statement is that you also get the following macro
definition:
This macro makes it easy to allocate storage for an SQLDA with a specified number of SQLVAR elements.
In the following example, the SQLDASIZE macro is used to allocate storage for an SQLDA with 20 SQLVAR
elements.
#include <stdlib.h>
EXEC SQL INCLUDE SQLDA;
Here are other macro definitions that are included with the INCLUDE SQLDA statement:
GETSQLDOUBLED(daptr)
Returns 1 if the SQLDA pointed to by daptr has been doubled, or 0 if it has not been doubled. The
SQLDA is doubled if the seventh byte in the SQLDAID field is set to '2'.
SETSQLDOUBLED(daptr, newvalue)
Sets the seventh byte of SQLDAID to a new value.
GETSQLDALONGLEN(daptr,n)
Returns the length attribute of the nth entry in the SQLDA to which daptr points. Use this only if the
SQLDA was doubled and the nth SQLVAR entry has a LOB data type.
SETSQLDALONGLEN(daptr,n,len)
Sets the SQLLONGLEN field of the SQLDA to which daptr points to len for the nth entry. Use this only if
the SQLDA was doubled and the nth SQLVAR entry has a LOB datatype.
GETSQLDALENPTR(daptr,n)
Returns a pointer to the actual length of the data for the nth entry in the SQLDA to which daptr points.
The SQLDATALEN pointer field returns a pointer to a long (4 byte) integer. If the SQLDATALEN pointer
is zero, a NULL pointer is returned. Use this only if the SQLDA has been doubled.
SETSQLDALENPTR(daptr,n,ptr)
Sets a pointer to the actual length of the data for the nth entry in the SQLDA to which daptr points. Use
this only if the SQLDA has been doubled.
When you have declared an SQLDA as a pointer, you must reference it exactly as declared when you
use it in an SQL statement, just as you would for a host variable that was declared as a pointer. To
avoid compiler errors, the type of the value that is assigned to the sqldata field of the SQLDA must be a
pointer of unsigned character. This helps avoid compiler errors. The type casting is only necessary for the
EXECUTE, OPEN, CALL, and FETCH statements where the application program is passing the address of
the host variables in the program. For example, if you declared a pointer to an SQLDA called mydaptr, you
would use it in a PREPARE statement as:
SQLDA declarations can appear wherever a structure definition is allowed. Normal C scope rules apply.
Dynamic SQL is an advanced programming technique. With dynamic SQL, your program can develop and
then run SQL statements while the program is running. A SELECT statement with a variable SELECT list
(that is a list of the data to be returned as part of the query) that runs dynamically requires an SQL
descriptor area (SQLDA). This is because you will not know in advance how many or what type of variables
to allocate in order to receive the results of the SELECT.
Related concepts
Dynamic SQL applications
Related reference
SQL descriptor area
EXEC SQL
UPDATE DEPARTMENT
SET MGRNO = :MGR_NUM
WHERE DEPTNO = :INT_DEPT ;
Do not use #pragma convert to modify the CCSID of any literals that could be used by SQL. All literals
used by SQL are assumed to be in the CCSID of the source file.
Continuation for SQL statements in C and C++ applications that use SQL
SQL statements can be contained in one or more lines.
You can split an SQL statement wherever a blank can appear. The backslash (\) can be used to continue a
string constant or delimited identifier. Identifiers that are not delimited cannot be continued.
Constants containing DBCS data may be continued across multiple lines in two ways:
• If the character at the right margin of the continued line is a shift-in and the character at the left margin
of the continuation line is a shift-out, then the shift characters located at the left and right margin are
removed.
This SQL statement has a valid graphic constant of G'<AABBCCDDEEFFGGHHIIJJKK>'. The redundant
shifts at the margin are removed.
*...+....1....+....2....+....3....+....4....+....5....+....6....+....7....*....8
EXEC SQL SELECT * FROM GRAPHTAB WHERE GRAPHCOL = G'<AABBCCDDEEFFGGHH>
<IIJJKK>';
• It is possible to place the shift characters outside of the margins. For this example, assume the margins
are 5 and 75. This SQL statement has a valid graphic constant of G'<AABBCCDDEEFFGGHHIIJJKK>'.
*...(....1....+....2....+....3....+....4....+....5....+....6....+....7....)....8
EXEC SQL SELECT * FROM GRAPHTAB WHERE GRAPHCOL = G'<AABBCCDD>
<EEFFGGHHIIJJKK>';
You cannot use C and C++ #include statements to include SQL statements or declarations of C or C++
host variables that are referred to in SQL statements.
Numeric
auto const
extern volatile
static
float
double
decimal ( precision )
, scale
_Decimal32
_Decimal64
_Decimal128
int
long long
signed long
short
sqlint32
sqlint64
variable-name ;
= expression
Notes:
1. Precision and scale must be integer constants. Precision may be in the range from 1 to 63. Scale may
be in the range from 0 to the precision.
2. If using the decimal data type, the header file decimal.h must be included.
3. If using sqlint32 or sqlint64, the header file sqlsystm.h must be included.
4. _Decimal32, _Decimal64, and _Decimal128 are only supported for C.
Single-character form
char
auto const unsigned
extern volatile signed
static
variable-name ;
[ 1 ] = expression
variable-name [ length ] ;
= expression
Notes:
1. The length must be an integer constant that is greater than 1 and not greater than 32 741.
2. If the *CNULRQD option is specified on the CRTSQLCI or CRTSQLCPPI command, the input host
variables must contain the NUL-terminator. Output host variables are padded with blanks, and the last
character is the NUL-terminator. If the output host variable is too small to contain both the data and
the NUL-terminator, the following actions are taken:
• The data is truncated
• The last character is the NUL-terminator
• SQLWARN1 is set to 'W'
3. If the *NOCNULRQD option is specified on the CRTSQLCI or CRTSQLCPPI command, the input
variables do not need to contain the NUL-terminator.
The following applies to output host variables.
• If the host variable is large enough to contain the data and the NUL-terminator, then the following
actions are taken:
– The data is returned, but the data is not padded with blanks
– The NUL-terminator immediately follows the data
• If the host variable is large enough to contain the data but not the NUL-terminator, then the following
actions are taken:
– The data is returned
– A NUL-terminator is not returned
– SQLWARN1 is set to 'N'
• If the host variable is not large enough to contain the data, the following actions are taken:
int
short var-1 ; char var-2
signed unsigned
signed
[ length ] ; }
variable-name ;
= { expression , expression }
Notes:
1. length must be an integer constant that is greater than 0 and not greater than 32 740.
2. var-1 and var-2 must be simple variable references and cannot be used individually as integer and
character host variables.
3. The struct tag can be used to define other data areas, but these cannot be used as host variables.
4. The VARCHAR structured form should be used for bit data that may contain the NULL character. The
VARCHAR structured form will not be ended using the nul-terminator.
5. _Packed must not be used in C++. Instead, specify #pragma pack(1) prior to the declaration and
#pragma pack() after the declaration.
Note: You can use #pragma pack (reset) instead of #pragma pack() because they are the same.
#pragma pack(1)
struct VARCHAR {
short len;
char s[10];
} vstring;
#pragma pack()
Example:
struct VARCHAR {
short len;
char s[10];
} vstring;
Notes:
1. VARCHAR can be in mixed case.
2. length must be an integer constant that is greater than 0 and not greater than 32 740.
3. The SQL VARCHAR form should be used for bit data that may contain the NULL character. The SQL
VARCHAR form will not be ended using the nul-terminator.
Example
The following declaration:
VARCHAR vstring[528]="mydata";
VARCHAR vstring1[111],
vstring2[222]="mydata",
vstring3[333]="more data";
wchar_t variable-name
auto const = expression
extern volatile
static
variable-name [ length ] ;
= expression
Notes:
1. length must be an integer constant that is greater than 1 and not greater than 16371.
2. If the *CNULRQD option is specified on the CRTSQLCI or CRTSQLCPPI command, then input host
variables must contain the graphic NUL-terminator (/0/0). Output host variables are padded with DBCS
blanks, and the last character is the graphic NUL-terminator. If the output host variable is too small to
contain both the data and the NUL-terminator, the following actions are taken:
• The data is truncated
• The last character is the graphic NUL-terminator
• SQLWARN1 is set to 'W'
If the *NOCNULRQD option is specified on the CRTSQLCI or CRTSQLCPPI command, the input host
variables do not need to contain the graphic NUL-terminator. The following is true for output host
variables.
• If the host variable is large enough to contain the data and the graphic NUL-terminator, the following
actions are taken:
– The data is returned, but is not padded with DBCS blanks
– The graphic NUL-terminator immediately follows the data
• If the host variable is large enough to contain the data but not the graphic NUL-terminator, the
following actions are taken:
– The data is returned
– A graphic NUL-terminator is not returned
– SQLWARN1 is set to 'N'
• If the host variable is not large enough to contain the data, the following actions are taken:
– The data is truncated
– A graphic NUL-terminator is not returned
– SQLWARN1 is set to 'W'
int
short var-1 ; wchar_t var-2 [ length ]
signed
; } variable-name ;
= { expression , expression }
Notes:
1. length must be an integer constant that is greater than 0 and not greater than 16370.
2. var-1 and var-2 must be simple variable references and cannot be used as host variables.
3. The struct tag can be used to define other data areas, but these cannot be used as host variables.
4. _Packed must not be used in C++. Instead, specify #pragma pack(1) prior to the declaration and
#pragma pack() after the declaration.
#pragma pack(1)
struct VARGRAPH {
short len;
wchar_t s[10];
} vstring;
#pragma pack()
Example
EXEC SQL BEGIN DECLARE SECTION;
struct VARGRAPH {
short len;
wchar_t s[10];
} vstring;
BINARY
SQL TYPE IS BINARY (length)
auto const
extern volatile
static
variable-name ;
= init-data
VARBINARY
SQL TYPE IS VARBINARY (length)
auto const BINARY VARYING
extern volatile
static
variable-name ;
= { init-len,"init-data" }
= SQL_VARBINARY_INIT("init-data")
Notes:
1. For BINARY host variables, the length must be in the range 1 to 32 766.
2. For VARBINARY and BINARY VARYING host variables, the length must in the range 1 to 32 740.
3. SQL TYPE IS, BINARY, VARBINARY, and BINARY VARYING can be in mixed case.
BINARY example
The following declaration:
char myBinField[4];
VARBINARY example
The following declaration:
variable-name ;
= { init-value }
BOOLEAN example
The following declaration:
char myBooleanField;
) variable-name ;
= { init-len,"init-data" }
= SQL_CLOB_INIT("init-data")
= SQL_DBCLOB_INIT("init-data")
= SQL_BLOB_INIT("init-data")
CLOB example
The following declaration:
DBCLOB example
The following declaration:
BLOB example
The following declaration:
variable-name ;
= init-value
Notes:
1. SQL TYPE IS, BLOB_LOCATOR, CLOB_LOCATOR, DBCLOB_LOCATOR can be in mixed case.
2. init-value permits the initialization of pointer locator variables. Other types of initialization will have no
meaning.
3. Pointers to LOB locators can be declared with the same rules and restrictions as for pointers to other
host variable types.
variable-name ;
= init-value
Notes:
1. SQL TYPE IS, BLOB_FILE, CLOB_FILE, DBCLOB_FILE can be in mixed case.
2. Pointers to LOB File Reference Variables can be declared, with the same rules and restrictions as for
pointers to other host variable types.
) variable-name ;
K = { init-len,"init-data" }
M = SQL_CLOB_INIT("init-data")
G = SQL_DBCLOB_INIT("init-data")
= SQL_BLOB_INIT("init-data")
Notes:
1. K multiplies length by 1024. M multiplies length by 1 048 576. G multiplies length by 1 073 741 824.
2. For BLOB and CLOB, 1 ≤ length ≤ 2 147 483 647
3. For DBCLOB, 1 ≤ length ≤ 1 073 741 823
4. SQL TYPE IS, XML AS, BLOB, CLOB, DBCLOB, K, M, G can be in mixed case.
5. The maximum length allowed for the initialization string is 32 766 bytes.
6. The initialization length, init-len, must be a numeric constant (that is, it cannot include K, M, or G).
7. If the XML variable is not initialized within the declaration, then no initialization will be done within
the precompiler generated code.
8. The precompiler generates a structure tag which can be used to cast to the host variable's type.
9. Pointers to XML host variables can be declared, with the same rules and restrictions as for pointers to
other host variable types.
XML example
The following declaration:
XML locator
SQL TYPE IS XML AS LOCATOR
auto const
extern volatile
static
variable-name ;
= init-value
Notes:
1. SQL TYPE IS, XML AS LOCATOR can be in mixed case.
2. init-value permits the initialization of pointer locator variables. Other types of initialization will have no
meaning.
3. Pointers to XML locators can be declared with the same rules and restrictions as for pointers to other
host variable types.
variable-name ;
= init-value
Notes:
1. SQL TYPE IS, XML AS, BLOB_FILE, CLOB_FILE, DBCLOB_FILE can be in mixed case.
2. Pointers to XML File Reference Variables can be declared, with the same rules and restrictions as for
pointers to other host variable types.
The precompiler generates declarations for the following file option constants. You can use these
constants to set the file_options variable when you use file reference host variables.
• SQL_FILE_READ (2)
• SQL_FILE_CREATE (8)
• SQL_FILE_OVERWRITE (16)
• SQL_FILE_APPEND (32)
ROWID
,
Result set locator host variables in C and C++ applications that use SQL
C and C++ do not have a variable that corresponds to the SQL result set locator data type. To create host
variables that can be used for this data type, use the SQL TYPE IS clause. The SQL precompiler replaces
this declaration with a C language structure in the output source member.
struct {
struct {
char c1;
char c2;
} b_st;
} a_st;
In this example, b_st is the name of a host structure consisting of the elementary items c1 and c2.
You can use the structure name as a shorthand notation for a list of scalars, but only for a two-level
structure. You can qualify a host variable with a structure name (for example, structure.field). Host
structures are limited to two levels. (For example, in the above host structure example, the a_st cannot be
referred to in SQL.) A structure cannot contain an intermediate level structure. In the previous example,
a_st could not be used as a host variable or referred to in an SQL statement. A host structure for SQL data
has two levels and can be thought of as a named set of host variables. After the host structure is defined,
Notice that in the declaration of pemp1, two varying-length string elements are included in the structure:
firstname and lastname.
Host structures
struct {
auto const _Packed tag
extern volatile
static
float var-1 ;
double
decimal ( precision )
, scale
_Decimal32
_Decimal64
_Decimal128
int
long long
signed long
short
sqlint32
sqlint64
varchar-structure
vargraphic-structure
binary
lob
boolean
xml
SQL-varchar
rowid
result-set-locator
,
char var-2 ;
signed [ length ]
unsigned
,
wchar_t var-5 ;
[ length ]
} variable-name ;
= expression
unsigned
var-7 [ length ] ; }
binary
SQL TYPE IS BINARY ( length )
VARBINARY
BINARY VARYING
lob
SQL TYPE IS CLOB ( length )
DBCLOB K
BLOB M
CLOB_LOCATOR
DBCLOB_LOCATOR
BLOB_LOCATOR
CLOB_FILE
DBCLOB_FILE
BLOB_FILE
boolean
SQL TYPE IS BOOLEAN
xml
SQL TYPE IS XML AS CLOB ( length )
DBCLOB K
BLOB M
LOCATOR
CLOB_FILE
DBCLOB_FILE
BLOB_FILE
rowid
SQL TYPE IS ROWID
result-set-locator
SQL TYPE IS RESULT_SET_LOCATOR
Notes:
1. For details on declaring numeric, character, graphic, binary, LOB, Boolean, XML, ROWID, and result set
locator host variables, see the notes under numeric, character, graphic, binary, LOB, Boolean, XML,
ROWID, and result set locator host variables.
2. A structure of a short int followed by either a char or wchar_t array is always interpreted by the SQL C
and C++ precompilers as either a VARCHAR or VARGRAPHIC structure.
3. _Packed must not be used in C++. Instead, specify #pragma pack(1) prior to the declaration and
#pragma pack() after the declaration.
#pragma pack(1)
struct {
short myshort;
long mylong;
char mychar[5];
} a_st;
#pragma pack()
Host structure indicator array in C and C++ applications that use SQL
This figure shows the valid syntax for host structure indicator array declarations.
variable-name [ dimension ] ;
= expression
Using arrays of host structures in C and C++ applications that use SQL
In C and C++ programs, you can define a host structure array that has the dimension attribute. Host
structure arrays have a maximum of two levels, even though the array might occur within a multiple-level
structure. Another structure is not needed if a varying-length character string or a varying-length graphic
string is not used.
In this C example,
struct {
_Packed struct{
char c1_var[20];
#pragma pack(1)
struct {
struct{
char c1_var[20];
short c2_var;
} b_array[10];
} a_struct;
#pragma pack()
_Packed struct {
auto const tag
extern volatile
static
float var-1 ;
double
decimal ( precision )
, scale
_Decimal32
_Decimal64
_Decimal128
int
long long
signed long
short
sqlint32
sqlint64
varchar-structure
vargraphic-structure
binary
lob
boolean
xml
SQL-varchar
rowid
result-set-locator
,
char var-2 ;
signed [ length ]
unsigned
,
wchar_t var-5 ;
[ length ]
} variable-name [ dimension ] ;
= expression
varchar-structure
unsigned
vargraphic-structure
int
_Packed struct { short var-6 ;
tag signed
binary
SQL TYPE IS BINARY ( length )
VARBINARY
BINARY VARYING
lob
SQL TYPE IS CLOB ( length )
DBCLOB K
BLOB M
CLOB_LOCATOR
DBCLOB_LOCATOR
BLOB_LOCATOR
CLOB_FILE
DBCLOB_FILE
BLOB_FILE
boolean
SQL TYPE IS BOOLEAN
xml
SQL TYPE IS XML AS CLOB ( length )
DBCLOB K
BLOB M
LOCATOR
CLOB_FILE
DBCLOB_FILE
BLOB_FILE
SQL-varchar
VARCHAR variable-name [ length ]
result-set-locator
SQL TYPE IS RESULT_SET_LOCATOR
Notes:
1. For details on declaring numeric, character, graphic, binary, LOB, Boolean, XML, ROWID, and result set
locator host variables, see the notes under numeric-host variables, character-host variables, graphic-
host variables, binary host variables, LOB host variables, Boolean host variables, XML host variables,
ROWID host variables, and result set locator host variables.
2. The struct tag can be used to define other data areas, but these cannot be used as host variables.
3. _Packed must not be used in C++. Instead, specify #pragma pack(1) prior to the declaration and
#pragma pack() after the declaration.
4. If using sqlint32 or sqlint64, the header file sqlsystm.h must be included.
5. _Decimal32, _Decimal64, and _Decimal128 are only supported for C.
Host structure array indicator structure in C and C++ applications that use
SQL
The figure shows the valid syntax for host structure array indicator structure declarations.
int
short var-1 [ dimension-1 ] ; }
signed
variable-name [ dimension-2 ] ;
= expression
Notes:
1. The struct tag can be used to define other data areas, but they cannot be used as host variables.
2. _Packed must not be used in C++. Instead, specify #pragma pack(1) prior to the declaration and
#pragma pack() after the declaration.
Using pointer data types in C and C++ applications that use SQL
You can also declare host variables that are pointers to the supported C and C++ data types, with the
following restrictions.
• If a host variable is declared as a pointer, then that host variable must be declared with asterisks
followed by a host variable. The following examples are all valid:
Note: Parentheses are only allowed when declaring a pointer to a NUL-terminated character array, in
which case they are required. If the parentheses were not used, you would be declaring an array of
pointers rather than the desired pointer to an array. For example:
• If a host variable is declared as a pointer, then no other host variable can be declared with that same
name within the same source file. For example, the second declaration below would be invalid:
• When a host variable is referenced within an SQL statement, that host variable must be referenced
exactly as declared, with the exception of pointers to NUL-terminated character arrays. For example,
the following declaration required parentheses:
However, the parentheses are not allowed when the host variable is referenced in an SQL statement,
such as a SELECT:
• Only the asterisk can be used as an operator over a host variable name.
• The maximum length of a host variable name is affected by the number of asterisks specified, as these
asterisks are considered part of the name.
• Pointers to structures are not usable as host variables except for variable character structures. Also,
pointer fields in structures are not usable as host variables.
• SQL requires that all specified storage for based host variables be allocated. If the storage is not
allocated, unpredictable results can occur.
• The character array length may be specified in either the typedef or on the host variable declaration but
not in both.
• Storage class (auto, extern, static), volatile, or const qualifiers may be specified on the host variable
declaration.
Using ILE C compiler external file descriptions in C and C++ applications that
use SQL
You can use the C or C++ #pragma mapinc directive with the #include directive to include external file
descriptions in your program.
When used with SQL, only a particular format of the #pragma mapinc directive is recognized by the SQL
precompiler. If all of the required elements are not specified, the precompiler ignores the directive and
does not generate host variable structures. The required elements are:
• Include name
• Externally described file name
• Format name or a list of format names
• Options
• Conversion options
The library name, union name, conversion options, and prefix name are optional. Although typedef
statements coded by the user are not recognized by the precompiler, those created by the #pragma
mapinc and #include directives are recognized. SQL supports input, output, both, and key values for the
options parameter. For the conversion options, the supported values are D, p, z, _P, and 1BYTE_CHAR.
These options may be specified in any order except that both D and p cannot be specified. Unions
declared using the typedef union created by the #pragma mapinc and #include directive cannot be used
as host variables in SQL statements; the members of the unions can be used. Structures that contain
the typedef structure cannot be used in SQL statements; the structure declared using the typedef can be
used.
To retrieve the definition of the sample table DEPARTMENT described in Db2 for i sample tables in the
SQL programming topic collection, you can code the following:
A host structure named Dept_Structure is defined with the following elements: DEPTNO, DEPTNAME,
MGRNO, and ADMRDEPT. These field names can be used as host variables in SQL statements.
Note: DATE, TIME, TIMESTAMP, and BOOLEAN columns generate character host variable definitions. They
are treated by SQL with the same comparison and assignment rules as a DATE, TIME, TIMESTAMP, or
You can use the following table to determine the C or C++ data type that is equivalent to a given SQL data
type.
Example
Given the statement:
Related reference
References to variables
Indicator variables in applications that use SQL
An indicator variable is a halfword integer variable used to communicate additional information about its
associated host variable.
Defining the SQL communication area in COBOL applications that use SQL
A COBOL program can be written to use the SQL communication area (SQLCA) to check return status for
embedded SQL statements, or the program can use the SQL diagnostics area to check return status.
To use the SQL diagnostics area instead of the SQLCA, use the SET OPTION SQL statement with the option
SQLCA = *NO.
When using the SQLCA, a COBOL program that contains SQL statements must include one or both of the
following:
• An SQLCODE variable declared as PICTURE S9(9) BINARY, PICTURE S9(9) COMP-4, or PICTURE S9(9)
COMP.
• An SQLSTATE variable declared as PICTURE X(5).
Or,
• An SQLCA (which contains an SQLCODE and SQLSTATE variable).
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.
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:
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.
When you use the INCLUDE statement, the SQL COBOL precompiler includes COBOL source statements
for the SQLCA:
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.
For ILE COBOL, the SQLCA is declared using the GLOBAL clause. SQLCODE is replaced with SQLCADE
when a declaration for SQLCODE is found in the program and the SQLCA is provided by the precompiler.
SQLSTATE is replaced with SQLSTOTE when a declaration for SQLSTATE is found in the program and the
SQLCA is provided by the precompiler.
Related concepts
Using the SQL diagnostics area
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.
Related reference
SQL communication area
SQLDA 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. For ILE
COBOL, the SQLDA is declared using the GLOBAL clause.
Dynamic SQL is an advanced programming technique. With dynamic SQL, your program can develop and
then run SQL statements while the program is running. A SELECT statement with a variable SELECT list
(that is, a list of the data to be returned as part of the query) that runs dynamically requires an SQL
descriptor area (SQLDA). This is because you cannot know in advance how many or what type of variables
to allocate in order to receive the results of the SELECT.
Related concepts
Dynamic SQL applications
Related reference
SQL descriptor area
DECLARE VARIABLE
DECLARE STATEMENT
INCLUDE SQLDA
Each SQL statement in a COBOL program must begin with EXEC SQL and end with END-EXEC. If the SQL
statement appears between two COBOL statements, the period is optional and might not be appropriate.
The EXEC SQL keywords must appear all on one line, but the remainder of the statement can appear on
the next and subsequent lines.
Example
An UPDATE statement coded in a COBOL program might be coded as follows:
EXEC SQL
UPDATE DEPARTMENT
SET MGRNO = :MGR-NUM
WHERE DEPTNO = :INT-DEPT
END-EXEC.
*...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
EXEC SQL
SELECT * FROM GRAPHTAB WHERE GRAPHCOL = G'<AABB>
- '<CCDDEEFFGGHHIIJJKK>'
END-EXEC.
COBOL COPY statements cannot be used to include SQL statements or declarations of COBOL host
variables that are referenced in SQL statements.
77 PIC
level-1
IS
USAGE
BINARY
COMPUTATIONAL-4
COMP-4
COMPUTATIONAL-5
COMP-5
.
IS
VALUE numeric-constant
Notes:
1. BINARY, COMPUTATIONAL-4, COMP-4, COMPUTATIONAL-5, and COMP-5 are equivalent. A portable
application should code BINARY, because COMPUTATIONAL-4, COMP-4, COMPUTATIONAL-5, and
COMP-5 are IBM extensions that are not supported in International Organization for Standardization
(ISO)/ANSI COBOL. The picture-string associated with these types must have the form S9(i)V9(d) (or
S9...9V9...9, with i and d instances of 9). i + d must be less than or equal to 18.
2. level-1 indicates a COBOL level between 2 and 48.
3. COMPUTATIONAL-5 and COMP-5 are only supported for ILE COBOL.
The following figure shows the syntax for valid decimal host variable declarations.
77 PIC
level-1
IS
USAGE
PACKED-DECIMAL
COMPUTATIONAL-3
COMP-3
COMPUTATIONAL
COMP
.
IS
VALUE numeric-constant
Notes:
1. PACKED-DECIMAL, COMPUTATIONAL-3, and COMP-3 are equivalent. A portable application should
code PACKED-DECIMAL, because COMPUTATIONAL-3 and COMP-3 are IBM extensions that are not
supported in ISO/ANS COBOL. The picture-string associated with these types must have the form
S9(i)V9(d) (or S9...9V9...9, with i and d instances of 9). i + d must be less than or equal to 63.
2. COMPUTATIONAL and COMP are equivalent. The picture strings associated with these and the data
types they represent are product-specific. Therefore, COMP and COMPUTATIONAL should not be used
in a portable application. In an OPM COBOL program, the picture-string associated with these types
must have the form S9(i)V9(d) (or S9...9V9...9, with i and d instances of 9). i + d must be less than or
equal to 63.
3. level-1 indicates a COBOL level between 2 and 48.
The following figure shows the syntax for valid numeric host variable declarations.
Numeric
IS
01 variable-name PICTURE picture-string
77 PIC
level-1
IS
USAGE
DISPLAY
display clause
.
IS
VALUE numeric-constant
display clause
DISPLAY IS CHARACTER
SIGN LEADING SEPARATE
Floating-point
IS
USAGE
01 variable-name COMPUTATIONAL-1
77 COMP-1
level-1 COMPUTATIONAL-2
COMP-2
.
IS
VALUE numeric-constant
Notes:
1. COMPUTATIONAL-1 and COMP-1 are equivalent. COMPUTATIONAL-2 and COMP-2 are equivalent.
2. level-1 indicates a COBOL level between 2 and 48.
77 PIC
level-1
IS
USAGE
DISPLAY
.
IS
VALUE string-constant
Notes:
1. The picture-string associated with these forms must be X(m) (or XXX...X, with m instances of X) with 1
≤ m ≤ 32 766.
2. level-1 indicates a COBOL level between 2 and 48.
level-1 PIC
IS
IS USAGE
picture-string-1 BINARY
COMPUTATIONAL-4
COMP-4
COMPUTATIONAL-5
COMP-5
. 49 var-2
IS
VALUE numeric-constant
IS
PICTURE picture-string-2
PIC
IS
USAGE
DISPLAY
.
IS
VALUE string-constant
Notes:
1. The picture-string-1 associated with these forms must be S9(m) or S9...9 with m instances of 9. m
must be from 1 to 4.
Note that the database manager uses the full size of the S9(m) variable even though OPM COBOL only
recognizes values up to the specified precision. This can cause data truncation errors when COBOL
statements are being run, and might effectively limit the maximum length of variable-length character
strings to the specified precision.
2. The picture-string-2 associated with these forms must be either X(m), or XX...X, with m instances of X,
and with 1 ≤ m ≤ 32 740.
3. var-1 and var-2 cannot be used as host variables.
4. level-1 indicates a COBOL level between 2 and 48.
5. COMPUTATIONAL-5 and COMP-5 are only supported for ILE COBOL.
77 PIC
level-1
IS
USAGE
DISPLAY-1
NATIONAL
.
IS
VALUE string-constant
Notes:
1. The picture-string associated with the DISPLAY-1 form must be G(m) (or GGG...G, with m instances of
G) or N(m) (or NNN...N, with m instances of N) with 1 ≤ m ≤ 16 383.
2. The picture-string associated with the NATIONAL form must be N(m) (or NNN...N, with m instances of
N) with 1 ≤ m ≤ 16 383. NATIONAL is only supported for ILE COBOL. The CCSID is always 1200. You
cannot specify a variable that is declared as NATIONAL on the DECLARE VARIABLE statement.
3. level-1 indicates a COBOL level between 2 and 48.
level-1
IS
IS USAGE
PICTURE picture-string-1
PIC
BINARY . 49
COMPUTATIONAL-4 IS
VALUE numeric-constant
COMP-4
COMPUTATIONAL-5
COMP-5
IS
IS USAGE
var-2 PICTURE picture-string-2
PIC
DISPLAY-1 .
NATIONAL IS
VALUE string-constant
Notes:
VARBINARY
BINARY VARYING
( length ) .
Notes:
1. For BINARY host variables, the length must be in the range 1 to 32766.
2. For VARBINARY or BINARY VARYING host variables, the length must be in the range 1 to 32740.
3. SQL TYPE IS, BINARY, VARBINARY, and BINARY VARYING can be in mixed case.
BINARY Example
The following declaration:
VARBINARY Example
The following declaration:
01 MY-VARBINARY.
49 MY-VARBINARY-LENGTH PIC 9(5) BINARY.
49 MY-VARBINARY-DATA PIC X(250).
DBCLOB
BLOB
( lob-length ) .
K
Notes:
1. For BLOB and CLOB, 1 ≤ lob-length ≤ 15,728,640
2. For DBCLOB, 1 ≤ lob-length ≤ 7,864,320
3. SQL TYPE IS, BLOB, CLOB, DBCLOB can be in mixed case.
CLOB example
The following declaration:
01 MY-CLOB.
49 MY-CLOB-LENGTH PIC 9(9) BINARY.
49 MY-CLOB-DATA PIC X(16384).
DBCLOB example
The following declaration:
01 MY-DBCLOB.
49 MY-DBCLOB-LENGTH PIC 9(9) BINARY.
49 MY-DBCLOB-DATA PIC G(8192) DISPLAY-1.
01 MY-BLOB.
49 MY-BLOB-LENGTH PIC 9(9) BINARY.
49 MY-BLOB-DATA PIC X(16384).
LOB locator
IS
USAGE
01 variable-name
DBCLOB-LOCATOR
BLOB-LOCATOR
Notes:
1. SQL TYPE IS, BLOB-LOCATOR, CLOB-LOCATOR, DBCLOB-LOCATOR can be in mixed case.
2. LOB locators cannot be initialized in the SQL TYPE IS statement.
CLOB and DBCLOB locators have similar syntax.
DBCLOB-FILE
BLOB-FILE
Note: SQL TYPE IS, BLOB-FILE, CLOB-FILE, DBCLOB-FILE can be in mixed case.
01 MY-FILE.
49 MY-FILE-NAME-LENGTH PIC S9(9) COMP-5.
DBCLOB K
BLOB M
Notes:
1. For BLOB and CLOB, 1 ≤ lob-length ≤ 15,728,640
2. For DBCLOB, 1 ≤ lob-length ≤ 7,864,320
3. SQL TYPE IS, XML AS, BLOB, CLOB, DBCLOB can be in mixed case.
4. The CCSID value for an XML host variable can be explicitly set by the DECLARE VARIABLE statement.
Otherwise, the value specified by the SQL_XML_DATA_CCSID QAQQINI option will be used. The
default for this QAQQINI option is CCSID 1208.
XML example
The following declaration:
01 MY-XML.
49 MY-XML-LENGTH PIC 9(9) BINARY.
49 MY-XML-DATA PIC X(5000).
Notes:
1. SQL TYPE IS, XML AS, XML-LOCATOR can be in mixed case.
2. LOB locators cannot be initialized in the SQL TYPE IS statement.
DBCLOB-FILE
BLOB-FILE
Note: SQL TYPE IS, XML AS, BLOB-FILE, CLOB-FILE, DBCLOB-FILE can be in mixed case.
01 MY-FILE.
49 MY-FILE-NAME-LENGTH PIC S9(9) COMP-5.
49 MY-FILE-DATA-LENGTH PIC S9(9) COMP-5.
49 MY-FILE-FILE-OPTIONS PIC S9(9) COMP-5.
49 MY-FILE-NAME PIC X(255).
The precompiler generates declarations for the following file option constants. You can use these
constants to set the xxx-FILE-OPTIONS variable when you use file reference host variables.
• SQL_FILE_READ (2)
• SQL_FILE_CREATE (8)
• SQL_FILE_OVERWRITE (16)
• SQL_FILE_APPEND (32)
77
level-1
IS
DATE format-options
TIME
TIMESTAMP
IS IS
SIZE integer
Notes:
1. level-1 indicates a COBOL level between 2 and 48.
2. format-options indicates valid datetime options that are supported by the COBOL compiler. See the ILE
COBOL Language Reference manual for details.
3. The value for the TIMESTAMP SIZE integer must be 19 to 32.
77 PIC
level-1
IS
VALUE boolean-constant
Notes:
1. level-1 indicates a COBOL level between 2 and 48.
ROWID
01 variable-name SQL TYPE IS ROWID .
01 MY-ROWID.
49 MY-ROWID-LENGTH PIC 9(2) BINARY.
49 MY-ROWID-DATA PIC X(40).
Result set locator host variables in COBOL applications that use SQL
COBOL does not have a variable that corresponds to the SQL result set locator data type. To create host
variables that can be used with this data type, use the SQL TYPE IS clause. The SQL precompiler replaces
this declaration with a COBOL language structure in the output source member.
01 A
02 B
03 C1 PICTURE ...
03 C2 PICTURE ...
In this example, B is the name of a host structure consisting of the basic items C1 and C2.
When writing an SQL statement using a qualified host variable name (for example, to identify a field within
a structure), use the name of the structure followed by a period and the name of the field. For example,
specify B.C1 rather than C1 OF B or C1 IN B. However, this guideline applies only to qualified names
within SQL statements; you cannot use this technique for writing qualified names in COBOL statements.
A host structure is considered complete if any of the following items are found:
• A COBOL item that must begin in area A
• Any SQL statement (except SQL INCLUDE)
01 PEMPL.
10 EMPNO PIC X(6).
10 FIRSTNME.
49 FIRSTNME-LEN PIC S9(4) USAGE BINARY.
49 FIRSTNME-TEXT PIC X(12).
10 MIDINIT PIC X(1).
10 LASTNAME.
49 LASTNAME-LEN PIC S9(4) USAGE BINARY.
49 LASTNAME-TEXT PIC X(15).
10 WORKDEPT PIC X(3).
…
MOVE "000220" TO EMPNO.
…
EXEC SQL
SELECT *
INTO :PEMPL
FROM CORPDATA.EMPLOYEE
WHERE EMPNO = :EMPNO
END-EXEC.
Notice that in the declaration of PEMPL, two varying-length string elements are included in the structure:
FIRSTNME and LASTNAME.
level-1 variable-name .
IS
level-2 var-1 PICTURE picture-string usage-clause .
PIC
floating-point .
. varchar-string .
. vargraphic-string .
binary .
lob .
xml .
datetime .
boolean .
rowid .
result-set-locator .
usage-clause
COMPUTATIONAL-4
COMP-4
COMPUTATIONAL-5
COMP-5
PACKED-DECIMAL
COMPUTATIONAL-3
COMP-3
COMPUTATIONAL
COMP
DISPLAY
display-clause
DISPLAY-1
NATIONAL
IS
VALUE constant
display-clause
DISPLAY IS CHARACTER
SIGN LEADING SEPARATE
floating-point
IS
USAGE
COMPUTATIONAL-1
COMP-1
COMPUTATIONAL-2
COMP-2
IS
VALUE constant
varchar-string
PIC
IS
USAGE
BINARY
COMPUTATIONAL-4
COMP-4
COMPUTATIONAL-5
COMP-5
. 49 var-3
IS
VALUE numeric-constant
IS
PICTURE picture-string-2
PIC
IS IS
USAGE VALUE constant
DISPLAY
vargraphic-string
IS
IS USAGE
49 var-2 PICTURE picture-string-1
PIC
BINARY . 49
COMPUTATIONAL-4 IS
VALUE numeric-constant
COMP-4
COMPUTATIONAL-5
COMP-5
IS
var-3 PICTURE picture-string-2
PIC
IS
USAGE
DISPLAY-1
NATIONAL
IS
VALUE constant
binary
VARBINARY
BINARY VARYING
lob
IS
USAGE
SQL TYPE IS
CLOB ( lob-length )
DBCLOB K
BLOB M
CLOB-LOCATOR
DBCLOB-LOCATOR
BLOB-LOCATOR
CLOB-FILE
DBCLOB-FILE
BLOB-FILE
xml
IS
USAGE
SQL TYPE IS
DBCLOB K
BLOB M
XML-LOCATOR
XML AS CLOB-FILE
DBCLOB-FILE
BLOB-FILE
datetime
OF
variable-name FORMAT
IS
DATE format-options
TIME
TIMESTAMP
IS IS
SIZE integer
boolean
PIC IS
VALUE constant
rowid
SQL TYPE IS ROWID
result-set-locator
SQL TYPE IS RESULT_SET_LOCATOR
Notes:
1. level-1 indicates a COBOL level between 1 and 47.
2. level-2 indicates a COBOL level between 2 and 48 where level-2 > level-1.
3. Graphic host variables, LOB host variables, Boolean host variables, XML host variables, floating-point
host variables, and COMP-5 host variables are only supported for ILE COBOL.
4. For details on declaring numeric, character, graphic, binary, LOB, Boolean, XML, ROWID, and result set
locator host variables, see the notes under numeric-host variables, character-host variables, graphic-
host variables, binary host variables, LOB host variables, Boolean host variables, XML host variables,
ROWID, and result set locator host variables.
5. The variable format-options indicates valid datetime options that are supported by the COBOL
compiler. See the ILE COBOL Language Reference manual for details.
6. The value for the TIMESTAMP SIZE integer must be 19 to 32.
PIC
IS
USAGE
BINARY OCCURS dimension
COMPUTATIONAL-4
COMP-4
COMPUTATIONAL-5
COMP-5
TIMES
.
IS
VALUE constant
Notes:
1. level-1 must be an integer between 2 and 48.
2. BINARY, COMPUTATIONAL-4, COMP-4, COMPUTATIONAL-5, and COMP-5 are equivalent. A portable
application should code BINARY because COMPUTATIONAL-4, COMP-4, COMPUTATIONAL-5, and
01 A-STRUCT.
02 B-ARRAY OCCURS 10 TIMES.
03 C1-VAR PIC X(20).
03 C2-VAR PIC S9(4).
To retrieve 10 rows from the CORPDATA.DEPARTMENT table, use the following example:
01 TABLE-1.
02 DEPT OCCURS 10 TIMES.
05 DEPTNO PIC X(3).
05 DEPTNAME.
49 DEPTNAME-LEN PIC S9(4) BINARY.
49 DEPTNAME-TEXT PIC X(29).
05 MGRNO PIC X(6).
05 ADMRDEPT PIC X(3).
01 TABLE-2.
02 IND-ARRAY OCCURS 10 TIMES.
05 INDS PIC S9(4) BINARY OCCURS 4 TIMES.
....
EXEC SQL
DECLARE C1 CURSOR FOR
SELECT *
FROM CORPDATA.DEPARTMENT
END-EXEC.
....
EXEC SQL
FETCH C1 FOR 10 ROWS INTO :DEPT :IND-ARRAY
END-EXEC.
TIMES
level-1 variable-name OCCURS dimension .
IS
level-2 var-1 PICTURE picture-string-1 usage-clause .
PIC
floating-point .
. varchar-string .
. vargraphic-string .
binary .
lob .
xml .
datetime .
boolean .
rowid .
result-set-locator .
usage-clause
IS
USAGE
BINARY
COMPUTATIONAL-4
COMP-4
COMPUTATIONAL-5
COMP-5
PACKED-DECIMAL
COMPUTATIONAL-3
COMP-3
COMPUTATIONAL
COMP
DISPLAY
display-clause
DISPLAY-1
NATIONAL
IS
VALUE constant
display-clause
floating-point
IS
USAGE
COMPUTATIONAL-1
COMP-1
COMPUTATIONAL-2
COMP-2
IS
VALUE constant
varchar-string
IS
IS USAGE
49 var-2 PICTURE picture-string-2
PIC
BINARY . 49
COMPUTATIONAL-4 IS
VALUE numeric-constant
COMP-4
COMPUTATIONAL-5
COMP-5
IS
var-3 PICTURE picture-string-3
PIC
IS IS
USAGE VALUE constant
DISPLAY
vargraphic-string
PIC
BINARY . 49
COMPUTATIONAL-4 IS
VALUE numeric-constant
COMP-4
COMPUTATIONAL-5
COMP-5
IS
var-3 PICTURE picture-string-3
PIC
IS
USAGE
DISPLAY-1
NATIONAL
IS
VALUE constant
binary
IS
USAGE
SQL TYPE IS BINARY ( length )
VARBINARY
BINARY VARYING
lob
IS
USAGE
SQL TYPE IS
CLOB ( lob-length )
DBCLOB K
BLOB M
CLOB-LOCATOR
DBCLOB-LOCATOR
BLOB-LOCATOR
CLOB-FILE
DBCLOB-FILE
BLOB-FILE
xml
DBCLOB K
BLOB M
XML-LOCATOR
XML AS CLOB-FILE
DBCLOB-FILE
BLOB-FILE
datetime
OF
variable-name FORMAT
IS
DATE format-options
TIME
TIMESTAMP
IS IS
SIZE integer
boolean
IS
PICTURE 1
PIC IS
VALUE constant
rowid
SQL TYPE IS ROWID
Notes:
1. level-1 indicates a COBOL level between 2 and 47.
2. level-2 indicates a COBOL level between 3 and 48 where level-2 > level-1.
3. Graphic host variables, LOB host variables, Boolean host variables, XML host variables, and floating-
point host variables are only supported for ILE COBOL.
4. For details on declaring numeric, character, graphic, binary, LOB, Boolean, XML, ROWID, and result set
locator host variables, see the notes under numeric-host variables, character-host variables, graphic-
host variables, binary host variables, LOB, Boolean , XML, ROWID, and result set locator host variables.
5. The variable format-options indicates valid datetime options that are supported by the COBOL
compiler. See the ILE COBOL Language Reference manual for details.
6. The value for the TIMESTAMP SIZE integer must be 19 to 32.
TIMES
level-1 variable-name OCCURS dimension . level-2 var-1
IS
IS USAGE
PICTURE picture-string
PIC
BINARY .
COMPUTATIONAL-4 IS
VALUE constant
COMP-4
COMPUTATIONAL-5
COMP-5
Notes:
1. level-1 indicates a COBOL level between 2 and 48.
2. level-2 indicates a COBOL level between 3 and 48 where level-2 > level-1.
3. BINARY, COMPUTATIONAL-4, COMP-4, COMPUTATIONAL-5, and COMP-5 are equivalent. A portable
application should code BINARY, because COMPUTATIONAL-4, COMP-4, COMPUTATIONAL-5, and
COMP-5 are IBM extensions that are not supported in ISO/ANSI COBOL. The picture-string associated
with these types must have the form S9(i) (or S9...9, with i instances of 9). i must be less than or equal
to 4.
01 DEPARTMENT-STRUCTURE.
COPY DDS-ALL-FORMATS OF DEPARTMENT.
A host structure named DEPARTMENT-STRUCTURE is defined with an 05 level field named DEPARTMENT-
RECORD that contains four 06 level fields named DEPTNO, DEPTNAME, MGRNO, and ADMRDEPT. These
field names can be used as host variables in SQL statements.
For more information about the COBOL COPY verb, see the ILE COBOL Language Reference and
COBOL/400 User's Guide at IBM Publications Center .
CLOB, BLOB, and DBCLOB columns in the external file are ignored. No host variable definition will be
generated in the host structure for these types.
01 DEPT.
04 DEPT-ARRAY OCCURS 10 TIMES.
COPY DDS-ALL-FORMATS OF DEPARTMENT.
...
Note: DATE, TIME, TIMESTAMP, and BOOLEAN columns will generate character host variable definitions
that are treated by SQL with the same comparison and assignment rules as the DATE, TIME, TIMESTAMP,
or BOOLEAN column. For example, a date host variable can only be compared against a DATE column or a
string which is a valid representation of a date.
Although GRAPHIC and VARGRAPHIC are mapped to character variables in OPM COBOL, SQL considers
these GRAPHIC and VARGRAPHIC variables. If the GRAPHIC or VARGRAPHIC column has a UCS-2 CCSID,
the generated host variable has the UCS-2 CCSID assigned to it. If the GRAPHIC or VARGRAPHIC column
has a UTF-16 CCSID, the generated host variable has the UTF-16 CCSID assigned to it.
The following table can be used to determine the COBOL data type that is equivalent to a given SQL data
type.
Related reference
References to variables
Indicator variables in applications that use SQL
An indicator variable is a halfword integer variable used to communicate additional information about its
associated host variable.
Defining the SQL communication area in PL/I applications that use SQL
A PL/I program that contains SQL statements must include one or both of these fields.
• An SQLCODE variable declared as FIXED BINARY(31)
• An SQLSTATE variable declared as CHAR(5)
Or,
• An SQLCA (which contains an SQLCODE and SQLSTATE variable).
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.
The scope of the SQLCODE, SQLSTATE, and SQLCA variables must include the scope of all SQL statements
in the program.
The included PL/I source statements for the SQLCA are:
DCL 1 SQLCA,
2 SQLCAID CHAR(8),
2 SQLCABC FIXED(31) BINARY,
2 SQLCODE FIXED(31) BINARY,
2 SQLERRM CHAR(70) VAR,
2 SQLERRP CHAR(8),
2 SQLERRD(6) FIXED(31) BINARY,
2 SQLWARN,
3 SQLWARN0 CHAR(1),
3 SQLWARN1 CHAR(1),
3 SQLWARN2 CHAR(1),
3 SQLWARN3 CHAR(1),
3 SQLWARN4 CHAR(1),
3 SQLWARN5 CHAR(1),
3 SQLWARN6 CHAR(1),
3 SQLWARN7 CHAR(1),
3 SQLWARN8 CHAR(1),
3 SQLWARN9 CHAR(1),
3 SQLWARNA CHAR(1),
2 SQLSTATE CHAR(5);
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.
Related reference
SQL communication area
Dynamic SQL is an advanced programming technique. With dynamic SQL, your program can develop and
then run SQL statements while the program is running. A SELECT statement with a variable SELECT list
(that is, a list of the data to be returned as part of the query) that runs dynamically requires an SQL
descriptor area (SQLDA). This is because you cannot know in advance how many or what type of variables
to allocate in order to receive the results of the SELECT.
Related concepts
Dynamic SQL applications
Related reference
SQL descriptor area
*(..+....1....+....2....+....3....+....4....+....5....+....6....+....7.)..
EXEC SQL SELECT * FROM GRAPHTAB WHERE GRAPHCOL = G'<AABBCCDD>
<EEFFGGHHIIJJKK>';
No PL/I preprocessor directives are permitted within SQL statements. PL/I %INCLUDE statements cannot
be used to include SQL statements or declarations of PL/I host variables that are referenced in SQL
statements.
Numeric
DECLARE variable-name
DCL ,
( variable-name )
BINARY FIXED
BIN ( precision )
FLOAT
( precision )
DECIMAL FIXED
DEC ( precision )
,scale
FLOAT
( precision )
PICTURE picture-string
;
Alignment and/or Scope and/or Storage
Notes:
1. (BINARY, BIN, DECIMAL, or DEC) and (FIXED or FLOAT) and (precision, scale) can be specified in any
order.
2. A picture-string in the form '9...9V9...R' indicates a numeric host variable. The R is required. The
optional V indicates the implied decimal point.
3. A picture-string in the form 'S9...9V9...9' indicates a sign leading separate host variable. The S is
required. The optional V indicates the implied decimal point.
Character
DECLARE variable-name CHARACTER
DCL , CHAR
( variable-name )
( length ) VARYING
VAR
;
Alignment and/or Scope and/or Storage
Notes:
1. The variable length must be an integer constant not greater than 32766 if VARYING or VAR is not
specified.
2. If VARYING or VAR is specified, length must be a constant no greater than 32740.
DCL ,
( variable-name )
BINARY ( length ) ;
VARBINARY
BINARY VARYING
Notes:
1. For BINARY host variables, the length must be in the range 1 to 32766.
2. For VARBINARY and BINARY VARYING host variables, the length must be in the range 1 to 32740.
3. SQL TYPE IS, BINARY, VARBINARY, BINARY VARYING can be in mixed case.
BINARY example
The following declaration:
LOB
DECLARE variable-name SQL TYPE IS CLOB (
DCL , BLOB
( variable-name )
lob-length ) ;
K
Notes:
1. For BLOB and CLOB, 1 ≤ lob-length ≤ 32,766
2. SQL TYPE IS, BLOB, CLOB can be in mixed case.
CLOB example
The following declaration:
DCL 1 MY_CLOB,
3 MY_CLOB_LENGTH BINARY FIXED (31) UNALIGNED,
3 MY_CLOB_DATA CHARACTER (16384);
BLOB example
The following declaration:
DCL 1 MY_BLOB,
3 MY_BLOB_LENGTH BINARY FIXED (31) UNALIGNED,
3 MY_BLOB_DATA CHARACTER (16384);
The following figure shows the syntax for valid LOB locators.
DCL ,
( variable-name )
CLOB_LOCATOR ;
DBCLOB_LOCATOR
BLOB_LOCATOR
Note: SQL TYPE IS, BLOB_LOCATOR, CLOB_LOCATOR, DBCLOB_LOCATOR can be in mixed case.
DCL ,
( variable-name )
CLOB_FILE ;
DBCLOB_FILE
BLOB_FILE
Note: SQL TYPE IS, BLOB_FILE, CLOB_FILE, and DBCLOB_FILE can be in mixed case.
DCL 1 MY_FILE,
3 MY_FILE_NAME_LENGTH BINARY FIXED(31) UNALIGNED,
3 MY_FILE_DATA_LENGTH BINARY FIXED(31) UNALIGNED,
3 MY_FILE_FILE_OPTIONS BINARY FIXED(31) UNALIGNED,
3 MY_FILE_NAME CHAR(255);
ROWID
DECLARE variable-name SQL TYPE IS ROWID
DCL ,
( variable-name )
ROWID example
The following declaration:
DCL 1 A,
2 B,
3 C1 CHAR(...),
3 C2 CHAR(...);
In this example, B is the name of a host structure consisting of the elementary items C1 and C2.
You can use the structure name as shorthand notation for a list of scalars. You can qualify a host variable
with a structure name (for example, STRUCTURE.FIELD). Host structures are limited to two levels. (For
example, in the above host structure example, the A cannot be referred to in SQL.) A structure cannot
contain an intermediate level structure. In the previous example, A could not be used as a host variable
or referred to in an SQL statement. However, B is the first level structure. B can be referred to in an SQL
statement. A host structure for SQL data is two levels deep and can be thought of as a named set of host
variables. After the host structure is defined, you can refer to it in an SQL statement instead of listing the
several host variables (that is, the names of the host variables that make up the host structure).
For example, you can retrieve all column values from selected rows of the table CORPDATA.EMPLOYEE
with:
DCL 1 PEMPL,
5 EMPNO CHAR(6),
5 FIRSTNME CHAR(12) VAR,
5 MIDINIT CHAR(1),
Host structures
DECLARE 1 variable-name ,
level-1 variable-name ,
( var-2 )
data-types
DECIMAL FIXED
DEC ( precision )
, scale
FLOAT
( precision ) UNALIGNED
PICTURE picture-string
CHARACTER
VAR ALIGNED
BLOB K
CLOB_LOCATOR
DBCLOB_LOCATOR
BLOB_LOCATOR
CLOB_FILE
DBCLOB_FILE
BLOB_FILE
VARBINARY
BINARY VARYING
Notes:
1. level-1 indicates that there is an intermediate level structure.
2. level-1 must be an integer constant between 1 and 254.
3. level-2 must be an integer constant between 2 and 255.
4. For details on declaring numeric, character, LOB, ROWID, and binary host variables, see the notes
under numeric-host variables, character-host variables, LOB host variables, ROWID host variables, and
binary host variables.
DCL ,
( variable-name ( dimension ) )
BINARY FIXED
BIN ( precision )
;
Alignment and/or scope and/or storage
DCL 1 A_STRUCT,
2 B_ARRAY(10),
3 C1_VAR CHAR(20),
3 C2_FIXED BIN(15) UNALIGNED;
DCL 1 DEPT(10),
5 DEPTPNO CHAR(3),
5 DEPTNAME CHAR(29) VAR,
5 MGRNO CHAR(6),
5 ADMRDEPT CHAR (3);
DCL 1 IND_ARRAY(10),
5 INDS(4) FIXED BIN(15);
EXEC SQL
DECLARE C1 CURSOR FOR
SELECT *
FROM CORPDATA.DEPARTMENT;
EXEC SQL
FETCH C1 FOR 10 ROWS INTO :DEPT :IND_ARRAY;
level-1 variable-name ,
( var-2 )
data-types
BINARY FIXED UNALIGNED
DECIMAL FIXED
DEC ( precision )
, scale
FLOAT UNALIGNED
( precision )
PICTURE picture-string
CHARACTER
VAR
BLOB K
CLOB_LOCATOR
DBCLOB_LOCATOR
BLOB_LOCATOR
CLOB_FILE
DBCLOB_FILE
BLOB_FILE
VARBINARY
BINARY VARYING
Notes:
1. level-1 indicates that there is an intermediate level structure.
2. level-1 must be an integer constant between 1 and 254.
3. level-2 must be an integer constant between 2 and 255.
level-1 variable-name ,
BIN
;
( precision )
Notes:
1. level-1 indicates that there is an intermediate level structure.
2. level-1 must be an integer constant between 1 and 254.
3. level-2 must be an integer constant between 2 and 255.
4. Dimension-1 and dimension-2 must be integer constants between 1 and 32 767.
DCL 1 TDEPT_STRUCTURE,
%INCLUDE DEPARTMENT(DEPARTMENT,RECORD);
In the above example, a host structure named TDEPT_STRUCTURE would be defined having four fields.
The fields would be DEPTNO, DEPTNAME, MGRNO, and ADMRDEPT.
For device files, if INDARA is not specified and the file contains indicators, the declaration cannot be used
as a host structure array. The indicator area is included in the generated structure and causes the storage
to not be contiguous.
DCL 1 DEPT_REC(10),
%INCLUDE DEPARTMENT(DEPARTMENT,RECORD);
The following table can be used to determine the PL/I data type that is equivalent to a given SQL data
type.
FLOAT (double precision) BIN FLOAT(p) or DEC FLOAT(m) p is a positive integer from 25 to
53.
m is a positive integer from 8 to
16.
Example
Given the statement:
Related reference
References to variables
Indicator variables in applications that use SQL
An indicator variable is a halfword integer variable used to communicate additional information about its
associated host variable.
Defining the SQL communication area in RPG/400 applications that use SQL
The SQL precompiler automatically places the SQLCA in the input specifications of the RPG/400 program
prior to the first calculation specification.
INCLUDE SQLCA should not be coded in the source program. If the source program specifies INCLUDE
SQLCA, the statement will be accepted, but it is redundant. The SQLCA, as defined for RPG/400:
ISQLCA DS SQL
I* SQL COMMUNICATION AREA SQL
I I X'0000000000000000' 1 8 SQLAID SQL
I B 9 120SQLABC SQL
I B 13 160SQLCOD SQL
I B 17 180SQLERL SQL
I 19 88 SQLERM SQL
I 89 96 SQLERP SQL
I 97 120 SQLERR SQL
I B 97 1000SQLER1 SQL
I B 101 1040SQLER2 SQL
I B 105 1080SQLER3 SQL
I B 109 1120SQLER4 SQL
I B 113 1160SQLER5 SQL
I B 117 1200SQLER6 SQL
I 121 131 SQLWRN SQL
I 121 121 SQLWN0 SQL
I 122 122 SQLWN1 SQL
I 123 123 SQLWN2 SQL
I 124 124 SQLWN3 SQL
I 125 125 SQLWN4 SQL
I 126 126 SQLWN5 SQL
I 127 127 SQLWN6 SQL
I 128 128 SQLWN7 SQL
Note: Variable names in RPG/400 are limited to 6 characters. The standard SQLCA names have been
changed to a length of 6. RPG/400 does not have a way of defining arrays in a data structure without also
defining them in the extension specification. SQLERR is defined as character with SQLER1 through 6 used
as the names of the elements.
Related reference
SQL communication area
*...1....+....2....+....3....+....4....+....5....+....6....+....7...*
C/EXEC SQL UPDATE DEPARTMENT
C+ SET MANAGER = :MGRNUM
C+ WHERE DEPTNO = :INTDEP
C/END-EXEC
*...1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
C/EXEC SQL SELECT * FROM GRAPHTAB WHERE GRAPHCOL = G'<AABB>
C+<CCDDEEFFGGHHIIJJKK>'
C/END-EXEC
*...1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
C/EXEC SQL INCLUDE member-name
C/END-EXEC
The /COPY statement can be used to include SQL statements or RPG/400 specifications.
*...1....+....2....+....3....+....4....+....5....+....6....+....7...*
IBIGCHR DS 642
In the next example, PEMPL is the name of the host structure consisting of the subfields EMPNO, FIRSTN,
MIDINT, LASTNAME, and DEPTNO. The referral to PEMPL uses the subfields. For example, the first
column of EMPLOYEE is placed in EMPNO, the second column is placed in FIRSTN, and so on.
*...1....+....2....+....3....+....4....+....5....+....6....+....7. ..*
IPEMPL DS
I 01 06 EMPNO
I 07 18 FIRSTN
I 19 19 MIDINT
I 20 34 LASTNA
I 35 37 DEPTNO
…
C MOVE '000220' EMPNO
…
C/EXEC SQL
C+ SELECT * INTO :PEMPL
C+ FROM CORPDATA.EMPLOYEE
C+ WHERE EMPNO = :EMPNO
C/END-EXEC
When writing an SQL statement, referrals to subfields can be qualified. Use the name of the data
structure, followed by a period and the name of the subfield. For example, PEMPL.MIDINT is the same as
specifying only MIDINT.
*...1....+....2....+....3....+....4....+....5....+....6....+....7. ..*
IBARRAY DS 10
I 01 20 C1VAR
I B 21 220C2VAR
The following example uses a host structure array called DEPT and a multiple-row FETCH statement to
retrieve 10 rows from the DEPARTMENT table.
*...1....+....2....+....3....+....4....+....5....+....6....+....7...*
E INDS 4 4 0
IDEPT DS 10
I 01 03 DEPTNO
I 04 32 DEPTNM
I 33 38 MGRNO
I 39 41 ADMRD
IINDARR DS 10
I B 1 80INDS
…
C/EXEC SQL
C+ DECLARE C1 CURSOR FOR
C+ SELECT *
C+ FROM CORPDATA.DEPARTMENT
*...1....+....2....+....3....+....4....+....5....+....6....+....7....*
FTDEPT IP E DISK
F TDEPT KRENAMEDEPTREC
IDEPTREC
I DEPTNAME DEPTN
I ADMRDEPT ADMRD
Note: Code an F-spec for a file in your RPG program only if you use RPG/400 statements to do I/O
operations to the file. If you use only SQL statements to do I/O operations to the file, you can include the
external definition by using an external data structure.
In the following example, the sample table is specified as an external data structure. The SQL precompiler
retrieves the field (column) definitions as subfields of the data structure. Subfield names can be used as
host variable names, and the data structure name TDEPT can be used as a host structure name. The field
names must be changed because they are greater than six characters.
*...1....+....2....+....3....+....4....+....5....+....6....+....7....*
ITDEPT E DSDEPARTMENT
I DEPTNAME DEPTN
I ADMRDEPT ADMRD
Note: DATE, TIME, and TIMESTAMP columns will generate host variable definitions that are treated by
SQL with the same comparison and assignment rules as a DATE, TIME, and TIMESTAMP column. For
example, a date host variable can only be compared against a DATE column or a character string that is a
valid representation of a date.
Although varying-length columns generate fixed-length character-host variable definitions, to SQL they
are varying-length character variables.
Although GRAPHIC and VARGRAPHIC columns are mapped to character variables in RPG/400, SQL
considers these GRAPHIC and VARGRAPHIC variables. If the GRAPHIC or VARGRAPHIC column has a
UCS-2 CCSID, the generated host variable will have the UCS-2 CCSID assigned to it. If the GRAPHIC
or VARGRAPHIC column has a UTF-16 CCSID, the generated host variable will have the UTF-16 CCSID
assigned to it.
CLOB, BLOB, and DBCLOB columns in the external file are ignored. No host variable definition will be
generated in the host structure for these types.
*...1....+....2....+....3....+....4....+....5....+....6....*
ITDEPT E DSDEPARTMENT 10
I DEPARTMENT DEPTN
I ADMRDEPT ADMRD
C/EXEC SQL
C+ DECLARE C1 CURSOR FOR
C+ SELECT *
C+ FROM CORPDATA.DEPARTMENT
C/END-EXEC
C/EXEC SQL
C+ FETCH C1 FOR 10 ROWS INTO :TDEPT
C/END-EXEC
Use the information in the following table to determine the RPG/400 data type that is equivalent to a
given SQL data type.
NUMERIC Subfield of the data structure. Blank in Maximum length of 30 (precision 30) and
position 43 and 0 through 9 in position 52 maximum scale of 9.
of the subfield
TIMESTAMP Subfield of a data structure. Blank in Length must be at least 19. To include
position 52 of the subfield specification. microseconds at full precision, length must
be 26. If length is less than 26, truncation
OR
occurs on the microseconds part.
Field defined without decimal places.
*...1....+....2....+....3....+....4....+....5....+....6....+....7...*
C/EXEC SQL FETCH CLS_CURSOR INTO :CLSCD,
C+ :DAY :DAYIND,
C+ :BGN :BGNIND,
C+ :END :ENDIND
C/END-EXEC
*...1....+....2....+....3....+....4....+....5....+....6....+....7...*
I DS
I 1 7 CLSCD
I B 8 90DAY
I B 10 110DAYIND
I 12 19 BGN
I B 20 210BGNIND
I 22 29 END
I B 30 310ENDIND
For more information about programming using ILE RPG, see the ILE RPG Programmer's Guide topic
and the ILE RPG Language Reference topic.
Related concepts
Writing applications that use SQL
You can create database applications in host languages that use Db2 for i SQL statements and functions.
Related reference
Example programs: Using Db2 for i statements
Here is a sample application that shows how to code SQL statements in each of the languages that Db2
for i supports.
Example: SQL statements in ILE RPG programs
Defining the SQL communication area in ILE RPG applications that use SQL
The SQL precompiler automatically places the SQL communication area (SQLCA) in the definition
specifications of the ILE RPG program before the first calculation specification, unless a SET OPTION
SQLCA = *NO statement is found.
INCLUDE SQLCA should not be coded in the source program. If the source program specifies INCLUDE
SQLCA, the statement will be accepted, but it is redundant. The SQLCA source statements for ILE RPG
are:
If a SET OPTION SQLCA = *NO statement is found, the SQL precompiler automatically places SQLCODE
and SQLSTATE variables in the definition specification. They are defined as follows when the SQLCA is not
included:
Related reference
SQL communication area
Defining SQL descriptor areas in ILE RPG applications that use SQL
There are two types of SQL descriptor areas (SQLDAs). One is defined with the ALLOCATE DESCRIPTOR
statement. The other is defined using the SQLDA structure. In this topic, only the SQLDA form is
discussed.
The following statements can use an SQLDA:
• EXECUTE…USING DESCRIPTOR descriptor-name
• FETCH…USING DESCRIPTOR descriptor-name
The user is responsible for the definition of SQL_NUM. SQL_NUM must be defined as a numeric constant
with the dimension required for SQL_VAR.
The INCLUDE SQLDA generates two data structures. The second data structure is used to setup and
reference the part of the SQLDA that contains the field descriptions.
Fixed-form RPG
The keywords EXEC SQL indicate the beginning of an SQL statement. EXEC SQL must occupy positions
8 through 16 of the source statement, preceded by a / in position 7. The SQL statement may start in
position 17 and continue through position 80.
The keyword END-EXEC ends the SQL statement. END-EXEC must occupy positions 8 through 16 of the
source statement, preceded by a slash (/) in position 7. Positions 17 through 80 must be blank.
An UPDATE statement coded in an ILE RPG program might be coded as follows:
Free-form RPG
Each SQL statement must begin with EXEC SQL and end with a semicolon (;). The EXEC SQL keywords
must be on one line. The remaining part of the SQL statement can be on more than one line. Each
SQL statement should start on a new line. No other statement should be on the same line as the SQL
statement.
An UPDATE statement coded in free form might be coded in the following way:
Fixed-form RPG
To embed an ILE RPG comment within the SQL statement, place an asterisk (*) in position 7.
Continuation for SQL statements in ILE RPG applications that use SQL
SQL statements can be continued across many records in ILE RPG.
Fixed-form RPG
When additional records are needed to contain the SQL statement, positions 9 through 80 can be used.
Position 7 must be a plus sign (+), and position 8 must be blank. Position 80 of the continued line is
concatenated with position 9 of the continuation line.
Constants containing DBCS data can be continued across multiple lines by placing the shift-in character in
position 81 of the continued line and placing the shift-out character in position 8 of the continuation line.
In this example, the SQL statement has a valid graphic constant of G'<AABBCCDDEEFFGGHHIIJJKK>'.
Free-form RPG
SQL statements can be contained on one or more lines. To continue an SQL statement across multiple
lines, the SQL statement can be split wherever a blank is allowed. The plus sign (+) can be used to
indicate a continuation of a string constant. The literal continues with the first nonblank character on the
next line.
RPG directives are handled by the SQL precompiler according to the value of the RPG preprocessor
options parameter (RPGPPOPT).
Related reference
Using directives in ILE RPG applications that use SQL
RPG directives are handled by the SQL precompiler according to the value of the RPG preprocessor
options parameter (RPGPPOPT). If the RPG preprocessor is used, the SQL precompile will run using the
expanded preprocessed source.
Declaring binary host variables in ILE RPG applications that use SQL
ILE RPG does not have variables that correspond to the SQL binary data types.
To create host variables that can be used with these data types, use the SQLTYPE keyword. The SQL
precompiler replaces this declaration with an ILE RPG language declaration in the output source member.
Binary declarations can be either standalone or within a data structure.
BINARY example
• The following declaration in free-form:
D MYBINARY S SQLTYPE(BINARY:50)
VARBINARY example
• The following declaration in free-form:
D MYVARBINARY S SQLTYPE(VARBINARY:100)
Notes:
1. For BINARY host variables, the length must be in the range 1 to 32766.
2. For VARBINARY host variables, the length must be in the range 1 to 32740.
3. BINARY and VARBINARY host variables are allowed to be declared in host structures.
4. SQLTYPE, BINARY, and VARBINARY can be in mixed case.
5. SQLTYPE must be between positions 44 to 80 for fixed-form declarations.
6. When a BINARY or VARBINARY is declared as a standalone host variable, position 24 must contain the
character S and position 25 must be blank for fixed-form declarations.
7. The standalone field indicator S in position 24 for fixed-form declarations should be omitted when a
BINARY or VARBINARY host variable is declared in a host structure.
CLOB example
• The following declaration in free-form:
DCL-DS MYCLOB;
MYCLOB_LEN UNS(10);
MYCLOB_DATA CHAR(1000);
END-DS MYCLOB;
D MYCLOB S SQLTYPE(CLOB:1000)
D MYCLOB DS
D MYCLOB_LEN 10U
D MYCLOB_DATA 1000A
DBCLOB example
• The following declaration in free-form:
DCL-DS MYDBCLOB;
MYDBCLOB_LEN UNS(10);
MYDBCLOB_DATA GRAPH(400);
END-DS MYDBCLOB;
D MYDBCLOB S SQLTYPE(DBCLOB:400)
D MYDBCLOB DS
D MYDBCLOB_LEN 10U
D MYDBCLOB_DATA 400G
BLOB example
• The following declaration in free-form:
DCL-DS MYBLOB;
MYBLOB_LEN UNS(10);
MYBLOB_DATA CHAR(500) CCSID(*HEX);
END-DS MYBLOB;
D MYBLOB S SQLTYPE(BLOB:500)
D MYBLOB DS
D MYBLOB_LEN 10U
D MYBLOB_DATA 500A CCSID(*HEX)
Notes:
1. For BLOB and CLOB host variables, the length must be in the range 1 to 16 773 100.
2. For DBCLOB host variables, the length must be in the range 1 to 8 386 550.
3. LOB host variables are allowed to be declared in host structures.
4. LOB host variables are not allowed in host structure arrays. LOB locators should be used instead.
5. LOB host variables declared in structure arrays cannot be used as standalone host variables.
6. SQLTYPE, BLOB, CLOB, DBCLOB can be in mixed case.
7. SQLTYPE must be between positions 44 to 80 for fixed-form declarations.
8. When a LOB is declared as a stand-alone host variable, position 24 must contain the character 'S' and
position 25 must be blank for fixed-form declarations.
9. The stand-alone field indicator S in position 24 for fixed-form declarations should be omitted when a
LOB is declared in a host structure.
10. LOB host variables cannot be initialized.
D MYBLOB S SQLTYPE(BLOB_LOCATOR)
D MYBLOB S 10U
Notes:
1. LOB locators are allowed to be declared in host structures.
2. SQLTYPE, BLOB_LOCATOR, CLOB_LOCATOR, DBCLOB_LOCATOR can be in mixed case.
3. SQLTYPE must be between positions 44 to 80 for fixed-form declarations.
LOB file reference variables in ILE RPG applications that use SQL
Here is an example of a CLOB file reference variable in ILE RPG. BLOB and DBCLOB file reference
variables have similar syntax.
DCL-DS MY_FILE;
MY_FILE_NL UNS(10);
MY_FILE_DL UNS(10);
MY_FILE_FO UNS(10);
MY_FILE_NAME CHAR(255);
END-DS MY_FILE;
D MY_FILE S SQLTYPE(CLOB_FILE)
D MY_FILE DS
D MY_FILE_NL 10U
D MY_FILE_DL 10U
D MY_FILE_FO 10U
D MY_FILE_NAME 255A
Notes:
1. LOB file reference variables are allowed to be declared in host structures.
2. SQLTYPE, BLOB_FILE, CLOB_FILE, DBCLOB_FILE can be in mixed case.
3. SQLTYPE must be between positions 44 to 80 for fixed-form declarations.
4. When a LOB file reference is declared as a standalone host variable, position 24 must contain the
character 'S' and position 25 must be blank for fixed-form declarations.
5. The standalone field indicator 'S' in position 24 for fixed-form declarations should be omitted when a
LOB file reference variable is declared in a host structure.
6. LOB file reference variables cannot be initialized.
The pre-compiler will generate declarations for the following file option constants. You can use these
constants to set the xxx_FO variable when you use file reference host variables.
• SQFRD (2)
• SQFCRT (8)
• SQFOVR (16)
• SQFAPP (32)
Related reference
LOB file reference variables
DCL-DS MYXMLCLOB;
MYXMLCLOB_LEN UNS(10);
MYXMLCLOB_DATA CHAR(3000) CCSID(37);
END-DS MYXMLCLOB;
D MYXMLCLOB S SQLTYPE(XML_CLOB:3000)
D MYXMLCLOB DS
D MYXMLCLOB_LEN 10U
D MYXMLCLOB_DATA 3000A
DCL-DS MYXMLDBCLOB;
MYXMLDBCLOB_LEN UNS(10);
MYXMLDBCLOB_DATA UCS2(400) CCSID(13488);
END-DS MYXMLDBCLOB;
D MYXMLDBCLOB S SQLTYPE(XML_DBCLOB:400)
D MYXMLDBCLOB DS
D MYXMLDBCLOB_LEN 10U
D MYXMLDBCLOB_DATA 400C
DCL-DS MYXMLBLOB;
MYXMLBLOB_LEN UNS(10);
MYXMLBLOB_DATA CHAR(780) CCSID(*HEX);
END-DS MYXMLBLOB;
D MYXMLBLOB S SQLTYPE(XML_BLOB:780)
D MYXMLBLOB DS
D MYXMLBLOB_LEN 10U
D MYXMLBLOB_DATA 780A CCSID(*HEX)
Notes:
1. For XML_BLOB and XML_CLOB host variables, the length must be in the range 1 to 16 773 100.
2. For XML_DBCLOB host variables, the length must be in the range 1 to 8 386 550.
3. XML host variables are allowed to be declared in host structures.
4. XML host variables are not allowed in host structure arrays. XML locators should be used instead.
5. XML host variables declared in structure arrays cannot be used as standalone host variables.
6. SQLTYPE, XML_BLOB, XML_CLOB, XML_DBCLOB can be in mixed case.
7. SQLTYPE must be between positions 44 to 80 for fixed-form declarations.
8. The CCSID value for an XML host variable can be explicitly set by using the CCSID keyword or
the DECLARE VARIABLE statement. Otherwise, the value specified by the SQL_XML_DATA_CCSID
QAQQINI option will be used. The default for this QAQQINI option is CCSID 1208.
9. When XML is declared as a standalone host variable, position 24 must contain the character 'S' and
position 25 must be blank for fixed-form declarations.
10. The stand-alone field indicator S in position 24 for fixed-form declarations should be omitted when
XML is declared in a host structure.
11. XML host variables cannot be initialized.
D MYXMLLOC S SQLTYPE(XML_LOCATOR)
D MYXMLLOC S 10U
XML file reference variables in ILE RPG applications that use SQL
Here is an example of a XML file reference variable in ILE RPG.
DCL-DS MY_XMLFILE;
MY_XMLFILE_NL UNS(10);
MY_XMLFILE_DL UNS(10);
MY_XMLFILE_FO UNS(10);
MY_XMLFILE_NAME CHAR(255);
END-DS MY_XMLFILE;
D MY_XMLFILE S SQLTYPE(XML_CLOB_FILE)
D MY_XMLFILE DS
D MY_XMLFILE_NL 10U
D MY_XMLFILE_DL 10U
D MY_XMLFILE_FO 10U
D MY_XMLFILE_NAME 255A
ROWID example
• The following declaration in free-form:
D MY_ROWID S SQLTYPE(ROWID)
Notes:
1. SQLTYPE, ROWID can be in mixed case.
2. ROWID host variables are allowed to be declared in host structures.
3. SQLTYPE must be between positions 44 and 80 for fixed-form declarations.
4. When a ROWID is declared as a standalone host variable, position 24 must contain the character 'S'
and position 25 must be blank for fixed-form declarations.
5. The standalone field indicator 'S' in position 24 for fixed-form declarations should be omitted when a
ROWID is declared in a host structure.
6. ROWID host variables cannot be initialized.
Declaring result set locator variables in ILE RPG applications that use SQL
ILE RPG does not have a variable that corresponds to the SQL result set locator data type.
To create host variables that can be used with this data type, use the SQLTYPE keyword. The SQL
precompiler replaces this declaration with an ILE RPG language declaration in the output source member.
Result set locator declarations can be either standalone or within a data structure.
D RS_LOC1 S SQLTYPE(RESULT_SET_LOCATOR)
D RS_LOC1 S 20I 0
Notes:
1. SQLTYPE, RESULT_SET_LOCATOR can be in mixed case.
2. Result set locator host variables are allowed to be declared in host structures.
3. SQLTYPE must be between positions 44 and 80 for fixed-form declarations.
4. When a result set locator is declared as a standalone host variable, position 24 must contain the
character 'S' and position 25 must be blank for fixed-form declarations.
5. The standalone field indicator 'S' in position 24 for fixed-form declarations should be omitted when a
result set locator is declared in a host structure.
6. Result set locator host variables cannot be initialized.
DCL-DS PEMPL;
LASTNAME CHAR(10) POS(11);
FIRSTNAME CHAR(10) POS(1);
END-DS;
In the following example, BIGCHR is an ILE data structure without subfields. SQL treats any references to
BIGCHR as a character string with a length of 642.
In the next example, PEMPL is the name of the host structure consisting of the subfields EMPNO, FIRSTN,
MIDINT, LASTNA, and DEPTNO. A reference to PEMPL uses the subfields. For example, the first column of
CORPDATA.EMPLOYEE is placed in EMPNO, the second column is placed in FIRSTN, and so on.
DCL-DS PEMPL;
EMPNO CHAR(6);
FIRSTN CHAR(12);
MIDINT CHAR(1);
LASTNA CHAR(15);
DEPTNO CHAR(3);
END-DS;
...
EMPNO = '000220';
...
EXEC SQL SELECT * INTO :PEMPL
FROM CORPDATA.EMPLOYEE
When writing an SQL statement, references to subfields that are not in a QUALIFIED data structure can
be qualified. Use the name of the data structure, followed by a period and the name of the subfield. For
example, PEMPL.MIDINT is the same as specifying only MIDINT. If the data structure has the QUALIFIED
keyword, then the subfield must be referenced using the data structure name to qualify the subfield
name.
In this example, there are two data structures, one QUALIFIED and one not QUALIFIED, that contain the
same subfield names:
DCL-DS fststruct;
sub1 INT(5);
sub2 INT(10);
sub3 INT(20);
sub4 INT(10);
END-DS;
Example
DCL-DS CustomerInfo QUALIFIED;
Name CHAR(20);
Address CHAR(50);
END-DS;
Using host structure arrays in ILE RPG applications that use SQL
A host structure array is defined as an occurrence data structure or a data structure with the keyword
DIM coded. Both types of data structures can be used on the SQL FETCH or INSERT statement when
processing multiple rows.
The following list of items must be considered when using a data structure with multiple row blocking
support.
• All subfields must be valid host variables.
• All subfields must be contiguous. The first FROM position must be 1 and there cannot be overlaps in the
TO and FROM positions.
• No subfields using the POS or OVERLAY keywords can be included in the data structure.
• If the date and time format and separator of date and time subfields within the host structure are not
the same as the DATFMT, DATSEP, TIMFMT, and TIMSEP parameters on the CRTSQLRPGI command (or
in the SET OPTION statement), then the host structure array is not usable.
For all statements, other than the blocked FETCH and blocked INSERT, if an occurrence data structure is
used, the current occurrence is used. For the blocked FETCH and blocked INSERT, the occurrence is set to
1.
The following example uses a host structure array called DEPARTMENT and a blocked FETCH statement
to retrieve 10 rows from the DEPARTMENT table.
Blocked FETCH and blocked INSERT are the only SQL statements that allow a data structure with the
DIM keyword. Data structures with the DIM keyword cannot have a name that starts with 'TAB'. If the
data structure name starts with 'TAB', the data structure is considered a table instead of an array and is
not supported by SQL. A host variable reference with a subscript like MyStructure(index).Mysubfield is not
supported by SQL.
Using external file descriptions in ILE RPG applications that use SQL
Field definitions for externally described files, including renaming of fields, are recognized by the SQL
precompiler. The external definition form of the data structure can be used to obtain a copy of the column
names to be used as host variables.
How date and time field definition are retrieved and processed by the SQL precompiler depends on
whether *NOCVTDT or *CVTDT is specified on the OPTION parameter of the CRTSQLRPGI command.
If *NOCVTDT is specified, then date and time field definitions are retrieved including the format and
separator. If *CVTDT is specified, then the format and separator are ignored when date and time field
definitions are retrieved, and the precompiler assumes that the variable declarations are date/time host
variables in character format. *CVTDT is a compatibility option for the ILE RPG precompiler.
If the GRAPHIC or VARGRAPHIC column has a UCS-2 CCSID, the generated host variable will have the
UCS-2 CCSID assigned to it. If the GRAPHIC or VARGRAPHIC column has a UTF-16 CCSID, the generated
host variable will have the UTF-16 CCSID assigned to it.
CLOB, BLOB, and DBCLOB columns in the external file are ignored. No host variable definition will be
generated in the host structure for these types.
In the following example, the sample table DEPARTMENT is used as a file in an ILE RPG program. The SQL
precompiler retrieves the field (column) definitions for DEPARTMENT for use as host variables.
Note: Code an F-spec for a file in your ILE RPG program only if you use ILE RPG statements to do I/O
operations to the file. If you use only SQL statements to do I/O operations to the file, you can include the
external definition of the file (table) by using an external data structure.
In the following example, the sample table is specified as an external data structure. The SQL precompiler
retrieves the field (column) definitions as subfields of the data structure. Subfield names can be used
as host variable names, and the data structure name TDEPT can be used as a host structure name. The
example shows that the field names can be renamed if required by the program.
External file description considerations for host structure arrays in ILE RPG
applications that use SQL
For device files, if INDARA was not specified and the file contains indicators, the declaration is not used
as a host structure array. The indicator area is included in the structure that is generated and would cause
the storage to be separated.
If OPTION(*NOCVTDT) is specified and the date and time format and separator of date and time field
definitions within the file are not the same as the DATFMT, DATSEP, TIMFMT, and TIMSEP parameters on
the CRTSQLRPGI command, then the host structure array is not usable.
The following table can be used to determine the RPG data type that is equivalent to a given SQL data
type.
INTEGER Free-form:
• INT(10)
• BINDEC(n) where 5 <= n <= 9
Fixed-form:
• Definition specification. I in
position 40, length must be 10
and 0 in position 42.
• Definition specification. B in
position 40, length must be ≤ 9
and ≥ 5 and 0 in position 42.
BOOLEAN Free-form:
• IND
Fixed-form:
• Definition specification with a N in
position 40.
• Input field defined with N in
position 36.
Example: Using indicator variables in ILE RPG applications that use SQL
Here is an example of declaring indicator variables in ILE RPG.
Given the statement:
Example: SQLDA for a multiple row-area fetch in ILE RPG applications that
use SQL
Here is an example of the SQL descriptor area (SQLDA) for a multiple row-area fetch in ILE RPG.
//**************************************************
//* Declare program variables. *
//* STMT initialized to the *
//* listed SQL statement. *
//**************************************************
DCL-S EMPNUM CHAR(6);
DCL-S NAME CHAR(15);
DCL-S STMT CHAR(500)
INZ('SELECT LASTNAME FROM CORPDATA.EMPLOYEE +
WHERE EMPNO = ?');
...
//*************************************************************
//* Prepare STMT as initialized in declare section *
//*************************************************************
EXEC SQL PREPARE S1 FROM :STMT;
//*************************************
//* Declare Cursor for STMT *
//*************************************
EXEC SQL DECLARE C1 CURSOR FOR S1;
//*****************************************************
//* Assign employee number to use in select statement *
//*****************************************************
EMPNUM = '000110';
//**********************
//* Open Cursor *
//**********************
EXEC SQL OPEN C1 USING :EMPNUM;
//***********************************************
//* Fetch record and put value of *
//* LASTNAME into NAME *
//***********************************************
EXEC SQL FETCH C1 INTO :NAME;
//********************************
//* Program processes NAME here *
//********************************
...
//******************
EXECSQL “COMMIT”
is equivalent to:
rexxvar = “COMMIT”
EXECSQL rexxvar
The command follows normal REXX rules. For example, it can optionally be followed by a semicolon (;) to
allow a single line to contain more than one REXX statement. REXX also permits command names to be
included within single quotation marks, for example:
'EXECSQL COMMIT'
The following SQL statements are not supported by the SQL/REXX interface:
a = 1
b = 2
EXECSQL 'OPEN c1 USING :x.a.b'
Determining data types of input host variables in REXX applications that use
SQL
All data in REXX is in the form of strings.
The data type of input host variables (that is, host variables used in a 'USING host variable' clause in an
EXECUTE or OPEN statement) is inferred by the database manager at run time from the contents of the
variable according to the table below.
These rules define either numeric, character, or graphic values. A numeric value can be used as input to
a numeric column of any type. A character value can be used as input to a character column of any type,
or to a date, time, or timestamp column. A graphic value can be used as input to a graphic column of any
type.
A string with a leading and trailing single Varying-length graphic 464/465 VARGRAPHIC(n)
quotation mark (') or quotation marks (") string
preceded by: 1
• A string that starts with a G, g, N, or
n. This is followed by a single quotation
mark or a quotation mark and a shift-out
(x'0E') character. This is followed by n
graphic characters, each 2 characters long.
The string must end with a shift-in (X'0F')
character and a single quotation mark or
a quotation mark (whichever the string
started with).
• A string with a leading GX, Gx, gX, or gx,
followed by a single quotation mark or
a quotation mark and a shift-out (x'0E')
character. This is followed by n graphic
characters, each 2 characters long. The
string must end with a shift-in (X'0F')
character and a single quotation mark or
a quotation mark (whichever the string
started with). The string has a length of 4n
after removing the GX and the delimiters.
Each remaining group of 4 characters is
the hexadecimal representation of a single
graphic character.
Undefined Variable Variable for which a None Data that is not valid
value has not been was detected.
assigned
1The byte immediately following the leading single quotation mark is a X'0E' shift-out character, and the byte
immediately preceding the trailing single quotation mark is a X'0F' shift-in character.
stringvar = '100'
causes REXX to set the variable stringvar to the string of characters 100 (without the single quotation
marks). This is evaluated by the SQL/REXX interface as the number 100, and it is passed to SQL as such.
On the other hand,
stringvar = “'“100”'”
causes REXX to set the variable stringvar to the string of characters '100' (with the single quotation
marks). This is evaluated by the SQL/REXX interface as the string 100, and it is passed to SQL as such.
Listing
The output listing is sent to the printer file that is specified by the PRTFILE parameter of the CRTSQLxxx
command.
The following items are written to the printer file:
• Precompiler options
Options specified in the CRTSQLxxx command.
• Precompiler source
This output supplies precompiler source statements with the record numbers that are assigned by the
precompiler, if the listing option is in effect.
• Precompiler cross-reference
If *XREF was specified in the OPTION parameter, this output supplies a cross-reference listing. The
listing shows the precompiler record numbers of SQL statements that contain the referred to host
names and column names.
• Precompiler diagnostics
This output supplies diagnostic messages, showing the precompiler record numbers of statements in
error.
The output to the printer file will use a CCSID value of 65535. The data will not be converted when it is
written to the printer file.
xxxxST1 VxRxMx yymmdd Create SQL COBOL Program CBLTEST1 08/06/07 11:14:21 Page 1
Source type...............COBOL
Program name..............CORPDATA/CBLTEST1
Source file...............CORPDATA/SRC
Member....................CBLTEST1
To source file............QTEMP/QSQLTEMP
(1)Options...................*SRC *XREF *SQL
Target release............VxRxMx
INCLUDE file..............*SRCFILE
Commit....................*CHG
Allow copy of data........*YES
Close SQL cursor..........*ENDPGM
Allow blocking............*READ
Delay PREPARE.............*NO
Generation level..........10
Printer file..............*LIBL/QSYSPRT
Date format...............*JOB
Date separator............*JOB
Time format...............*HMS
Time separator ...........*JOB
Replace...................*YES
Relational database.......*LOCAL
User .....................*CURRENT
RDB connect method........*DUW
Default collection........*NONE
Dynamic default
collection..............*NO
Package name..............*PGMLIB/*PGM
Path......................*NAMING
SQL rules.................*DB2
User profile..............*NAMING
Dynamic user profile......*USER
Sort sequence.............*JOB
Language ID...............*JOB
IBM SQL flagging..........*NOFLAG
ANS flagging..............*NONE
Text......................*SRCMBRTXT
Source file CCSID.........65535
Job CCSID.................65535
Decimal result options:
Maximum precision.......31
Maximum scale...........31
Minimum divide scale....0
DECFLOAT rounding mode....*HALFEVEN
Compiler options..........*NONE
(2) Source member changed on 06/06/00 10:16:44
1
A list of the options you specified when the SQL precompiler was called.
2
The date the source member was last changed.
Figure 2. Sample COBOL precompiler output format
1
Record number assigned by the precompiler when it reads the source record. Record numbers are used to identify the source record in
error messages and SQL run-time processing.
2
Sequence number taken from the source record. The sequence number is the number seen when you use the source entry utility (SEU)
to edit the source member.
3
Date when the source record was last changed. If Last Change is blank, it indicates that the record has not been changed since it was
created.
1
Data names are the symbolic names used in source statements.
2
The define column specifies the line number at which the name is defined. The line number is
generated by the SQL precompiler. **** means that the object was not defined or the precompiler did
not recognize the declarations.
3
The reference column contains two types of information:
• The definition of the symbolic name (4)
• The line numbers where the symbolic name occurs (5)
If the symbolic name refers to a valid host variable, the data-type (6) or data-structure (7) is also
noted.
CALL pgm-name
xxxxST1 VxRxMx yymmdd Create SQL ILE C Object CEX 08/06/07 15:52:26
Page 1
Source type...............C
Object name...............CORPDATA/CEX
Source file...............CORPDATA/SRC
Member....................CEX
To source file............QTEMP/QSQLTEMP
Options...................*XREF
Listing option............*PRINT
Target release............VxRxMx
INCLUDE file..............*SRCFILE
Commit....................*CHG
Allow copy of data........*YES
Close SQL cursor..........*ENDACTGRP
Allow blocking............*READ
Delay PREPARE.............*NO
Generation level..........10
Margins...................*SRCFILE
Printer file..............*LIBL/QSYSPRT
Date format...............*JOB
Date separator............*JOB
Time format...............*HMS
Time separator ...........*JOB
Replace...................*YES
Relational database.......*LOCAL
User .....................*CURRENT
RDB connect method........*DUW
Default collection........*NONE
Dynamic default
collection..............*NO
Package name..............*OBJLIB/*OBJ
Path......................*NAMING
SQL rules.................*DB2
Created object type.......*PGM
Debugging view............*NONE
User profile..............*NAMING
Dynamic user profile......*USER
Sort sequence.............*JOB
Language ID...............*JOB
IBM SQL flagging..........*NOFLAG
ANS flagging..............*NONE
Text......................*SRCMBRTXT
Source file CCSID.........65535
Job CCSID.................65535
Decimal result options:
Maximum precision.......31
Maximum scale...........31
Minimum divide scale....0
DECFLOAT rounding mode....*HALFEVEN
Compiler options..........*NONE
Source member changed on 06/06/00 17:15:17
CROSS REFERENCE
Data Names Define Reference
commission 19 FLOAT(24)
54 75
done1 **** LABEL
81
done2 **** LABEL
126
employee_count 40 SMALL INTEGER PRECISION(4,0) IN rpt2
empno 31 VARCHAR(7) IN rpt1
85
name 32 VARCHAR(30) IN rpt1
86
percentage 20 FLOAT(24)
53
project_name 39 VARCHAR(37) IN rpt2
projno 38 VARCHAR(7) IN rpt2
raise_date 21 VARCHAR(12)
119
report_error **** LABEL
59
rpt1 34
rpt2 42 STRUCTURE
130
salary 33 FLOAT(24) IN rpt1
86
total_proj_cost 41 FLOAT(53) IN rpt2
update_error **** LABEL
50
work_days 18 SMALL INTEGER PRECISION(4,0)
115
ACTNO 74 SMALL INTEGER PRECISION(4,0) COLUMN (NOT NULL) IN
CORPDATA.EMPPROJACT
BIRTHDATE 74 DATE(10) COLUMN IN CORPDATA.EMPLOYEE
BONUS 74 DECIMAL(9,2) COLUMN IN CORPDATA.EMPLOYEE
COMM **** COLUMN
54 75
COMM 74 DECIMAL(9,2) COLUMN IN CORPDATA.EMPLOYEE
CORPDATA **** SCHEMA
52 74 74 116 116 116
C1 71 CURSOR
78 85 95
C2 112 CURSOR
123 130 139
DEPTNO 27 VARCHAR(3) IN Proj_struct
DEPTNO 116 CHARACTER(3) COLUMN (NOT NULL) IN CORPDATA.PROJECT
EDLEVEL 74 SMALL INTEGER PRECISION(4,0) COLUMN (NOT NULL) IN
CORPDATA.EMPLOYEE
EMENDATE 74 DATE(10) COLUMN IN CORPDATA.EMPPROJACT
EMENDATE **** COLUMN
114
EMPLOYEE **** TABLE IN CORPDATA
52 74 116
EMPLOYEE **** TABLE
75 118
EMPNO **** COLUMN IN EMPPROJACT
72 75 76 118
EMPNO **** COLUMN IN EMPLOYEE
75 118
EMPNO 74 CHARACTER(6) COLUMN (NOT NULL) IN CORPDATA.EMPPROJACT
EMPNO 74 CHARACTER(6) COLUMN (NOT NULL) IN CORPDATA.EMPLOYEE
EMPPROJACT **** TABLE
72 75 113 117 118 120
EMPPROJACT **** TABLE IN CORPDATA
74 116
Related concepts
Coding SQL statements in C and C++ applications
To embed SQL statements in an ILE C or C++ program, you need to be aware of some unique application
and coding requirements. This topic also defines the requirements for host structures and host variables.
Related concepts
Coding SQL statements in COBOL applications
There are unique application and coding requirements for embedding SQL statements in a COBOL
program. In this topic, requirements for host structures and host variables are defined.
1 /* A sample program that updates the salaries for those employees */ 100
2 /* whose current commission total is greater than or equal to the */ 200
3 /* value of COMMISSION. The salaries of those who qualify are */ 300
4 /* increased by the value of PERCENTAGE, retroactive to RAISE_DATE. */ 400
5 /* A report is generated showing the projects that these employees */ 500
6 /* have contributed to, ordered by project number and employee ID. */ 600
7 /* A second report shows each project having an end date occurring */ 700
8 /* after RAISE_DATE (that is, those projects potentially affected */ 800
9 /* by the retroactive raises) with its total salary expenses and a */ 900
10 /* count of employees who contributed to the project. */ 1000
11 /*********************************************************************/ 1100
12 1200
13 1300
14 PLIEX: PROC; 1400
15 1500
16 DCL RAISE_DATE CHAR(10); 1600
17 DCL WORK_DAYS FIXED BIN(15); 1700
18 DCL COMMISSION FIXED DECIMAL(8,2); 1800
19 DCL PERCENTAGE FIXED DECIMAL(5,2); 1900
20 2000
21 /* File declaration for sysprint */ 2100
22 DCL SYSPRINT FILE EXTERNAL OUTPUT STREAM PRINT; 2200
23 2300
24 /* Structure for report 1 */ 2400
25 DCL 1 RPT1, 2500
26 1%INCLUDE PROJECT (PROJECT, RECORD,,COMMA); 2600
27 15 EMPNO CHAR(6), 2700
28 15 NAME CHAR(30), 2800
29 15 SALARY FIXED DECIMAL(8,2); 2900
30 3000
31 /* Structure for report 2 */ 3100
32 DCL 1 RPT2, 3200
33 15 PROJNO CHAR(6), 3300
34 15 PROJECT_NAME CHAR(36), 3400
35 15 EMPLOYEE_COUNT FIXED BIN(15), 3500
36 15 TOTL_PROJ_COST FIXED DECIMAL(10,2); 3600
37 3700
38 2 EXEC SQL INCLUDE SQLCA; 3800
39 3900
40 COMMISSION = 2000.00; 4000
41 PERCENTAGE = 1.04; 4100
42 RAISE_DATE = '1982-06-01'; 4200
43 WORK_DAYS = 253; 4300
44 OPEN FILE(SYSPRINT); 4400
45 4500
46 /* Update the selected employees' salaries by the new percentage. */ 4600
47 /* If an error occurs during the update, roll back the changes. */ 4700
48 3 EXEC SQL WHENEVER SQLERROR GO TO UPDATE_ERROR; 4800
49 4 EXEC SQL 4900
50 UPDATE CORPDATA/EMPLOYEE 5000
51 SET SALARY = SALARY * :PERCENTAGE 5100
52 WHERE COMM >= :COMMISSION ; 5200
53 5300
54 /* Commit changes */ 5400
55 5 EXEC SQL 5500
56 COMMIT; 5600
57 EXEC SQL WHENEVER SQLERROR GO TO REPORT_ERROR; 5700
58 5800
Related concepts
Coding SQL statements in PL/I applications
There are some unique application and coding requirements for embedding SQL statements in a PL/I
program. In this topic, requirements for host structures and host variables are defined.
Related concepts
Coding SQL statements in RPG/400 applications
The RPG/400 licensed program supports both RPG II and RPG III programs.
Related concepts
Coding SQL statements in ILE RPG applications
You need to be aware of the unique application and coding requirements for embedding SQL statements
in an ILE RPG program. In this topic, the coding requirements for host variables are defined.
Related concepts
Coding SQL statements in REXX applications
REXX procedures do not have to be preprocessed. At run time, the REXX interpreter passes statements
that it does not understand to the current active command environment for processing.
Manuals
• ILE RPG Programmer's Guide
• ILE RPG Reference
• ILE COBOL Programmer's Guide
• ILE COBOL Reference
• REXX/400 Programmer's Guide
• REXX/400 Reference
• DB2 for i SQL reference
The following manuals are not included in the IBM i Information Center. However, these manuals might be
a useful reference to you. Each of the manuals is available from the IBM Publications Center as a printed
hardcopy that you can order, in an online format that you can download at no charge, or both.
• COBOL/400 User's Guide (about 5,980 KB)
• COBOL/400 Reference (about 2,150 KB)
Other information
You can view or download these related topics:
• Database performance and query optimization
• SQL call level interface
• SQL messages and codes
• SQL programming
Related reference
PDF file for Embedded SQL programming
You can view and print a PDF file of this information.
For license inquiries regarding double-byte (DBCS) information, contact the IBM Intellectual Property
Department in your country or send inquiries, in writing, to:
The following paragraph does not apply to the United Kingdom or any other country where such
provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION
PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR
IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of
express or implied warranties in certain transactions, therefore, this statement may not apply to you.
This information could include technical inaccuracies or typographical errors. Changes are periodically
made to the information herein; these changes will be incorporated in new editions of the publication.
IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this
publication at any time without notice.
Any references in this information to non-IBM Web sites are provided for convenience only and do not in
any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of
the materials for this IBM product and use of those Web sites is at your own risk.
IBM may use or distribute any of the information you supply in any way it believes appropriate without
incurring any obligation to you.
Licensees of this program who wish to have information about it for the purpose of enabling: (i) the
exchange of information between independently created programs and other programs (including this
one) and (ii) the mutual use of the information which has been exchanged, should contact:
IBM Corporation
Software Interoperability Coordinator, Department YBWA
2800 37th Street NW
Rochester, MN 55901-4441
U.S.A.
Trademarks
IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business
Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be
trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at
"Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml.
Adobe, the Adobe logo, PostScript, and the PostScript logo are either registered trademarks or
trademarks of Adobe Systems Incorporated in the United States, and/or other countries.
200 Notices
Other product and service names might be trademarks of IBM or other companies.
Notices 201
202 IBM i: Embedded SQL programming
IBM®