ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

RCV Loop

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

  • RCV Loop

    Hey everyone,

    Wonder if you could lend some assistance here. I have a program which I want to receive records and loop round until EOF, once it has processed all the records in the file I want it to delay for a set period of time and then start again from the first record.

    I though that closing and re-opening the file would work (as it does in RPG), but this doesn't seem to work..

    Code:
                 PGM                                                           
                 DCL        VAR(&WAIT) TYPE(*CHAR) LEN(5)                      
                 DCLF       FILE(OMS400/MRMMSTP)                               
                                                                               
    /* CHECK TO SEE IF THE OMS400 LIBRARY EXISTS, IF NOT THEN END PROGRAM */   
                 CHKOBJ     OBJ(OMS400) OBJTYPE(*LIB)                          
                 MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ENDPGM))           
                 RMVLIBLE   LIB(OMS400)                                        
                 MONMSG     MSGID(CPF0000)                                     
                 ADDLIBLE   LIB(OMS400) POSITION(*FIRST)                       
    /* IF WE GET TO HERE THEN WE CAN CONTINUE PROCESSING */                    
    LOOP:                                                                      
                 RCVF                                                          
                 MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(EOF)) /* If +      
                              end of file */                                   
                 RTVLNKSTS  LINK(&MMNAME) OUTFIL(*ADD)                         
                 GOTO       CMDLBL(LOOP) /* Read next record */                
    /* END OF FILE PROCESSING - DELAY JOB AND START AGAIN */                   
    EOF:                                                                       
                 CLOF       OPNID(MRMMSTP)                               
                 RTVDTAARA  DTAARA(OMCNTF (8 5)) RTNVAR(&WAIT)           
                 DLYJOB     DLY(&WAIT)                                   
                 OPNDBF     FILE(MRMMSTP) OPTION(*INP)                   
                 GOTO       CMDLBL(LOOP)                                 
    /* END PROGRAM */                                                    
     ENDPGM:     ENDPGM
    Whats the best way to start again from the first record in my file?

  • #2
    Re: RCV Loop

    Hello,

    the Helptext for DCLF tells us that RCVF will OPEN the file.
    So i assume CLOF and OPNDBF is not useable for you!

    Put the inner LOOP into a second CLP and make a call to that for going through the file...
    Looks not nice, but will work.

    kuempi

    Comment


    • #3
      Re: RCV Loop

      I've tried all kinds of things to get this to work. I know I can create another program and process it that way, but I wanted to try and fit it all into one program if I could.

      I've also tried using POSDBF but that doesnt seem to work either. I found some topics somewhere else on the web which suggested doing a RTVMBRD on the member to get the number of records, then checking to see how many records I have processed in my RCVF loop, and once I hit the correct amount of records do a POSDBF to *START. Tried this and it still doesn't work

      Code:
                   PGM                                                        
                   DCL        VAR(&WAIT) TYPE(*CHAR) LEN(5)                   
                   DCL        VAR(&NUMOFRECS) TYPE(*DEC) LEN(10 0)            
                   DCL        VAR(&COUNT) TYPE(*DEC) LEN(10 0)                
                   DCLF       FILE(OMS400/MRMMSTP)                            
                                                                              
      /* CHECK TO SEE IF THE OMS400 LIBRARY EXISTS, IF NOT THEN END PROGRAM */
                   CHKOBJ     OBJ(OMS400) OBJTYPE(*LIB)                       
                   MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ENDPGM))        
                   RMVLIBLE   LIB(OMS400)                                     
                   MONMSG     MSGID(CPF0000)                                  
                   ADDLIBLE   LIB(OMS400) POSITION(*FIRST)                    
      /* IF WE GET TO HERE THEN WE CAN CONTINUE PROCESSING */                 
      RTVFD:                                                                  
                   RTVMBRD    FILE(OMS400/MRMMSTP) MBR(*FIRST) +              
                                NBRCURRCD(&NUMOFRECS)                         
                   CHGVAR     VAR(&COUNT) VALUE(0)                            
                   OPNDBF     FILE(OMS400/MRMMSTP) OPTION(*INP) +             
                                MBR(*FIRST) OPNID(MRMMSTP)                    
      LOOP:                                                                 
                   RCVF                                                     
                   MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(ENDPGM)) /* + 
                                If we hit end of file end program because + 
                                we can't go back */                         
                   CHGVAR     VAR(&COUNT) VALUE(&COUNT + 1)                 
                   RTVLNKSTS  LINK(&MMNAME) OUTFIL(*ADD)                    
                   IF         COND(&NUMOFRECS *EQ &COUNT) THEN(GOTO +       
                                CMDLBL(EOF))                                
                   GOTO       CMDLBL(LOOP) /* Read next record */           
      /* END OF FILE PROCESSING - DELAY JOB AND START AGAIN */              
      EOF:                                                                  
                   RTVDTAARA  DTAARA(OMCNTF (8 5)) RTNVAR(&WAIT)            
                   DLYJOB     DLY(&WAIT)                                    
                   POSDBF     OPNID(MRMMSTP) POSITION(*START)               
                   GOTO       CMDLBL(LOOP)                                  
      /* END PROGRAM */                                                     
       ENDPGM:     ENDPGM

      Comment


      • #4
        Re: RCV Loop

        Ok I've changed my program some more, added in the RCLRSC LVL(*CALLER) and all seems to work as I want.

        I do have a question for you guys though.. In the help on the RCLRSC command it says the following..

        Do not specify LVL(*CALLER) on this command if it is used in a
        CL program that also uses the Send File (SNDF), Receive File
        (RCVF), or Send Receive File (SNDRCVF) commands. Specifying
        RCLRSC LVL(*CALLER) in such a program causes unpredictable
        results when the SNDF, RCVF, or SNDRCVF commands are used
        after the program runs.
        Does this mean that in this instance I really shouldn't use this command?

        Code:
        PGM                                                          
                     DCL        VAR(&WAIT) TYPE(*CHAR) LEN(5)                     
                     DCL        VAR(&NUMOFRECS) TYPE(*DEC) LEN(10 0)              
                     DCL        VAR(&COUNT) TYPE(*DEC) LEN(10 0)                  
                     DCLF       FILE(OMS400/MRMMSTP)                              
                                                                                  
        /* CHECK TO SEE IF THE OMS400 LIBRARY EXISTS, IF NOT THEN END PROGRAM */  
                     CHKOBJ     OBJ(OMS400) OBJTYPE(*LIB)                         
                     MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ENDPGM))          
                     RMVLIBLE   LIB(OMS400)                                       
                     MONMSG     MSGID(CPF0000)                                    
                     ADDLIBLE   LIB(OMS400) POSITION(*FIRST)                      
        /* IF WE GET TO HERE THEN WE CAN CONTINUE PROCESSING */                   
        RTVFD:                                                                    
                     RTVMBRD    FILE(OMS400/MRMMSTP) MBR(*FIRST) +                
                                  NBRCURRCD(&NUMOFRECS)                           
                     CHGVAR     VAR(&COUNT) VALUE(0)
        LOOP:                                                                 
                     RCVF                                                     
                     MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(ENDPGM)) /* + 
                                  If we hit end of file end program because + 
                                  we can't go back */                         
                     CHGVAR     VAR(&COUNT) VALUE(&COUNT + 1)                 
                     RTVLNKSTS  LINK(&MMNAME) OUTFIL(*ADD)                    
                     IF         COND(&NUMOFRECS *EQ &COUNT) THEN(GOTO +       
                                  CMDLBL(EOF))                                
                     GOTO       CMDLBL(LOOP) /* Read next record */           
        /* END OF FILE PROCESSING - DELAY JOB AND START AGAIN */              
        EOF:                                                                  
                     RTVDTAARA  DTAARA(OMCNTF (8 5)) RTNVAR(&WAIT)            
                     DLYJOB     DLY(&WAIT)                                    
                     RCLRSC     LVL(*CALLER)                                  
                     GOTO       CMDLBL(LOOP)                                  
        /* END PROGRAM */                                                     
         ENDPGM:     ENDPGM

        Comment


        • #5
          Re: RCV Loop

          Yes, have had the same idea when i think about you problem and found the same warning about RCLRSV...
          not sure about this, but i have a bad feeling.

          If it works in every way maybe you can leave it, but can you sleep well then after putting this to production?

          Have found a discussion about your Problem here http://www.mcpressonline.com/mc?14@1...6.0@.f01dd39/9
          resp. this can help to change your coding?

          Have a nice day

          kuempi

          Comment


          • #6
            Re: RCV Loop

            I've seen a few discussions like this on the web (spent all day so far trying to find a solution to my problem). The problem I have is that I am on v5r1 and the majority of solutions out there are for v5r2 or higher.

            I've tried using the POSDBF (see my earlier example) and couldn't get it to work, I'll have another play around now..

            Comment


            • #7
              Re: RCV Loop

              Chris,

              I'm assuming you're wanting this somewhat as an NEP? What about making this a recursive call? When you "delay", have your program submit a job calling itself. This way, it goes back, opens up your files and processes again from the beginning every time.

              Of course, you'll need some sort of flagging routine to kill the process as necessary... but, that's not hard to do.

              Oh well.. food for thought!

              -Rick

              Comment


              • #8
                Re: RCV Loop

                Correct Fastone..

                It now looks like I've got to the bottom of the problem, I needed an OVRDBF before the OPNDBF command, I've added to the code a bit now, but here is what I'm working on at the moment..

                Code:
                             PGM                                                           
                             DCL        VAR(&WAIT) TYPE(*CHAR) LEN(5)                      
                             DCL        VAR(&NUMOFRECS) TYPE(*DEC) LEN(10 0)               
                             DCL        VAR(&COUNT) TYPE(*DEC) LEN(10 0) VALUE(0)          
                             DCL        VAR(&MAXLIB) TYPE(*CHAR) LEN(10)                   
                             DCLF       FILE(OMS400/MRMMSTP)                               
                                                                                           
                             RTVOBJD    OBJ(*LIBL/OMBT01) OBJTYPE(*PGM) RTNLIB(&MAXLIB)    
                /* CHECK TO SEE IF THE OMS400 LIBRARY EXISTS, IF NOT THEN END PROGRAM */   
                             CHKOBJ     OBJ(OMS400) OBJTYPE(*LIB)                          
                             MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ENDPGM))           
                             RMVLIBLE   LIB(OMS400)                                        
                             MONMSG     MSGID(CPF0000)                                     
                             ADDLIBLE   LIB(OMS400) POSITION(*FIRST)                       
                /* ALLOCATE THE LAGOMS MESSAGE QUEUE */                                    
                             CHKOBJ     OBJ(&MAXLIB/LAGOMS) OBJTYPE(*MSGQ)                 
                             MONMSG     MSGID(CPF0000) EXEC(CRTMSGQ +                      
                                          MSGQ(&MAXLIB/LAGOMS) TEXT('OMS Lag +             
                                          Monitor Message Queue'))                         
                             ALCOBJ     OBJ((&MAXLIB/LAGOMS *MSGQ *EXCL))               
                             MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ENDPGM))        
                /* IF WE GET TO HERE THEN WE CAN CONTINUE PROCESSING */                 
                RTVFD:                                                                  
                             RTVMBRD    FILE(OMS400/MRMMSTP) MBR(*FIRST) +              
                                          NBRCURRCD(&NUMOFRECS)                         
                             OVRDBF     FILE(MRMMSTP) SHARE(*YES)                       
                             OPNDBF     FILE(MRMMSTP) OPTION(*INP)                      
                LOOP:                                                                   
                             RCVF                                                       
                             MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(ENDPGM)) /* +   
                                          If we hit end of file end program because +   
                                          we can't go back */                           
                             CHGVAR     VAR(&COUNT) VALUE(&COUNT + 1)                   
                             RTVLNKSTS  LINK(&MMNAME) OUTFIL(*ADD)                      
                             IF         COND(&NUMOFRECS *EQ &COUNT) THEN(GOTO +         
                                          CMDLBL(EOF))                                  
                             GOTO       CMDLBL(LOOP) /* Read next record */             
                /* END OF FILE PROCESSING - DELAY JOB AND START AGAIN */                
                EOF:                                                                    
                             RTVDTAARA  DTAARA(OMCNTF (8 5)) RTNVAR(&WAIT)       
                             RCVMSG     MSGQ(&MAXLIB/LAGOMS) WAIT(&WAIT)         
                             POSDBF     OPNID(MRMMSTP) POSITION(*START)          
                             CHGVAR     VAR(&COUNT) VALUE(0)                     
                             GOTO       CMDLBL(LOOP)                             
                /* END PROGRAM */                                                
                 ENDPGM:                                                         
                             DLTOVR     FILE(MRMMSTP)                            
                             MONMSG     MSGID(CPF0000)                           
                             DLCOBJ     OBJ((&MAXLIB/LAGOMS *MSGQ *EXCL))        
                             MONMSG     MSGID(CPF0000)                           
                             ENDPGM
                Just need to tie in some ENDJOB message processing check after the RCVMSG statement and that should work as I want (fingers crossed).

                Any comments from you CL gurus?

                Comment


                • #9
                  Re: RCV Loop

                  OK.. I guess I'm missing something here.

                  What I'm getting is that you have a file that has records put into it that you want to process. While you're processing, there is a possibility that more records could (may) be put into the file, and you want to process those as well.

                  With that being said, it would be very easy to do something like the following:

                  PHP Code:
                  CLLE:  THISJOB

                  If StopJob Flag (Goto EndPgm)

                  Get NumRecs of DBF
                  If NumRecs Zero Goto Delay

                  Open DBF
                  Loop
                  :
                     
                  Read DBF
                     
                  If EOF Goto Delay

                     
                  Do Something
                     
                  Goto Loop

                  Delay
                  :
                     
                  Wait 5 Minutes
                     SbmJob 
                  (THISJOB)

                  EndPgm
                  I guess the "reason" for the count and all really seems to be a bit much for such a simple job, if I am correct on my thinking (which is another story).

                  -Rick

                  Comment


                  • #10
                    Re: RCV Loop

                    The reason I haven't written the program in CLLE is because I my CLLE is worse than my CLP.

                    That being said, the reason I keep looping round the file is because I get statistics (the RTVLNKSTS LINK(&MMNAME) OUTFIL(*ADD) statement), and I need those collecting constantly throughout the day/night.

                    In actual fact, the likelyhood that any records will be added or removed from this file is pretty slim, which is why I am only getting the number of records in the member at the start of my process.

                    I'd prefer to have it all processed in one job (rather than a job which cubmits itself) because then I can monitor a message queue for the job ending and raise alerts if it ends that way - doing it your way would confuse the operators at my place unfortunately!

                    Hope that makes sense

                    Comment


                    • #11
                      Re: RCV Loop

                      CLLE...CLP (potato/potaato) <misspelled on purpose>

                      It's all the same... only the names have changed!

                      I truly understand the "confusing the operators" statement! It has a lot to do with how you program these days.

                      Although, monitoring a DataQ or DataArea with this is pretty easy.

                      Just wanted to provide some food for thought. (that way I can earn my pay around here)

                      Comment


                      • #12
                        Re: RCV Loop

                        Not exactly a CL Guru, but here is a structure I use for a server that sits waiting for work, and can be configured on the fly without having to restart it.
                        It can easily be modified (this is my basic skeleton) to have the server jobname, *DTAQ, *DTAQ library names all parameter driven so you only need the one piece of code to control all your in house servers. This template uses the DTAQ to maintain the server and does all it's intended processing when the RCVDTAQ command times out after the wait period. Changing the wait period changes the "delay" the server sits on before acting again.
                        The important reason for this is a job that is doing a DLY-3600 will not process an end command until the 3600 secs is up, while this server will end immediately when asked.

                        See attached 2 commands (make it easier to submit and maintain for Ops)
                        See attached 3 CLLE pgms (1 to sub, 1 for the server running, and 1 to chg the server properties on the fly)

                        This may be of use in controlling how you control the job ending/starting etc.
                        Just plug in your RCVF commands etc into the "Do Part 1" sections etc ...

                        (attachments as SAVF in the zip file and as text file)

                        Command GCSVRSUB
                        Code:
                        CMD        PROMPT('Change Server Parms')
                        PARM       KWD(CHANGE) TYPE(*CHAR) LEN(3) RSTD(*YES) +
                                     VALUES(KIL NOW 001 005 015 030 060 120) +
                                     MIN(1) CHOICE(*VALUES) PROMPT('Enter +   
                                     Update Choice')
                        Command GCSVRCHG
                        Code:
                        CMD        PROMPT('Submit Server Job')               
                        PARM       KWD(DELAY) TYPE(*CHAR) LEN(3) RSTD(*NO) + 
                                     MIN(1) CHOICE(MINUTES) PROMPT('Enter +  
                                     Delay Interval(minutes)')               
                        PARM       KWD(PARM1) TYPE(*CHAR) LEN(1) RSTD(*YES) +
                                     DFT(Y) VALUES(Y N) MIN(0) PROMPT('Do +  
                                     process for part 1')                    
                        PARM       KWD(PARM2) TYPE(*CHAR) LEN(1) RSTD(*YES) +
                                     DFT(Y) VALUES(Y N) MIN(0) PROMPT('Do +  
                                     process for part 2')                    
                        PARM       KWD(PARM3) TYPE(*CHAR) LEN(1) RSTD(*YES) +
                                     DFT(Y) VALUES(Y N) MIN(0) PROMPT('Do +  
                                     process for part 3')
                        CLLE program GCSVRC1
                        Code:
                        /*       +------------------------------------------------------------+ */          
                        /*       | Created by Greg Craill to automate servers.                | */          
                        /*       | Parm &DQWAIT is in minutes type *CHAR.                     | */          
                        /*       | Extra "PARM"s can be added as required ...                 | */          
                        /*       +------------------------------------------------------------+ */          
                                     PGM        PARM(&DQWAIT &PARM1 &PARM2 &PARM3)                          
                                     DCL        VAR(&DQWAIT)   TYPE(*CHAR) LEN(3)                           
                                     DCL        VAR(&PARM1)    TYPE(*CHAR) LEN(1)                           
                                     DCL        VAR(&PARM2)    TYPE(*CHAR) LEN(1)                           
                                     DCL        VAR(&PARM3)    TYPE(*CHAR) LEN(1)                           
                                     DCL        VAR(&JOB)      TYPE(*CHAR) LEN(10)                          
                        /*       +------------------------------------------------------------+ */          
                        /*       | If required add validation here to check the user-id,      | */          
                        /*       | library list etc before submitting the server.             | */          
                        /*       +------------------------------------------------------------+ */          
                                     IF         COND(COND1 = VALUE1) THEN(DO)                               
                                       GOTO       CMDLBL(ERRORS)                                            
                                     ENDDO                                                                  
                        /*       +------------------------------------------------------------+ */          
                        /*       | Validation is passed so submit the server                  | */          
                        /*       +------------------------------------------------------------+ */          
                                     CHGVAR     VAR(&JOB) VALUE('Server_1')                                 
                                     SBMJOB     CMD(CALL PGM(GCSVRCL2) PARM(&DQWAIT &PARM1 &PARM2 &PARM3)) +
                                                  JOB(&JOB) LOG(4 0 *SECLVL) LOGCLPGM(*YES)       
                                     GOTO       CMDLBL(END)                                       
                        /*       +------------------------------------------------------------+ */
                        /*       | Handle Validation errors here ...                          | */
                        /*       +------------------------------------------------------------+ */
                         ERRORS:                                                                  
                        /*       +------------------------------------------------------------+ */
                        /*       | End program.                                               | */
                        /*       +------------------------------------------------------------+ */
                         END:        ENDPGM
                        CLLE program GCSVRC2
                        Code:
                                     PGM        PARM(&DQWAITC &DOPT1 &DOPT2 &DOPT3)                     
                                     DCL        VAR(&DQWAITC)  TYPE(*CHAR) LEN(3)                       
                                     DCL        VAR(&DOPT1)    TYPE(*CHAR) LEN(1)                       
                                     DCL        VAR(&DOPT2)    TYPE(*CHAR) LEN(1)                       
                                     DCL        VAR(&DOPT3)    TYPE(*CHAR) LEN(1)                       
                                     DCL        VAR(&DQLIB)    TYPE(*CHAR) LEN(10)                      
                                     DCL        VAR(&DQNAME)   TYPE(*CHAR) LEN(10)                      
                                     DCL        VAR(&DQTXT)    TYPE(*CHAR) LEN(100)                     
                                     DCL        VAR(&DQWAITD)  TYPE(*DEC)  LEN(5 0)                     
                                     DCL        VAR(&DQWD)     TYPE(*DEC)  LEN(3 0)                     
                                     DCL        VAR(&DQDATA)   TYPE(*CHAR) LEN(50)                      
                                     DCL        VAR(&DQSIZE)   TYPE(*DEC)  LEN(5 0) VALUE(50)           
                                     DCL        VAR(&JOB)      TYPE(*CHAR) LEN(10)                      
                                     DCL        VAR(&USER)     TYPE(*CHAR) LEN(10)                      
                                     DCL        VAR(&ERRCODE)  TYPE(*CHAR) LEN(10)                      
                                                                                                        
                        /* ####      Setup and Validation Phase                                  #### */
                        /* +------------------------------------------------------------------------+ */
                        /* | Setup variables etc                                                    | */
                        /* +------------------------------------------------------------------------+ */  
                                     RTVJOBA    JOB(&JOB) USER(&USER)                                     
                                     CHGVAR     VAR(&DQLIB)  VALUE('UDELETEME')                           
                                     CHGVAR     VAR(&DQNAME) VALUE('GCDTAQ')                              
                        /* +------------------------------------------------------------------------+ */  
                        /* | Check that the data queue exists - if not create it                    | */  
                        /* +------------------------------------------------------------------------+ */  
                         CHKDQ:      CHKOBJ     OBJ(&DQLIB/&DQNAME) OBJTYPE(*DTAQ)                        
                                     MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(NOTFOUND))                
                                     ALCOBJ     OBJ((&DQLIB/&DQNAME *DTAQ *EXCL))                         
                                     MONMSG     MSGID(CPF1002) EXEC(GOTO CMDLBL(NOALLOC))                 
                                     GOTO       CMDLBL(CONTINUE)                                          
                        /* +------------------------------------------------------------------------+ */  
                        /* | Data Queue &DQNAME in &DQLIB is not found so create it                 | */  
                        /* +------------------------------------------------------------------------+ */  
                         NOTFOUND:   CHGVAR     VAR(&DQTXT) VALUE(&JOB *BCAT 'Data Queue.')               
                                     CRTDTAQ    DTAQ(&DQLIB/&DQNAME) MAXLEN(50) AUTORCL(*YES) TEXT(&DQTXT)
                                     MONMSG     MSGID(CPF9870)                                            
                                     ALCOBJ     OBJ((&DQLIB/&DQNAME *DTAQ *EXCL))                         
                                     GOTO       CMDLBL(CONTINUE)                                          
                        /* +------------------------------------------------------------------------+ */  
                        /* | Data Queue BPISSVRDQ already allocated so job might already be active  | */  
                        /* +------------------------------------------------------------------------+ */  
                         NOALLOC:    CHGVAR     VAR(&ERRCODE) VALUE('NOALLOC')                             
                                     GOTO       CMDLBL(ERROR)                                              
                        /* +------------------------------------------------------------------------+ */   
                        /* | Validation/Setup has passed so continue.                               | */   
                        /* +------------------------------------------------------------------------+ */   
                         CONTINUE:   CHGVAR     VAR(&DQWD) VALUE(&DQWAITC)                                 
                                     CHGVAR     VAR(&DQWAITD) VALUE(&DQWD * 60)                            
                                                                                                           
                        /* ####      Main Program Phase                                          #### */   
                        /* +------------------------------------------------------------------------+ */   
                        /* | Check DTAQ for entries, do processes after timeout is reached ...      | */   
                        /* +------------------------------------------------------------------------+ */   
                         LOOP:       CALL       PGM(QRCVDTAQ) PARM(&DQNAME &DQLIB &DQSIZE &DQDATA &DQWAITD)
                                     IF         COND(&DQSIZE *NE 0) THEN(DO)                               
                                       CHGVAR     VAR(&DQWD) VALUE(&DQWAITD / 60)                          
                                       CHGVAR     VAR(&DQWAITC) VALUE(&DQWD)                               
                        /* +------------------------------------------------------------------------+ */
                        /* | Terminate Request has been sent to the Data Queue so end the server    | */
                        /* +------------------------------------------------------------------------+ */
                                       IF         COND(%SST(&DQDATA 1 9) *EQ 'TERMINATE') THEN(DO)      
                                         CHGVAR     VAR(&ERRCODE) VALUE('TERMINATE')                    
                                         GOTO       CMDLBL(ERROR)                                       
                                       ENDDO                                                            
                        /* +------------------------------------------------------------------------+ */
                        /* | Immediate Request has been sent to the Data Queue so process now       | */
                        /* +------------------------------------------------------------------------+ */
                                       IF         COND(%SST(&DQDATA 1 9) *EQ 'IMMEDIATE') THEN(DO)      
                                         GOTO       CMDLBL(TIMEOUT)                                     
                                       ENDDO                                                            
                        /* +------------------------------------------------------------------------+ */
                        /* | Delay between checking the BPI Downloads changed, update and reloop    | */
                        /* +------------------------------------------------------------------------+ */
                                       IF         COND(%SST(&DQDATA 1 5) *EQ 'DELAY') THEN(DO)          
                                         CHGVAR     VAR(&DQWAITC) VALUE(%SST(&DQDATA 7 3))              
                                         CHGVAR     VAR(&DQWD) VALUE(&DQWAITC)                          
                                         CHGVAR     VAR(&DQWAITD) VALUE(&DQWD * 60)                     
                                         GOTO       CMDLBL(LOOP)                                        
                                       ENDDO                                                            
                        /* +------------------------------------------------------------------------+ */
                        /* | Loop back to start until end command is received                       | */
                        /* +------------------------------------------------------------------------+ */
                                       GOTO       CMDLBL(LOOP)                                          
                                     ENDDO                                                              
                        /* +------------------------------------------------------------------------+ */
                        /* | END of MAIN LOOP Procedure                                             | */
                        /* +------------------------------------------------------------------------+ */
                                                                                                        
                        /* ####      Timeout Processing Phase                                    #### */
                        /* +------------------------------------------------------------------------+ */
                        /* | If no command has been received by the DTAQ in the time interval then  | */
                        /* | Perform this action (Check for TAP3 downloads waiting)                 | */
                        /* +------------------------------------------------------------------------+ */
                         TIMEOUT:                                                                       
                        /* +------------------------------------------------------------------------+ */
                        /* | If DOPT1 parm is set to "Y" then perform "Do Part 1" actions           | */
                        /* +------------------------------------------------------------------------+ */
                         DoPart1:    IF         COND(&DOPT1 = 'Y') THEN(DO)                             
                                       /* Do something here */                                          
                                       SNDUSRMSG  MSG('Part 1 procesed') MSGTYPE(*INFO) TOUSR(&USER)    
                                     ENDDO                                                              
                        /* +------------------------------------------------------------------------+ */
                        /* | If DOPT2 parm is set to "Y" then perform "Do Part 2" actions           | */
                        /* +------------------------------------------------------------------------+ */
                         DoPart2:    IF         COND(&DOPT2 = 'Y') THEN(DO)                             
                                       /* Do something here */                                          
                                       SNDUSRMSG  MSG('Part 2 procesed') MSGTYPE(*INFO) TOUSR(&USER)    
                                     ENDDO                                                              
                        /* +------------------------------------------------------------------------+ */
                        /* | If DOPT3 parm is set to "Y" then perform "Do Part 3" actions           | */
                        /* +------------------------------------------------------------------------+ */
                         DoPart3:    IF         COND(&DOPT3 = 'Y') THEN(DO)                             
                                       /* Do something here */                                          
                                       SNDUSRMSG  MSG('Part 3 procesed') MSGTYPE(*INFO) TOUSR(&USER)    
                                     ENDDO                                                              
                        /* +------------------------------------------------------------------------+ */
                        /* | Processing is finished so return to loop until end command issued      | */
                        /* +------------------------------------------------------------------------+ */
                                     GOTO       CMDLBL(LOOP)                                            
                        
                        /* ####      Error Handling Phase                                        #### */
                         ERROR:                                                                         
                        /* +------------------------------------------------------------------------+ */
                        /* | Unable to allocate DTAQ so job may already be active. Do not submit.   | */
                        /* +------------------------------------------------------------------------+ */
                                     IF         COND(&ERRCODE *EQ 'NOALLOC') THEN(DO)                   
                                       SNDPGMMSG  MSG('Unable to allocate objects required. +           
                                                  Server may already be active, Server +                
                                                  failed to submit.')                                   
                                       SNDUSRMSG  MSG('Unable to allocate objects required. +           
                                                  Server may already be active, Server +                
                                                  failed to submit.') MSGTYPE(*INFO) +                  
                                                  TOUSR(&USER)                                          
                                     ENDDO                                                              
                        /* +------------------------------------------------------------------------+ */
                        /* | In case some other action is required later on a Terminate Request     | */
                        /* | then place the instructions here                                       | */
                        /* +------------------------------------------------------------------------+ */
                                     IF         COND(&ERRCODE *EQ 'TERMINATE') THEN(DO)                 
                                     ENDDO                                                              
                                                                                                        
                        /* ####      Program End Phase                                           #### */
                        /* +------------------------------------------------------------------------+ */
                        /* | Tidy up job, close files, deallocate objects and end nicely.           | */
                        /* +------------------------------------------------------------------------+ */
                         END:        RCLRSC                                                             
                                     RCLACTGRP  ACTGRP(*ELIGIBLE)                                       
                                     DLCOBJ     OBJ((&DQLIB/&DQNAME *DTAQ *EXCL))                       
                                     MONMSG     MSGID(CPF0000)                                          
                         KHALAS:     ENDPGM
                        CLLE program GCSVRC3
                        Code:
                                     PGM        PARM(&DELAYC)                                           
                                     DCL        VAR(&DELAYC)  TYPE(*CHAR) LEN(3)                        
                                     DCL        VAR(&DQNAME)  TYPE(*CHAR) LEN(10)                       
                                     DCL        VAR(&DQLIB)   TYPE(*CHAR) LEN(10)                       
                                     DCL        VAR(&DQSIZE)  TYPE(*DEC) LEN(5 0) VALUE(50)             
                                     DCL        VAR(&DQDATA)  TYPE(*CHAR) LEN(50)                       
                                     DCL        VAR(&USER)    TYPE(*CHAR) LEN(10)                       
                        /* +------------------------------------------------------------------------+ */
                        /* | Setup variables etc                                                    | */
                        /* +------------------------------------------------------------------------+ */
                                     CHGVAR     VAR(&DQLIB)  VALUE('UDELETEME')                         
                                     CHGVAR     VAR(&DQNAME) VALUE('GCDTAQ')                            
                        /* +------------------------------------------------------------------------+ */
                        /* | Check that the data queue exists - if not create it                    | */
                        /* +------------------------------------------------------------------------+ */
                         CHKDQ:      CHKOBJ     OBJ(&DQLIB/&DQNAME) OBJTYPE(*DTAQ)                      
                                     MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(NO_DTAQ))               
                        /* +------------------------------------------------------------------------+ */
                        /* | If the instruction is "KIL" then prepare a terminate request           | */
                        /* +------------------------------------------------------------------------+ */
                                     IF         COND(&DELAYC *EQ 'KIL') THEN(DO)                        
                                       CHGVAR     VAR(&DQDATA) VALUE('TERMINATE')                       
                                       GOTO       CMDLBL(UPDATE)                                        
                                     ENDDO                                                              
                        /* +------------------------------------------------------------------------+ */
                        /* | If the instruction is "NOW" then prepare an immediate request          | */
                        /* +------------------------------------------------------------------------+ */
                                     IF         COND(&DELAYC *EQ 'NOW') THEN(DO)                        
                                       CHGVAR     VAR(&DQDATA) VALUE('IMMEDIATE')                       
                                       GOTO       CMDLBL(UPDATE)                                        
                                     ENDDO                                                              
                        /* +------------------------------------------------------------------------+ */
                        /* | Else prepare a request to change the delay interval for the DTAQ       | */
                        /* +------------------------------------------------------------------------+ */
                                     CHGVAR     VAR(&DQDATA) VALUE('DELAY' *BCAT &DELAYC)               
                        /* +------------------------------------------------------------------------+ */
                        /* | Send the request to the DTAQ.                                          | */
                        /* +------------------------------------------------------------------------+ */
                         UPDATE:     CALL       PGM(QSNDDTAQ) PARM(&DQNAME &DQLIB &DQSIZE &DQDATA)      
                                     GOTO       CMDLBL(END)                                             
                        /* +------------------------------------------------------------------------+ */
                         NO_DTAQ:                                                                       
                        /* +------------------------------------------------------------------------+ */
                        /* | Unable to find the DTAQ, end job and send msg.                         | */
                        /* +------------------------------------------------------------------------+ */
                                     RTVJOBA    USER(&USER)                                             
                                     SNDPGMMSG  MSG('Unable to find the required Data Queue. +          
                                                  Request has not been sent to the server.')            
                                     SNDUSRMSG  MSG('Unable to find the required Data Queue. +          
                                                  Request has not been sent to the server.') +          
                                                  MSGTYPE(*INFO) TOUSR(&USER)                           
                        /* +------------------------------------------------------------------------+ */
                         END:        ENDPGM
                        Cheers
                        GC
                        Attached Files
                        Greg Craill: "Life's hard - Get a helmet !!"

                        Comment


                        • #13
                          Re: RCV Loop

                          Very Nice GC... Thanks for the example!

                          Comment


                          • #14
                            Re: RCV Loop

                            I agree thanks Greg for the extra effort of this monster post......Dont forget about those T-shirts......contact me off line!

                            take care
                            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

                            Working...
                            X