Automic Workload Automation

 View Only
  • 1.  JOBI recursion

    Posted Dec 04, 2018 05:32 AM

    I was playing around with the idea of building a set of JOBIs to perform basic XML parsing, and quickly realized that recursion would greatly simplify the work. A quick test however revealed that the AE might not support this capability.

     

    UCO.RECURSION_TEST.JOBI

    :SET &JOBI_Recursion_Depth# = &JOBI_Recursion_Depth#
    :IF &JOBI_Recursion_Depth# = ""
    : SET &JOBI_Recursion_Depth# = 0
    :ENDIF
    :SET &JOBI_Recursion_Depth# = &JOBI_Recursion_Depth# + 1
    :SET &Max_Recursion_Depth# = 2
    :PRINT --- BEGIN UC0.RECURSION_TEST.JOBI Depth: &JOBI_Recursion_Depth# ---
    :IF &JOBI_Recursion_Depth# < &Max_Recursion_Depth#
    : INCLUDE UC0.RECURSION_TEST.JOBI
    :ELSE
    : PRINT "Maximum recursion depth (&Max_Recursion_Depth#) reached."
    :ENDIF
    :PRINT --- END UC0.RECURSION_TEST.JOBI Depth: &JOBI_Recursion_Depth# ---

     

    UCO.RECURSION_TEST.SCRI

    :INC UC0.RECURSION_TEST.JOBI

     

    Result

    U00010001 Includes are nested too deep at 'UC0.RECURSION_TEST.SCRI'

     

    Is it ever permitted to call a JOBI recursively? How deep is too deep? I’m not trying to implement the Ackermann function here.



  • 2.  Re: JOBI recursion

    Posted Dec 04, 2018 07:30 AM

    Hi

    Recursion always ends up in: 04.12.2018 13:21:50 -  U00010001 Includes are nested too deep at 'SCRI.INCLUDE_BANG' :-)

     

    Following Automic docu:    : SET &TOO_DEEP# = 5

    Automic 

     

    When I started working as develper I got some objects with nested Includes 4 levels deep. Not funny to debug an object with 16 includes.

    Especially in the Jobs's report.

    We started implementing a print INCLUDE START and INCLUDE END in every include.

     

    Another disadvantage of JOBI is the limitation that you are not able to set it via script:

    :SET &MY_REAL_COOL_JOBI# = "JOBI.UC4.REKU_1"
    :inc &MY_REAL_COOL_JOBI#

    ends up in

     U00010002 Include '&MY_REAL_COOL_JOBI#' not found in object 'SCRI.INCLUDE_BANG', line '00003'.

     

    cheers, Wolfgang



  • 3.  Re: JOBI recursion

    Posted Dec 04, 2018 08:09 AM

    Wolfgang Brueckler wrote:

    Hi

    Recursion always ends up in: 04.12.2018 13:21:50 -  U00010001 Includes are nested too deep at 'SCRI.INCLUDE_BANG' :-)

     

    Following Automic docu:    : SET &TOO_DEEP# = 5

    Automic

    ...

    cheers, Wolfgang

     

    The documentation states:

    You can nest Includes within Includes up to five levels.

    It does not state that a JOBI may not include itself, but I suppose this is implicit given the way AE script is processed. My JOBI includes these lines:

    :IF &JOBI_Recursion_Depth# < &Max_Recursion_Depth#
    : INCLUDE UC0.RECURSION_TEST.JOBI
    :ELSE

    The problem is that the AE script parser expands all :INCLUDE statements before evaluating any branching statements like :IF. So the condition check intended to block recursion after a certain depth plays no role whatsoever during :INCLUDE expansion.

     

    If would be nice if there were some way to do this.



  • 4.  Re: JOBI recursion
    Best Answer

    Posted Dec 04, 2018 08:46 AM
      |   view attached

    It’s not recursion, but it works for XML up to 5 levels deep.

     

    UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_1.JOBI

    :PRINT --- BEGIN   UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_1.JOBI ---
    :SET &Depth0_Element# = &Depth0_Element#
    :SET &JOBI_Nesting_Depth# = 1
    :SET &Depth1_Children# = XML_GET_CHILD_COUNT(&Depth0_Element#)
    :IF &Depth1_Children# > 0
    :  SET &Depth1_Element# = XML_GET_FIRST_CHILD(&Depth0_Element#)
    :  WHILE &Depth1_Element# <> ""
    :    SET &Name# = XML_GET_NODE_NAME(&Depth1_Element#)
    :    SET &Text# = XML_GET_NODE_TEXT(&Depth1_Element#)
    :    P "Element name : &Name#"
    :    IF &Text# <> ""
    :      P "Element text : &Text#"
    :    ENDIF
    :    INCLUDE UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_2.JOBI
    :    SET &Depth1_Element# = XML_GET_NEXTSIBLING(&Depth1_Element#)
    :  ENDWHILE
    :ENDIF
    :PRINT --- END     UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_1.JOBI ---

     

    The include objects UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_[2-5].JOBI are identical to the one above, with two exceptions:

    • the depth numbers are incremented;
    • UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_5.JOBI has a :PRINT statement instead of an :INCLUDE statement.

     

    UC0.XML_TEST.SCRI

    :SET &XML_Docu_Name# = "UC0.XML_TEST.DOCU"
    :SET &XML_Docu_Tab#  = "XMLTest"
    :SET &XML_Root# = XML_OPEN(DOCU,"&XML_Docu_Name#","@&XML_Docu_Tab#")
    :SET &RootNode# = XML_GET_NODE_NAME(&XML_Root#)
    :P "Root node name: &RootNode#"
    :SET &Depth0_Element# = &XML_Root#
    :INCLUDE UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_1.JOBI

    ! Beautify XML
    :SET &XB_RC# = XML_BEAUTIFY(&XML_Root#)
    ! Convert XML DOM to string
    :SET &NewXmlString# = XML_TO_STRING(&XML_Root#)
    :SET &NL# = UC_CRLF()
    :PRINT "XML String:"
    :PRINT &NL#&NewXmlString#
    !Close the XML document
    :XML_CLOSE &XML_Root#

     

    Output

    2018-12-04 14:34:18 - U00020408 Root node name: Content
    2018-12-04 14:34:18 - U00020408 --- BEGIN   UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_1.JOBI ---
    2018-12-04 14:34:18 - U00020408 Element name : Level1
    2018-12-04 14:34:18 - U00020408 Element text : Level 1 content

    2018-12-04 14:34:18 - U00020408 --- BEGIN   UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_2.JOBI ---
    2018-12-04 14:34:18 - U00020408 Element name : Level2
    2018-12-04 14:34:18 - U00020408 Element text : Level 2 content

    2018-12-04 14:34:18 - U00020408 --- BEGIN   UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_3.JOBI ---
    2018-12-04 14:34:18 - U00020408 Element name : Level3
    2018-12-04 14:34:18 - U00020408 Element text : Level 3 content

    2018-12-04 14:34:18 - U00020408 --- BEGIN   UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_4.JOBI ---
    2018-12-04 14:34:18 - U00020408 Element name : Level4
    2018-12-04 14:34:18 - U00020408 Element text : Level 4 content

    2018-12-04 14:34:18 - U00020408 --- BEGIN   UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_5.JOBI ---
    2018-12-04 14:34:18 - U00020408 Element name : Level5
    2018-12-04 14:34:18 - U00020408 Element text : Level 5 content

    2018-12-04 14:34:18 - U00020408 Maximum :INCLUDE depth reached.
    2018-12-04 14:34:18 - U00020408 --- END     UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_5.JOBI ---
    2018-12-04 14:34:18 - U00020408 --- END     UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_4.JOBI ---
    2018-12-04 14:34:18 - U00020408 --- END     UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_3.JOBI ---
    2018-12-04 14:34:18 - U00020408 --- END     UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_2.JOBI ---
    2018-12-04 14:34:18 - U00020408 --- END     UC0.XML.PROCESS_CHILD_ELEMENTS_DEPTH_1.JOBI ---
    2018-12-04 14:34:18 - U00020408 XML String:
    2018-12-04 14:34:18 - U00020408
    <Content>Root node content<Level1 Color="Red">Level 1 content<Level2>Level 2 content<Level3>Level 3 content<Level4>Level 4 content<Level5>Level 5 content</Level5>
    </Level4>
    </Level3>
    </Level2>
    </Level1>
    </Content>

     

    Better than nothing I guess.

    Attachment(s)