自由形式構文 | RETURN{(HMR)} 式 |
コード | 演算項目 1 | 拡張演算項目 2 | ||||
---|---|---|---|---|---|---|
RETURN (H M/R) | 式 |
RETURN 命令は呼び出し元へ戻します。 呼び出し元に値が戻されると、式 オペランドに戻り値が示されます。
RETURN 命令の結果として行われる処置は、命令がサブプロシージャー内にあ るかどうかによって異なります。 プログラムまたはメイン・プロシージャーが戻すと、次のことが行われます。
サブプロシージャーが戻すと、戻り値 (呼び出されたプログラムまたはプロシ ージャーのプロトタイプで指定された場合) が呼び出し元に渡されます。 自動的には何も行われません。 ファイルおよびデータ域はすべて手操作でクローズしなければなりません。 LR などの標識を設定できますが、 これでプログラムの終了を行うことはできません。 命令拡張 H、M、および R がどのように使用されるかについて は、数値演算の精度の規則を参照してください。
値を戻すサブプロシージャーでは、RETURN 命令はそのサブプロシージャー内で コーディングしなければなりません。 実際に戻された値は EVAL 式の左側と同じ働きをし、RETURN 命令の拡張演算項目 2 は右側と同じ働きをします。 配列を戻すことができるのは、プロトタイプが戻り値を配列として定義してい る場合だけです。
サブプロシージャーが値を戻した場合には、プロシージャーの終わりに達する 前に RETURN 命令が実行されていることを確認してください。 サブプロシージャーが RETURN 命令を 見付けないで終了している場合には、呼び出し元に例外が通知されます。
詳細については、呼び出し命令を参照してください。
* This is the prototype for subprocedure RETNONE. Since the * prototype specification does not have a data type, this * subprocedure does not return a value. D RetNone PR * This is the prototype for subprocedure RETFLD. Since the * prototype specification has the type 5P 2, this subprocedure * returns a packed value with 5 digits and 2 decimals. * The subprocedure has a 5-digit integer parameter, PARM, * passed by reference. D RetFld PR 5P 2 D Parm 5I 0 * This is the prototype for subprocedure RETARR. The data * type entries for the prototype specification show that * this subprocedure returns a date array with 3 elements. * The dates are in *YMD/ format. D RetArr PR D DIM(3) DATFMT(*YMD/) * This procedure (P) specification indicates the beginning of * subprocedure RETNONE. The data specification (D) specification * immediately following is the procedure-interface * specification for this subprocedure. Note that the * procedure interface is the same as the prototype except for * the definition type (PI vs PR). P RetNone B D RetNone PI * RetNone does not return a value, so the RETURN * operation does not have factor 2 specified. C RETURN P RetNone E * The following 3 specifications contain the beginning of * the subprocedure RETFLD as well as its procedure interface. P RetFld B D RetFld PI 5P 2 D Parm 5I 0 D Fld S 12S 1 INZ(13.8) * RetFld returns a numeric value. The following RETURN * operations show returning a literal, an expression and a * variable. Note that the variable is not exactly the same * format or length as the actual return value. C RETURN 7 C RETURN Parm * 15 C RETURN Fld P RetFld E
* The following 3 specifications contain the beginning of the * subprocedure RETARR as well as its procedure interface. P RetArr B D RetArr PI D DIM(3) D SmallArr S D DIM(2) DATFMT(*ISO) D BigArr S D DIM(4) DATFMT(*USA) * RetArr returns a date array. Note that the date * format of the value specified on the RETURN operation * does not have to be the same as the defined return * value. * The following RETURN operation specifies a literal. * The caller receives an array with the value of the * literal in every element of the array. C RETURN D'1995-06-27' * The following return operation returns an array * with a smaller dimension than the actual return value. * In this case, the third element would be set to the * default value for the array. C RETURN SmallArr * The following return operation returns an array * with a larger dimension than the actual return * value. In this case, the fourth element of BigArr * would be ignored. C RETURN BigArr P RetArr E
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.