Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Example of Producing User-generated COBOL Run-Time System Errors

Example of Producing User-generated COBOL Run-Time System Errors

This example has been tested with Enterprise Developer 4.0 and with Visual COBOL 4.0 for Eclipse and Visual Studio.

In situations where an application fails with an error condition that it cannot recover from, you might want the application to terminate the process in such a way that error processing occurs. For such scenarios, Micro Focus provides the CBL_RUNTIME_ERROR library routine that enables you to display a custom message. 

You need to call the CBL_RUNTIME_ERROR library routine from your code and provide a message string to indicate the error. The API that uses this routine takes a flags parameter. Setting the flag to 0 forces the application to terminate and generate the specified user COBOL Run-Time System error displayed as an RTS 150 message. The message enables the user to determine which (of potentially several) error condition caused the termination.

If the core_on_error tunable is also set, CBL_RUNTIME_ERROR makes it easier to debug application errors from a production environment.

CBL_RUNTIME_ERROR is a cross-platform library routine and can be used on both Windows and UNIX/Linux.


The following is an example of how to call this routine from your code:

       identification division.

       program-id. RTSERR1.

       environment division.

       configuration section.


       data division.

       working-storage section.

       01 ws-flags               pic x(4) comp-5.

       01 ws-error-str           pic x(255).

       procedure division.

          display "This program will generate a COBOL Runtime"

                  " error to force termination."

          move 0 to ws-flags

      **** Null Terminated String for text is required.   

          move z"Application Generated Runtime Error" to ws-error-str

          call "CBL_RUNTIME_ERROR" using by value ws-flags

                                         by reference ws-error-str


          display "This will never be reached as RTS Error handling is"

                  " invoked."


       end program RTSERR1.


This code produces an error message at run time:

Execution error : file 'RTSERR1'

error code: 150, pc=0, call=1, seg=0

150     Program abandoned at user request (Application Generated Runtime Error)


Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.

The line:

move "Application Generated Runtime Error" to ws-error-str

Should be:

move z"Application Generated Runtime Error" to ws-error-str

Version history
Revision #:
1 of 1
Last update:
‎2018-08-03 04:12
Updated by:
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.