Tutorial Chapter 6: Add, Update and Delete |
The INPUT statement allows the user to enter or change the values in a program record, which can then be used as the data for new rows in a database table, or to update existing rows.
In the INPUT statement you list:
INPUT <program-variables> FROM <form-fields>
The FROM clause explicitly binds the fields in the screen record to the program variables, so the INPUT instruction can manipulate values that the user enters in the screen record. The number of 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.
When invoked, the INPUT statement enables the specified fields of the form in the current BDL window, and waits for the user to supply data for the fields. The user moves the cursor from field to field and types new values. Each time the cursor leaves a field, the value typed into that field is deposited into the corresponding program variable. You can write blocks of code as clauses in the INPUT statement that will be called automatically during input, so that you can monitor and control the actions of your user within this statement.
The INPUT statement ends when the user selects the accept or cancel actions.
INPUT supports the same shortcuts for naming records as the DISPLAY statement. You can ask for input to all members of a record, from all fields of a screen record, and you can ask for input BY NAME from fields that have the same names as the program variables.
INPUT BY NAME <program record>.*
By default, field values are buffered. The UNBUFFERED attribute makes the INPUT dialog "sensitive", allowing you to easily change some form field values programmatically during INPUT execution.
When you assign a value to a program variable, the runtime system will automatically display that value in the form; when you input values in a form field, the runtime system will automatically store that value in the corresponding program variable. Using the UNBUFFERED attribute is strongly recommended.
An INPUT with the WITHOUT DEFAULTS attribute can be used to allow the user to make changes to an existing program record representing a row in the database.
The same INPUT statement can be used, with the WITHOUT DEFAULTS attribute, to allow the user to make changes to an existing program record representing a row in the database. This attribute prevents BDL from automatically displaying any default values that have been defined for the form fields when INPUT is invoked, allowing you to display the existing database values on the screen before the user begins editing the data. In this case, when the INPUT statement is used to allow the user to add a new row, any existing values in the program record must first be nulled out. Note however that the REQUIRED attribute is ignored when WITHOUT DEFAULTS is TRUE. If you want to use REQUIRED, for example to force the end user to visit all required fields and fire the AFTER FIELD trigger to validate the entered data, you can turn off or on the WITHOUT DEFAULTS attribute according to the need, by using a Boolean expression.