You can also handle violations of the edit rules (specified in the Extended Field Definition fill‑in) in the application program. To use the program to handle errors, you must specify A for the Edit‑rule Error Proc parameter in the Panel Parameter fill‑in.
To determine whether an error occurred in the panel entries, use the function $PANEL‑ERROR. The $PANEL‑ERROR function has a value of TRUE if any field on the panel contains an error. The value remains TRUE until the user or the application program corrects all the errors on the panel.
To determine what type of error occurred for a specific field, use the $PANEL‑FIELD‑ERROR function. This function returns a number that indicates the specific type of error that occurred:
|
Number |
Error |
|---|---|
|
0 |
No error. |
|
1 |
A required field is missing. |
|
2 |
Non‑numeric data is detected in a numeric field. |
|
3 |
Field content is outside the range specified as the minimum and maximum values allowed for the field. |
|
4 |
An invalid check digit was specified. |
|
5 |
The field entry does not have the required number of decimal places. |
|
6 |
A field specified as must‑fill was not filled. |
Example
The following section of program code shows how you can use $PANEL‑ERROR and $PANEL‑FIELD‑ERROR to handle both edit‑rule and application‑rule errors.
LOOP
SET USER‑ERROR = FALSE
TRANSMIT TRACKING REINPUT
SELECT
WHEN $PANEL‑FIELD‑ERROR(ID) = 1
SET MESSAGE = "REQUIRED FIELD (ID) IS MISSING"
WHEN $PANEL‑FIELD‑ERROR(ID) = 0 AND NAME = ' '
FOR THE FIRST EMP
WHERE EMP.ID = TRACKING.ID
MOVE EMP.NAME TO TRACKING.NAME
WHEN NONE
SET MESSAGE = "ID DOES NOT EXIST ON MASTER FILE"
SET USER‑ERROR = TRUE
ENDFOR
WHEN $PANEL‑FIELD‑ERROR(LOG‑IN) = 3
SET MESSAGE = "LOG‑IN TIME IS OUTSIDE OF RANGE"
WHEN $PANEL‑FIELD‑ERROR(LOG‑OUT) = 1
SET LOG‑OUT = '05:00'
ENDSELECT
WHILE $PANEL‑ERROR(TRACKING) OR USER‑ERROR
ENDLOOP
In this example, the TRACKING panel is analyzed for field entries that violate the panel definition's validation rules or the application's rules. The LOOP, which transmits the panel and analyzes field entries, continues until all input errors are corrected. The WHILE statement controls the exit from the loop by testing the value of the $PANEL‑ERROR function and the USER‑ERROR flag field. (USER‑ERROR is reinitialized before the TRANSMIT statement because it is reevaluated each time the panel is transmitted.)
If a value is not entered in the ID field, which is required, an error message moves to the MESSAGE field. The MESSAGE field must be defined on the panel definition. If the ID entered is not in error but the NAME field is blank, the name is retrieved from the employee master file. If there is no match for the ID on the employee master file, an error message is issued.
If the LOG‑IN value is outside the minimum and maximum values specified for the field, an error message moves to the MESSAGE field. If there is no value supplied for the LOG‑OUT field, a default value moves to the field. You could also specify the default value on the Field Definition fill‑in.
|
Copyright © 2015 CA Technologies.
All rights reserved.
|
|