You can pass Java instances to native procedural COBOL application using the com.microfocus.cobol.lang.JObject interface. The interface retrieves the object as a pointer, which requires that you use a Java JNI method.
In the following example, the myclass instance is passed to native COBOL:
class-id. myclass implements type com.microfocus.cobol.lang.JObject. method-id. invokeMe. display "Hello from invokeMe method". goback. end method. method-id. main static public. local-storage section. 01 myclass-instance type myclass. procedure division. set myclass-instance to type myclass::new() call "natsub" using by value myclass-instance stop run end method.
Then, native COBOL invokes the invokeMe method.
$set ooctrl(+p) ooctrl(-f) dialect(iso2002) mf warning(1)
identification division.
program-id. natsub as "natsub".
repository.
class javasup as "javasup"
class cls-myclass as "$java$myclass".
working-storage section.
01 myclass object reference cls-myclass.
linkage section.
01 myclass-jptr pointer.
procedure division using by value myclass-jptr.
invoke javasup "getCOBOLObject" using myclass-jptr
returning myclass
invoke myclass "invokeMe"
invoke myclass "finalize" returning myclass
goback.