SQL/MP Programming Manual for COBOL

Host Variables
HP NonStop SQL/MP Programming Manual for COBOL529758-003
2-26
Treatment in COBOL Statements
COBOL-clause
is a COBOL clause such as VALUE or USAGE. For a description of the
COBOL clauses, see the COBOL85 for NonStop Systems Manual.
Treatment in COBOL Statements
A COBOL statement treats a host variable declared with the CHARACTER SET clause
as if the host variable had been declared without the clause. The total length of the
host variable is the length in the PICTURE clause multiplied by the number of bytes
per character for the specified character set.
For example, the total length of the first two declarations in this table is the same as
the length in the PICTURE clause. However, the total length of the third declaration is
twice the length in the PICTURE clause because KANJI is a double-byte character set.
VARCHAR Data Type
If you specify the CHARACTER SET clause with a host variable declared as a
VARCHAR data type, you must set the length data item (LEN) of the VARCHAR group
item to the host variable length in bytes and not characters. For example, this host
variable declaration uses the double-byte KSC5601 character set. The MOVE
statement sets the length (LEN OF EMPLOYEE-NAME) of the host variable name to
16, because the name (VAL OF EMPLOYEE-NAME) contains 8 double-byte
characters (represented as “c1c2c3c4c5c6c7c8”).
DATA DIVISION.
WORKING-STORAGE SECTION.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 EMPLOYEE-NAME.
02 LEN PIC S9(4) COMP.
02 VAL CHARACTER SET "KSC5601" PIC X(10).
EXEC SQL END DECLARE SECTION END-EXEC.
...
PROCEDURE-DIVISION.
...
MOVE "c1c2c3c4c5c6c7c8" TO VAL OF EMPLOYEE-NAME.
MOVE 16 TO LEN OF EMPLOYEE-NAME.
EXEC SQL
INSERT INTO EMPLOYEE VALUES (:EMPLOYEE-NAME)
END-EXEC.
...
Host Variable Declaration Treatment in COBOL Statement
77 HVAR-1 CHARACTER SET "ISO88591"
PIC X(5).
77 HVAR-1 PIC X(5).
77 HVAR-1 CHARACTER SET "ISO88591"
PIC X(10).
77 HVAR-1 PIC X(10).
77 HVAR-2 CHARACTER SET "KANJI"
PIC X(10).
77 HVAR-2 PIC X(20).