Declaring binary host variables in ILE RPG applications that use SQL

ILE RPG 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 SQLTYPE keyword. The SQL precompiler replaces this declaration with an ILE RPG language declaration in the output source member. Binary declarations can be either standalone or within a data structure.

BINARY example

  • The following declaration in free-form:
      DCL-S MYBINARY	SQLTYPE(BINARY:50);

    results in the generation of the following code:

      DCL-S MYBINARY CHAR(50) CCSID(*HEX);
  • The following declaration in fixed-form:
      D MYBINARY     S        SQLTYPE(BINARY:50)

    results in the generation of the following code:

      D MYBINARY     S        50A CCSID(*HEX)

VARBINARY example

  • The following declaration in free-form:
      DCL-S MYVARBINARY SQLTYPE(VARBINARY:100);

    results in the generation of the following code:

      DCL-S MYVARBINARY VARCHAR(100) CCSID(*HEX)
  • The following declaration in fixed-form:
      D MYVARBINARY   S        SQLTYPE(VARBINARY:100)

    results in the generation of the following code:

      D MYVARBINARY   S        100A VARYING CCSID(*HEX)
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. BINARY and VARBINARY host variables are allowed to be declared in host structures.
  4. SQLTYPE, BINARY, and VARBINARY can be in mixed case.
  5. SQLTYPE must be between positions 44 to 80 for fixed-form declarations.
  6. When a BINARY or VARBINARY is declared as a standalone host variable, position 24 must contain the character S and position 25 must be blank for fixed-form declarations.
  7. The standalone field indicator S in position 24 for fixed-form declarations should be omitted when a BINARY or VARBINARY host variable is declared in a host structure.