Michael_Lowry

Use a variable regardless of whether it has already been set

Discussion created by Michael_Lowry on Aug 12, 2016
Latest reply on Mar 28, 2018 by Michael_Lowry
I just added a [DEAD LINK https://community.automic.com/discussion/comment/23651/#Comment_23651]comment to the v11.2 documentation page for GET_SCRIPT_VAR. I thought this might be of more general interest, so I am reposting it here.

The GET_SCRIPT_VAR scripting command can be used in places where it is necessary to use a variable, but you do not know whether the variable has already been set.
:SET &My_Var# = GET_SCRIPT_VAR(My_Var#)
This will not change the value of a variable if it is already set, and will set it to an empty string otherwise. By testing the length of the variable after running GET_SCRIPT_VAR, you can tell it it was already set or not.
:SET &My_Var# = "ABC123"
:SET &My_Var# = GET_SCRIPT_VAR(My_Var#)
:IF STR_LENGTH(&My_Var# ) = 0
:  PRINT "Variable &&My_Var# is not set."
:ELSE
:  PRINT "Variable &&My_Var# is set to '&My_Var#'."
:ENDIF
Run this script as-is, and the output will be:
U00020408 Variable &My_Var# is set to 'ABC123'.
Run it with the first line commented-out, and the output will be:
U00020408 Variable &My_Var# is not set.
Using this approach, you can more easily create general-purpose job includes (JOBI objects) that may be included in a wide variety of different executable objects — including executable objects that may not set all of the variables that the JOBI objects use.

Outcomes