ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Resequencing notes

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

  • Resequencing notes

    Here's one for ya all,

    I'm in a JD Edwards shop (only RPG III allowed) and I have an application that has an option to add notes to individual entries. This worked fine with users entering note after note until someone asked if there was a way to insert or delete a line.

    Well, this sparked my imagination, of course my mouth said "sure" before my brain could think, so now I'm faced with this challenge. I've been toying with it and have come across some issues I can't seem to get around.

    If they request insertion, (I have a sequence number field that is 7,1 and I added an option field so they could enter 1=insert, 2=edit and 4=delete) no problem I add .5 to the sequence number of the line just above (where they entered the 1), write the record to the sfl and display the screen positioning the the cursor to the new inserted record then, write the record to the file after they enter whatever. Then, the programn listed below is called to resequence the entries and then the sfl is reloaded. It's all worked pretty well until...

    Here's the issue; if there are 99 lines and the new line causes line 100, everything goes wacky after that. So I added code to adjust the count....
    Code:
    FTDNPF   UF  E           K        DISK                 
     *                                                     
    C           *ENTRY    PLIST                            
    C                     PARM           USER   10         
    C                     PARM           ITM#    40        
     *                                                     
    C           KEY       KLIST                            
    C                     KFLD           USER              
    C                     KFLD           ITM#              
     *                                                     
    C           KEY1      KLIST                            
    C                     KFLD           USER              
    C                     KFLD           ITM#              
    C                     KFLD           $$KEY             
     *                                                     
    C                     Z-ADD0         COUNT   60        
    C                     Z-ADD0         @ITER   60        
     * Set low key.                                        
    C                     Z-ADD.1        $$KEY   71        
     * Position file.                                      
    C           KEY1      SETLLTDNPF                       
     * Count records.                                      
    C           *IN99     DOUEQ*ON                         
    C           KEY       READETDNPF               N    99 
    C           *IN99     IFEQ *OFF                        
    C                     ADD  1         COUNT             
    C                     ENDIF                            
    C                     ENDDO                            
     * Multiply count to bypass lower numbers.             
    C                     SELEC                            
    C           COUNT     WHLE 100                         
    C           COUNT     MULT 10        @ITER             
    C           COUNT     WHLE 1000                        
    C           COUNT     MULT 100       @ITER             
    C                     ENDSL                            
     * Set high key.                                       
    C                     Z-ADD9999999   $$KEY             
     * Resequence from end of file to eliminate lower numbers
    C           KEY1      SETGTTDNPF                       
    C           *IN99     DOUEQ*ON                         
    C           KEY       REDPETDNPF                    99 
    C           *IN99     IFEQ *OFF                        
    C                     Z-ADD@ITER     TNSEQ#            
    C                     UPDATTNPFR                       
    C                     SELEC                            
    C           COUNT     WHLE 100                         
    C                     SUB  10        @ITER             
    C           COUNT     WHLE 1000                       
    C                     SUB  100       @ITER            
    C                     ENDSL                           
    C           @ITER     IFEQ 0                          
    C                     LEAVE                           
    C                     ENDIF                           
    C                     ENDIF                           
    C                     ENDDO                           
     * Set high key.                                      
    C                     Z-ADD9999999   $$KEY            
     * Resequence from end of file.                       
    C           KEY1      SETGTTDNPF                      
    C           *IN99     DOUEQ*ON                        
    C           KEY       REDPETDNPF                    99
    C           *IN99     IFEQ *OFF                       
    C                     Z-ADDCOUNT     TNSEQ#           
    C                     UPDATTNPFR                      
    C                     SUB  1         COUNT            
    C           COUNT     IFEQ 0                          
    C                     LEAVE                           
    C                     ENDIF                           
    C                     ENDIF                           
    C                     ENDDO                     
     *                                                 
    C                     SETON                     LR
    What I mean by "wacky" is this;
    If there are 101 lines, the line count is ...98, 99, 100, 100, 101
    If I continue to add lines, ...98, 99, 100, 100, 101, 102, 103... AND the lines gets mixed up, out of order.

    Any ideas or suggestions?
    Everyday's a school day, what grade are you in?

  • #2
    Re: Resequencing notes

    I havent read thru the entire program, but I think I understand where your problem will lie with resequencing. Because you are updating inserted lines in ascedning order, an inserted line will get assigned a line number that already exists for another comment.

    One idea is to read thru the list BACKWARDS, assigning the highest value to each note in reverse order, then read it forwards, assigning the lowest.

    In other words, SETGT on the notes, READPE on your key, and start the sequencing at 999999 and subtract 1 for each note. That will ensure that each note would have it's own unique sequence number. Then run your code the way it currently is behind this, and each note will be sequence from 1 to whatever, without the possibility of a sequence being duplicated.
    Last edited by MichaelCatalani; April 9, 2010, 09:13 AM.
    Michael Catalani
    IS Director, eCommerce & Web Development
    Acceptance Insurance Corporation
    www.AcceptanceInsurance.com
    www.ProvatoSys.com

    Comment


    • #3
      Re: Resequencing notes

      I'm already doing that but I thought there was a problem with the 'lower' numbers so I added code to eliminate that posibility but it's still happening.
      Everyday's a school day, what grade are you in?

      Comment


      • #4
        Re: Resequencing notes

        I see in your code now where you are doing something similar to this, but the checks and multiplications arent needed, and is probably screwing with the @iter value which eventually gets put into the note sequence.

        It's really a two-step process. 1) read the notes backwards and give each a descending sequence in whole numbers. 1) Read the notes forward and resequence each of them them starting with 1.

        If you do anything but this, then there is the possibility of a note getting assigned a sequence that will cause it to be re-read in the do loop, which will cause it to get assigned yet another sequence, which will likely put it out of sequence from where it belongs.
        Michael Catalani
        IS Director, eCommerce & Web Development
        Acceptance Insurance Corporation
        www.AcceptanceInsurance.com
        www.ProvatoSys.com

        Comment


        • #5
          Re: Resequencing notes

          BINGO, you hit the nail on the head.
          I'm over-complicating it.
          Now it all makes sense.
          Thank you.
          Everyday's a school day, what grade are you in?

          Comment


          • #6
            Re: Resequencing notes

            I stripped out the unneccessary code, started at the end of the file with 999999, then from the begining with 1 and it all works perfectly...

            YAHOO, today is turning out to be a great day!
            (Just found out we're getting a bonus.)
            Everyday's a school day, what grade are you in?

            Comment

            Working...
            X