以下の例では、main という名前のファクトリー・メソッドを含む COBOL クラス定義を示します。
いずれの場合も、main には RETURNING 句がなく、java.lang.String 型のエレメントの配列であるクラスへのオブジェクト参照である単一の USING パラメーターがあります。これらのアプリケーションは、java コマンドを使用して実行できます。
cbl dll,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 dll,thread,lib,pgmname(longmixed),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 Sbuffer pic X(65535). 01 P pointer. Linkage section. 01 SA object reference stringArray. 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 "GetStringPlatformLength" using by value JNIEnvPtr SAelement address of SAelementlen 0 Call "GetStringPlatform" using by value JNIEnvPtr SAelement address of Sbuffer length of Sbuffer 0 Display Sbuffer(1:SAelementlen) End-perform . End method "main". End factory. End class Echo.