Declaration of fixed length and variable length character host variables in COBOL embedded SQL applications
Fixed-length and variable-length
character host variables that you declare in your embedded COBOL application
are treated as if they were declared in a COBOL program. You can use
host variables to exchange data between the embedded application and
the database manager.
The syntax for character host variables is:
Fixed Length
Variable length
Character host variable consideration:
- Picture-string must have the form X(m). Alternatively, X's can be expanded (for example, "XXX" instead of "X(3)").
- m is from 1 to 254 for fixed-length strings.
- m is from 1 to 32 700 for variable-length strings.
- If m is greater than 32 672, the host variable will be treated as a LONG VARCHAR string, and its use might be restricted.
- Use X and 9 as the picture characters in any PICTURE clause. Other characters are not allowed.
- Variable-length strings consist of a length item and a value item. You can use acceptable COBOL names for the length item and the string item. However, refer to the variable-length string by the collective name in SQL statements.
- In a CONNECT statement, such as the following example, COBOL character
string host variables
dbnameanduseridwill have any trailing blanks removed before processing:EXEC SQL CONNECT TO :dbname USER :userid USING :p-word END-EXEC.However, because blanks can be significant in passwords, thep-wordhost variable should be declared as a VARCHAR data item, so that your application can explicitly indicate the significant password length for the CONNECT statement as follows:EXEC SQL BEGIN DECLARE SECTION END-EXEC. 01 dbname PIC X(8). 01 userid PIC X(8). 01 p-word. 49 L PIC S9(4) COMP-5. 49 D PIC X(18). EXEC SQL END DECLARE SECTION END-EXEC. PROCEDURE DIVISION. MOVE "sample" TO dbname. MOVE "userid" TO userid. MOVE "password" TO D OF p-word. MOVE 8 TO L of p-word. EXEC SQL CONNECT TO :dbname USER :userid USING :p-word END-EXEC.
