Try OpenEdge Now
skip to main content
Programming Interfaces
External Program Interfaces : Host Language Call Interface : Writing C functions : Returning error codes from a top-level function
Returning error codes from a top-level function
There are two ways to return errors from a top-level function:
*Return from your top-level function with a non-zero value. ABL receives the non-zero value from PRODSP() and raises an error condition.
*Before returning from your top-level function, set an ABL shared variable to a specific value using an HLC library function.
If you use the first technique, the PRODSP() dispatch routine returns a long data type value to ABL. ABL uses this value as a return code to determine whether the HLC routine dispatched by PRODSP() was successful. If the return code is 0, ABL considers the routine successful and continues processing. If the return code is non-zero, ABL considers the routine unsuccessful and raises an error condition.
The FUNCTEST macro ensures that the value returned from your top-level function is passed on as the return code of PRODSP(). However, you must make sure that your top-level function returns an appropriate value for the return code. For example, when your top-level function runs successfully, make sure that the last statement executes the equivalent of the following:
return 0;
If you use the second method, you can set unique error codes that you can test from ABL and respond to each type of error as needed.
The first technique provides an efficient way to return to ABL when your HLC function encounters an unexpected error, such as an unsuccessful HLC library call. The second technique provides more fine-grained error processing, and allows your ABL procedure to handle conditions specific to your application.