Previous Topic Next topic Print topic


JVM_LOAD_NATIVE

Loads a native shared library into the JVM runtime. Once the shared library is loaded, use the CALL statement to call one of its entry points, from your JVM COBOL programs.
Note: We recommend that you load native shared libraries using procedure-point syntax, thereby eliminating the need to load them using the JVM_LOAD_NATIVE library routine, which is now deprecated.

Syntax:

call "JVM_LOAD_NATIVE" using by reference myLibrary

Parameters:

myLibrary
pic x(n).

On entry:

myLibrary
The name of the native shared library (.dll or .so on most platforms), without the file extension.

On exit:

None.

Example:

The following pair of programs show group items being used to interoperate between JVM COBOL and native COBOL.

Native COBOL:

    program-id. NativeProgram as "NativeProgram".
    linkage section.
    01 pets.
       03 p1 pic xxx.
       03 p2 pic xxx.
       03 result pic x(6).
    procedure division.
       goback.
       entry "SwapStrings" using pets.
          display "p1='" p1 "' p2='" p2 "'"
          move p1 to result(4:3)
          move p2 to result(1:3)
          goback.
    end program NativeProgram.  

JVM COBOL:

    program-id. JVMProgram as "JVMProgram".
    01 pets.
        03 dog pic xxx value "dog".
        03 cat pic xxx value "cat".
        03 result pic x(6).
    01 nat-ptr procedure-pointer.
    procedure division.
       set nat-ptr to entry “NativeProgram"
        display ""           
        display "Calling native program"
        display "======================="
        display "Pass in 2 strings: '" dog "' & '" cat "'"
        perform reset-all
       call "SwapStrings" using pets
        display "Native program swaps strings"
        display "result = '" result "'"
        display "" 
        goback.
    reset-all section.
        move spaces to result
        .   
    end program. 

Comments:

The myLibrary parameter must be passed as a literal; it cannot be declared in a COBOL storage section.

You cannot call a native entry point that has the same name as a JVM COBOL entry point.

You cannot load two native libraries that have the same named entry point.

Previous Topic Next topic Print topic