Requirements for PL/I Host Variables - Preprocessor2 for Embedded SQL

Teradata Preprocessor2 for Embedded SQL Programmer Guide

Product
Preprocessor2 for Embedded SQL
Release Number
15.10
Language
English (United States)
Last Update
2018-10-07
dita:id
B035-2446
lifecycle
previous
Product Category
Teradata Tools and Utilities
  • Any valid PL/I host variable can be used in a SQL statement. This does not mean that all variables are valid, however. Host variables must meet certain requirements before PP2 can accept them as usable in SQL statements. See “Host Variable Declaration” on page 197.
  • Any valid PL/I variable name can be used as a host variable name, including names with embedded underscores ( _ ). Variable names must be unique within an application, even if they are within different blocks or procedures. PP2 does not recognize the PL/I scope concept rules and thus uses the first variable definition it encounters. A warning is issued when the same variable name is used more than once, if it cannot be qualified by a structure name.
  • If a base level variable is declared and the name is also declared in a structure, but the referenced field is not qualified, the precompiler uses the base level variable declaration.
  • With the following structure:

    DCL   FIELD1   CHAR(6);
    DCL   01 STRUCTURE1,
             02 FIELD1    CHAR(10),
             02 FIELD2    CHAR(3);
    EXEC SQL
          SELECT FIELDA
          INTO :FIELD1
          FROM TABLE1
          WHERE FIELDB = ’ABC’;

    The precompiler uses the address and definition of FIELD1, length 6, to receive the data. Qualify the reference to FIELD1 in the SELECT to STRUCTURE1.FIELD1 if that is the intended field. This is the only instance where the duplicate field name is not considered ambiguous. The order of declaration makes no difference as to the variable used.

  • Host variables that are not SQL strings can represent data values only. Do not use them to represent database, table, view, macro or column names.
  • Specify host variable attributes in any order that is acceptable to the PL/I compiler. Legal PL/I abbreviations can be used for attributes in the attribute specifications.
  • A host variable reference in a SQL statement must be within the scope of the variable. PP2 does not enforce this rule because no scope checking is performed. At compilation and execution time, however, if the reference is not within the scope, unexpected results can occur.
  • Begin each host variable declaration with the keyword DECLARE or DCL. Exceptions are structure definitions where subsequent variables are a part of the structure, or in specifying multiple variables with a single declare (that is, DCL VAR1 CHAR(6), VAR2 CHAR(3);).
  • The only arrays recognized by PP2 are indicator arrays.
  • Host variables can be AUTOMATIC, BASED, CONTROLLED or STATIC.
  • PICTURE clauses are not considered valid definitions for variables used in SQL statements.
  • Host variables having the same attributes can be declared using a list format (that is, DCL (VAR1,VAR2,VAR3) CHAR(6) ; ).
  • The DEFINES clause is valid for a variable declaration only if:
  • The variable is an 01 level
  • The variable name is valid
  • The variable definition is valid (that is, the PIC clause)
  • The variable is not an array