13.5 Returning Program Status
A PROGRAM unit lets you return a status from a BASIC
image by optionally including an integer expression with the
END PROGRAM and EXIT PROGRAM statements. After
executing a program, you can examine this status by check-
ing the DCL symbol $STATUS. By default, BASIC returns
a status of 1, indicating success. Success is signaled with an
odd numbered status value, while an error is signaled with
an even numbered value. $STATUS contains the same value
as the integer expression for the exit status in the EXIT and
END PROGRAM statements. Note that if a program is ter-
minated with an EXIT PROGRAM statement, the expression
on the EXIT PROGRAM statement overrides any expression
on the END PROGRAM statement.
In the following example, exit_status contains the status
value returned by the program. After program execution,
$STATUS has the value of exit_status . You can examine the
value of $STATUS and display the corresponding message
text with the lexical function F$MESSAGE at DCL level, as
shown in the following example:
EXAMPLE: Click to display example.
After program execution, you can examine the status of the
program at DCL level:
$ SHOW SYMBOL $STATUS
$ STATUS = "%X10"
$ error_text = F$MESSAGE(%X10)
$ SHOW SYMBOL error_text
ERROR_TEXT = "SYSTEM-W-BADPARAM, bad parameter value"
The PROGRAM statement is always optional; EXIT
PROGRAM and END PROGRAM are legal without a
matching PROGRAM statement. Without a PROGRAM
statement, these statements still exit the main compilation
unit. The EXIT PROGRAM and END PROGRAM state-
ments are not valid within SUB, FUNCTION, or PICTURE
subprograms.