Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.

For information on migrating to InterSystems IRIS, see How to Migrate to InterSystems IRIS, available on the WRC Distributions page (login required).

Procedures

As in other languages, a procedure is a series of ObjectScript commands (a section of a larger routine) that accomplishes a specific task. The code of a procedure is contained within curly braces.

By default, procedures are private, which means that you can only call them from elsewhere in the same routine. You can also create procedures that are public, using the Public keyword after the procedure name. Public procedures can be called from other routines.

Procedures need not have defined parameters. To create procedures with parameters, place a parenthesized list of variables immediately after the label.

Later on you'll also learn how to write your own functions, which are procedures which take parameters and return a value.

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>

The procexample.mac code:

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 }
Feedback