Was this helpful?
Programming for Error Message Output
By default, all Ingres and forms system errors are returned to the EQUEL program, and default error messages are printed on the standard output device. As discussed in the QUEL Reference Guide and the Forms-based Application Development Tools User Guide, you can also detect the occurrences of errors by means of the program using the inquire_ingres and inquire_frs statements. (Use the latter for checking errors after forms statements. Use inquire_ingres for all other EQUEL statements.)
Because COBOL does not allow the use of local function arguments, you cannot use the EQUEL error handling procedure described in the QUEL Reference Guide that entails creating an error-handling function and passing its address to the Ingres runtime routine IIseterr().
Instead, you can simulate the operations of an error function using the set_ingres statement. You can also use this statement to suppress the default messages. The general syntax of the set_ingres statement is:
##  set_ingres(EQUELconst=val{,EQUELconst=val})
EQUELconst is one of the valid EQUEL constants to which status information can be assigned.
val is the value that is assigned to the EQUEL status flag. This may be a constant or a program variable containing the value to assign.
The following table presents two of the legal values and types for EQUELconst.
Set_ingres Constant Values
Indicates to EQUEL whether to display Ingres error messages or not, using the normal Ingres error printing routines. Assigning 0 to errormode silences Ingres error printing. Assigning 1 to errormode normalizes Ingres error printing. The default value is 1, and error messages are printed.
Displays the error message that corresponds to the last error encountered by Ingres or EQUEL. Assigning 1 to errordisp displays the message.
With these commands, you can perform most of the error-handling functions available in other EQUEL languages. However, the errordisp constant used with the set_ingres statement displays the last Ingres or EQUEL error on the standard output device. If you wish to obtain the text of the last error while at the same time suppressing the default printing of messages, you can use the set_ingres statement in conjunction with the inquire_ingres statement, as follows:
*   Silence EQUEL errors messages

##  REPLACE employee (empname = "Fred")

*   Check to see if an error occurred.
*   Assume that "errorvar" is a numeric data item that
*   has been declared to EQUEL.

    IF (errorvar  0) THEN

. . .


*   Assume that "errorstr" is an alphanumeric data item 
*   that   has been declared to EQUEL.

    DISPLAY "Error text is" errorstr

    . . .
You should be aware that the set_ingres method of error handling makes it difficult for the program to detect conversion errors when returning data to the COBOL program in a retrieve loop. This happens because the check for the error condition can only be made at the completion of the retrieve loop.
The following example demonstrates how the set_ingres command may be used to process error message printing:
##  01 REAL-VAR PIC S9(8)V9(6) USAGE COMP-3 VALUE 0.469.
##  01 CON-ERR PIC Z999.

##  INGRES "Equeldb".

##  /* Create a temporary table */
##  CREATE temp (ccol = c2, icol = i2)
##  APPEND TO temp (ccol = "ab", icol = 1)

##  /*
##  Silence EQUEL error messages and do a replacement 
##  that causes a conversion error between a c2 
##  column and a numeric data item.
##  */

##  REPLACE temp (icol = 2) WHERE temp.ccol = REAL-VAR

##  /* Check the EQUEL conversion error and display 
##  the message. */
    DISPLAY "Conversion error was ", CON-ERR.

##  DESTROY temp
*   Continue program here.
A more practical example is a handler to catch deadlock errors. For deadlock, a reasonable handling technique in most applications is to suppress the normal error message and simply restart the transaction.
The following EQUEL program executes a Multi-Query Transaction and handles Ingres errors, including restarting the transaction on deadlock.
In this example, Ingres error messages are silenced, using the set_ingres command with the errormode option. When errors do occur, they are tested for deadlock. Note that if deadlock does occur, the transaction is restarted automatically without your knowledge.



##  01 INGERR              PIC S9(4) USAGE COMP.
    01 ERR-DISP            PIC ZZZZ99 USAGE DISPLAY.
##  01 ERR-TEXT            PIC X(80).
    01 ING-DEADLOCK        PIC S9(4) USAGE COMP.


*   Initialize test data & Ingres table, and silence
*   Ingres errors.

*   Perform transaction, it includes appending 
*   and replacing data.

*   End multi-statement transaction and Ingres
*   interface.
##  EXIT
*   Start up Ingres and create a temporary 
*   test relation.
##  INGRES testdb
##  CREATE item (name=c10, number=i4)

*   Silence Ingres error messages

*   Begin a multi-query transaction and reset
*   deadlock flag.

##  APPEND TO item (name = "Barbara", number=38)
    IF (ING-DEADLOCK = 1) 
##  REPLACE item (number=39) WHERE item.name="Barbara"

##  DELETE item WHERE item.number=38
*    If the Ingres error is deadlock, the DBMS will
*    automatically abort an existing MQT. If the error is 
*    not deadlock, abort  the transaction and the program.

       IF (INGERR > 0) THEN
           IF (INGERR = 4700) THEN
*    Deadlock has occurred 
              MOVE 1 TO ING-DEADLOCK
*    DISPLAY Ingres error message & abort the
*    transaction
             DISPLAY "Aborting on Error" ERR-DISP
             DISPLAY ERR-TEXT
##           ABORT
##           DESTROY item
##           EXIT
             STOP RUN
*    Reset deadlock flag
Last modified date: 06/10/2024