Using program variables in static SQL
Static SQL syntax supports the usage of program variables as SQL parameters.
Using program variables directly in static SQL
statements gives a better understanding of the source code and requires less lines as when using SQL
parameters in dynamic SQL
statements.
MAIN
DEFINE c_num INTEGER
DEFINE c_name CHAR(10)
DATABASE stock
SELECT cust_name INTO c_name FROM customer WHERE cust_num = c_num
END MAIN
If a database column name conflicts with a program variable, you can use the
@
sign as the column prefix. The compiler will treat the identifier following the @
as a table
column:MAIN
DEFINE cust_name CHAR(10)
DEFINE cnt INTEGER
DATABASE stock
SELECT COUNT(*) INTO cnt FROM customer WHERE @cust_name = cust_name
END MAIN
The @
sign will not figure in the resulting SQL statement stored in the
.42m compiled module.