ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Does anyone Know Why?

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

  • Does anyone Know Why?

    Why is this happening?

    I ran the code that is listed below through the debugger and at this statement:

    If MSGTEST = ' ' ;
    Leave;
    Endif;
    when MSGTEST = ' ' it doesn't leave my loop. I looked at the variable MSGTEST and it is blank. It is alpha. It should leave the loop and it doesn't. I am at a loss!

    Why???

    DAC



    __________________________________________________ ____________

    Code:
         H Option(*NODEBUGIO:*SRCSTMT)
         H Debug
          ****************************************************************
          *                                                              *
          * Program name: AMQ3GET4                                       *
          *                                                              *
          * Description: Sample RPG program that gets messages from      *
          *              a message queue (example using MQGET)           *
          *                                                              *
          * @START_COPYRIGHT@                                            *
          * Licensed Materials - Property of IBM                         *
          *                                                              *
          * 0704923, 5733-A38                                            *
          *                                                              *
          * (C) Copyright IBM Corporation 1994, 2000                     *
          *                                                              *
          * Status: Version 5 Release 2                                  *
          * @END_COPYRIGHT@                                              *
          *                                                              *
          ****************************************************************
          *                                                              *
          * Function:                                                    *
          *                                                              *
          *                                                              *
          *   AMQ3GET4 is a sample RPG program to get messages from a    *
          *   message queue, and is an example of MQGET                  *
          *                                                              *
          *      -- sample gets messages from the queue named in         *
          *         the parameter                                        *
          *                                                              *
          *      -- displays the contents of the message queue,          *
          *         assuming each message data to represent a line       *
          *         of text to be written                                *
          *                                                              *
          *         messages are removed from the queue                  *
          *                                                              *
          *      -- writes a message for each MQI reason other than      *
          *         RCNONE; stops if there is a MQI completion code      *
          *         of CCFAIL                                            *
          *                                                              *
          *    Program logic:                                            *
          *         MQCONN to the target queue manager                   *
          *         MQOPEN queue for INPUT                               *
          *         while no MQI failures,                               *
          *         .  MQGET next message, remove from queue             *
          *         .  display the result                                *
          *         .  (no message available is failure, and ends loop)  *
          *         MQCLOSE the subject queue                            *
          *         MQDISC from the queue manager                        *
          *                                                              *
          ****************************************************************
          *                                                              *
          *                                                              *
          *                                                              *
          *   Exceptions signaled:  none                                 *
          *   Exceptions monitored: none                                 *
          *                                                              *
          *   AMQ3GET4 has 2 parameters - (1) name of the target queue   *
          *                               (2) name of the queue manager  *
          *                                                              *
          ****************************************************************
         fmqmsgpf   o    e             disk
         fReconout  o    e             disk
          *
          ** call parameters
          *  Connection handle
         D HCONN           S             10I 0
          * Options
         D OPTS            S             10I 0
          * Object handle
         D HOBJ            S             10I 0
          * Completion codes
         D OCODE           S             10I 0
         D CCODE           S             10I 0
          * Buffer length
         D BUFLEN          S             10I 0
          * Message length
         D MSGLEN          S             10I 0
          * Buffer
         D BUFFER          DS         65484    qualified Dim(255)  based(pBUFFER)
          * Buffer pointer
         D BUFPTR          S               *   INZ (%ADDR(pBUFFER))
    
         d endtext         s             23    inz (' ended with Reason Code')
         d uconntext       s             34    inz('Unable to connect to queue mgr')
         d uopentext       s             30    inz ('Unable to open queue')
         d nomesstext      s             16    inz ('no more messages')
         D Reconflg        s              1A   inz(' ')
         d Wrtmsgs         s              9  0 inz(0)
         d BX              s              6  0 inz(001)
         d MsgX            s              9  0 inz(01)
         d BufCount        s              6  0 inz(0)
         d BufCount2       s              9  0 inz(65484)
         d Remain1         s              6  0 inz(0)
         d MSGTEST         s              1    inz(*blanks)
          * Determine what kind of Message it is; Recon or General
         d                 ds                  inz
         d Msgtext                 1    102    Inz(*blanks)
         d MsgP1                   1     32
         d MsgP2                  33     34
         d MsgP3                  35    102
          * Reason
         d                 ds                  inz
         d reason                        10i 0
         d reasonc                 1     10
    
          *
          **  Declare MQI structures needed
          * MQI named constants
         D/COPY CMQG
          * Object Descriptor
         D MQOD            DS
         D/COPY CMQODG
          * Message Descriptor
         D MQMD            DS
         D/COPY CMQMDG
          * Get message options
         D MQGMO           DS
         I/COPY CMQGMOG
          ** note, sample uses defaults where it can
          *
          * program parameters are: 48-character target queue name
          *                         48-character queue manager name
         C     *ENTRY        PLIST
         C                   PARM                    QNAME            48
         C                   PARM                    QMNAME           48
          ** indicate that sample program has started
         C                   MOVEL     'start'       mqdata
         C                   write     mqmsgpfr
          *
          ****************************************************************
          *                                                              *
          *   Create object descriptor for source queue                  *
          *                                                              *
          ****************************************************************
         C                   MOVEL     QNAME         ODON             48
          *
          ****************************************************************
          *                                                              *
          *   Connect to the queue manager                               *
          *                                                              *
          ****************************************************************
         C                   CALLP     MQCONN(QMNAME : HCONN : OCODE : REASON)
          *
          * report reason and stop if it failed
         C     OCODE         IFEQ      CCFAIL
          **  "MQCONN ended with reason code ...."
         C                   eval      mqdata = 'MQCONN' + endtext + reasonc
         C                   write     mqmsgpfr
          **  "unable to connect to MQM"
         C                   eval      mqdata = uconntext
         C                   write     mqmsgpfr
         C                   SETON                                        LR
         C                   RETURN
         C                   ENDIF
          ****************************************************************
          *                                                              *
          *   Open the named message queue for input (and fail if MQM    *
          *   is quiescing); exclusive or shared use of the queue is     *
          *   controlled by the queue definition here                    *
          *                                                              *
          *   Resulting queue handle is HOBJ                             *
          *                                                              *
          ****************************************************************
          * options are input-as-queue-def and fail-if-quiescing
         C     OOBRW         ADD       OOFIQ         OPTS
          * call ...
         C                   CALLP     MQOPEN(HCONN : MQOD : OPTS : HOBJ :
         C                              OCODE : REASON)
          *
          * report reason, if any; stop if failed
         C     REASON        IFNE      RCNONE
          **  "MQOPEN ended with reason code ...."
         C                   eval      mqdata = 'MQOPEN' + uopentext + reasonc
         C                   write     mqmsgpfr
         C                   ENDIF
          *
         C     OCODE         IFEQ      CCFAIL
          **  "unable to open queue for input"
         c                   eval      mqdata = uopentext
         c                   write     mqmsgpfr
         C                   ENDIF
          *
          ****************************************************************
          *                                                              *
          *   Get messages from message queue                            *
          *                                                              *
          ****************************************************************
          **  initial loop condition based on result of MQOPEN
         C                   MOVE      OCODE         CCODE
          *   buffer length available ...
         C                   Z-ADD     65484         BUFLEN
          **  start of loop to read all the messages . . .
         C     CCODE         DOWNE     CCFAIL
          * option is to wait up to 15 seconds for next message
         C                   Z-ADD     GMWT          GMOPT
          *   wait
         C                   ADD       GMCONV        GMOPT
         C                   ADD       GMBRWF        GMOPT
         C                   Z-ADD     15000         GMWI
          *   up to 15sec
          **  MsgId and CorrelId are selectors that must be cleared
          **  to get messages in sequence, and they are set each MQGET
         C                   MOVEL     MINONE        MDMID
         C                   MOVEL     CINONE        MDCID
          **  clear buffer because MQGET only fills to length of message
         C*                  MOVEL     *BLANKS       BUFFER(BX)
          /Free
             pBuffer = %Alloc(%Size(Buffer:*all));
             MQGET( HCONN  : HOBJ   : MQMD   : MQGMO : %Size(Buffer:*all) :
                   pBUFFER : MSGLEN : CCODE  : REASON) ;
             // After the MQGET function returns BUFFER will contain the Data.
             // Access the data by whatever means suits your application.
              //
          /End-Free
          *  call ...
         C*                  CALLP     MQGET(HCONN : HOBJ : MQMD : MQGMO :
         C*                             BUFLEN : BUFPTR : MSGLEN : CCODE :
         C*                             REASON)
          *
          ** report reason, if any
         C                   SELECT
         C     REASON        WHENEQ    RCNONE
          ** special text for  "no more messages"
         C     REASON        WHENEQ    RC2033
         c                   eval      mqdata = nomesstext
         C                   write     mqmsgpfr
          **  otherwise say "MQGET ended with reason code ...."
         C                   OTHER
         c                   eval      mqdata = 'MQGET' + endtext + reasonc
         C                   write     mqmsgpfr
         C                   ENDSL
          *
          ** . . .display each message received
         C     CCODE         IFNE      CCFAIL
         C                   Exsr      WrtMsg
         C                   ENDIF
          *
          **  end DO-while loop; MQI failure causes loop to end
         C                   ENDDO
          *
          ****************************************************************
          *                                                              *
          *   Close the source queue (if it was opened)                  *
          *                                                              *
          ****************************************************************
          * test if queue had been opened
         C     OCODE         IFNE      CCFAIL
          * ... close queue (with no options) if it is open
         C                   Z-ADD     CONONE        OPTS
         C                   CALLP     MQCLOSE(HCONN : HOBJ : OPTS :
         C                              CCODE : REASON)
          *
          * report reason, if any, resulting from this call
         C     REASON        IFNE      RCNONE
          **  "MQCLOS ended with reason code ...."
         c                   eval      mqdata = 'MQCLOS' + endtext + reasonc
         C                   write     mqmsgpfr
         C                   ENDIF
          *
          * end if (OCODE  not CCFAIL)
         C                   ENDIF
          ****************************************************************
          *                                                              *
          *   Disconnect from the queue manager                          *
          *                                                              *
          ****************************************************************
         C                   CALLP     MQDISC(HCONN : OCODE : REASON)
          *
          * report reason and stop if it failed
         C     OCODE         IFEQ      CCFAIL
          **  "MQDISC ended with reason code ...."
         c                   eval      mqdata = 'MQDISC' + endtext + reasonc
         c                   write     mqmsgpfr
         C                   ENDIF
          *
          ** "Sample AMQ3GET4 end"
         C                   MOVEL     'end  '       mqdata
         C                   write     mqmsgpfr
         C                   SETON                                        LR
          /Free
             //*********************************************************************
             //   Parsh out Message and Determine which File to Write
             //*********************************************************************
    
                  begsr WrtMsg;
    
                  //  Determine if Message is Recon or General Message
                        Msgtext  = %subst(buffer(BX):1:102);
                        If MsgP2 = 'HD';
                           Reconflg = '1';
                        Else;
                           Reconflg = ' ';
                        Endif;
    
                  Dow Msgtext <> ' ' and BX <= 254;
    
                  MsgX  = 01;
    
                  Dow Wrtmsgs <= 641;
                        Msgtext  = %subst(buffer(BX):MsgX:102);
                        MSGTEST  = Msgtext;
    
                        If MSGTEST = ' ' ;
                           Leave;
                        Endif;
    
                           If Reconflg = '1';
                              RECONP5VX = Msgtext;
                              Write RECONOUTR;
                           Else;
                              MQDATA = Msgtext;
                              Write MQMSGPFR;
                           Endif;
    
                           BufCount2 = BufCount2 - 102;
                           Remain1 = BufCount2 - MsgX;
                           Wrtmsgs = Wrtmsgs + 1;
                           MsgX  = MsgX + 102;
    
                  Enddo;
    
                                MsgX  = 01;
                                Wrtmsgs= 0;
                                BX    = BX + 1;
                                BufCount2 = 65484;
    
                  Enddo;
    
                  endSr;
          /End-Free
          ****************************************************************
         O*QSYSPRT   E            SAMPLE         1
         O*                                           20 'Sample AMQ3GET4 '
         O*                       STATUS              25
         O*         E            TEXT           1
         O*                                          10 'message <'
         O*                      BUFFER
         O*                                             '>'
         O*         E            MQCALL         1
         O*                      CNAME               10
         O*                                             ' ended with reason code'
         O*                      RCODE               45
         O*         E            MESSC          1
         O*                                          25 'Unable to connect to'
         O*                                             ' queue manager'
         O*         E            MESS           1
         O*                                          25 'Unable to open queue'
         O*                                             ' for input'
         O*         E            NOMESS         1
         O*                                          25 'no more messages'
          ****************************************************************
          *                                                              *
          * END OF AMQ3GET4                                              *
          *                                                              *
          ****************************************************************

  • #2
    Re: Does anyone Know Why?

    Use this

    if MSGTXT = *blanks
    leave
    endif
    Your future President
    Bryce

    ---------------------------------------------
    http://www.bravobryce.com

    Comment


    • #3
      Re: Does anyone Know Why?

      Yes you are only comparing msgtxt to one (1) blank. And as bryce says compare it to all *blanks or *blank same diff.
      Bill
      "A good friend will bail you out of jail,
      A true friend would be sitting beside you saying,
      'Wow, that was fun.'"

      Comment


      • #4
        Re: Does anyone Know Why?

        LEAVE (Leave a Do/For Group)


        The LEAVE operation transfers control from within a DO or FOR group to the
        statement following the ENDDO or ENDFOR operation.
        You can use LEAVE within a DO, DOU, DOUxx, DOW, DOWxx, or FOR loop to
        transfer control immediately from the innermost loop to the statement following
        the innermost loop?s ENDDO or ENDFOR operation. Using LEAVE to leave a DO
        or FOR group does not increment the index.
        In nested loops, LEAVE causes control to transfer ?outwards? by one level only.
        LEAVE is not allowed outside a DO or FOR group.
        Your friends list is empty!

        Comment


        • #5
          Re: Does anyone Know Why?

          The leave will jump out of its parent loop when used in an IF statement. I do it all the time

          It just has to be inside of a Loop Block. Doesn't matter what other blocks its inside of.
          Your future President
          Bryce

          ---------------------------------------------
          http://www.bravobryce.com

          Comment


          • #6
            Re: Does anyone Know Why?

            I tried *blanks before I posted the question. Still didn't work.


            DAC

            Comment


            • #7
              Re: Does anyone Know Why?

              What release are you on? I'm on V5R4 and found that reference in that manual. I just went to test and it wouldn't even compile.


              Msg id Sv Number Message text
              *RNF5232 30 1 LEAVE and ITER operations are only allowed in DO, DOWxx, or
              DOUxx loops; specification is ignored.
              Your friends list is empty!

              Comment


              • #8
                Re: Does anyone Know Why?

                It is MQ technology so you need to link the qmqm libraries.

                DAC

                Comment


                • #9
                  Re: Does anyone Know Why?

                  Hi,

                  you are using two do loop. Leave comman exits in the inner do loop so once leave command excute control will move to mgx =01 place.
                  Outer loop excute.


                  Thanks
                  Babu

                  Comment


                  • #10
                    Re: Does anyone Know Why?

                    Code:
                      *                                                                         
                      * Was F3 or F12 pressed                                                   
                     C                   IF        EXIT OR RETURN                               
                     C                   MOVE      'Y'           XIT                            
                     C                   OUT       LDA                                          
                     C                   LEAVE                                                  
                     C                   ENDIF                                                  
                     C
                    This IF statement is in a while loop that is dependent on a key press. The LEAVE jumps out of the loop, even though its inside of the IF conditional. You just have to make sure that your IF block starts and stops inside a loop block.

                    Your future President
                    Bryce

                    ---------------------------------------------
                    http://www.bravobryce.com

                    Comment


                    • #11
                      Re: Does anyone Know Why?

                      DAC,
                      How do you know that the variable MSGTEST is blank ?
                      Debug your program and display the MSGTEST value in hex w/ EVAL MSGTEST:X on the involved line. Does it show X'40' (blank character) ?
                      Last edited by Mercury; November 16, 2007, 08:01 AM.
                      Philippe

                      Comment


                      • #12
                        Re: Does anyone Know Why?

                        Mercury,
                        Are you seeing that the If Reconflg = '1'; statement executes when MSGTEST is blank ? If should, as noted, execute the MsgX = 01 line.

                        The LEAVE jumps out one "DO" level only. "IF" expressions are not a loop. So the LEAVE jumps to the next "EndDO" only.

                        Comment


                        • #13
                          Re: Does anyone Know Why?

                          Just realized my compile error was because I didn't wrap my test with a Do or For loop.

                          Anyway, just to clarify ... Leave takes you out of the Do loop and Iter takes you to the next EndDo.
                          Your friends list is empty!

                          Comment


                          • #14
                            Re: Does anyone Know Why?

                            EVAL msgtext2:x
                            00000 00000000 00000000 00000000 00000000 - ................
                            00010 00000000 00000000 00000000 00000000 - ................
                            00020 00000000 00000000 00000000 00000000 - ................
                            00030 00000000 00000000 00000000 00000000 - ................
                            00040 00000000 00000000 00000000 00000000 - ................
                            00050 00000000 00000000 00000000 00000000 - ................
                            00060 00000000 0000.... ........ ........ - ................

                            When I try what murcury said. I get the above. Is this telling me the field msgtext2 isn't blank but filled with periods? If so, how do I check for periods?

                            DAC

                            Comment


                            • #15
                              Re: Does anyone Know Why?

                              You can test for periods like any other char. But if that display is hex, those aren't periods, they are hex zeros (an non-displayable character). Try testing for X'00' and see if that is what you have.

                              Comment

                              Working...
                              X