Host variables in Fortran
In Fortran programs, you can specify numeric, character, LOB, and ROWID host variables. You can also specify result set and LOB locators.
Restrictions:
- Only some of the valid Fortran declarations are valid host variable declarations. If the declaration for a variable is not valid, any SQL statement that references the variable might result in the message UNDECLARED HOST VARIABLE.
- Fortran supports some data types with no SQL equivalent (for example, REAL*16 and COMPLEX). In most cases, you can use Fortran statements to convert between the unsupported data types and the data types that SQL allows.
- You can not use locators as column types. The following locator data types are Fortran data types and SQL data types:
- Result set locator
- LOB locators
- Because Fortran does not support graphic data types, Fortran applications can process only Unicode tables that use UTF-8 encoding.
Recommendations:
- Be careful of overflow. For example, if you retrieve an INTEGER column value into a INTEGER*2 host variable and the column value is larger than 32767 or -32768, you get an overflow warning or an error, depending on whether you provided an indicator variable.
- Be careful of truncation. For example, if you retrieve an 80-character CHAR column value into a CHARACTER*70 host variable, the rightmost ten characters of the retrieved string are truncated. Retrieving a double-precision floating-point or decimal column value into an INTEGER*4 host variable removes any fractional value.
Numeric host variables
The following diagram shows the syntax for declaring numeric host variables.
Restrictions:
- Fortran does not provide an equivalent for the decimal data type.
To hold a decimal value, use one of the following variables:
- An integer or floating-point variable, which converts the value. If you use an integer variable, you lose the fractional part of the number. If the decimal number can exceed the maximum value for an integer or you want to preserve a fractional value, use a floating-point variable. Floating-point numbers are approximations of real numbers. Therefore, when you assign a decimal number to a floating-point variable, the result might be different from the original number.
- A character string host variable. Use the CHAR function to retrieve a decimal value into it.
- The SQL data type DECFLOAT has no equivalent in Fortran.
Character host variables
The following diagram shows the syntax for declaring character host variables other than CLOBs.
Result set locators
The following diagram shows the syntax for declaring result set locators.
LOB variables and locators
The following diagram shows the syntax for declaring BLOB and CLOB host variables and locators.
ROWID host variables
The following diagram shows the syntax for declarations of ROWID variables.
Constants
The syntax for constants in Fortran programs differs from the syntax for constants in SQL statements in the following ways:
- Fortran interprets a string of digits with a decimal point to be a real constant. An SQL statement interprets such a string to be a decimal constant. Therefore, use exponent notation when specifying a real (that is, floating-point) constant in an SQL statement.
- In Fortran, a real (floating-point) constant that has a length of 8 bytes uses a D as the exponent indicator (for example, 3.14159D+04). An 8-byte floating-point constant in an SQL statement must use an E (for example, 3.14159E+04).