ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

End a program thru another program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • End a program thru another program

    I was wondering if there's an opcode that would allow for a program to terminate another program. Say, Program A calls Program B and within Program B it can end Program A. I could probably use RETURN opcode but another program is also able to call both Program A and Program B.

  • #2
    Re: End a program thru another program

    Im still not following this question...The point of programs is that you can call them multiple times with no problems at all.

    in cl there is a TFRCTL (??) not sure in RPG

    jamie
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: End a program thru another program

      Sorry about the confusion, I am a wee bit confused myself as to what my instructor wants me to do with our current project. Anyway, I think TFRCTL is what I need. Only problem is I need something like that in RPG ILE.

      Comment


      • #4
        Re: End a program thru another program

        One option would be to have a "Shutdown" routine in Program A. Have Program B call Program A with the "shutdown" option flagged... set *INLR = *On and then return to Program B.

        And BTW .. you can run CL Commands via RPG... just ask Jamie!

        Comment


        • #5
          Re: End a program thru another program

          If I want my programs to end immediately I tend to set on the H1 indicator and return, that pretty much does the trick for me, or like Fastone says have some sort of parameter passed between all your programs which is a control code, then get Program A to check for that control code when program B ends, if its switched on then return straight away.

          Comment


          • #6
            Re: End a program thru another program

            Just had to do this the other day. You can write a CL program that uses the ENDRQS command, which will end that CL program as well as all others in the call stack. Then call the CL program from the RPG program. It's effectively the same as using System Request option 2.

            However, in order to work as intended the CL program needs to become a Request Processor program. This is accomplished by sending a request message to the external program message queue.

            The following excerpt from the CL Programming manual, Chapter 8, explains how to do this (see the entire section for more info, but this was really all that was needed for this particular approach). Here's a link to the entire chapter: http://publib.boulder.ibm.com/iserie...c415721512.htm

            Writing Request-Processing Procedures and Programs

            Specifying a CL procedure as a request processor within a program has many advantages. The following list specifies three advantages:

            * Processes request messages as described in Request Messages.
            * Allows the use of the End Request (ENDRQS) command, which can be used from the System Request menu or as part of the disconnect job function.
            * Allows filtering of messages to occur.

            To become a request-processor procedure or program, your procedure or program must include the Send Program Message (SNDPGMMSG) and Receive Message (RCVMSG) commands. For example, the following commands would allow a procedure or program to become a request processor:

            SNDPGMMSG MSG('Request Message') TOPGMQ(*EXT) MSGTYPE(*RQS)
            RCVMSG PGMQ(*EXT) MSGTYPE(*RQS) RMV(*NO)

            Here's the final code from the program I put this into:

            0049.00 /* These two message commands make this pgm a request processor, */
            0050.00 /* which enables the ENDRQS command to terminate this process */
            0051.00 /* cleanly without returning to the calling program. */
            0052.00
            0053.00 SNDPGMMSG MSG('Request Message') TOPGMQ(*EXT) MSGTYPE(*RQS)
            0054.00 RCVMSG PGMQ(*EXT) MSGTYPE(*RQS) RMV(*NO)
            0055.00
            0056.00 /* End this pgm and all lower level (calling) pgms */
            0057.00 ENDRQS RQSLVL(*PRV)

            Good luck.

            Comment


            • #7
              Re: End a program thru another program

              I usually do it like FaStOnE says. Just use a field that has a value to check for--RETURN or SETON *INLR. I have three "modes"

              1) Terminate program B right away (before doing anything else). First thing the program does.
              2) Terminate program B after it's done processing its code
              3) Return instead of set on LR

              Usually what I do is call Program B from A leaving LR off (return), and then at the end of Program A, call all Program Bs where I leave LR off, and set LR on then.

              Comment

              Working...
              X