Summary:
See also: Variables, Records, Windows, Forms, Record Display, Display Array
The programs maintain data in variables and use the INPUT statement to bind variables to screen-records or screen-arrays of forms for data entry into form fields. The INPUT statement activates the current form (the form that was most recently displayed or the form in the current window):
During the INPUT statement execution, the user can edit the record fields, while the program controls the behavior of the instruction with control blocks:
To terminate the INPUT execution, the user can validate (or cancel) the dialog to commit (or invalidate) the modifications made in the record:
When the statement completes execution, the form is de-activated. After the user terminates the input (for example, with the Accept key), the program must test the INT_FLAG variable to check if the dialog was validated (or canceled), and then can use the INSERT or UPDATE SQL statements to modify the appropriate database tables.
The INPUT statement supports data entry into the fields of the current form.
INPUT BY NAME { variable | record.* } [,...]
[ WITHOUT DEFAULTS ]
[ ATTRIBUTE ( { display-attribute |
control-attribute } [,...] ) ]
[ HELP help-number ]
[ dialog-control-block
[...]
END INPUT ]
INPUT { variable | record.* } [,...]
[ WITHOUT DEFAULTS ]
FROM
field-list
[ ATTRIBUTE ( { display-attribute |
control-attribute } [,...] ) ]
[ HELP help-number ]
[ dialog-control-block
[...]
END INPUT ]
where dialog-control-block is one of:
{ BEFORE INPUT
dialog-statement
[...]
| AFTER INPUT
dialog-statement
[...]
| BEFORE FIELD field-list
dialog-statement
[...]
| AFTER FIELD field-list
dialog-statement
[...]
| ON CHANGE field-list
dialog-statement
[...]
| ON IDLE idle-seconds
dialog-statement
[...]
| ON ACTION action-name
dialog-statement
[...]
| ON KEY ( key-name [,...] )
dialog-statement
[...]
}
where dialog-statement is one of:
{ statement
| ACCEPT INPUT
| CONTINUE INPUT
| EXIT INPUT
| NEXT FIELD { CURRENT | NEXT | PREVIOUS | field-name
}
}
where field-list is:
{ field-name
| table-name.*
| table-name.field-name
| screen-array[line].*
| screen-array[line].field-name
|
screen-record.*
|
screen-record.field-name
}
[,...]
The following table shows the display-attributes supported by the INPUT statement:
Attribute | Description |
BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, WHITE, YELLOW Console Only! |
The color of the displayed data. |
BOLD, DIM, INVISIBLE, NORMAL Console Only! |
The font attribute of the displayed data. |
REVERSE, BLINK, UNDERLINE Console Only! |
The video attribute of the displayed data. |
The following table shows the control-attributes supported by the INPUT statement:
Attribute | Description |
HELP = help-number | Defines the help number when help is invoked by the user, where help-number is an integer literal or a program variable. |
FIELD ORDER FORM | Indicates that the tabbing order of fields is defined by the TABINDEX attribute of form fields. |
UNBUFFERED [ =bool] | Indicates that the dialog must be sensitive to program variable changes. The bool parameter can be an integer literal or a program variable. |
WITHOUT DEFAULTS [=bool] | Indicates if the data rows must be filled (FALSE) or not (TRUE) with the column default values defined in the form specification file or the database schema files. The bool parameter can be an integer literal or a program variable. |
CANCEL = bool | Indicates if the default action 'cancel' should be added to the dialog. If not specified, the action is registered. |
ACCEPT = bool | Indicates if the default action 'accept' should be added to the dialog. If not specified, the action is registered. |
When the runtime system encounters an INPUT statement, it does the following::
The INPUT statement does not terminate until the user validates or cancels the dialog.
The following steps describe how to use the INPUT statement:
The program record member variables are bound to the fields of a screen record, so the INPUT instruction can manipulate the values that the user enters in the screen record.
The BY NAME clause implicitly binds the fields to the variables that have the same identifiers as the field names. You must first declare variables with the same names as the fields from which they accept input. The runtime system ignores any record name prefix when making the match. The unqualified names of the variables and of the fields must be unique and unambiguous within their respective domains. If they are not, the runtime system generates an exception, and sets the STATUS variable to a negative value.
The FROM clause explicitly binds the fields in the screen record to a list of program variables that can be simple variables or records. The form can include other fields that are not part of the specified variable list, but the number of variables or record members must equal the number of fields listed in the FROM clause. Each variable must be of the same (or a compatible) data type as the corresponding screen field. When the user enters data, the runtime system checks the entered value against the data type of the variable, not the data type of the screen field.
The member variables of the records in a program array can be of any data type. If a variable is declared LIKE a SERIAL column, however, the runtime system does not allow the screen cursor to stop in the field. (Values in SERIAL columns are automatically generated by the database server, not by the runtime system.)
The variables are the interface to display data or to get user input through the INPUT instruction. Always use the variables if you want to change some field values programmatically. When using the UNBUFFERED attribute, the instruction is sensitive to program variable changes. If you need to display new data during the INPUT execution, use the UNBUFFERED attribute and assign the values to the program variables; the runtime system will automatically display the values to the screen:
01
INPUT p_items.* FROM s_items.* ATTRIBUTES(UNBUFFERED)02
ON CHANGE code03
IF p_items.code = "A34" THEN04
LET p_items.desc = "Item A34"05
END IF06
END INPUT
When the INPUT instruction executes, any column default values are displayed in the screen fields, unless you specify the WITHOUT DEFAULTS keywords. The column default values are specified in the form specification file with the DEFAULT attribute, or in the database schema files.
If you specify the WITHOUT DEFAULTS option, however, the form fields display the current values of the variables when the INPUT statement begins. This option is available with both the BY NAME and the FROM binding clauses.
01
LET p_items.code = "A34"02
INPUT p_items.* FROM s_items.* WITHOUT DEFAULTS03
BEFORE INPUT04
MESSAGE "You should see A34 in field 'code'..."05
END INPUT
The ATTRIBUTE clause specifications override all default attributes and temporarily override any display attributes that the OPTIONS or the OPEN WINDOW statement specified for these fields. While the INPUT statement is executing, the runtime system ignores the INVISIBLE attribute.
Using the FIELD ORDER FORM attribute: By default, the tabbing order is defined by the variable binding list in the instruction description. You can control the tabbing order by using the FIELD ORDER FORM attribute: When this attribute is used, the tabbing order is defined by the TABINDEX attribute of the form fields.
The HELP clause specifies the number of a help message to display if the user invokes the help while the focus is in any field used by the instruction. The predefined 'help' action is automatically created by the runtime system. You can bind action views to the 'help' action.
The default order in which the focus moves from field to field in the screen array is determined by the order of the variables used by the INPUT statement. The program options instruction can also change the behavior of the INPUT instruction, with the INPUT WRAP or FIELD ORDER options.
When an INPUT instruction executes, the runtime system creates a set of default actions. See the control block execution order to understand what control blocks are executed when a specific action is fired.
The following table lists the default actions created for this dialog:
Default action | Control Block execution order |
accept | Validates the INPUT dialog (validates fields) Creation can be avoided with ACCEPT attribute. |
cancel | Cancels the INPUT dialog (no validation, int_flag is set) Creation can be avoided with CANCEL attribute. |
close | By default, cancels the INPUT dialog (no validation, int_flag is set) Default action view is hidden. See Windows closed by the user. |
help | Shows the help topic defined by the HELP clause. Only created when a HELP clause is defined. |
The accept and cancel default actions can be avoided with the ACCEPT and CANCEL dialog control attributes:
01
INPUT BY NAME field1 ATTRIBUTES( CANCEL=FALSE )02
...
The BEFORE INPUT block is executed one time, before the runtime system gives control to the user. You can implement initialization in this block.
The AFTER INPUT block is executed one time, after the user has validated or canceled the dialog, and before the runtime system executes the instruction that appears just after the INPUT block. You typically implement dialog finalization in this block. The AFTER INPUT block is not executed if EXIT INPUT executes.
A BEFORE FIELD block is executed each time the cursor enters into the specified field, when moving the focus from field to field.
An ON CHANGE block is executed when the value changes in the specified field for RadioGroup, ComboBox and CheckBox views, when the cursor leaves the specified field and the value was changed by the user since the field got the focus. If both an ON CHANGE block and AFTER FIELD block are defined for a field, the ON CHANGE block is executed before the AFTER FIELD block.
An AFTER FIELD block is executed each time the cursor leaves the specified field, when moving the focus from field to field.
The following table shows the order in which the runtime system executes the control blocks in the INPUT instruction, according to the user action:
User action | Control Block execution order |
Entering the dialog |
|
Moving from field A to field B |
|
Changing the value of a field with a specific field like checkbox |
|
Validating the dialog |
|
Canceling the dialog |
|
The ON IDLE idle-seconds clause defines a set of instructions that must be executed after idle-seconds of inactivity. This can be used, for example, to quit the dialog after the user has not interacted with the program for a specified period of time. The parameter idle-seconds must be an integer expression. If it evaluates to zero, the timeout is disabled.
01
...02
ON IDLE 1003
IF ask_question("Do you want to leave the dialog?") THEN04
EXIT INPUT05
END IF06
...
You can use ON ACTION blocks to execute a sequence of instructions when the user raises a specific action. This is the preferred solution compared to ON KEY blocks, because ON ACTION blocks use abstract names to control user interaction.
01
...02
ON ACTION zoom03
CALL zoom_customers() RETURNING st, cust_id, cust_name04
...
For backward compatibility, you can use ON KEY blocks to execute a sequence of instructions when the user presses a specific key. The following key names are accepted by the compiler:
Key Name | Description |
ACCEPT | The validation key. |
INTERRUPT | The interruption key. |
ESC or ESCAPE | The ESC key (not recommended, use ACCEPT instead). |
TAB | The TAB key (not recommended). |
Control-char | A control key where char can be any character except A, D, H, I, J, K, L, M, R, or X. |
F1 through F255 | A function key. |
DELETE | The key used to delete a new row in an array. |
INSERT | The key used to delete a new row in an array. |
HELP | The help key. |
LEFT | The left arrow key. |
RIGHT | The right arrow key. |
DOWN | The down arrow key. |
UP | The up arrow key. |
PREVIOUS or PREVPAGE | The previous page key. |
NEXT or NEXTPAGE | The next page key. |
The NEXT FIELD field-name instruction gives the focus to the specified field. You typically use this instruction to control field input dynamically, in BEFORE FIELD or AFTER FIELD blocks. Abstract field identification is supported with the CURRENT, NEXT and PREVIOUS keywords. These keywords represent respectively the current, next and previous fields, corresponding to variables as defined in the input binding list (with the FROM or BY NAME clause).
The CONTINUE INPUT instruction continues the execution of the INPUT instruction, skipping all statements appearing after this instruction. Use this instruction to give control back to the interactive dialog, for example after testing for a special situation where the user must continue to input data.
You can use the EXIT INPUT statement to terminate the INPUT instruction and resume the program execution at the instruction following the INPUT block.
The ACCEPT INPUT instruction validates the INPUT instruction and exits the INPUT instruction if no error is raised. The AFTER FIELD, ON CHANGE, etc. control blocks will be executed. Statements after the ACCEPT INPUT will not be executed: the statement acts like a CONTINUE {INPUT|CONSTRUCT}.
The CLEAR field-list instruction can be used to clear a specific field or all fields in a line of the screen record. You can specify the screen record as described in the following table:
CLEAR instruction | Result |
CLEAR field-name | Clears the specified field. |
CLEAR screen-record.* | Clears all fields members of the screen record. |
Inside the dialog instruction, the predefined keyword DIALOG represents the current dialog object. It can be used to execute methods provided in the dialog built-in class.
For example, you can enable or disable an action with the setActionAction() dialog method, or you can also hide and show the default action view with the setActionHidden() method:
01
...02
BEFORE INPUT03
CALL DIALOG.setActionActive("zoom",FALSE)04
AFTER FIELD field105
CALL DIALOG.setActionHidden("zoom",1)06
...
The setFieldActive() method can be used to enable or disable a field during the dialog. This instruction takes an integer expression as argument.
01
...02
ON CHANGE custname03
CALL DIALOG.setFieldActive( "custaddr", (rec.custname IS NOT NULL) )04
...
The language provides several built-in functions and operators to use in a INPUT statement. For example: FIELD_TOUCHED(), FGL_DIALOG_GETFIELDNAME(), FGL_DIALOG_GETBUFFER().
Form definition file:
01
DATABASE stores02
03
LAYOUT04
GRID05
{06
Customer : [f001 ]07
Name : [f002 ]08
Last Name: [f003 ]09
}10
END11
END12
13
TABLES14
customer15
END16
17
ATTRIBUTES18
f001 = customer.customer_num ;19
f002 = customer.fname, default = "<no name>", upshift ;20
f003 = customer.lname ;21
END22
23
INSTRUCTIONS24
SCREEN RECORD sr_cust(25
customer.customer_num,26
customer.fname,27
customer.lname);28
END
Program source code:
01
MAIN02
03
DEFINE custrec RECORD04
id INTEGER,05
first_name CHAR(30),06
last_name CHAR(30)07
END RECORD09
10
DEFER INTERRUPT11
DEFER QUIT12
13
OPEN WINDOW w1 AT 1,1 WITH FORM "FormFile"14
15
LET INT_FLAG = FALSE16
INPUT custrec.* FROM sr_cust.*17
18
IF INT_FLAG = FALSE THEN19
DISPLAY custrec.*20
END IF21
22
CLOSE WINDOW w123
24
END MAIN
Form definition file:
01
DATABASE stores02
03
LAYOUT04
GRID05
{06
Customer : [f001 ]07
Name : [f002 ]08
Last Name: [f003 ]09
}10
END11
END12
13
TABLES14
customer15
END16
17
ATTRIBUTES18
f001 = customer.customer_num ;19
f002 = customer.fname, upshift ;20
f003 = customer.lname ;21
END
Program source code:
01
MAIN02
03
DEFINE custrec RECORD04
customer_num INTEGER,05
fname CHAR(30),06
lname CHAR(30)07
END RECORD09
10
DEFER INTERRUPT11
DEFER QUIT12
13
OPEN WINDOW w1 AT 1,1 WITH FORM "FormFile"14
15
LET INT_FLAG = FALSE16
LET custrec.customer_num = 017
LET custrec.fname = "<no name>"18
LET custrec.lname = NULL19
INPUT BY NAME custrec.* WITHOUT DEFAULTS20
BEFORE INPUT21
MESSAGE "Enter customer details..."22
AFTER FIELD fname23
IF FIELD_TOUCHED(custrec.fname)24
AND custrec.fname IS NULL THEN25
LET custrec.lname = NULL26
DISPLAY BY NAME custrec.lname27
END IF28
BEFORE FIELD lname29
IF NOT canEditLastName() THEN30
NEXT FIELD fname31
END IF32
AFTER INPUT33
MESSAGE "Input terminated..."34
END INPUT35
36
IF INT_FLAG = FALSE THEN37
DISPLAY custrec.*38
END IF39
40
CLOSE WINDOW w141
42
END MAIN