Example

The following sample code is a simple COBOL program calling a Java program. It shows the minimum necessary pieces to call a Java method from a COBOL program.

identification division.
program-id.  CobolToJava.
data division.
working-storage section.

01 CLASS-NAME   PIC X(80).
01 METHOD-NAME   PIC X(80).
01 METHOD-SIGNATURE  PIC X(80).
01 STATUS-VAL   PIC S9(02) VALUE ZERO.
01 FIELD-INT  USAGE IS SIGNED-INT.   
01 FIELD-RETURN  USAGE IS SIGNED-INT.   

procedure division.
main-logic.

move "com.acucobolgt.CVM" TO CLASS-NAME
move "CobolCallingJavaInt" TO METHOD-NAME 
move "(I)I" TO METHOD-SIGNATURE 
move 0 to FIELD-INT
move -1 to FIELD-RETURN

CALL "C$JAVA" USING CLASS-NAME, METHOD-NAME, METHOD-SIGNATURE, FIELD-INT, FIELD-RETURN GIVING STATUS-VAL.