The following examples show COBOL class definitions that contain a factory method called main.
In each case, main has no RETURNING phrase and has a single USING parameter, an object reference to a class that is an array with elements of type java.lang.String. You can run these applications by using the java command.
cbl thread
Identification Division.
Class-id. CBLmain inherits Base.
Environment Division.
Configuration section.
Repository.
Class Base is “java.lang.Object”
Class stringArray is “jobjectArray:java.lang.String”
Class CBLmain is “CBLmain”.
*
Identification Division.
Factory.
Procedure division.
*
Identification Division.
Method-id. “main”.
Data division.
Linkage section.
01 SA usage object reference stringArray.
Procedure division using by value SA.
Display “ >> COBOL main method entered”
.
End method “main”.
End factory.
End class CBLmain.
cbl thread,lib,ssrange
Identification Division.
Class-id. Echo inherits Base.
Environment Division.
Configuration section.
Repository.
Class Base is “java.lang.Object”
Class stringArray is “jobjectArray:java.lang.String”
Class jstring is “java.lang.String”
Class Echo is “Echo”.
*
Identification Division.
Factory.
Procedure division.
*
Identification Division.
Method-id. “main”.
Data division.
Local-storage section.
01 SAlen pic s9(9) binary.
01 I pic s9(9) binary.
01 SAelement object reference jstring.
01 SAelementlen pic s9(9) binary.
01 P pointer.
Linkage section.
01 SA object reference stringArray.
01 Sbuffer pic N(65535).
Copy “JNI.cpy” suppress.
Procedure division using by value SA.
Set address of JNIEnv to JNIEnvPtr
Set address of JNINativeInterface to JNIEnv
Call GetArrayLength using by value JNIEnvPtr SA
returning SAlen
Display “Input string array length: ” SAlen
Display “Input strings:”
Perform varying I from 0 by 1 until I = SAlen
Call GetObjectArrayElement
using by value JNIEnvPtr SA I
returning SAelement
Call GetStringLength
using by value JNIEnvPtr SAelement
returning SAelementlen
Call GetStringChars
using by value JNIEnvPtr SAelement 0
returning P
Set address of Sbuffer to P
Display function display-of(Sbuffer(1:SAelementlen))
Call ReleaseStringChars
using by value JNIEnvPtr SAelement P
End-perform
.
End method “main”.
End factory.
End class Echo.
related tasks
Compiling, linking, and running OO applications
Defining a factory method
Communicating with Java methods