Building on @Brendan Sapience’s approach (using a data sequence instead of a temporary VARA), I developed a couple of JOBI objects that can be used as pseudo-functions in AE scripts to quickly define a variable or set of variables based on data that are generated dynamically — that is, pieces of information that are not known prior to script execution. To use these JOBIs, you must be running Automation Engine v12.1 or later, and you must set the GENERATE_UNDEFINED_SCRIPT_VARS
setting in UC_SYSTEM_SETTINGS
to Y.
UC4.GSV.JOBI
Generate a script variable from a dynamically provided variable name & value.
:PRINT "Generating script variable."
:SET &TempDS# = CREATE_PROCESS(NEW)
:SET &PPL_RC# = PUT_PROCESS_LINE(&TempDS#, "&VariableName#|&VariableValue#", "|")
!:PRINT "Added data sequence entry: '&VariableName#|&VariableValue#'"
:SET &SP_RC# = SAVE_PROCESS(&TempDS#)
:SET &GSV_RC# = GENERATE_SCRIPT_VARS(&TempDS#,,UPDATE)
:SET &GSV_RC# = FORMAT(&GSV_RC#)
:PRINT "Return code from GENERATE_SCRIPT_VARS: &GSV_RC#"
:IF &GSV_RC# <> 0
: PRINT "WARNING: Could not read variables from data sequence."
:ENDIF
To use the JOBI, simply set the values of &VariableName#
and &VariableValue#
, and then include the .JOBI.
:SET &VariableName# = "MyVariable#"
:SET &VariableValue# = "This is a test value"
:INC UC4.GSV.JOBI
:PRINT "&&&VariableName# : &VariableValue#"
The output should look like this:
U00020408 Generating script variable.
U00020408 Return code from GENERATE_SCRIPT_VARS: 0
U00020408 &MyVariable# : This is a test value
And here is another JOBI that does the same thing, but with a set of multiple variable names and values (specified in arrays).
UC4.GSV_ARRAY.JOBI
Generate script variables from arrays of variable names & values.
:PRINT "Generating script variables."
:SET &VariableArraySize# = &VariableArraySize#
:IF &VariableArraySize# = ""
: SET &VariableArraySize# = 1
:ENDIF
:IF &VariableArraySize# <> 0
: SET &TempDS# = CREATE_PROCESS(NEW)
: SET &Counter# = 0
: WHILE &Counter# < &VariableArraySize#
: SET &Counter# = &Counter# + 1
: SET &Counter# = FORMAT(&Counter#)
: SET &VariableName# = &VariableNames#[&Counter#]
: SET &VariableValue# = &VariableValues#[&Counter#]
: SET &PPL_RC# = PUT_PROCESS_LINE(&TempDS#, "&VariableName#|&VariableValue#", "|")
! : PRINT "Added data sequence entry: '&VariableName#|&VariableValue#'"
: ENDWHILE
: SET &SP_RC# = SAVE_PROCESS(&TempDS#)
: SET &GSV_RC# = GENERATE_SCRIPT_VARS(&TempDS#,,UPDATE)
: SET &GSV_RC# = FORMAT(&GSV_RC#)
: PRINT "Return code from GENERATE_SCRIPT_VARS: &GSV_RC"
: IF &GSV_RC# <> 0
: PRINT "WARNING: Could not read variables from data sequence."
: ENDIF
:ENDIF
To use the JOBI, simply define the arrays &VariableNames#
and &VariableValues#
, indicate the size in &VariableArraySize#
, and then include the JOBI.
:DEFINE &VariableNames#,string,5
:DEFINE &VariableValues#,string,5
:SET &Counter# = 0
:WHILE &Counter# < 5
: SET &Counter# = &Counter# + 1
: SET &Counter# = FORMAT(&Counter#)
: SET &VariableNames#[&Counter#] = "Variable_&Counter##"
: SET &VariableValues#[&Counter#] = "Test Value &Counter#"
! : PRINT "Added array entry: &VariableNames#[&Counter#] : &VariableValues#[&Counter#]"
:ENDWHILE
:SET &VariableArraySize# = 5
:INC UC4.GSV_ARRAY.JOBI
:SET &Counter# = 0
:WHILE &Counter# < 5
: SET &Counter# = &Counter# + 1
: SET &Counter# = FORMAT(&Counter#)
: SET &VariableName# = "&Variable_&Counter##"
: SET &VariableValue# = GET_SCRIPT_VAR("&VariableName#")
: PRINT "&VariableName# : &VariableValue#"
:ENDWHILE
The output should look like this:
U00020408 Generating script variables.
U00020408 Return code from GENERATE_SCRIPT_VARS: 0
U00020408 &Variable_1# : Test Value 1
U00020408 &Variable_2# : Test Value 2
U00020408 &Variable_3# : Test Value 3
U00020408 &Variable_4# : Test Value 4
U00020408 &Variable_5# : Test Value 5
Enjoy!