Previous Topic

Next Topic

ESQL Declare Statements

The ESQL precompiler is used to parse and translate ESQL constructs, prefixed with EXEC SQL, to C language statements. ESQL does not allow the use of host language defined variables in ESQL constructs. To declare variables for use in the ESQL constructs, ESQL provides declare statements. The ESQL constructs within which the variables can be declared for use in ESQL statements are referred to as the declare section. For more information on the declare section, see "BEGIN-END DECLARE SECTION". The following ESQL constructs are used to mark the beginning and end of a declare section:

EXEC SQL BEGIN DECLARE SECTION ;
...
EXEC SQL END DECLARE SECTION ;

The declare section should appear before any other ESQL constructs are used. Only C statements can precede the declare section in an ESQL program. The variables appearing in the declare section can either be declared as local variables or global variables. The following is an example showing the declaration for variables that would be used in the order processing application program:

 ...

 EXEC SQL BEGIN DECLARE SECTION ;

long order_no_v ;
char order_date_v [10] ;  
char product_v [5] ;
long qty_v ;

 EXEC SQL END DECLARE SECTION ;

 ...

The above ESQL constructs declare the variable order_no_v to be of type long, product_v to be an array of char and qty_v to be a variable of type long. The ESQL precompiler generates the corresponding host language declarations for these variables and hence these variables can be used by the C language statements at the application developer’s convenience.

The variables that could be declared in the declare section are host variables and indicator variables. These variables and their usage are discussed in more detail in the following sections.

Note: The ESQL precompiler does not check for or generate messages about unused variables in the declare section.