Next, I’d like to tackle the topic of the custom of terminating variable names with a symbol like ‘#
’. This is a topic that often confuses new users, and it is not fully explained in the documentation.
In the Automation Engine documentation, virtually all variable names mentioned in examples are terminated with a hash symbol (#
). E.g., &CLIENT#
or &HOST#
. Pre-defined variables for system and object attributes are also all terminated with a #
symbol. E.g., &$SYSTEM#
or &$RUNID#
.
At Automic, and among customers too, it is standard practice to terminate AE variable names with a single #
character. This is not a hard and fast requirement, but it is a recommended convention. Why? A basic limitation of the Automation Engine:
Variable names may not be substrings of other variable names.
This means that if you define the variable called &APP
, you cannot also define a variable called &APP_ID
. This is because the former is a substring of the latter. If you try to save an object wherein two such variables are defined, message U01001312 will appear:
U01001312 Variable name 'APP_ID' is not allowed. A variable with the name 'APP' already exists.
Terminating the variable names with a symbol such as #
gets around this limitation. A termination character at the end of variable names ensures that the names do not overlap¹. E.g., &APP#
is not a substring of &APP_ID#
. If you do not terminate variable names, you must do more work name them in such a way as to ensure that the names do not overlap. Terminating variable names makes scripting easier, because you do not have to work to prevent variable name overlaps; you must simply ensure name uniqueness.
Any character that is allowed in variable names² may be used as a termination character. It is merely convention to use the #
character. For this convention to be most effective, you must follow two rules:
- Use the same termination character consistently, in all variable names. Again, it is a common convention to terminate variable names with the
#
character. - Do not use the termination character in the middle of variable names. Use it only at the end.
Notes:
1. If you examine the AE scripts used internally in the Automation Engine, you will find many variables names that are not terminated. For example, here is an excerpt from the UNIX header include object from client 0 (HEADER.UNIX):
:set &UC_EXVER = get_var(UC_EX_VERSION)
:set &UC_MANDANT = SYS_ACT_CLIENT
:set &UC_REALNR = SYS_ACT_RESTART_ME_NR
:set &UC_NAME = SYS_ACT_JOBNAME
:set &UC_JOBMD = get_var(UC_EX_JOB_MD)
:set &UC_IP_ADDR = get_var(UC_EX_IP_ADDR)
:set &UC_IP_PORT = get_var(UC_EX_IP_PORT)
:set &UC_UNIX_SHELL = get_att(UNIX_SHELL)
Note that although these variable names are not terminated, none of them is a substring of any other.
2. The characters allowed in variable names are A-Z, a-z, 0-9, _, $, @, §, and #. (See this thread for details.)