STR_SUBSTITUTE_VAR, STR_SUB_VAR

Use the STR_SUBSTITUTE_VAR script function to replace one or more script variable names — stored as a string in another script variable — with their actual values. To make the same kind of replacements in data sequence lines, use the GET_PROCESS_LINE script function with the STR_SUBSTITUTE parameter. For more information, see GET_PROCESS_LINE.

Syntax

STR_SUB[STITUTE]_VAR (Variables)

Parameters

Parameter Description Format
Variables Script variable or string containing one or more variable names to be replaced with their values Script literal or script variable

Return Codes

Return Value Condition
String The input string with all variable names replaced by their actual values

Examples

The following example stores the name of a script variable (&VAR#) in another variable (&VAR_NOSUB#) by using the ampersand character twice. Printing &VAR_NOSUB# writes the variable name to the activation report. Using STR_SUB_VAR replaces the variable name with its value.

:SET &VAR# = "script variable"

:SET &VAR_NOSUB# = "&&VAR# = &VAR#"

:PRINT &VAR_NOSUB#

:SET &VAR_SUB# = STR_SUB_VAR(&VAR_NOSUB#)

:PRINT &VAR_SUB#

The activation report output looks like this:

2022-05-06 10:34:04 - U0020408 &VAR# = script variable
2022-05-06 10:34:04 - U0020408 script variable = script variable

The following example retrieves a value from the VARA object VARA.SUB, which contains the names of two script variables. The variables are created and set, then printed without substitution. Using STR_SUB_VAR in the last two lines replaces the variable names with their values.

:SET &VARA# = GET_VAR(VARA.SUB, "SUBVAR")

:SET &VAR1# = "Hello"

:SET &VAR2# = "World"

:PRINT "Content without replacements: &VARA#"

:SET &VARA_SUB_VAR# = STR_SUB_VAR(&VARA#)

:PRINT "Content with replacements: &VARA_SUB_VAR#"

The activation report output looks like this:

2022-05-06 10:34:04 - U0020408 Content without replacements: &VAR1# &VAR2#
2022-05-06 10:34:04 - U0020408 Content with replacements: Hello World

See also: