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.

LOB host variables

Read syntax diagramSkip visual syntax diagram01variable-name USAGEIS SQL TYPE ISCLOBDBCLOBBLOB (lob-lengthKM)  . 
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 diagram01variable-name USAGEIS SQL TYPE ISCLOB-LOCATORDBCLOB-LOCATORBLOB-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 diagram01variable-name USAGEIS SQL TYPE ISCLOB-FILEDBCLOB-FILEBLOB-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 precompiler generates 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.

  • SQL_FILE_READ (2)
  • SQL_FILE_CREATE (8)
  • SQL_FILE_OVERWRITE (16)
  • SQL_FILE_APPEND (32)