Binary host variables in COBOL applications that use SQL

COBOL does not have variables that correspond to the SQL binary data types. To create host variables that can be used with these data types, use the SQL TYPE IS clause. The SQL precompiler replaces this declaration with a COBOL language structure in the output source member.

BINARY and VARBINARY

Read syntax diagramSkip visual syntax diagram
>>-01--variable-name-------------------------------------------->

            .-IS-.                                                    
   .-USAGE--+----+-.                                                  
>--+---------------+--SQL TYPE IS--+-BINARY---------+--(--length--)-->
                                   +-VARBINARY------+                 
                                   '-BINARY VARYING-'                 

>-- . ---------------------------------------------------------><

Notes:
  1. For BINARY host variables, the length must be in the range 1 to 32766.
  2. For VARBINARY host variables, the length must be in the range 1 to 32740.
  3. SQL TYPE IS, BINARY, VARBINARY, and BINARY VARYING can be in mixed case.

BINARY Example

The following declaration:

01 MY-BINARY SQL TYPE IS BINARY(200).

Results in the generation of the following code:

01 MY-BINARY PIC X(200).

VARBINARY Example

The following declaration:

01 MY-VARBINARY SQL TYPE IS VARBINARY(250).

Results in the generation of the following structure:

01 MY-VARBINARY.
	49 MY-VARBINARY-LENGTH PIC 9(5) BINARY.
	49 MY-VARBINARY-DATA PIC X(250).