Previous Topic Next topic Print topic


Calling Native COBOL from JVM COBOL

In JVM COBOL, you use the CALL statement to interoperate with native code. For example:

 call xxx using by yyy p by zzz q returning r

Where:

xxx
is a storage or linkage item or a literal. This holds the entry point to which the CALL statement calls.
p and q

are the items between the using and returning key words. These are parameters. There can be zero or more parameters.

yyy and zzz
indicate the parameter passing mode (by content, by reference or by value). By reference is the default.
The returning clause
is optional

To call a native entry point in a shared library (.dll file on Windows or .so file on UNIX), you need to load the shared library to ensure that the JVM runtime system is aware of it. You must load the library before making the call to the native entry point.

For example, given program A compiled as JVM (JVMGEN):
       01 my-dll       procedure-pointer.

       set my-dll to entry "b"
       call "c"
And the native DLL containing COBOL programs B and C:
       program-id. b.
       display "IN B"notep

       program-id. c.

        display "INFO: in C"
        display "PASS"

This loads the native DLL (b.dll Windows) or CSO (b.so UNIX), making the programs it contains visible such that the CALL to program C succeeds.

The JVM run-time system attempts to resolve requested entry points to JVM methods that have the Callable attribute. If the entry point for a particular name is not found in JVM, the JVM run-time system attempts to resolve the entry point to a native entry point. If a native entry point is found, that entry point is called and that name is associated with the native entry point from then on, so that a full search is not done again.

Note:
  • You cannot call a native entry point that has the same name as a JVM entry point.
  • You cannot load two native libraries that have the same named entry point.
Previous Topic Next topic Print topic