STATIC キーワードに関する規則:

  • STATIC キーワードは、サブプロシージャー内のファイル定義にしか指定できません。 グローバル定義で定義されたファイルに対して、STATIC キーワードが暗黙的に指定されます。
  • STATIC キーワードで定義されたファイルは、CLOSE 命令によって明示的にクローズされるまで、あるいは活動化グループが終了するまで、開いたままになります。
  • ファイル情報データ構造 (INFDS) がファイルに定義されている場合、データ構造に対して指定した STATIC キーワードは、ファイルに対して指定した STATIC キーワードと一致している必要があります。
図 1. ファイル仕様書での STATIC キーワードの例
P numInStock      b                   export
 * File "partInfo" is defined as STATIC.  The file will be
 * opened the first time the procedure is called, because
 * the USROPN keyword is not specified.
 * Since there is no CLOSE operation for the file, it
 * will remain open until the activation group ends.
FpartInfo  if   e           k disk    static
 * File "partErrs" is not defined as STATIC, and the USROPN
 * keyword is used.  The file will be opened by the OPEN
 * operation, and it will be closed automatically when the
 * procedure ends.
FpartErrs  o    e             disk    usropn

D numInStock      pi            10i 0
D    id_no                      10i 0 value
D partInfoDs      ds                  likerec(partRec:*input)
D partErrDs       ds                  likerec(errRec:*output)

 /free       // Search for the input value in the file
       chain id_no partRrec partInfoDs;
       if  not %found(partInfo);          // write a record to the partErrs file indicating
          // that the id_no record was not found.  The
          // file must be opened before the record can
          // be written, since the USROPN keyword was
          // specified.
          partErrDs.id_no = id_no;
          open partErrs;
          write errRec partErrDs;
          return -1; // unknown id
       endif;
       return partInfoDs.qty; /end-free
P numInStock      e