It is now possible in v12.1 to dynamically create Automic Variables (ex:&MYVAR#) in a script (Pre or PostProcess included) without knowing the names of the variables prior (to my knowledge this was not possible before).
Here is an example:a JOBS object returns an arbitrary output in the following format:
MATCHWASFOUND|VAR1#|U02001096
MATCHWASFOUND|VAR2#|100:STORE.CONN.UPDATE/CONN_UPDATE
MATCHWASFOUND|MYOTHERVAR#|Some Value here
- the number of lines varies and isunpredictable
- the second column (which eventually we want to use as the name of an automic variable) is alwaysunpredictable
Our goal:
After we are done with the postprocessing, we want:
- set as many Automic Variables as I have lines that start with "MATCHWASFOUND"
- Use the second column as the Automic Variable name
- Use the third column as the automic Variable value
So, in this case, once done with postprocessing, I want the following automic variables to exist:
- &VAR1# = “U02001096”
- &VAR2# = “100:STORE.CONN.UPDATE/CONN_UPDATE”
- &MYOTHERVAR# = “Some Value here”
In order do so, we will use a combo of the :CREATE_PROCESS (and related commands) and :GENERATE_SCRIPT_VARS commands
Important Note: to leverage GENERATE_SCRIPT_VARS you need to set GENERATE_UNDEFINED_SCRIPT_VARS to Y in UC_SYSTEM_SETTINGS
Here is the content of the PostProcess Tab:
! Create a new Data Sequence that will contain the new Variables' Names and Values
! Conceptually it is similar to a "virtual" VARA object with one Key and one Column
:SET &VarHND# = CREATE_PROCESS(NEW)
! normal processing of the REP
:SET &HND# = PREP_PROCESS_REPORT("JOBS",, "REP",,"COL=DELIMITER", "DELIMITER=*|*")
:PROCESS &HND#
: SET &MatchFound# = GET_PROCESS_LINE(&HND#,1)
: IF STR_STARTS_WITH(&MatchFound#, "MATCHWASFOUND") = "Y"
: SET &VarName# = GET_PROCESS_LINE(&HND#,2)
: SET &Value# = GET_PROCESS_LINE(&HND#,3)
: PRINT "&Varname# !! &VALUE# !! &MatchFound#"
! Add data to the new Data Sequence (delimiter is |)
: SET &CHECK# = PUT_PROCESS_LINE(&VarHND#, "&VarName#|&Value#", "|")
: ENDIF
:ENDPROCESS
:SET &RET# = SAVE_PROCESS(&VarHND#)
! Generate all Variables stored in the data sequence
:SET &ret# = generate_script_vars(&VarHND#, , UPDATE)
:P &ret#
:P &&VAR2#:&VAR2#
:P &&VAR1#:&VAR1#
and here is the corresponding output generated: &VAR1# and &VAR2# now exist and their respective values correspond the column 3 of the original output:
An export of the corresponding JOBS Object is attached.