Was this helpful?
Macro Concepts
All Terminal Monitor macros are defined as two parts:
The template part
The replacement part
A macro can be created using the {define} macro statement. The basic form of the {define} command is:
{define; $$t; $$r}
Where "t" and "r" are the template and replacement parts of the macro.
The Terminal Monitor contains a macro processor that substitutes the replacement part of the macro for the template part. For example:
{define; ins $t $v; insert into $t VALUES ( $v )}\eval
ins t001 27\list
This macro causes the word "ins" followed by the next two values to be expanded into:
INSERT INTO t001 VALUES ( 27 )
The template part establishes a symbol that, when encountered in the Terminal Monitor macro workspace, signals Terminal Monitor to invoke the symbol's definition. When a macro is encountered, the template part is removed and replaced with the replacement part.
For example, the template "get" causes the corresponding definition of "get" to be invoked. If the replacement part of the "get" macro is "SELECT", all instances of the word "get" in the query text are replaced with the word "SELECT":
\macro
{define;get;SELECT}\eval
get * from iitables\g
The Terminal Monitor expands the "get" macro as follows:
SELECT * FROM iitables\g
The following example shows all instances of the word "get" in the query text being replaced with the word "foo":
\macro
{define;get;foo}\eval
SELECT get.* FROM iitables get\g
The Terminal Monitor expands the "get" macro as follows:
SELECT foo.* FROM iitables foo\g
Macros can accept parameters. Parameters are specified as a single letter or digit preceded by a dollar sign, e.g. $2 or $k.
For example, the template "get $1" allows the "get" macro to accept a single parameter.
If the "get" macro is defined as:
{define;get $1;SELECT table_name FROM iitables t1 WHERE t1.table_reltid=$1}
get 24
selects table_name from iitables where table_reltid is 24 (this will return two rows).
If the "get" macro were defined as:
{define;get $a $1;SELECT first $a * FROM iitables t1 WHERE t1.table_reltid=$1}
get 1 24
selects the first row from iitables where table_reltid is 24.
Last modified date: 08/28/2024