LOB host variables in COBOL applications that use SQL

COBOL does not have variables that correspond to the SQL data types for LOBs (large objects). 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.

LOB host variables are only supported in ILE COBOL for iSeries™.

LOB host variables

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

            .-IS-.                                                       
   .-USAGE--+----+-.                                                     
>--+---------------+--SQL TYPE IS--+-CLOB---+--(--lob-length--+---+--)-->
                                   +-DBCLOB-+                 +-K-+      
                                   '-BLOB---'                 '-M-'      

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

Notes:
  1. For BLOB and CLOB, 1 ≤ lob-length ≤ 15,728,640
  2. For DBCLOB, 1 ≤ lob-length ≤ 7,864,320
  3. SQL TYPE IS, BLOB, CLOB, DBCLOB can be in mixed case.

CLOB Example

The following declaration:

01 MY-CLOB SQL TYPE IS CLOB(16384).

Results in the generation of the following structure:

01 MY-CLOB.
   49 MY-CLOB-LENGTH PIC 9(9) BINARY.
   49 MY-CLOB-DATA PIC X(16384).

DBCLOB Example

The following declaration:

01 MY-DBCLOB SQL TYPE IS DBCLOB(8192).

Results in the generation of the following structure:

01 MY-DBCLOB.
   49 MY-DBCLOB-LENGTH PIC 9(9) BINARY.
   49 MY-DBCLOB-DATA PIC G(8192) DISPLAY-1.

BLOB Example

The following declaration:

01 MY-BLOB SQL TYPE IS BLOB(16384).

Results in the generation of the following structure:

01 MY-BLOB.
   49 MY-BLOB-LENGTH PIC 9(9) BINARY.
   49 MY-BLOB-DATA PIC X(16384).

LOB Locator

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

            .-IS-.                                           
   .-USAGE--+----+-.                                         
>--+---------------+--SQL TYPE IS--+-CLOB-LOCATOR---+-- . -----><
                                   +-DBCLOB-LOCATOR-+        
                                   '-BLOB-LOCATOR---'        

Notes:
  1. SQL TYPE IS, BLOB-LOCATOR, CLOB-LOCATOR, DBCLOB-LOCATOR can be in mixed case.
  2. LOB Locators cannot be initialized in the SQL TYPE IS statement.

CLOB and DBCLOB locators have similar syntax.

BLOB Locator Example

The following declaration:

01 MY-LOCATOR SQL TYPE IS BLOB_LOCATOR.

Results in the following generation:

01 MY-LOCATOR PIC 9(9) BINARY.

LOB File Reference Variable

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

            .-IS-.                                        
   .-USAGE--+----+-.                                      
>--+---------------+--SQL TYPE IS--+-CLOB-FILE---+-- . --------><
                                   +-DBCLOB-FILE-+        
                                   '-BLOB-FILE---'        

Note: SQL TYPE IS, BLOB-FILE, CLOB-FILE, DBCLOB-FILE can be in mixed case.

BLOB File Reference Example

The following declaration:

01 MY-FILE SQL TYPE IS BLOB-FILE.

Results in the generation of the following structure:

01 MY-FILE.
   49 MY-FILE-NAME-LENGTH PIC S9(9) COMP-5.
   49 MY-FILE-DATA-LENGTH PIC S9(9) COMP-5.
   49 MY-FILE-FILE-OPTIONS PIC S9(9) COMP-5.
   49 MY-FILE-NAME PIC X(255).

CLOB and DBCLOB file reference variables have similar syntax.

The pre-compiler will generate declarations for the following file option constants. You can use these constants to set the xxx-FILE-OPTIONS variable when you use File Reference host variables.

Related information
LOB file reference variables