CONSTRUCT

The CONSTRUCT statement stores in a character variable the 4GL Boolean expression that corresponds to the query by example that a user specifies. You can use this character variable as the WHERE clause of a SELECT statement.

4GLREF00000119.gif

number is a literal integer to specify a Help message number.

The CONSTRUCT statement is among the statements required to allow users to perform a query by example. Query by example lets a user query a database by specifying values or ranges of values for screen fields that correspond to database columns. 4GL converts these values into a Boolean expression that specifies search criteria in the WHERE clause of a SELECT statement.

The CONSTRUCT statement can also control the environment in which the user enters search criteria, and can restrict the values that the user enters.

To use the CONSTRUCT statement, you must do the following:

  1. Define fields linked to database columns in a form specification file.

  2. Declare a character variable with the DEFINE statement.

  3. Open and display the screen form with either of the following:

OPEN FORM and DISPLAY FORM statements.

OPEN WINDOW statement with a WITH FORM clause.

  1. Use the CONSTRUCT statement to store in the character variable a Boolean expression based on search criteria that the user enters in the fields.

The CONSTRUCT statement activates the current form. This is the form most recently displayed or, if you are using more than one 4GL window, the form currently displayed in the current window. You can specify the current window by using the CURRENT WINDOW statement. When the CONSTRUCT statement completes execution, the form is deactivated.

When it encounters the CONSTRUCT statement, 4GL does the following:

  1. Displays blank spaces in all the screen fields of the CONSTRUCT field list.

  2. Moves the screen cursor to the first screen field in that list.

  3. Waits for the user to enter some value as search criteria in the field. (For fields where the user enters no value, any value in the corresponding database column satisfies the search criteria.)

After the user presses the Accept key, CONSTRUCT uses AND operators to combine field values as search criteria in a Boolean expression, and stores this in a character variable.

By performing the following steps, you can use this variable in a WHERE clause to search the database for matching rows:

  1. Concatenate the character variable that contains the Boolean expression with one or more character strings to create the string representation of an SQL statement to be executed. (The Boolean expression generated by the CONSTRUCT statement is typically used to create SELECT statements.)

  2. Use the PREPARE statement to create an executable SQL statement from the character string that was generated in the previous step.

  3. Execute the prepared statement in one of the following ways:

Use an SQL cursor with DECLARE and FOREACH statements (or else OPEN and FETCH statements) to execute a prepared SELECT statement that includes no INTO clause.

Use the EXECUTE statement to execute other SQL statements.

Environment variables that format data values, such as DBTIME, DBFORMAT, or DBFLTMASK, have no effect on the contents of the Boolean expression.

The CONSTRUCT Variable Clause

The CONSTRUCT variable clause specifies a character variable to store search criteria, and one or more screen fields in which the user can enter search criteria for database columns. The CONSTRUCT variable clause has this syntax:

4GLREF00000120.gif

column is the name of some database column in table.

database is the name of the database in which the table resides.

owner is the user name of the owner of the table containing the column.

server is the name of the OnLine server. The @ symbol is required.

table is the name or synonym of a table or view in the specified database, or in the database referenced in the DATABASE statement that was most recently encountered before this CONSTRUCT statement.

The CONSTRUCT Form Management Blocks

Each CONSTRUCT Form Management block includes a statement block of at least one statement, and an activation clause that specifies when to execute the statement block. The activation clause and statement block correspond respectively to the left-hand and right-hand syntax elements in this diagram:

4GLREF00000121.gif

field is the name of a field either explicitly or implicitly referenced in the CONSTRUCT Variable clause.

key is one of the keywords to specify a key that are listed in the section "The ON KEY Blocks".

statement is an SQL or other 4GL statement.

References

DEFER

DISPLAY FORM

LET

OPEN FORM

OPEN WINDOW

OPTIONS