Because keywords are implemented as a global data structure, different MIDAS procedures can access the same keyword. This useful feature can cause problems, however, if these keywords just serve as local, temporary variables like the DO variables. Consider the procedures below:
!+Executing @@ exa11 will give some unexpected results, since both procedures access the same integer keyword N as a common variable.
! Example 11, MIDAS procedure exa11.prg
!+
WRITE/KEYWORD N/I/1/1 0
DO N = 1 10
@@ test
ENDDO !+
! MIDAS procedure test.prg
!+
WRITE/KEYWORD N/I/1/1 0
DO N = 1 12
WRITE/KEYWORD INPUTI/I/12/1 N
ENDDO
!+Local keywords are deleted when returning to the next higher level at the end of a procedure.
! Example 12, MIDAS procedure exa12.prg
!+
DEFINE/LOCAL N/I/1/1 0
DO N = 1 10
@@ test
ENDDO
!+
! MIDAS procedure test.prg
!+
DEFINE/LOCAL N/I/1/1 0
DO N = 1 12
WRITE/KEYWORD INPUTI/I/12/1 N
ENDDO
NoteAlways provide all initial values to a keyword. For example,
define/local lola/r/1/6 0 usually works as intended, i.e. all elements of keyword lola are filled with 0, but depending upon the computer and operating system the contents of lola(2,...,6) may be unpredictable. So, use
define/local lola/r/1/6 0 all in order to fill all elements of keyword lola with 0.