CALLP (プロトタイプ・プロシージャーまたはプログラムの呼び出し)
自由形式構文 | {CALLP{(EMR) } } 名前( {パラメーター1{:パラメーター2... } } ) |
コード | 演算項目 1 | 拡張演算項目 2 | ||||
---|---|---|---|---|---|---|
CALLP (E M/R) | 名前{ (パラメーター1 {:パラメーター2… }) } |
CALLP 命令は、プロトタイプ・プロシージャーまたはプログラムの呼び出しに使用されます。
他の呼び出し命令とは違って、CALLP では自由形式の構文が使用されます。 呼び出されるプログラムまたはプロシージャーのプロトタイプの名前および渡されるパラメーターを指定するためには、名前 オペランドを使用します。(これは組み込み関数の呼び出しに似ています。) プログラム呼び出しには最大 255、プロシージャー呼び出しには最大 399 の パラメーターを使用することができます。
自由形式演算仕様においては、拡張が不要である場合、およびプロトタイプに命令コードと同じ名前がない場合は、命令コード名を省略できます。
次に、コンパイラーはこのプロトタイプ名を使用して、 呼び出しに必要な外部名を取り出します。 プロトタイプにキーワード EXTPGM が指定されている場合には、呼び出しは動的外部 呼び出しになります。そうでない場合には、これはバインド・プロシージャー呼び出しです。
呼び出し先のプログラムまたはプロシージャーが別のモジュールで定義されている場合、 呼び出されるプログラムまたはプロシージャーのプロトタイプは、CALLP の前 の定義仕様書に含まれていなければなりません。 呼び出し先のプログラムまたはプロシージャーが、呼び出しと同じモジュールに定義されている場合、明示的なプロトタイプは必要ありません。 プロトタイプは、呼び出し先のプログラムまたはプロシージャーのプロシージャー・インターフェースから暗黙的に定義できます。
値を戻すプロシージャーの呼び出しに CALLP を使用した場合には、呼び出し元はそ の値を使用できないことに注意してください。 値が必要な場合は、式の中でプロトタイプ・プロシージャーを呼び出します。
CALLP(E) PROGNAME(FileRecs(Fld) + 1)
呼び出し命令の詳細については、呼び出し命令を参照してください。プロトタイプの定義 の詳細については、プロトタイプおよびパラメーターを参照してください。 命令拡張 M および R が どのように使用されるかについては、数値演算の精度の規則を参照してください。
*..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
*-------------------------------------------------------------
* This prototype for QCMDEXC defines two parameters:
* 1- a character field that may be shorter in length
* than expected
* 2- any numeric field
*-------------------------------------------------------------
D qcmdexc PR extpgm('QCMDEXC')
D cmd 200A options(*varsize) const
D cmdlen 15P 5 const
/FREE
qcmdexc ('WRKSPLF' : %size ('WRKSPLF'));
/END-FREE
* The prototype for the procedure has an array parameter.
D proc pr
D parm 10a dim(5)
* An array to pass to the procedure
D array s 10a dim(5)
* Call the procedure, passing the array
C callp proc (array)
CALLP の次の例は「Rational Development Studio for i ILE RPG プログラマーの手引き」のサービス・プログラムの例からのもの です。 CvtToHex は、変換ルーチンを入れるために作成されたサービス・プログラムの プロシージャーです。 CvtToHex は入力ストリングをその 16 進数形式に変換します。 プロトタイプ呼び出しは ILE CEE API, CEEDOD (操作記述子の検索) に対する ものです。 これは入力ストリングの長さを確認するために使用されます。
*..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
*=================================================================*
* CvtToHex - convert input string to hex output string *
*=================================================================*
D/COPY MYLIB/QRPGLESRC,CVTHEXPR
*-----------------------------------------------------------------*
* Main entry parameters *
* 1. Input: string character(n) *
* 2. Output: hex string character(2 * n) *
*-----------------------------------------------------------------*
D CvtToHex PI OPDESC
D InString 16383 CONST OPTIONS(*VARSIZE)
D HexString 32766 OPTIONS(*VARSIZE)
*-----------------------------------------------------------------*
* Prototype for CEEDOD (Retrieve operational descriptor) *
*-----------------------------------------------------------------*
D CEEDOD PR
D 10I 0 CONST
D 10I 0
D 10I 0
D 10I 0
D 10I 0
D 10I 0
D 12A OPTIONS(*OMIT)
* Parameters passed to CEEDOD
D ParmNum S 10I 0
D DescType S 10I 0
D DataType S 10I 0
D DescInfo1 S 10I 0
D DescInfo2 S 10I 0
D InLen S 10I 0
D HexLen S 10I 0
*-----------------------------------------------------------------*
* Other fields used by the program *
*-----------------------------------------------------------------*
D HexDigits C CONST('0123456789ABCDEF')
D IntDs DS
D IntNum 5I 0 INZ(0)
D IntChar 1 OVERLAY(IntNum:2)
D HexDs DS
D HexC1 1
D HexC2 1
D InChar S 1
D Pos S 5P 0
D HexPos S 5P 0
/FREE
//-------------------------------------------------------------//
// Use the operational descriptors to determine the lengths of //
// the parameters that were passed. //
//-------------------------------------------------------------//
CEEDOD (1 : DescType : DataType :
DescInfo1 : DescInfo2 : Inlen : *OMIT);
CEEDOD (2 : DescType : DataType :
DescInfo1 : DescInfo2 : HexLen : *OMIT);
//-------------------------------------------------------------//
// Determine the length to handle (minimum of the input length //
// and half of the hex length) //
//-------------------------------------------------------------//
if InLen > HexLen / 2;
InLen = HexLen / 2;
endif;
//-------------------------------------------------------------//
// For each character in the input string, convert to a 2-byte //
// hexadecimal representation (for example, '5' --> 'F5') //
//-------------------------------------------------------------//
HexPos = 1;
for Pos = 1 to InLen;
InChar = %SUBST(InString : Pos :1);
exsr GetHex;
%subst (HexString: HexPos: 2) = HexDs;
HexPos = HexPos + 2;
endfor;
return;
//================================================================//
// GetHex - subroutine to convert 'InChar' to 'HexDs' //
// Use division by 16 to separate the two hexadecimal digits. //
// The quotient is the first digit, the remainder is the second. //
//================================================================//
begsr GetHex;
IntChar = InChar;
//-----------------------------------------------------//
// Use the hexadecimal digit (plus 1) to substring the //
// list of hexadecimal characters '012...CDEF'. //
//-----------------------------------------------------//
HexC1 = %subst (HexDigits: %div(IntNum:16) + 1: 1);
HexC2 = %subst (HexDigits: %rem(IntNum:16) + 1: 1);
endsr; // GetHex