Global Variables

Description

Global variables are variables that can be read and modified by all routines within all processes from the time it is SET until it is KILLed.

They can be used by multiple users and stay in the system until they are explicitly killed. Global variables are written to the disk and remain even after the program is terminated.

Global variables can be used interchangeably with local variables except for these cases:

-As control variables in a FOR command

-As subarguments of the Kill command

-As arguments in the NEW command, parameter passing, and extrinsic functions

Note: Make sure to use the HALT command at the end of a user session or the global variable may not be saved and written to disk.

Example

SET ^A="Luis"

SET B="Ibanez"

HALT

WRITE ^A

WRITE B

KILL ^A

WRITE ^A

This code will write out “Luis” for A then garbage for B because B is a local variable and will be erased when the program is HALTed. It will then write garbage for the second write of A because the variable was KILLed.

Material prepared from M Programming Book [WALTERS1997]

Page 145-148