RECEIVE
The RECEIVE keyword can be used for different purposes. The RECEIVE statement works with the PASS statement to implement true subroutines. Or, it works without the PASS statement to essentially declare a local variable (a field that is automatically restored to its initial value when the subroutine, event point, or process ends).
••••• RECEIVE ••• •••••••••••••••••••••• •••
•••••••••••••• FAIL
•
(1)
(2) (3) (4)
(5) (6)
(2) Application ID |
(4) Occurrence (constant/index) |
(5) Area type (FIELD) |
(6) Fail action (0=nothing, 1=warning, 2=error, 3=cancel) |
The RECEIVE statement sets the next status indicator to T if a matching PASS statement was found and to F if not. If you RECEIVE without a PASS statement, you are simply declaring a local variable that is restored to its initial value when the subroutine, event point, or process ends.
The RECEIVE statement can be used in three locations:
· Inside a subroutine marked by the LABEL statement. Field values are restored when the RETURN is executed.
· Inside an event point. Field values are restored when the event point ends.
· Inside the Start of Process event point. Field values are restored when the process ends.
Data types of related PASS and RECEIVE statements do not have to match. The same rules that are used for SET statements convert the PASS field into the RECEIVE field (and back again). Fields are received in the same order they are passed so passing and receiving the same field names is not required.
PASS TAR
CUSTOMER NAME FIELD SHARE?
N
PASS TAR
WORK STRING LENGTH FIELD SHARE?
Y
GOSUB :COMPUTE
NAME LENGTH
END
*
LABEL :COMPUTE
NAME LENGTH
RECEIVE ---
TEMP 2K FIELD
FAIL
N
RECEIVE ---
A1 FIELD
FAIL
N
CNV BIN ---
TEMP 1 = 0
APPEND ---
TEMP 2K 0 ---
TEMP 1
IF ---
TEMP 2K IN ---
TEMP 1
T SET ---
A1 = ---
TEXT AT POSITION
T COMPUTE ---
A1 - 1
RETURN
In this example, the initial value of CUSTOMER NAME is returned following the subroutine. Even if the subroutine altered the value of this field, it would still be returned in its initial state because the PASS statement does not share the field. The WORK STRING LENGTH field (paired with the value of the AI field), however, is modified to contain the length of the value in the CUSTOMER NAME field. This new value is returned following the subroutine because the WORK STRING LENGTH field was passed as a shared field.