Rational Developer for System z
COBOL for Windows バージョン 7.5 プログラミング・ガイド


例: java コマンドを使用して実行できる COBOL アプリケーション

以下の例では、main という名前のファクトリー・メソッドを含む COBOL クラス定義を示します。

いずれの場合も、main には RETURNING 句がなく、java.lang.String 型のエレメントの配列であるクラスへのオブジェクト参照である単一の USING パラメーターがあります。これらのアプリケーションは、java コマンドを使用して実行できます。

メッセージの表示

 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.

関連タスク
オブジェクト指向アプリケーションのコンパイル、リンク、および実行
ファクトリー・メソッドの定義
Java メソッドとの通信


ご利用条件 | フィードバック

Copyright IBM Corporation 1996, 2008.
このインフォメーション・センターでは Eclipse テクノロジーが採用されています。(http://www.eclipse.org)