Michael_Lowry

Create static VARA if it does not already exist

Discussion created by Michael_Lowry on Dec 12, 2017
Latest reply on Jan 16, 2018 by Michael_Lowry
Here’s a JOBI I wrote to create a static VARA object if it does not already exist. It works like a function. Its inputs are the four variables at the top.

UC4.CREATE_STATIC_VARA.JOBI

:PRINT "--- BEGIN JOBI --- UC4.CREATE_STATIC_VARA.JOBI"
! Set variables to their current values. This avoids a runtime error if they have not already been set.
:SET &Static_VARA_Name# = &Static_VARA_Name#
:SET &Static_VARA_Path# = &Static_VARA_Path#
:SET &Static_VARA_Title# = &Static_VARA_Title#
:SET &Static_VARA_Overwrite# = &Static_VARA_Overwrite#
:SET &Validate_Name# = "NO"
:SET &Validate_Path# = "NO"
:PRINT "Checking task status to determine the active scripting tab."
:SET &Task_Status# = GET_UC_OBJECT_STATUS()
:PRINT "Task status: &Task_Status#"
:IF &Task_Status# < 1573
:  SET &Active_Tab# = "pre-process or process"
:ELSE
:  SET &Active_Tab# = "post-process"
:ENDIF
:PRINT "JOBI running in &Active_Tab# tab."
:SET &Task_Prefix# = STR_CUT(&$NAME#,1,3)
:PRINT "Task prefix: &Task_Prefix#"
:PRINT "Testing required input variables for JOBI."
:IF &Static_VARA_Name# = "" OR " "
:  PRINT "ERROR: Input variable &&Static_VARA_Name# is null."
:  IF &Active_Tab# = "post-process"
:    MODIFY_STATE RETCODE=8
:    MODIFY_STATE STATUS_TEXT="JOBI input variable is null."
:  ELSE
:    STOP MSG,51,"JOBI input variable is null."
:  ENDIF
:ELSE
:  PRINT "&&Static_VARA_Name# : &Static_VARA_Name#"
:  IF &Validate_Name# = "YES" or "yes" or "Y" or "y" or "Yes"
:    SET &VARA_Prefix# = STR_CUT(&Static_VARA_Name#,1,4)
:    IF &VARA_Prefix# <> "&Task_Prefix#."
:      PRINT "ERROR: VARA name '&Static_VARA_Name#' does not begin with '&Task_Prefix#.'."
:      IF &Active_Tab# = "post-process"
:        MODIFY_STATE RETCODE=8
:      ELSE
:        STOP MSG,51,"Invalid VARA name."
:        MODIFY_STATE STATUS_TEXT="Invalid VARA name."
:      ENDIF
:    ENDIF
:  ENDIF
:ENDIF
:IF &Static_VARA_Path# = "" OR " "
:  PRINT "ERROR: Input variable &&Static_VARA_Path# is null."
:  IF &Active_Tab# = "post-process"
:    MODIFY_STATE RETCODE=8
:    MODIFY_STATE STATUS_TEXT="JOBI input variable is null."
:  ELSE
:    STOP MSG,51,"JOBI input variable is null."
:  ENDIF
:ELSE
:  PRINT "&&Static_VARA_Path# : &Static_VARA_Path#"
:  IF &Validate_Path# = "YES" or "yes" or "Y" or "y" or "Yes"
:    SET &Path_Prefix# = STR_CUT(&Static_VARA_Path#,1,9)
:    IF "&Path_Prefix#" <> "/APPS/&Task_Prefix#"
:      PRINT "ERROR: Path '&Path_Prefix#' does not begin with '/APPS/&Task_Prefix#'."
:      IF &Active_Tab# = "post-process"
:        MODIFY_STATE RETCODE=8
:      ELSE
:        STOP MSG,51,"Invalid target path."
:        MODIFY_STATE STATUS_TEXT="Invalid target path."
:      ENDIF
:    ENDIF
:  ENDIF
:ENDIF
:SET &Static_VARA_Already_Exists# = ""
:PRINT "Checking whether object &Static_VARA_Name# already exists."
:SET &OBJ_ID# = GET_OH_IDNR(&Static_VARA_Name#)
:IF &OBJ_ID# = "0"
!  Object does not exist.
:  PRINT "Object &Static_VARA_Name# does not exist."
:  SET &Static_VARA_Already_Exists# = "NO"
:ELSE
!  Object exists.
:  PRINT "Object &Static_VARA_Name# already exists."
:  PRINT "Checking whether &Static_VARA_Name# is a VARA object."
:  SET &OBJ_TYPE# = GET_OBJECT_TYPE(&Static_VARA_Name#)
:  IF &OBJ_TYPE# <> "VARA"
:    PRINT "ERROR: Object &Static_VARA_Name# exists, but is NOT of type VARA."
:    IF &Active_Tab# = "post-process"
:      MODIFY_STATE RETCODE=8
:    ELSE
:      STOP MSG,51,"Object type mismatch."
:      MODIFY_STATE STATUS_TEXT="Object type mismatch."
:    ENDIF
:  ELSE
:    PRINT "Object &Static_VARA_Name# is of type VARA."
:    SET &Static_VARA_Already_Exists# = "YES"
:  ENDIF
:ENDIF
:IF &Static_VARA_Already_Exists# = "YES"
:  IF &Static_VARA_Overwrite# = "YES" or "yes" or "Y" or "y" or "Yes"
:    PRINT "&&Static_VARA_Overwrite# is set to YES. Removing existing VARA &Static_VARA_Name#"
:    SET &RC# = REMOVE_OBJECT(&Static_VARA_Name#)
:    IF &RC# <> 0
:      PRINT "ERROR: Could not remove existing VARA &Static_VARA_Name#"
:      IF &Active_Tab# = "post-process"
:        MODIFY_STATE RETCODE=8
:        MODIFY_STATE STATUS_TEXT="REMOVE_OBJECT RC: &RC#"
:      ELSE
:        STOP MSG,51,"REMOVE_OBJECT RC: &RC#"
:      ENDIF
:    ELSE
:      SET &Create_VARA# = "YES"
:    ENDIF
:  ENDIF
:ELSE
:  SET &Create_VARA# = "YES"
:ENDIF
:IF &Create_VARA# = "YES"
:  PRINT "Creating VARA object &Static_VARA_Name# in folder &Static_VARA_Path#."
:  SET &RC#= CREATE_OBJECT(VARA,&Static_VARA_Name#,&Static_VARA_Path#,&Static_VARA_Title#,"I","C","FREE")
:  IF &RC# <> 0
:    SET &RC# = FORMAT(&RC#)
:    PRINT "ERROR: RC &RC# when attempting to create object &Static_VARA_Name#."
:    IF &Active_Tab# = "post-process"
:      MODIFY_STATE RETCODE=8
:      MODIFY_STATE STATUS_TEXT="CREATE_OBJECT RC: &RC#"
:    ELSE
:      STOP MSG,51,"CREATE_OBJECT RC: &RC#"
:    ENDIF
:  ELSE
:    PRINT "Successfully created object &Static_VARA_Name#."
:    SET &Static_VARA_Created# = "YES"
:  ENDIF
:ENDIF
:PRINT "--- END JOBI ---  UC4.CREATE_STATIC_VARA.JOBI"
To use the JOBI, simply set the four input variables and run it using an :INCLUDE statement:
:SET &Static_VARA_Name# = "UC0.TEMP.VARA_STATIC"
:SET &Static_VARA_Path# = "/APPS/UC0/MAL"
:SET &Static_VARA_Title# = "Temporary VARA."
:SET &Static_VARA_Overwrite# = "YES"
:INCLUDE UC0.CREATE_STATIC_VARA.JOBI
The script output will look something like this:
U00020408 --- BEGIN JOBI --- UC4.CREATE_STATIC_VARA.JOBI
U00020408 Checking task status to determine the active scripting tab.
U00020408 Task status: 1900
U00020408 JOBI running in post-process tab.
U00020408 Testing required input variables for JOBI.
U00020408 &Static_VARA_Name# :
UC0.TEMP.VARA_STATIC
U00020408 &Static_VARA_Path# : /APPS/UC0 
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 in folder /APPS/UC0.
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 ---  UC4.CREATE_STATIC_VARA.JOBI
I use this JOBI object any time I need to create a VARA object that may or may not already exist.

Enjoy!

Outcomes