Using Program Variables

As a 4GL query is handled via the bshell, you can directly relate program variables to it. Linking program variables is required for both the SELECT clause and the WHERE clause.
SELECT clause
In the <select list> of the SELECT clause, program variables are used to indicate the elements in which the query results must be stored. You can do this by explicitly specifying a program variable. The general syntax is:
<select part>:<program variable>

For example:
SELECT ppmod123.field1:my_val1
Or you can directly use a program variable (a table or field name) from the calling program in the <select list>. For example:
SELECT ppmod123.field1
In the first example, the program places the result in the <program variable>. In the second example, the name in the query and the name of the program variable are identical.

FROM clause
You can also use program variables in the WHERE clause. When evaluating the query, the program loads the values of the program variables into the query and includes them in the evaluation. This link can be realized by incorporating a program variable in the query, preceded by a colon [:]. For example:
WHERE ppmod123.field1 = :myval1
A table field can be a program variable as well as a query variable. Note that the following query:
select tccom010.*
where tccom010.cuno = tccom010.cuno
has a different result from:
select tccom010.*
where tccom010.cuno = :tccom010.cuno
The latter selects one record; the former selects all records from the table tccom010, as tccom010.cuno by definition equals tccom010.cuno for each row.

Related Post:

People who read this post also read :


Post a Comment


Twitter Delicious Facebook Digg Stumbleupon Favorites More