SQL Programming Manual for TAL

NonStop SQL Statements and Directives
HP NonStop SQL Programming Manual for TAL527887-001
3-24
INVOKE
To use the structure template in your program, declare an instance of the structure.
This example declares a structure named EMPLOYEE that has the layout of the
structure template EMPLOYEE^TYPE:
STRUCT .employee (employee^type);
You must qualify the host variables defined by INVOKE (for example,
EMPLOYEE.EMP^ID).
You cannot reference a structure name by itself as a host identifier. The only
exceptions are structures that conform to the definition of SQL type VARCHAR, and
the SQLDA structure.
Using VARCHAR Data Types
An SQL VARCHAR column corresponds to a single logical data element; however, for
TAL correspondence, a VARCHAR column is converted to a structure with two
elementary data items. The group item name is derived from the VARCHAR column
name. The data names of the subordinate data items are LEN, a numeric field for the
current length, and VAL, a fixed-length character field for the string. For example, a
column CUSTNAME defined as VARCHAR(26) is described with this structure
template:
STRUCT custname(*);
BEGIN
INT len;
STRING val[0:25];
END;
Using Scaled Data Types
When you invoke a column with a scaled numeric type, the SQL compiler generates a
comment that gives the scale of the column being declared. For example, if PRICE
with data type NUMERIC (8,2) is invoked in TAL, INVOKE generates this:
INT(32) price; ! scale is 2
To communicate a scale factor to SQL, either change the host variable price to TAL
data type FIXED(2), which is a larger number but allows you to represent the scale, or
use the SQL SETSCALE function.
Using Date-Time and INTERVAL Data Types
When you invoke a column with a date-time (DATETIME, DATE, TIME, or
TIMESTAMP) or INTERVAL data type, the data is represented as a character field. The
size of the field is determined by the range of the date-time or INTERVAL column. You
control the display format by inserting the value in the format you want and retrieving
the value using the DATEFORMAT function. If you use INVOKE to generate host
variables from an SQL table definition, you can specify the DATEFORMAT clause to
determine the size.