The following steps describe how to implement the CONSTRUCT statement:
Declare a variable with the DEFINE statement,
it can be CHAR, VARCHAR or STRING.
Prefer STRING to avoid any size limitation.
Open and display the form, using an OPEN WINDOW
WITH FORM or the OPEN FORM / DISPLAY
FORM instructions.
Set the INT_FLAG variable to FALSE.
Define the CONSTRUCT block with the list
of form fields to be used for the query by example. If needed,
define dialog control blocks to implement rules for the query by
example.
Inside the CONSTRUCT statement, control
the behavior of the instruction with BEFORE CONSTRUCT, BEFORE
FIELD, AFTER FIELD, AFTER
CONSTRUCT and ON ACTION blocks.
After the interaction statement block, test the INT_FLAG predefined
variable to check if the dialog was canceled (INT_FLAG=TRUE)
or validated (INT_FLAG=FALSE). If
the INT_FLAG variable is TRUE, you
should reset it to FALSE to not disturb code
that relies on this variable to detect interruption events from
the GUI front-end or TUI console.
To build the complete SQL statement, concatenate "SELECT
... WHERE" to the string variable that contains the
boolean SQL expression produced by CONSTRUCT.
Define a database cursor with the DECLARE FROM instruction,
by using the SELECT statement.
Execute the cursor and fetch the rows found by the database
server. You can for example implement a FOREACH loop
to fill a program array, to be shown by a DISPLAY ARRAY statement.