Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

プロシージャ

他のプログラミング言語と同様、プロシージャは特定のタスクを実行する一連の ObjectScript コマンド (大規模なルーチン) です。プロシージャのコードは中括弧 ({}) で囲まれています。

既定では、プロシージャはプライベートであるため、同じルーチン内からのみ呼び出すことができます。また、プロシージャ名の後に PUBLIC キーワードを使用して、パブリック・プロシージャを生成できます。パブリック・プロシージャは他のルーチンからも呼び出せます。

プロシージャでは、定義済みのパラメータは必要ありません。パラメータ付きでプロシージャを生成する場合、ラベルの直後に括弧で囲んだ変数リストを置きます。

プロシージャでパラメータを取得し、値を返すユーザ関数の記述方法は後で学習します。

SAMPLES>do ^procexample

Enter a number: 4
setting a
setting b
setting c
setting d
SAMPLES>do proc2^procexample(7)

my favorite number is 7
SAMPLES>

以下は、procexample.mac コードです。

procexample ; examples of procedures
    read !, "Enter a number: ", x
    if x = 4  {do proc1()}   ; call a procedure
    quit    ; end of the main routine

proc1() ; a private procedure
    {
    write !, "setting a"  set a = 1
    write !, "setting b"  set b = 2
    write !, "setting c"  set c = 3
    write !, "setting d"  set d = 4
    }

proc2(num) PUBLIC
    ; a public procedure with a parameter
    { write !, "my favorite number is ",num }
FeedbackOpens in a new tab