Automic Workload Automation

 View Only
Expand all | Collapse all

GOTO does not work

  • 1.  GOTO does not work

    Posted Oct 23, 2019 10:34 AM
    Hi Guys,
         I would like to use the GOTO command to jump to points in the code and thus manage the error level and any exits from the JOB but, apparently, the engine still runs the whole script instead of jumping.
    This is part of code:

    :IF &ORIGPATH# = ""
    : SET &OA_MessageAction#="ERRORE - Variabile 'ORIGPATH' non valorizzata "
    : SET &OA_CodeAc#=4
    :DATA @GOTO :ACTION_CHECK
    :ENDIF
    :IF &NOMEFILE1# = ""
    : SET &OA_MessageAction#="ERRORE - Variabile 'NOMEFILE1' non valorizzata "
    : SET &OA_CodeAct#=4
    GOTO ACTION_CHECK
    :ENDIF

    echo "°°°°°°°°° 8"
    &DISCO#
    cd &ORIGPATH#
    echo "°°°°°°°°° 9"

    :IF &NFoldersORIG#>0
    echo "°°°°°°°°° 10"
    &COMMAND# &ORIGPATH#&NomeFIle1# &DESTPATH#&NomeFIle2#
    echo "°°°°°°°°° 11"
    : SET &OA_CodeAct#=0
    : SET &OA_MessageAction#="#MSG: OPERAZIONE CORRETTAMENTE ESEGUITA (AllarmLevel=0)"
    echo "°°°°°°°°° 12"
    :ELSE
    : SET &OA_CodeAct#=4
    : SET &OA_MessageAction#="#MSG: OPERAZIONE MOMENTANEAMENTE INTERDETTA - Path di origine non trovato (AllarmLevel=4)"
    :ENDIF
    echo "°°°°°°°°° 13"

    :DATA ":ACTION_CHECK"
    echo "°°°°°°°°° 14"
    echo °
    echo °
    echo °
    echo °
    echo ° $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    echo [ESITO OPERAZIONE]: &OA_MessageAction#
    echo [RETURN CODE]: &OA_CodeAct#
    echo ° $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    echo °
    echo °
    echo °
    verifying the condition X and going out with the GOTO, I would have expected that the printed echo was the one of the variables updated at point 7 instead the one of point 12 is printed which is the last condition that is managed. So the GOTO seems to work. How about? can you help me?
    Thanks

    ------------------------------
    Employee
    Postevita
    ------------------------------


  • 2.  RE: GOTO does not work

    Posted Oct 23, 2019 02:36 PM
    One of your GOTO statements fails to specify the colon(:) character when referring to the target label, which could invalidate the operation.  Could this be your problem?

    ------------------------------
    Pete
    ------------------------------



  • 3.  RE: GOTO does not work

    Posted Oct 24, 2019 04:46 AM
    ​The colon in the GOTO jump statement is, as far as I know, NOT mandatory in batch files, only the colon that prefixes the actual jump label. The original syntax has always been (at least what I recall from MS-DOS 3.3):

    goto flamingofarm
    :flamingofarm

    Using a colon with the jump statement is merely tolerated as a syntax alternative with recent cmd.exe, as far as I know.

    https://ss64.com/nt/goto.html


  • 4.  RE: GOTO does not work

    Posted Oct 24, 2019 04:47 AM
    ​at least what I recall from MS-DOS 3.3

    Aw **** I'm old :(


  • 5.  RE: GOTO does not work

    Posted Oct 25, 2019 02:15 AM

    In Automic script the colon is a special character. As you can see in Michael Kutswa examples you have to "hide" it using ":DATA":

    !...
    goto flamingofarm
    !...
    :DATA ":flamingofarm"
    !...


    But I also have to agree with Michael: I think you expect the wrong thing from mixing AE script and batch script. First the AE script is processed, then the generated batch script is transferred to the agent and executed there. You can find more informations here: Execution Stages



    ------------------------------
    Automation Evangelist
    Fiducia & GAD IT AG
    ---
    Mitglied des deutschsprachigen Automic-Anwendervereins FOKUS e.V.
    Member of the German speaking Automic user association FOKUS e.V.
    ------------------------------



  • 6.  RE: GOTO does not work

    Posted Oct 24, 2019 06:20 AM

    Hi Daniele,

    it looks like you're mixing up AE Script and JCL. Therefor you must know AE Script is executed during the activation of the job and generates the JCL that is executed on the agent.

    So if I understand your problem right, the AE Script is generating the GOTO in the JCL, but that doesn't mean that the AE Script is also jumping to the GOTO point. It will continue generating the JCL. Which means depending on :IF &NFoldersORIG#>0 The variables &OA_MessageAction# and &OA_CodeAct# will ever contain what is set in the block between echo 9 and 13.

    An easier example:

    :set &A# = x
    :IF &A# = 1
    : SET &MSG# = "A = 1"
    :ELSE
    : SET &MSG# = "A <> 1"
    GOTO :ENDE
    :ENDIF
    !do something
    @echo "Do something"
    :SET &MSG# = "&MSG# I did something"
    :DATA ":ENDE"
    @echo &MSG#

     Will generate this JCL (you can check the generated JCL when the job is in the activity view, or chose extended reports to store the JCL in the report):

    GOTO :ENDE
    @echo "Do something"
    :ENDE
    @echo A <> 1 I did something

    It will never reach the @echo "Do something", but the "I did something" message was already generated during the activation of the job. The AE Script doesn't know what the interpreter will do with the GOTO in the JCL and that this whole part is skipped.

    Better would be:

    :set &A# = x
    :IF &A# = 1
    !do something
    @echo "Do something"
    @echo "A = 1 I did something"
    :ELSE
    : STOP MSG,50,"A <> 1"
    :ENDIF

     It wouldn't even send a JCL to the agent when the AE Script realizes that there is nothing to execute.


     I hope it's understandable and not even more confusing




  • 7.  RE: GOTO does not work

    Posted Oct 25, 2019 04:57 AM
    Hello,
         well! Thank you for information. At this point question is; I need to make jump in portion code script into AE environment; can I do it somehow?
    Regads
    Daniele

    ------------------------------
    Employee
    Postevita
    ------------------------------



  • 8.  RE: GOTO does not work

    Posted Oct 25, 2019 05:08 AM
    Hi Daniele,
    there is no GOTO or something similar in AE script... You can only use :IF...:ELSE...:ENDIF to achieve this. :-(
    Greetings to Italy
    Tim

    ------------------------------
    Automation Evangelist
    Fiducia & GAD IT AG
    ---
    Mitglied des deutschsprachigen Automic-Anwendervereins FOKUS e.V.
    Member of the German speaking Automic user association FOKUS e.V.
    ------------------------------



  • 9.  RE: GOTO does not work

    Posted Oct 25, 2019 05:23 AM

    Without guarantee:

    :SET SET &FLAG_CHECK# = "FALSE"
    :IF &ORIGPATH# = ""

    : SET &OA_MessageAction#="ERRORE - Variabile 'ORIGPATH' non valorizzata "
    : SET &OA_CodeAc#=4
    : SET &FLAG_CHECK# = "TRUE"
    :ENDIF
    !

    :IF &NOMEFILE1# = ""
    : SET &OA_MessageAction#="ERRORE - Variabile 'NOMEFILE1' non valorizzata "
    : SET &OA_CodeAct#=4
    : SET &FLAG_CHECK# = "TRUE"
    :ENDIF
    !
    :IF &FLAG_CHECK# = "FALSE"

    echo "°°°°°°°°° 8"
    &DISCO#
    cd &ORIGPATH#
    echo "°°°°°°°°° 9"
    !
    :IF &NFoldersORIG#>0

    echo "°°°°°°°°° 10"
    &COMMAND# &ORIGPATH#&NomeFIle1# &DESTPATH#&NomeFIle2#
    echo "°°°°°°°°° 11"
    : SET &OA_CodeAct#=0
    : SET &OA_MessageAction#="#MSG: OPERAZIONE CORRETTAMENTE ESEGUITA (AllarmLevel=0)"
    echo "°°°°°°°°° 12"
    :ELSE
    : SET &OA_CodeAct#=4
    : SET &OA_MessageAction#="#MSG: OPERAZIONE MOMENTANEAMENTE INTERDETTA - Path di origine non trovato (AllarmLevel=4)"
    :ENDIF
    echo "°°°°°°°°° 13"
    :ENDIF
    !

    echo "°°°°°°°°° 14"
    echo °
    echo ° $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    echo [ESITO OPERAZIONE]: &OA_MessageAction#
    echo [RETURN CODE]: &OA_CodeAct#
    echo ° $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    echo °

    May I suggest to insert also a error check after your commands? Otherwise this job will always ends with ENDED_OK...



    ------------------------------
    Automation Evangelist
    Fiducia & GAD IT AG
    ---
    Mitglied des deutschsprachigen Automic-Anwendervereins FOKUS e.V.
    Member of the German speaking Automic user association FOKUS e.V.
    ------------------------------



  • 10.  RE: GOTO does not work
    Best Answer

    Posted Oct 25, 2019 05:36 AM
    ​The only way to skip is with IF ELSE conditions. This should work or as I said before, if you know that there is nothing to execute stop the processing with :STOP
    :IF &ORIGPATH# = ""
    :  SET &OA_MessageAction#="ERRORE - Variabile 'ORIGPATH' non valorizzata "
    :  SET &OA_CodeAc#=4
    :ELSE
    :  IF &NOMEFILE1# = ""
    :    SET &OA_MessageAction#="ERRORE - Variabile 'NOMEFILE1' non valorizzata "
    :    SET &OA_CodeAct#=4
    :  ELSE
    echo "°°°°°°°°° 8"
    &DISCO#
    cd &ORIGPATH#
    echo "°°°°°°°°° 9"
    :    IF &NFoldersORIG#>0
    echo "°°°°°°°°° 10"
     &COMMAND# &ORIGPATH#&NomeFIle1# &DESTPATH#&NomeFIle2#
    echo "°°°°°°°°° 11"
    :       SET &OA_CodeAct#=0
    :       SET &OA_MessageAction#="#MSG: OPERAZIONE CORRETTAMENTE ESEGUITA (AllarmLevel=0)"
    echo "°°°°°°°°° 12"
    :    ELSE
    :       SET &OA_CodeAct#=4
    :       SET &OA_MessageAction#="#MSG: OPERAZIONE MOMENTANEAMENTE INTERDETTA - Path di origine non trovato (AllarmLevel=4)"
    :    ENDIF
    echo "°°°°°°°°° 13"
    :  ENDIF
    :ENDIF
    echo "°°°°°°°°° 14"
    echo °
    echo °
    echo °
    echo °
    echo ° $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    echo [ESITO OPERAZIONE]: &OA_MessageAction#
    echo [RETURN CODE]: &OA_CodeAct#
    echo ° $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    echo °
    echo °
    echo °