NewBie's Corner Session 20 Parameters and Status Part I
NewBie's Corner Session 20 Parameters and Status Part I
Welcome to NewBie's Corner, a weekly or biweekly post covering basic Caché Material.
Parameters
Parameters are another name for Variables when used in passing data from one Routine to another.
Let us say we have 2 routines (RtnA and RtnB), and we want to pass 3 parameters (Parm1, Parm2, Parm3) from RtnA to RtnB.
RtnA would look like:
RtnA
Set Parm1 = "Value for Parm1"
Set Parm2 = "Value for Parm2"
Set Parm3 = "Value for Parm3"
Do ^RtnB(Parm1, Parm2, Parm3) ; Actual Call List
Quit
RtnB would look like:
RtnB(Parm1, Parm2, Parm3) ; Formal Call List
Write !,"Parm1 = ",Parm1
Write !,"Parm2 = ",Parm2
Write !,"Parm3 = ",Parm3
Quit
Actual Call List and Formal Call List
When RtnA calls RtnB with the three parameters, this is referred to as the "Actual Call List."
When RtnB receives the three parameters, this is referred to as the "Formal Call List."
The number of parameters in the Actual Call List should match the number of parameters in the Formal Call List. (This is not a hard and fast rule, see the InterSystems documentation for exceptions to this rule.)
In addition to passing parameters, a Status can be passed back, see the new RtnA and RtnB below.
RtnA would look like:
RtnA
Set Var1 = "Value for Var1"
Set Var2 = "Value for Var2"
Set Var3 = "Value for Var3"
Set Status = $$^RtnB(Var1, Var2, Var3) ; Call to RtnB and receive a Status in return
Quit
RtnB would look like:
RtnB(Var1, Var2, Var3)
Write !,"Var1 = ",Var1
Write !,"Var2 = ",Var2
Write !,"Var3 = ",Var3
Set Status = 1
Quit Status ; Quit passing back a Status
In RtnA please note, the call to RtnB is not just a "Do" but a "Set Status = ".
And two dollar signs now precede ^RtnB, to give $$^RtnB.
User Defined Function
RtnB now becomes a User Defined Function since it returns a value.
And in RtnB the "Quit Status" passes back the Status.
Successful Status and Unsuccessful Status
By convention when the first character of the Status is a 1, that signifies a success.
And when the first character of the Status is a 0 (Zero), that signifies a failure.
--Mike Kadow
If you have a comment, please respond through the InterSystems Developer Community, don't send me private email, unless of course you wish to address me only.
See "Newbie's Corner Index" for an index of all NewBies' Posts
For more flexibility/fun with parameters, also check out:
http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GCOS_usercode#GCOS_usercode_args_variable
and
http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GOBJ_methods#GOBJ_methods_args_variable
:)