Automic Workload Automation

  • 1.  Using special characters like tab in UC4 scripts

    Posted Mar 31, 2016 11:16 AM
    Recently I was looking for a way to strip leading and trailing white space characters from UC4 strings. STR_TRIM was my first hope, but it removes only spaces, not tabs. I began writing a script that would use STR_FIND to search for tab characters, but immediately ran into a problem: I could find no way to paste a tab character into the script editor. The UC4 UI seems to automatically replace pasted tabs with a pair of spaces. I worked around this by inserting the tab into a static VARA object.
    :SET &TAB# = GET_VAR(UC0.MAL.SPECIAL_CHARACTERS.VARA,"tab")
    :SET &STRING_WITH_TAB# = "Hello, world.&tab#"
    This works fine, but I assume there must be more straightforward way. Any ideas?


  • 2.  Using special characters like tab in UC4 scripts

    Posted Mar 31, 2016 12:21 PM
    By the way, here is the JOBI I came up with to trim leading and trailing tabs and spaces.
    :SET &TAB# = GET_VAR(UC0.MAL.SPECIAL_CHARACTERS.VARA,"tab")
    ! :PRINT "Original string: &STRING#"
    :SET &STR_LEN_ORIG# = STR_LENGTH(&STRING#)
    ! :PRINT "Original string length: &STR_LEN_ORIG#"
    :SET &STR_LEN# = &STR_LEN_ORIG#
    :DEFINE &TAB_POS#, unsigned
    ! Trim leading tabs and spaces
    :SET &CUT_START# = 1
    :SET &TAB_POS# = STR_FIND(&STRING#,&TAB#)
    :WHILE &TAB_POS# = 1
    :  SET &CUT_START# = &TAB_POS# + 1
    :  SET &STRING# = STR_CUT(&STRING#,&CUT_START#)
    :  SET &STRING# = STR_TRIM(&STRING#)
    :  SET &TAB_POS# = STR_FIND(&STRING#,&TAB#)
    :ENDWHILE
    :SET &STR_LEN# = STR_LENGTH(&STRING#)
    ! Trim trailing tabs and spaces"
    :SET &TAB_POS# = STR_FIND_REVERSE(&STRING#,&TAB#)
    :WHILE &TAB_POS# = &STR_LEN#
    :  SET &CUT_LEN# = &TAB_POS# - 1
    :  SET &STRING# = STR_CUT(&STRING#,1,&CUT_LEN#)
    :  SET &STRING# = STR_TRIM(&STRING#)
    :  SET &TAB_POS# = STR_FIND_REVERSE(&STRING#,&TAB#)
    :  SET &STR_LEN# = STR_LENGTH(&STRING#)
    :ENDWHILE
    :SET &STR_LEN# = STR_LENGTH(&STRING#)
    ! :PRINT "Final string length: &STR_LEN#"
    :SET &DIFF# = &STR_LEN_ORIG# - &STR_LEN#
    :SET &DIFF# = FORMAT(&DIFF#)
    :PRINT "Trimmed &DIFF# tabs and/or spaces."
    :PRINT Trimmed string: "&STRING#"

    Let’s say &MYVAR# is the variable with leading and/or trailing tabs and/or spaces. Just stick the string you want to trim into the variable &STRING#, and run the JOBI. E.g.,

    :SET &STRING# = &MYVAR#
    :INCLUDE UC0.TRIM_WHITESPACE.JOBI
    :SET &MYVAR#  = &STRING#
    And obviously, this depends on the existence of the VARA object UC0.MAL.SPECIAL_CHARACTERS.VARA containing a single tab in Value 1 of the key tab.


  • 3.  Using special characters like tab in UC4 scripts

    Posted Mar 31, 2016 02:33 PM
    I tried your script, but I was unable to save a VARA with the tab in value field. I've copied a tab from notepad++ and could successfully paste on the VARA field, but it disappears after I save it.

    One silly option that I've thought about, is to filter only be alphanumeric characters inside your loop, removing everything else. This way you can also include other special characters that you don't want to trim (based on the ASCII code) and in the end you will not need to type a tab or simulate it.
    !ASCII 48 to 57 :if &char >= '0' :  if &char <= '9' :    print "[0-9]" :  endif :endif !ASCII 65 to 90 :if &char >= 'A' :  if &char <= 'Z' :    print "[A-Z]" :  endif :endif !ASCII 97 to 122 :if &char >= 'a' :  if &char <= 'z' :    print "[a-z]" :  endif :endif

    It would be good to have another function like UC_CRLF(), but returning the tab code, or have a CHAR(121) function that we could use the ASCII code.


  • 4.  Using special characters like tab in UC4 scripts

    Posted Mar 31, 2016 03:40 PM
    Roney said:
    It would be good to ... have a CHAR(121) function that we could use the ASCII code.
    Agreed. Better yet, with an optional second argument for specifying an alternative code table. I.e.,

    CHAR

    Convert a decimal character ID to the specified character.

    Syntax

    CHAR(Code point [,Code page])
    SyntaxDescription/Format
    Code pointThe decimal ID of the character in the character set
    Format: script literal or script variable
    Code tableThe name of a CODE object to specify a different character set than UC_CODE.
    Format: script literal or script variable

    Comments

    The default code table is UC_CODE.

    Examples

    Example 1

    :SET &TAB# = CHAR(5)
    :PRINT "Line 1:&TAB#Hello"
    :PRINT "Line 2:&TAB#world"

    Prints the output:

    Line1:     Hello
    Line2:     world

    (Code point 5 refers to the tabcharacter in the default UC_CODE code table.)

    Example 2

    :SET &TAB# = CHAR(9, IBM_3270_INTERNATIONAL) :PRINT "Line 1:&TAB#Hello" :PRINT "Line 2:&TAB#world"

    Prints the output:

    Line1:     Hello
    Line2:     world

    (Code point 9 refers to the tabcharacter in the IBM_3270_INTERNATIONAL code table.)


    I don’t know much about the internal workings of the Automation Engine, but I can imagine that it might be necessary to restrict which characters can be returned by such a command.