Domain: Command return code
The MAINCODE( ) function accesses the return code of the last command which resulted in an error or which was followed by a /SAVE-RETURNCODE. It returns the seven-byte error code of the return code, which is also the message code for error messages (the remaining components of the command return code are requested with the SUBCODE1( ) and SUBCODE2( ) functions).
The error code supplied by the MAINCODE( ) function consists of two parts: the first three bytes designate the message class, while the last four bytes specify the error. The error code can subsequently be used as the message code in the MSG( ) function; MSG( ) then supplies the corresponding message text if this is available.
MAINCODE( ) is not available, and general command return codes cannot be requested, outside dialog blocks and procedures.
Format
MAINCODE( ) MC( ) |
Result type
STRING (<string 7..7>)
Input parameters
None
Result
Error code in the form of a string.
Error messages
SDP0428 COMMAND RETURN CODE NOT AVAILABLE IN DIALOG SDP0435 DESIRED INFORMATION NOT AVAILABLE
Example
Error handling with MAINCODE( )
/BL1: BEGIN-BLOCK /... / IF-BLOCK-ERROR / WRITE-TEXT '&(MSG(MAINCODE()))' / END-IF /... /END-BLOCK BLOCK = BL1
Irrespective of whether or not an error occurs in the related block (BL1 here) , the current maincode is evaluated and the corresponding message is displayed.
It should be noted, however, that the message &(MSG(MAINCODE( ))) may itself contain parentheses and apostrophes, and that this will produce problems in specifying the WRITE-TEXT. These problems can be avoided by using the TO-C-LITERAL( ) function, e.g.:
/WRITE-TEXT &(TO-C-LITERAL('*** ' // MSG(MAINCODE()) // ' ***'))