Automic Workload Automation

Expand all | Collapse all

GENERATE_SCRIPT_VARS — generate script variables on-the-fly

  • 1.  GENERATE_SCRIPT_VARS — generate script variables on-the-fly

    Posted Dec 11, 2017 08:20 AM

    AE v12.1 introduces a useful new scripting function called GENERATE_SCRIPT_VARS. This function is not mentioned in the v12.1 release highlights or release notes, so I thought I would mention it here.

     

    The GENERATE_SCRIPT_VARS function allows one to generate script variables on-the-fly based on information stored in a VARA object. (To use this scripting statement, you must set the GENERATE_UNDEFINED_SCRIPT_VARS setting in UC_SYSTEM_SETTINGS to Y.)

     

    Imagine you have the static VARA “UC0.TEST1.VARA_STATIC” object defined with the following keys & values:

    KeyValue 1Value 2Value 3Value 4Value 5
    vara1key1vara1key1value1vara1key1value3vara1key1value3vara1key1value4vara1key1value5
    vara1key2vara1key2value1vara1key2value3vara1key2value3vara1key2value4vara1key2value5


    Using the GENERATE_SCRIPT_VARS function, you can generate script variables based on the values stored in the VARA object. E.g.,:

    :SET &RC1# = GENERATE_SCRIPT_VARS(UC0.TEST1.VARA_STATIC,APPEND_POUND_SIGN,ABORT)
    :PRINT GENERATE_SCRIPT_VARS RC: &RC1#
    :PRINT &VARA1KEY1#
    :PRINT &VARA1KEY2#

    This will produce the following output:

    2017-12-11 13:59:31 - U00020408 GENERATE_SCRIPT_VARS RC: 0000000000000000
    2017-12-11 13:59:31 - U00020408 vara1key1value1
    2017-12-11 13:59:31 - U00020408 vara1key2value1

    The the GENERATE_SCRIPT_VARS function also accepts as its first argument the name of a variable containing a data sequence created using the PREP_PROCESS_VAR function. The following script will produce the same result as the one in the first example above.

    :SET &VARA_HND# = PREP_PROCESS_VAR(UC0.TEST1.VARA_STATIC)
    :SET &RC2# = GENERATE_SCRIPT_VARS(&VARA_HND#,APPEND_POUND_SIGN,ABORT)
    :PRINT GENERATE_SCRIPT_VARS RC: &RC2#
    :PRINT &VARA2KEY1#
    :PRINT &VARA2KEY2#

    I was unable to find a way to use values from any value column other than #1.



  • 2.  GENERATE_SCRIPT_VARS — generate script variables on-the-fly

    Posted Dec 12, 2017 04:30 AM
    The v12.1 AWI is not yet aware of the new function. The function is not colored red, and there is no tooltip syntax description.
    dm4beakm184e.pnghttps://us.v-cdn.net/5019921/uploads/editor/59/dm4beakm184e.png" width="468">


  • 3.  GENERATE_SCRIPT_VARS — generate script variables on-the-fly

    Posted Dec 12, 2017 06:00 AM

    The documentation does not provide a detailed description of the GENERATE_UNDEFINED_SCRIPT_VARS setting in UC_SYSTEM_SETTINGS, other than stating:

    Allows you to use the GENERATE_SCRIPT_VARS script function when set to Y.

    In fact, setting GENERATE_UNDEFINED_SCRIPT_VARS to Y does not enable the script function. The script function will run fine, and will return RC 0, whether or not the setting is set to Y.

     

    Setting GENERATE_UNDEFINED_SCRIPT_VARS to Y actually just instructs the AE script parser to permit the use of variables that have not been explicitly defined. Take for example this script with only one line:

    PRINT &ABC#

    Up until v12.1, if the variable &ABC# had not been previously set, e.g., in the parent workflow, this script would end during activation with the status FAULT_OTHER, due to the following syntax error:

    U00021719 Syntax error in object 'UC0.EXP2.TEST#1_1.SCRI', line '00011'. 'U01001308 Variable 'UNDEFVAR1#' has not yet been defined.'

    Now, starting with v12.1, if you set GENERATE_UNDEFINED_SCRIPT_VARS to Y, the script will run fine. This new setting thus allows you to completely avoid the variable not yet defined syntax error.

     

    Initially, I thought this might allow more flexibility in setting and retrieving variable values by indirect reference. E.g., scripts 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#"

    Unfortunately, this does not work as hoped. This script runs OK, but simply results in the following output.

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

    If the line :SET &ABC = "" is added to the top of the script, the output looks like this:

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

    So with the new GENERATE_UNDEFINED_SCRIPT_VARS set to Y:

    • One can use a variable that has not been explicitly defined.
    • One still cannot set the variable indirectly using:SET_SCRIPT_VAR unless the variable has already been explicitly defined. Perhaps this capability will be added later.


  • 4.  GENERATE_SCRIPT_VARS — generate script variables on-the-fly

    Posted Dec 12, 2017 07:42 AM

    If one wishes to set previously undefined script variables by indirect reference, one can use a VARA object as a temporary placeholder for the variable names and values, and then set the script variables using the GENERATE_SCRIPT_VARS script function.

    :SET &var_name1# = "ABC#"
    :SET &var_val1# = "123"
    !--- The following line works only if the variable is already explicitly defined.
    !:SET_SCRIPT_VAR &var_name1# = &var_val1#
    !--- Instead, we can use a static VARA as temporary placeholder for script variable names and values.
    :SET &Static_VARA_Name# = "UC0.TEMP.VARA_STATIC"
    :SET &Static_VARA_Path# = "/APPS/UC0/MAL"
    :SET &Static_VARA_Title# = "Temporary VARA for creating script variables by indirect reference."
    :SET &Static_VARA_Overwrite# = "YES"
    :INCLUDE UC0.CREATE_STATIC_VARA.JOBI
    :IF &Static_VARA_Created# <> "YES"
    : STOP MSG,50,"Error creating VARA."
    :ENDIF
    :PRINT "Writing {Key:&var_name1#, Value1: &var_val1#} to VARA &Static_VARA_Name#."
    :PUT_VAR &Static_VARA_Name#,"&var_name1#","&var_val1#"
    :PRINT "Generating script variables based on keys & values (#1) in VARA &Static_VARA_Name#."
    :SET &RC# = GENERATE_SCRIPT_VARS(&Static_VARA_Name#,,ABORT)
    !---
    :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#"

    This approach works-around the fact that even with GENERATE_UNDEFINED_SCRIPT_VARS to Y,

    :SET_SCRIPT_VAR is not able to set the values of variables that were not explicitly defined. This script produces the following output:

    U00020408 --- BEGIN JOBI --- UC0.CREATE_STATIC_VARA.JOBI
    U00020408 Testing required input variables for JOBI.
    U00020408 Checking whether object UC0.TEMP.VARA_STATIC already exists.
    U00020408 Object UC0.TEMP.VARA_STATIC already exists.
    U00020408 Checking whether UC0.TEMP.VARA_STATIC is a VARA object.
    U00020408 Object UC0.TEMP.VARA_STATIC is of type VARA.
    U00020408 &Static_VARA_Overwrite# is set to YES. Removing existing VARA UC0.TEMP.VARA_STATIC
    U00020646 User ('TESTUSER/DEV') removed object 'UC0.TEMP.VARA_STATIC' via script.
    U00020408 Creating VARA object UC0.TEMP.VARA_STATIC.
    U00020647 Object 'UC0.TEMP.VARA_STATIC' was created by script from user: ('TESTUSER/DEV').
    U00020408 Successfully created object UC0.TEMP.VARA_STATIC.
    U00020408 --- END JOBI ---  UC0.CREATE_STATIC_VARA.JOBI
    U00020408 Writing {Key:ABC#, Value1: 123} to VARA UC0.TEMP.VARA_STATIC.
    U00020408 Generating script variables based on keys & values (#1) in VARA UC0.TEMP.VARA_STATIC.
    U00020408 Value of variable &temp_name# : ABC#
    U00020408 Value of variable &ABC#       : 123

    Note: in the above script, I used a JOBI for creating a VARA object if it does not already exist.



  • 5.  GENERATE_SCRIPT_VARS — generate script variables on-the-fly

    Posted Jan 03, 2018 04:39 AM
    kay_koll_automic & brendan_sapience_automic came up with a way to generate script variables dynamically using a data sequence instead of a temporary static VARA object. This is probably a bit more efficient, and it certainly requires fewer lines of AE scripting.


  • 6.  GENERATE_SCRIPT_VARS — generate script variables on-the-fly

    Posted Jan 03, 2018 04:42 AM

    Michael Lowry wrote:

         [Even] with the new GENERATE_UNDEFINED_SCRIPT_VARS set to Y… [o]ne still cannot set the variable indirectly using :SET_SCRIPT_VAR unless the variable has already been explicitly defined. Perhaps this capability will be added later.

    I opened an enhancement request for this.

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

    Please vote for the idea if you like it.



  • 7.  GENERATE_SCRIPT_VARS — generate script variables on-the-fly

    Posted Mar 28, 2018 05:24 AM
      |   view attached

    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!

    Attachment(s)

    xml
    GSV uc4_export.xml   7 KB 1 version


  • 8.  GENERATE_SCRIPT_VARS — generate script variables on-the-fly

    Posted Apr 06, 2018 08:57 AM
    Today I tried using an SEC_SQLI VARA object as the data source for GENERATE_SCRIPT_VARS:
    :SET &GSV_RC# = GENERATE_SCRIPT_VARS(UC0.GET_VARIABLE_VALUES.VARA_SEC_SQLI,,)
    The SQL is configured such that result column 1 contains variable names, and result column 2 contains variable values. This did not work though, and I’m still trying to figure out why. The SCRI ends in FAULT_OTHER, and this error message appears:
    U00003892 Interrupt (generating system variables)
    I’ll post an update if I find a solution.


  • 9.  GENERATE_SCRIPT_VARS — generate script variables on-the-fly

    Posted Apr 06, 2018 09:56 AM

    I’m still not sure why GENERATE_SCRIPT_VARS doesn’t like SEC_SQLI-type VARA objects, but I was able to work around the problem by piping the data through a temporary data sequence.

    :SET &Counter# = 0
    :SET &GetVarValuesHnd# = PREP_PROCESS_VAR(UC0.GET_VARIABLE_VALUES.VARA_SEC_SQLI)
    :PROCESS &GetVarValuesHnd#
    : SET &Counter# = &Counter# + 1
    : IF &Counter# = 1
    : SET &TempDS# = CREATE_PROCESS(NEW)
    : ENDIF
    : SET &Var_Name# = GET_PROCESS_LINE(&GetVarValuesHnd#,2)
    : SET &Var_Value# = GET_PROCESS_LINE(&GetVarValuesHnd#,3)
    : SET &PPL_RC# = PUT_PROCESS_LINE(&TempDS#, "&Var_Name#|&Var_Value#", "|")
    :ENDPROCESS
    :IF &Counter# > 0
    : SET &SP_RC# = SAVE_PROCESS(&TempDS#)
    : SET &GSV_RC# = GENERATE_SCRIPT_VARS(&TempDS#,,)
    : SET &GSV_RC# = FORMAT(&GSV_RC#)
    : PRINT "Return code from GENERATE_SCRIPT_VARS: &GSV_RC#"
    :ENDIF
    :CLOSE_PROCESS &GetVarValuesHnd#

    In my testing, the return code from GENERATE_SCRIPT_VARS was always 7, even though there was no problem setting the variables. I noticed that 7 corresponded to the number of variables being set. At first I thought perhaps this was not a coincidence, and that the return code indicated the number of variables that had been set. This turns out not to be true though; I added an eighth variable, but the RC remained 7.

     

    Would someone from Automic_Community_5543 care to enlighten us?



  • 10.  Re: GENERATE_SCRIPT_VARS — generate script variables on-the-fly

    Posted Jun 19, 2018 04:33 AM

    Would anyone from CA care to comment on GENERATE_SCRIPT_VARS return codes?



  • 11.  RE: GENERATE_SCRIPT_VARS — generate script variables on-the-fly

    Posted Jul 02, 2020 11:26 AM
    Great. Thanks Michael. Nevertheless, small issue, temp process handler (TempDS) has to be closed as well.


  • 12.  RE: GENERATE_SCRIPT_VARS — generate script variables on-the-fly

    Posted Jul 02, 2020 01:13 PM
      |   view attached
    Thanks to Sandro for the tip about closing the temporary data sequence.

    I am attaching an updated version of the objects.

    Attachment(s)

    xml
    GSV uc4_export.xml   7 KB 1 version