This article describes how to decode RETURN-CODE after calling a CBL_ file handling library routine.
Problem:
When the RETURN-CODE is NON-ZERO after calling a CBL_ file library routine how can it be decoded in order to provide information about the cause of the failure?
Resolution:
The return code is X'0000' if it has been successful.
If it has not been successful, the return code is 9<byte> where byte is PIC 9(4) COMP. For example, if the file status is 9/188 (file name too large), the return code will be X'39BC', where "39" is the ASCII character "9" and "BC" is decimal 188. If the RETURN-CODE special register is inspected or displayed in decimal, the value will be 14780 (X'39BC' converted literally to decimal).
The easiest way to decode the RETURN-CODE is to move it to a data item which describes FILE STATUS.
01 file-status pic xx comp-x.
01 redefines file-status.
03 fs-byte-1 pic x.
03 fs-byte-2 cblt-x1-compx
. . .
call "CBL_xxx_xxx" using parameters
if return-code not = 0
move return-code to file-status
. . .
At this point, fs-byte-1 contains "9" and fs-byte-2 contains the run-time system error number. Look up the error number in the Product Documentation under Run Time System Errors.