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

Read syntax diagramSkip visual syntax diagram0177variable-namePICTUREPICISpicture-string VALUEISvalue.

Variable length

Read syntax diagramSkip visual syntax diagram01variable-name .
Read syntax diagramSkip visual syntax diagram49identifier-1 PICTUREPICISS9(4)USAGEISCOMP-5COMPUTATIONAL-5VALUEISvalue.
Read syntax diagramSkip visual syntax diagram49identifier-2 PICTUREPICISpicture-string VALUEISvalue.
Character host variable consideration:
  1. Picture-string must have the form X(m). Alternatively, X's can be expanded (for example, "XXX" instead of "X(3)").
  2. m is from 1 to 254 for fixed-length strings.
  3. m is from 1 to 32 700 for variable-length strings.
  4. If m is greater than 32 672, the host variable will be treated as a LONG VARCHAR string, and its use might be restricted.
  5. Use X and 9 as the picture characters in any PICTURE clause. Other characters are not allowed.
  6. 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.
  7. In a CONNECT statement, such as the following example, COBOL character string host variables dbname and userid will 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, the p-word host 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.