Figure 1 is a simple example of a COBOL
COMMIT wrapper that, while compiled with the DLL option required for Java™,
can be statically
linked with a main non-DLL application module. In this example,
a procedural COBOL program invokes a Java method.
Only the non-DLL module objects that need to call
the new COMMIT function need to be recompiled. You can also perform
a similar function for ROLLBACK.
Figure 1. Example: COBOL COMMIT wrapper*----------------------------------------------------------------
*
* Program Name : COBCOMIT
* Objective : Call RSS global commit via batch container
*
*----------------------------------------------------------------
IDENTIFICATION DIVISION.
PROGRAM-ID. "COBCOMIT" IS RECURSIVE.
/
ENVIRONMENT DIVISION.
*--------------------
CONFIGURATION SECTION.
REPOSITORY.
Class JavaException is "java.lang.Exception"
Class UserControlledTransaction is
"com.ibm.batch.spi.UserControlledTransactionHelper".
INPUT-OUTPUT SECTION.
FILE-CONTROL.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 ex object reference JavaException.
LINKAGE SECTION.
01 RETCODE PIC S9(9) USAGE IS BINARY.
COPY JNI.
PROCEDURE DIVISION RETURNING RETCODE.
*----------------------------------------------------------------
*
* Test batch cobol commit.
*
*----------------------------------------------------------------
PROGRAM-BEGIN.
SET ADDRESS OF JNIENV TO JNIENVPTR
SET ADDRESS OF JNINATIVEINTERFACE TO JNIENV
Display "Calling into Java commit"
Invoke UserControlledTransaction "commit"
Display "Returned from Java commit"
Perform ErrorCheck
Goback
.
PROGRAM-END.
GOBACK.
* need to perform exception check / stack trace at this point ?
ErrorCheck.
Compute RETCODE = 0
Call ExceptionOccurred
using by value JNIEnvPtr
returning ex
If ex not = null then
Call ExceptionClear using by value JNIEnvPtr
Display "Caught an unexpected exception"
Invoke ex "printStackTrace"
Compute RETCODE = 99
End-if
.
End program "COBCOMIT".
Figure 2 shows an example
of the JCL that would be needed to compile the COMMIT wrapper shown
in
Figure 1.
Figure 2. Example: JCL used to
compile COMMIT wrapper//COMPCMIT JOB ,'STEVE PROGRAM ',
// NOTIFY=&SYSUID,
// MSGCLASS=X,
// CLASS=A,
// REGION=0M,
// TIME=120
//COMPILE EXEC IGYWC,LNGPRFX='SYSPROG.MNT.COBOL42',
// COND=(4,LT),
// PARM.COBOL=(NOSEQUENCE,RENT,LIB,THREAD,
// NODYNAM,DLL)
//COBOL.SYSLIB DD DSN=SUIMGJB.PRIVATE.JNI.COPY,
// DISP=SHR
//COBOL.SYSIN DD DSN=SUIMGJB.PRIVATE.DOCXMP.COBOL(COBCOMIT),
// DISP=SHR
//COBOL.SYSLIN DD DSN=SUIMGJB.PRIVATE.COBOL.OBJ(COBCOMIT),
// DISP=SHR
//