Idea Details

:SET_SCRIPT_VAR should be able to set the values of previously undefined variables

Last activity 6 days ago
Michael Lowry's profile image
04-13-2018 04:39 PM

Automation Engine v12.1 introduced the GENERATE_UNDEFINED_SCRIPT_VARS system setting. When this setting set to Y, variables that have not already been defined do not cause syntax errors when they are used in scripts. This also faciliates using the new  GENERATE_SCRIPT_VARS script function to generate script variables based on the keys and values stored in a static VARA object.

When GENERATE_UNDEFINED_SCRIPT_VARS is set to Y, it should also be possible to generate script variables by indirect reference using the :SET_SCRIPT_VAR script statement.

Consider a script like this:

:SET &var_name1# = "ABC#"
:SET &var_val1#  = "123"
:SET_SCRIPT_VAR &VAR_NAME1# = &var_val1#
:SET &temp_name# = "VAR_NAME1#"
:SET &temp_val#  = GET_SCRIPT_VAR(&temp_name#)
:PRINT "Value of variable &&temp_name# : &temp_val#"
:SET &temp_val2#  = GET_SCRIPT_VAR(&temp_val#)
:PRINT "Value of variable &&&temp_val#       : &temp_val2#"


Because the &ABC#  variable has not be explicitly defined in the script, this results in the following output (again, assuming GENERATE_UNDEFINED_SCRIPT_VARS is set to Y):

U00020408 Value of variable &temp_name# : ABC#
U00020408 Value of variable &ABC#       : &ABC#


If :SET_SCRIPT_VAR were able to generate previously-undefined script variables the output would look like this:

U00020408 Value of variable &temp_name# : ABC#
U00020408 Value of variable &ABC#       : 123


This would offer a great deal of flexibility, because it would make it even easier to define script variables dynamically, on-the-fly, based on information that is not known ahead of time.

This idea originates in a discussion thread in the Automic Community.