Consultor Eletrônico



Kbase 12876: Trap for NOT AVAILABLE NO-ERROR type condition on FOR EACH
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/10/1998
Trap for NOT AVAILABLE NO-ERROR type condition on FOR EACH

The FOR EACH statement is designed to have the following properties:
- record reading
- block property
- record scoping

It does not allow you to trap for the NOT AVAILABLE condition if
no records meet the selection criteria: PROGRESS treats this

- PROGRESS treats this as a "normal" condition
- no error condition is triggerd
- the procedure block preocesses the next statement following the END
of the FOR EACH block.

To provide a graceful message to the user that there
are no records meeting the selection criteria, or that the records
requested are locked and cannot be used at the current time, use
a REPEAT block with FIND NEXT with logic for handling the NOT
AVAILABLE condition using NO-ERROR as illustrated in the following
example code.

DEFINE VARIABLE user-choice AS CHAR LABEL "NAME SELECTION".
UPDATE user-choice WITH FRAME fe-fr.

FOR EACH customer EXCLUSIVE-LOCK USE-INDEX name
WHERE name BEGINS user-choice WITH TITLE " Using FOR EACH ":
DISPLAY name cust-num city st zip.
END.

UPDATE user-choice WITH FRAME r-fr COLUMN 40.

REPEAT WITH TITLE " Using REPEAT/FIND/NO-ERROR test ":
FIND NEXT customer EXCLUSIVE-LOCK USE-INDEX name
WHERE name BEGINS user-choice NO-ERROR.
IF LOCKED customer THEN
DO:
MESSAGE "That record is locked..
MESSAGE "Please select another" UPDATE user-choice.
FIND FIRST CUSTOMER EXCLUSIVE-LOCK USE-INDEX name NO-ERROR.
END.
ELSE
IF NOT AVAILABLE customer THEN
DO:
MESSAGE "No more records begin with that string.".
MESSAGE "Please select another" UPDATE user-choice.
FIND FIRST CUSTOMER EXCLUSIVE-LOCK USE-INDEX name NO-ERROR.
END.
ELSE
DISPLAY name cust-num city st zip.
END.

Progress Software Technical Support Note # 12876