$XECUTE
Synopsis
$XECUTE expression
Arguments
expression | An expression that evaluates to one or more valid ObjectScript commands, specified as a quoted string. The expression string delimiter character cannot be used within expression. For example, if the expression string contains double quotation marks (delimiting an ObjectScript string literal), you must enclose expression with either single quote marks (') or backslash (\) characters. |
Description
$XECUTE is used to invoke an ObjectScript command from within Caché MVBasic. $XECUTE executes ObjectScript commands that result from the process of expression evaluation of the specified argument. Each $XECUTE argument must evaluate to a string containing ObjectScript commands. The string must not contain a tab character at the beginning or a <Return> at the end. The string must be no longer than a valid ObjectScript program line.
In effect, the $XECUTE argument is like calling a one-line subroutine. It is terminated when the end of the argument is reached or an ObjectScript QUIT command is encountered. After Caché executes the argument, it returns control to the point immediately after the $XECUTE argument.
Each invocation of $XECUTE places a new context frame on the call stack for your process. The ObjectScript $STACK special variable contains the current number of context frames on the call stack.
Local Variables
Variables in MVBasic are local, private variables. They are hidden from the ObjectScript code being executed by a $XECUTE statement. Therefore, $XECUTE can only be used for ObjectScript code that does not access MVBasic variables or expressions containing MVBasic variables.
If you wish to execute ObjectScript that uses MVBasic variables, your MVBasic code must pass those variables as actual parameters to an external ObjectScript routine.
Invoking Other Command Shells
You can use the EXECUTE, PERFORM, and CHAIN commands to issue MultiValue commands from within Caché MVBasic.
You can use the PCPERFORM command to issue an operating system command from within Caché MVBasic.
Examples
The following example executes the subroutine that is the value of CosSub.
CosSub="WRITE ! FOR I=1:1:5 { WRITE ?I*5,I+1 }"
$XECUTE CosSub
Returns:
2 3 4 5 6
Notes
$XECUTE and Objects
You can use $XECUTE to call object methods and properties and execute the returned value, as shown in the following examples:
$XECUTE patient.Name
$XECUTE "WRITE patient.Name"
$XECUTE and FOR
If the $XECUTE argument contains an ObjectScript FOR command, the scope of the FOR is the remainder of the argument. When the outermost FOR in an $XECUTE argument is terminated, the $XECUTE argument is also terminated.
$XECUTE and DO
If the $XECUTE argument contains an ObjectScript DO command, Caché executes the routine or routines specified in the DO argument or arguments. When it encounters a QUIT, it returns control to the point immediately following the DO argument.
For example, in the following commands, Caché executes the routine ROUT and returns to the point immediately following the DO argument to write the string “DONE”.
$XECUTE 'DO ^ROUT WRITE !,"DONE"'
$XECUTE and GOTO
A ObjectScript command specified in $XECUTE cannot specify an ObjectScript label. An ObjectScript command specified in $XECUTE cannot access an MVBasic label. Therefore the use of GOTO within $XECUTE is not supported.
$XECUTE and QUIT
There is an implied QUIT at the end of each $XECUTE argument.
Nested Invocation of $XECUTE
Caché supports the use of the ObjectScript XECUTE command within the $XECUTE argument. However, you should use nested invocation of $XECUTE with caution because it can be difficult to determine the exact flow of processing at execution time.
Execution Time for Commands Called by $XECUTE
The execution time for code called within $XECUTE can be slower than the execution time for the same code encountered in the body of a routine. This is because Caché compiles source code that is specified with the $XECUTE command or that is contained in a referenced global variable each time it processes the $XECUTE.