Executing M Routines Interactively

To execute an M routine interactively, it is not necessary to explicitly compile and link your program. When you refer to an M routine that is not part of the current image, GT.M automatically attempts to compile and ZLINK the program.

Example:

        GTM>DO ^dmex
        Name: Revere, Paul
        %GTM-E-UNDEF, Undefined local variable: bame
        At M source location name+3^DMEX
        GTM>
        

In this example GT.M places you in Direct Mode, but also cites an error found in the program with a run-time error message. In this example, it was a reference to bame, which is undefined.

To see additional information about the error message, examine the $ECODE or $ZSTATUS special variables.

$ECODE is read-write intrinsic special variable that maintains a list of comma delimited codes that describe a history of past errors - the most recent ones appear at the end of the list. In $ECODE, standard errors are prefixed with an "M", user defined errors with a "U", and GT.M errors with a "Z". A GT.M code always follows a standard code.

$ZSTATUS is a read-write intrinsic special variable that maintains a string containing the error condition code and location of the last exception condition occurring during routine execution. $ZSTATUS information always contains all components of the VMS error message format (message number, facility, error severity, identification and text). GT.M updates $ZSTATUS only for errors found in routines and not for errors entered at the Direct Mode prompt.

[Note]

For more information on $ECODE and $STATUS refer to the "Intrinsic Special Variables" chapter in this manual.

Example:

        GTM>WRITE $ECODE
        ,M6,Z150373850
        

This example uses a WRITE command to display $ECODE.

Example:

        GTM>WRITE $ZS
          
        150373850,name+3^DMEX,%GTM-E-UNDEF,Undefined
        local variable: bame
          
          
        

This example uses a WRITE command to display $ZSTATUS. Note that the $ZSTATUS code is the same as the "Z" code in $ECODE.

You can record the error message number, and use the $ZMESSAGE function later to re-display the error message text.

Example:

        GTM>WRITE $ZM(150373850)
        %GTM-E-UNDEF, Undefined local variable: !AD
        

This example uses a WRITE command and the $ZMESSAGE function to display the error message generated in the previous example. $ZMESSAGE() is useful when you have a routine that produces several error messages that you may want to examine later. The error message reprinted using $ZMESSAGE() is generic; therefore, the code !AD appears instead of the specific undefined local variable displayed with the original message.