3. Embedded SQL for COBOL : Advanced Processing : User-Defined Error, DBevent, and Message Handlers : Include User-Defined Handlers in the Micro Focus RTS--UNIX
 
Share this page                  
Include User-Defined Handlers in the Micro Focus RTS--UNIX
You must follow the procedures below to include user-defined handlers in the new Micro Focus Runtime System (RTS) that you create. For a complete description of how to incorporate Ingres into the Micro Focus RTS, see How to Incorporate Ingres into the Micro Focus RTS--UNIX in this chapter.
To include user-defined handlers in the Micro Focus RTS
1. For each user-defined handler, build the object code as follows:
% esqlcbl errhandler.scb
% cob -x -c errhandler.cbl
% esqlcbl msghandler.scb
% cob -x -c msghandler.cbl
% esqlcbl evthandler.scb
% cob -x -c evthandler.cbl
2. Because Micro Focus COBOL does not support a Function Pointer data type, you must write a short embedded SQL/C procedure to register your user-defined handler with the Ingres Runtime System. This embedded SQL/C procedure only needs to declare the handler, and execute the appropriate set_sql statement. For example:
ErrTrap()
{
extern int ErrProg();
exec sql set_sql(errorhandler = ErrProg);
}
MsgTrap()
{
extern int MsgProg();
exec sql set_sql(messagehandler = MsgProg);
}
EvtTrap()
{
extern int EvtProg();
exec sql set_sql(dbeventhandler = EvtProg);
}
ErrProg, MsgProg and EvtProg are embedded SQL/COBOL programs that handle Ingres errors, database procedure messages and database events respectively.
3. Build the object code of the embedded SQL/C registration procedure, as follows:
% esqlc cproc.sc
% cc -c cproc.c
where cproc.sc is the name of the file containing the procedure(s) that you wrote for Step 2.
4. Link the compiled handlers and the C registration procedure(s) into your RTS by modifying the COB command line to include the object files. Specify the object files before the list of system libraries, as follows:
cob -x -e "" -o ingrts
iimfdata.o iimflibq.o\
cproc.o              \
errhandler.o msghandler.o evthandler.o\
$II_SYSTEM/ingres/lib/libingres.a\
-lc -lm
cproc.o is the name of the object file that Step 3 produces. It contains the C registration procedure(s) for the user-defined handlers.
5. Add COBOL CALL statements to your source program wherever you wish to set the handler. For example:
* To set the errorhandler on:
CALL "ErrTrap".
* To set the messagehandler on:
CALL "MsgTrap".
* To set the dbeventhandler on:
CALL "EvtTrap".
You may unset the user-defined handler directly from your embedded SQL/COBOL program with the SET_SQL statement:
exec sql set_sql (errorhandler = 0) end-exec.
exec sql set_sql (messagehandler = 0) end-exec.
exec sql set_sql (dbeventhandler = 0) end-exec.