SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Host Variables in COBOL Programs
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
4-12
Variable-Length Character Data
Variable-Length Character Data
Use a group item with two data items to declare a host variable for variable length
character data (SQL VARCHAR data type) as:
nn group-name.
mm LEN PIC S9(4) COMP.
mm VAL PIC X(len).
The group-name must follow COBOL naming conventions. The level numbers are
indicated by nn and mm. The level number nn can be any level in the range 01 to 49,
and mm is a greater level than nn. LEN specifies the actual length of the character item
in VAL. VAL is a character data item with len specifying the maximum number of
characters that can be stored in VAL.
Example
The EMPLOYEE table has the LAST_NAME column defined as VARCHAR(20). In a
COBOL program, this column is specified as:
05 HV-LAST-NAME.
10 LEN PIC S9(4) COMP.
10 VAL PIC X(20).
In the Procedure Division, you must explicitly move a value to LEN before using HV-
LAST-NAME in an SQL statement:
...
MOVE "SMITH" TO VAL OF HV-LAST-NAME.
MOVE 5 to LEN OF HV-LAST-NAME.
EXEC SQL UPDATE persnl.employee
SET last_name = :HV-LAST-NAME
WHERE empnum = :HV-EMPNUM
END-EXEC.
Numeric Data
Use this PICTURE DISPLAY clause to declare a host variable for the SQL DECIMAL
and PICTURE 9’s DISPLAY data types:
PICTURE [S] { 9(integer) [V9(scale)] | V9(scale) }
[USAGE [IS]] DISPLAY [SIGN [IS] LEADING SEPARATE [CHARACTER]]
Use this PICTURE COMP or PICTURE BINARY clause to declare a host variable for
the SQL NUMERIC, PICTURE 9’s COMP, SMALLINT, LARGEINT, and INTEGER
data types:
PICTURE [S] { 9(integer) [V9(scale)] | V9(scale) }
[USAGE [IS]] { COMP[UTATIONAL] | COMP | BINARY }
COBOL