Article
Mike Kadow · Aug 9, 2016 4m read

NewBie's Corner Session 15 Executing Routines and Labels

NewBie's Corner Session 15 Executing Routines and Labels

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

Routines and Labels

Routines are computer programs with a number of executable code lines.

Labels (also called tags) are points in a routine that can be called (executed). They subdivide routines into manageable modules (or subroutines).

Routines, Subroutines/Modules and Functions

  • Routines are the name that COS calls computer programs
  • Subroutines and Modules are subsections within a Routine that start with a Label Line and end with a Quit command
  • Functions are the same as Subroutines but Functions always return a value

Executing Routines

ROUTINEA                                          ; name of the routine on the first line
                Do ^ROUTINEB                 ; execution jumps to ^ROUTINEB
                                                                ; when ROUTINEB ends, execution comes back here
                Quit                                       ; exit the routine

 

This example shows ROUTINEA, identified by the routine name on the first line. When the Do command "Do ^ROUTINEB" is encountered, execution jumps to ROUTINEB. The Caret (^) before ROUTINEB signifies that ROUTINEB is a separate routine. If no Caret (^) is found on the Do command, execution jumps to a Label inside the current routine.

Executing a Label in a Routine

ROUTINEA
                ;
                Do PROC              ; execution jumps to the PROC label
                ; code
                Quit
PROC     ;                               ; Label
                ; code
                Quit                       ; execution jumps back to the line following "Do PROC"

 

In the above example, when the line "Do PROC" is encountered, execution jumps to the PROC Label and continues until it reaches the Quit command. At the Quit, execution jumps back to the line following "Do PROC".

Executing a Label in another Routine

ROUTINEA          ; Routine ROUTINEA
                ;
                Do PROC^ROUTINEB      ; execution jumps to PROC in ^ROUTINEB
                ; code
                Quit
ROUTINEB           ; Routine ROUTINEB
                ;
PROC
                ; code
                Quit       ; execution jumps to the line following PROC in ^ROUTINEA

 

This example shows two separate routines, ROUTINEA and ROUTINEB. In ROUTINEA, when the line "Do PROC^ROUTINEB" is encountered, execution jumps to the PROC label inside ROUTINEB. When the Quit command under PROC^ROUTINEB is reached, execution jumps to the line following "Do PROC^ROUTINEB" in ROUTINEA

--Mike Kadow

PaulMikeKadow@gmail.com

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 Index for an index of all NewBie Corner's Posts.

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