Retrieving Messages with C$RERR

You might want to separate the error codes and their associated text, and store them in variables. The variables can then be displayed to the screen or handled in whatever way you deem appropriate.

You saw an example of the usage of C$RERR in the sample program in Getting Started. The simplified example shown below uses the library routine C$RERR with two parameters to retrieve the complete error code (first parameter) and its associated text (second parameter).

DATA DIVISION. 
   . 
   . 
working-storage section. 
01  file-status                   pic xx. 
01  error-status. 
    03 primary-error              pic x(2). 
    03 secondary-error            pic x(40). 
01  error-text                    pic x(40). 
 
PROCEDURE DIVISION. 
   . 
   . 
get-file-err. 
call "C$RERR" using error-status, error-text, status-type. 
display "FILE ERROR:", primary-error. 
display "DATABASE ERROR:",  secondary-error. 
display error-text. 
accept omitted. 
stop run. 
Here's an example of the output you might get from this: 

FILE ERROR: 9D 
DATABASE ERROR: 1608 

For Informix

Remember that the extended code can consist of two parts (database error and ISAM error), separated by a comma. In the example shown below, we use the library routine C$RERR with two parameters to retrieve the complete error code (first parameter) and its associated text (second parameter). Then we use the UNSTRING verb to separate the code into its parts:

DATA DIVISION 
   . 
   . 
   . 
working-storage section. 
01  file-status                          pic xx. 
01  error-status. 
    03 primary-error                     pic x(2). 
    03 extended-error                    pic x(40). 
01  secondary-error                      pic x(10). 
01  isam-error                           pic x(40). 
01  error-text                           pic x(40). 
 
PROCEDURE DIVISION 
   . 
   . 
   . 
get-file-err. 
   call "C$RERR" using error-status, error-text. 
   unstring extended-error delimited by "," into 
      secondary-error, isam-error. 
 
   display "FILE ERROR:", primary-error. 
   display "DATABASE ERROR:", secondary-error. 
   display "ISAM ERROR:", isam-error. 
 
   display error-text. 
   accept omitted. 
   stop run. 
Here's an example of the output you might get from this: 

FILE ERROR: 9D 
DATABASE ERROR: 350 
ISAM ERROR: 108 
Index already exists on column. 

An additional method, also for Informix only, allows you to take the Informix error number and use the "finderr" syntax to discover error information. More information on this syntax can be found in your Informix documentation. The syntax is:

finderr xxxxx

Where xxxxx is the Informix error number.