Form field initialization

Form field initialization can be controlled by the WITHOUT DEFAULTS dialog option.

The INPUT and INPUT ARRAY dialogs provide the WITHOUT DEFAULTS option to use program variable values when the dialog starts, or to apply the DEFAULT attribute defined in forms. The semantics of this option is slightly different in INPUT and INPUT ARRAY dialogs. Use of the WITHOUT DEFAULTS clause is always recommended in INPUT ARRAY.

The WITHOUT DEFAULTS option can be used in the binding clause or as an ATTRIBUTES option. When used in the binding clause, the option is defined statically at compile time as TRUE. When used as an ATTRIBUTES option, it can be specified with an integer expression that is evaluated when the DIALOG interactive instruction starts:

INPUT BY NAME p_cust.* ATTRIBUTES (WITHOUT DEFAULTS = NOT new)
   ...
END INPUT

The WITHOUT DEFAULTS clause in INPUT

In the default mode, an INPUT clears the program variables and assigns the values defined by the DEFAULT attribute in the form file (or indirectly, the default value defined in the database schema files). This mode is typically used to input and INSERT a new record in the database. The REQUIRED field attributes are checked to make sure that the user has entered all data that is mandatory. Note that REQUIRED only forces the user to enter the field, the value can be NULL unless the NOT NULL attribute is used. Therefore, if you have an AFTER FIELD or ON CHANGE control block with validation rules, you can use the REQUIRED attribute to force the user to enter the field and trigger that block.

In contrast, the WITHOUT DEFAULTS option starts the INPUT dialog with the existing values of program variables. This mode is typically used in order to UPDATE an existing database row. Existing values are considered valid, thus the REQUIRED attributes are ignored when this option is used.

The NOT NULL field attribute is always checked at dialog validation, even if the WITHOUT DEFAULTS option is set.

The WITHOUT DEFAULTS clause in INPUT ARRAY

With an INPUT ARRAY, the WITHOUT DEFAULT option defines whether the program array is populated when the dialog begins. Once the dialog is started, existing rows are always handled as records to be updated in the database (WITHOUT DEFAULTS=TRUE), while newly created rows are handled as records to be inserted in the database (WITHOUT DEFAULTS=FALSE). In other words, column default values defined in the form specification file or the database schema files are only used for newly-created rows.

It is unusual to implement an INPUT ARRAY with no WITHOUT DEFAULTS option, because the program array would be cleared and the list would appear empty.

Important:

The default in INPUT ARRAY used inside DIALOG is WITHOUT DEFAULTS=TRUE, but in a singular INPUT ARRAY dialog, the default is WITHOUT DEFAULTS=FALSE.