Using the CONSTRUCT dialog
The CONSTRUCT
statement temporarily binds the specified form fields
to database columns. It allows you to identify database columns for which the user can enter
search criteria.
A basic CONSTRUCT
statement has the following format:
CONSTRUCT variable-name ON column-list FROM field-list
Each field and CONSTRUCT
corresponding column must be the same or compatible
data types. The field data types are defined in the form specification file, by using a
SCHEMA
clause, TABLES
section and tabname.colname
specification in the field definitions of the ATTRIBUTES
section.
You can use the BY NAME
clause when the fields on the screen form have the same
names as the corresponding columns in the ON
clause.
CONSTRUCT BY NAME variable-name ON column-list
The runtime system converts the entered criteria into a Boolean SQL condition that can appear in
the WHERE
clause of a SELECT
statement. The variable to hold the
query condition can be defined as a STRING
data type. The STRING
variable can be concatenated, using the double pipe operator (||), with the text required to form a
complete SQL SELECT
statement. The LET
statement can be used to
assign a value to the variable. For example:
DEFINE where_clause, sqltext STRING
CONSTRUCT BY NAME where_clause ON customer.*
LET sql_text = "SELECT COUNT(*) FROM customer WHERE " || where_clause
![This figure is a screenshot of user select criteria in the form used for query-by-example.](images/bdl_tut_ch4_query_by_ex_form.jpg)
In this example the user has entered the criteria ">101"
in the customer
number (cust_num
) field. The where_clause
value would be generated
as:
"cust_num > 101"
And the complete sql text would be:
"SELECT COUNT(*) FROM customer WHERE cust_num > 101"