Host-variables can be defined only in the WORKING-STORAGE SECTION of your DATA DIVISION. See Host Variables for rules on naming host-variables. Host-variable definitions:
|
Z |
$ (dollar sign) |
. (period) |
|
B |
* (asterisk) |
+ (plus sign) |
|
0 (zero) |
, (comma) |
- (minus sign) |
If the CA Datacom/DB Preprocessor encounters any host-variable which includes any of the above clauses, data types or symbols, it issues an error message and the variable is not stored in the host-variable symbol table.
The following sections describe ANSI and extended mode requirements for host-variables.
ANSI SQL Standard Host-Variable Definitions
If you specify in the CA Datacom/DB SQL Preprocessor options that all SQL statements must be ANSI standard, then all host-variables:
All host-variables do not have to be defined within the same SQL DECLARE section. However, any host-variable you define must appear in only one SQL DECLARE section. Host-variables defined in an ANSI SQL DECLARE section become standard COBOL variables after processing by the Preprocessor. The form of an ANSI SQL DECLARE section is:
EXEC SQL
BEGIN DECLARE SECTION
END-EXEC
host-variable definitions
EXEC SQL
END DECLARE SECTION
END-EXEC
ANSI Standard Host-Variable Data Types
The ANSI standard allowable data types are as follows:
|
SQL Data Type |
COBOL Definition |
|---|---|
|
CHARACTER or CHAR |
PIC X(n) |
|
NUMERIC |
PIC S9(n)V9(n) DISPLAY SIGN LEADING SEPARATE |
|
INTEGER or INT |
PIC S9(n) COMP |
Extended Mode SQL Host-Variable Definitions
Host-variables can appear outside an SQL DECLARE section if you specify in the CA Datacom/DB SQL Preprocessor options that SQL statements can include CA Datacom/DB extensions.
Non-ANSI Host-Variable Data Types
The non-ANSI standard allowable data types are as follows:
|
SQL Data Type |
COBOL Definition |
|---|---|
|
CHARACTER or CHAR |
PIC X(n) |
|
NUMERIC |
PIC 9(n)V9(n) DISPLAY or |
|
DECIMAL or DEC |
PIC 9(n)V9(n) COMP-3 or |
|
SMALLINT |
PIC S9(n) COMP or |
|
INTEGER or INT |
PIC S9(n) COMP or |
|
FLOAT |
USAGE COMP-2 |
|
REAL |
USAGE COMP-2 |
|
DOUBLE PRECISION |
USAGE COMP-2 |
Note: Variable-name-length and variable-name-text are user-defined names. The required level for these two VARCHAR elementary items is 49. The group level may be numbered 01 through 48.
|
SQL Data Type |
COBOL Definition |
|---|---|
|
VARCHAR (character) |
49 variable-name-length PIC S9(4) COMP 49 variable-name-text PIC X(n) |
|
LONG VARCHAR (character) |
49 variable-name-length PIC S9(4) COMP 49 variable-name-text PIC X(n) |
|
DATE |
PIC X(10) |
|
TIME |
PIC X(8) |
|
TIMESTAMP |
PIC X(26) |
|
GRAPHIC |
PIC G(n) USAGE DISPLAY-1 or PIC N(n) USAGE DISPLAY-1 |
|
VARGRAPHIC (character) |
49 variable-name-length PIC S9(4) COMP 49 variable-name-text PIC G(n) USAGE DISPLAY-1 or PIC N(n) USAGE DISPLAY-1 Note: Variable-name-length and variable-name-text are user-defined names. The required level for these two VARGRAPHIC elementary items is 49. The group level may be numbered 01 through 48. See GRAPHIC, VARGRAPHIC, and LONG VARGRAPHIC. |
|
LONG VARGRAPHIC (character) |
49 variable-name-length PIC S9(4) COMP 49 variable-name-text PIC G(n) USAGE DISPLAY-1 or PIC N(n) USAGE DISPLAY-1 Note: Variable-name-length and variable-name-text are user-defined names. The required level for these two LONG VARGRAPHIC elementary items is 49. The group level may be numbered 01 through 48. See GRAPHIC, VARGRAPHIC, and LONG VARGRAPHIC. |
Note: The lengths shown for DATEs, TIMEs, and TIMESTAMPs are minimum length requirements. See Character String Literals for more information.
The CA Datacom/DB Preprocessor for COBOL recognizes GRAPHIC host variables and allows mixed data in literals. The Shift-Out and Shift-In characters specified in the CXXMAINT option of the CA Datacom/DB Utility (DBUTLTY) are used by the Preprocessor. Support is provided for both the IBM COBOL and COBOL II compilers and the Fujitsu COBOL85 compiler, but only in COBOL can host-variable names include DBCS characters (delimited by Shift characters).
For more information about SQL data types, see Data Types.
|
Copyright © 2014 CA.
All rights reserved.
|
|