Mike Kadow · Jun 2, 2016 3m read

NewBie's Corner Session 6 If and Kill commands

NewBie's Corner Session 6 If and Kill commands

Welcome to NewBie's Corner, a weekly or biweekly post covering basic Caché Material.

Click on the Caché Cube in your system tray and select Terminal to try out the commands.

As in other computer programming languages, the If command is the primary decision makes.

If command with numeric operands

Set X=12
If X=12 Set X=13
Write X

If command with alphanumeric operands

Set X="ABC"
If X="ABC" Set X="XYZ"
Write X

Whenever alphanumeric data is being referenced, quotation marks are required.

Kill command

Thus far, we have learned how to set a variable to a value with the Set command; display that value using the Write command; and using the If command, conditionally set a variable to another value.

Now we will completely delete the variable and its value.

Set X="ABC"
Kill X
Write X

In this example the Kill command completely deletes the variable and any value that it contains. After killing the variable X, any attempt to access X results in an <UNDEFINED> error. Notice that the Kill command not only removes the value a variable holds, but completely removes or deletes the variable as well.

Kill all variables

The Kill command used with no parameters or variables removes all variables defined thus far.

Set X=12,Y=13,Z=14         ;set variables
Write                                     ;write all variables
Kill                                          ;kill all variables
Write                                     ;write all variables, but none exist

This shows the Kill command with no variables, a Write command with no variable produces no output because no variables exist.

Kill all variables except Y and Z

The Kill command used with adjoining parenthesis, save variable(s)

Set X=12,Y=13,Z=14         ;set variables
Kill (Y,Z)                                ;kill all variables except Y and Z
Write                                     ;write all variables

This shows the Kill command kill except Y and Z

I suggest you spend some time on the Terminal trying some of these combinations. They are not always as obvious as you think.

--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 Index for an index of all NewBie Corner posts

0 324
Discussion (0)1
Log in or sign up to continue