ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

SETGT and CHAIN

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

  • SETGT and CHAIN

    I have a program where I do a keyed SETGT and then a READP to get the last sequence number in an item's notes. Then I do a key listed CHAIN to see if a certain entry already exists. If it does exist I need to do an update. If it doesn't exist I add 1 to the sequence number and write a new record.

    Here's the problem. After I do the CHAIN it sees that a record is already there. But when I update the record the file pointer doesn't set itself to where I just chained. It stays where the SETGT put it. How do I reset the file pointer???
    Your future President
    Bryce

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

  • #2
    Re: SETGT and CHAIN

    It should, if you are using the same file name. Can you post a snippet of the code ?

    Comment


    • #3
      Re: SETGT and CHAIN

      PHP Code:
            *NOTES ENTRY
           C
           C     MPNKEY        CHAIN     MPNL01
           C                   
      IF        NOT %FOUND(MPNL01)
           
      C
           C                   MOVEL     NRMPNDESC1    PNDES
           C                   MOVE      1             PNSEQ
           C                   MOVE      ITMNUM        PNPROD
           C                   MOVE      
      'I'           PNTYPE
           C                   WRITE     IPM100PN
           C
           C                   MOVEL     NRMPNDESC2    PNDES
           C                   MOVE      2             PNSEQ
           C                   MOVE      
      'I'           PNTYPE
           C                   MOVE      ITMNUM        PNPROD
           C                   WRITE     IPM100PN
           C
           C                   MOVEL     NRMPNDESC3    PNDES
           C                   MOVE      3             PNSEQ
           C                   MOVE      
      'I'           PNTYPE
           C                   MOVE      ITMNUM        PNPROD
           C                   WRITE     IPM100PN
           C
           C                   
      ELSE
           
      C
           C     MPNKEY        SETGT     MPNL01
           C                   READP     MPNL01
           C                   MOVE      PNSEQ         SEQ
           C
           C                   MOVE      
      *BLANKS       NOTES
           C                   MOVEL     NRMPNDESC1    NOTES
           C
           C     MPNKEY2       SETLL     MPNX02
           C     MPNKEY2       READE     MPNX02
           C                   
      IF        NOT %EOF(MPNX02)
           
      C*    MPNKEY2       CHAIN     MPNX02
           C
      *                  IF        %FOUND(MPNX02)
           
      C                   EXSR      SETVALUES
           C                   MOVE      NOTES         PNDES
           C                   UPDATE    IPM100PN
           C                   
      ELSE
           
      C                   EVAL      SEQ SEQ 1
           C                   MOVE      SEQ           PNSEQ
           C                   MOVE      NOTES         PNDES
           C                   MOVE      
      'I'           PNTYPE
           C                   WRITE     IPM100PN
           C                   
      ENDIF
           
      C
           C                   MOVE      
      *BLANKS       NOTES
           C                   MOVEL     NRMPNDESC2    NOTES
           C
           C     MPNKEY2       SETLL     MPNX02
           C     MPNKEY2       READE     MPNX02
           C                   
      IF        NOT %EOF(MPNX02)
           
      C*    MPNKEY2       CHAIN     MPNX02
           C
      *                  IF        %FOUND(MPNX02)
           
      C                   EXSR      SETVALUES
           C                   MOVE      NOTES         PNDES
           C                   UPDATE    IPM100PN
           C                   
      ELSE
           
      C                   EVAL      SEQ SEQ 1
           C                   MOVE      SEQ           PNSEQ
           C                   MOVE      NOTES         PNDES
           C                   MOVE      
      'I'           PNTYPE
           C                   WRITE     IPM100PN
           C                   
      ENDIF
           
      C
           C                   MOVE      
      *BLANKS       NOTES
           C                   MOVEL     NRMPNDESC3    NOTES
           C
           C     MPNKEY2       SETLL     MPNX02
           C     MPNKEY2       READE     MPNX02
           C                   
      IF        NOT %EOF(MPNX02)
           
      C*    MPNKEY2       CHAIN     MPNX02
           C
      *                  IF        %FOUND(MPNX02)
           
      C                   EXSR      SETVALUES
           C                   MOVE      NOTES         PNDES
           C                   UPDATE    IPM100PN
           C                   
      ELSE
           
      C                   EVAL      SEQ SEQ 1
           C                   MOVE      SEQ           PNSEQ
           C                   MOVE      NOTES         PNDES
           C                   MOVE      
      'I'           PNTYPE
           C                   WRITE     IPM100PN
           C                   
      ENDIF
           
      C
           C                   
      ENDIF 
      Here is the section. I have the original way commented out. I get the same error either way.
      Your future President
      Bryce

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

      Comment


      • #4
        Re: SETGT and CHAIN

        You are updating and writing to format IPM100PN. Which file is this MPNL01 or MPXL02 ?

        Comment


        • #5
          Re: SETGT and CHAIN

          the file is MPN. I have a logica MPNL01 and an index MPNX02. I did a RENAME in my F SPECS. Do I need to use the other name if I'm using MPNX02?

          PHP Code:
               FMPNL01    UF A E           K DISK
               FMPNX02    UF A E           K DISK    RENAME
          (IPM100PN:IPM100PN2
          Your future President
          Bryce

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

          Comment


          • #6
            Re: SETGT and CHAIN

            The pgm should see them as 2 different files. To update based on read of MPNX02 you need to reference IPM100PN2. I'll bet it has to do with this. The update of MPNL01 format IPM100PN will be based on the last chain/read/set for file MPNL01 only.

            Comment


            • #7
              Re: SETGT and CHAIN

              Ok. Well I changed it to do just that. But now, when it gets to the third chain it take s a crap. I can't figure out why its crapping out. It goes through the first two just fine, but when it does the chain the third time it blows up on me telling me that I encountered an error. Very non specific. But the session freezes for like a minute. Oops...I think I know....that record has a lock on it I think. brb...
              Your future President
              Bryce

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

              Comment


              • #8
                Re: SETGT and CHAIN

                Yep, I was stepping on my own toes. When I did the READP I needed it to be a READP (N). That way I can still know what the last sequence number is and not lock that record. That is why the program was sitting still for a minute...it had to wait to time out on the record lock.
                Your future President
                Bryce

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

                Comment


                • #9
                  Re: SETGT and CHAIN

                  Easy to get in trouble that way. If possible, its usually better to try to set it up so that only one of the "files" gets updated. Read from both, as needed, but do all the updates on one of them.

                  Comment

                  Working...
                  X