MUMPS Programming/variables
Appearance
Variables are names that refer to values. In MUMPS, there are are two kinds of variables, "global variables" and "local variables".
- The first kind of MUMPS variables is called a "global" variable. These variables store information in a similar way to DISK memory in a computer. When the computer is shut down, the disk information is still saved. MUMPS global variables are persistent, and available after a MUMPS JOB is HALTed. These variables are persistent, and permanent until they are KILLed. They can be explicitly erased by the KILL command. These global variabless are process-public, and accessible from any JOB on the system at any time and can be changed by any JOB at any time even though they are actually stored on disk. These global variables are available from any subroutine, and there is only one shared copy available to every subroutine. These MUMPS global variables are not replicated in other programming languages. In other languages, information that persists over time is not as accessible as global variables, as it is stored in a database, and requires a different way of access.
- The second kind of MUMPS variable is called a "local" variable. These variables store information in a similar way to RAM memory in a computer. When the computer is shut down, the memory is erased. MUMPS local variables are erased when a MUMPS JOB is HALTed. These variables are temporary, only existing as long as a JOB. They can be explicitly erased by the KILL command. These variables are also private to a JOB, so that only the subroutines in that JOB can view them. These local variables are available in every subroutine unless a NEWed local variable exists that hides their name. Other programming languages refer to this type of variable as "globals", because they are visible to any part of the program that is currently running. This name is inappropriate in MUMPS, because in contrast to other languages, MUMPS global variables are variables that have a higher visibility than the "global" variables used in other languages.
- Since all MUMPS local variables are temporary and local to a JOB, there are times that a program needs to use a variable name that has already been used to refer to its own variables. The NEW command allows any already existing local variables to be hidden and a new variable name to be made available. These NEWed local variables have the same properties as other local variables, but are only visible to a particular subroutine and all subroutines that are called from it.