ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Procedures, update file and dowhile loop

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

  • Procedures, update file and dowhile loop

    Hello
    The problem is: i have one file, which i write once and then i do updates to it several times.
    In detail:
    - I have one procedure to write the file, that is called only once.
    - I have one procedure to update the file written. This procedure is called only in one place in the whole code, but this call is placed into a dowhile, because i need to update the file several times.

    So, i call the procedure to write the file. Then i call the procedure to update it (by first time), and updates successfully. When i call the update procedure again, the "dow not %eof" that is placed inside the procedure, to update all records on file, seems like it never reachs the "%eof" condition, because it keeps in a loop! Once it reads the last record it begins again with the first and so on.

    I have tried closing and opening the file before the update, nothing changed.

    I can't update by SQL because not all fields of all records must have the same data.

    My concern is why the file is updated on the procedure first call and in the second the procedure stays in a loop?

    I have not the real code here, but something like this:

    main procedure:
    PHP Code:
    WriteFile();
    dow some_condition;
        
    DoSomeCalculations();
        
    UpdateFile();
        
    CopyUpdatedRecordsToAnotherFile();
    enddo
    Update procedure:
    PHP Code:
    setll *loval file;
    read file;
    dow not %eof;
        
    field1 number1 tax1;
        
    field2 number2 tax2;
        
    update file;
        
    read file;
    enddo
    When i call the update procedure for the second time, it keeps looping in the "dow", but not when the first time!

    Any suggestion please?

  • #2
    Re: Procedures, update file and dowhile loop

    Is it a keyed file ? Pls paste here the relative F-spec.
    Philippe

    Comment


    • #3
      Re: Procedures, update file and dowhile loop

      Yes it is a keyed file with DDS, the most common (ILE RPG):

      PHP Code:
      Fsfl001pf  uf a e           k disk 

      Comment


      • #4
        Re: Procedures, update file and dowhile loop

        If access is by key, search-arg can be a a single key in the form of a field name, a named constant, a figurative constant, or a literal or a composite key in the form of a KLIST name, a list of values, or %KDS. The Relative Record Number used in your template above does not apply to such a file, I'm not sure of that though but I know that *LOVAL/*HIVAL can have weird behaviour in some circumstances. Therefore it is much better and preferable to use the special values *START and *END for search-arg. *START positions to the beginning of the file and *END positions to the end of the file. And this is what I'd use instead.
        Philippe

        Comment


        • #5
          Re: Procedures, update file and dowhile loop

          I now. But that is not the issue i have.
          Because doing a debug, i correctly see that the SETLL positions effectively on the first record, the READ reads ok, and the UPDATE, updates ok.
          The issue is why when the READ reachs the end of file, it does not sets on the %EOF.
          Why this happens in the second procedure call, and not in the first call.
          - First time procedure call, it does the loop till EOF and leaves the dowhile.
          - Second time procedure call, it does the loop and keeps doing the loop even though it reaches the last record and again starts with the first, and so on.

          Comment


          • #6
            Re: Procedures, update file and dowhile loop

            make the file usropn...

            open at the top and close at LR....


            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


            • #7
              Re: Procedures, update file and dowhile loop

              I have tried this:
              PHP Code:
              close file;
              open file;
              setll *loval file
              read file
              dow not %eof
                  
              field1 number1 tax1
                  
              field2 number2 tax2
                  
              update file
                  
              read file
              enddo
              and nothing changed.
              (note that i closed first, as the file comes open at this point).

              Comment


              • #8
                Re: Procedures, update file and dowhile loop

                is the key a descending key?
                please post the dds source.
                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


                • #9
                  Re: Procedures, update file and dowhile loop

                  is the key a descending key?
                  NO.

                  ok jamie, tomorrow i will post the dds and some code (now i am at home, no access to as400)

                  Comment


                  • #10
                    Re: Procedures, update file and dowhile loop

                    the f spec on the file you posted does NOT have usropn on it....
                    have you changed it?
                    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


                    • #11
                      Re: Procedures, update file and dowhile loop

                      no jamie, the problem is that i do not have the real code here to post, so i posted a similar F-spec, i forgot the usropn, but the real one has it, even though it would not compile.
                      tomorrow will post all relevant code as it is.
                      thanks for keep answering!

                      Comment


                      • #12
                        Re: Procedures, update file and dowhile loop

                        Are you not perhaps changing (and thereby updating) a key field? This could cause a loop.
                        Regards

                        Kit
                        http://www.ecofitonline.com
                        DeskfIT - ChangefIT - XrefIT
                        ___________________________________
                        There are only 3 kinds of people -
                        Those that can count and those that can't.

                        Comment


                        • #13
                          Re: Procedures, update file and dowhile loop

                          I'd insert
                          PHP Code:
                          FEOD MyFile
                          immediately after the WRITE statement in the WriteFile() procedure.

                          It's a bit at random but worth giving a try.
                          Philippe

                          Comment


                          • #14
                            Re: Procedures, update file and dowhile loop

                            Originally posted by kitvb1 View Post
                            Are you not perhaps changing (and thereby updating) a key field? This could cause a loop.
                            Yes, i am changing the key.
                            The file key is composed by 6 fields, i am updating the 3rd and 5th field. But i don't think that has something to see, because as i told, in the first procedure call i update those two fields and the dowhile finishes ok at EOF, and then in the second call must do the same, if it is the same procedure, i update the same two fields, but this time the dowhile never ends.

                            Comment


                            • #15
                              Re: Procedures, update file and dowhile loop

                              Here i post the code (relevant code):

                              PHP Code:
                              FPOLEL70A  if   e           k disk 
                              FPROLEF12  
                              if   e           k disk 
                              FDETALLE25 uf a e           k disk    rename
                              (prolf25r:det25rusropn 
                              *
                              D CreateData25    pr
                              D Update25        pr
                              D CopyFile        pr  
                              D ClearFile       pr 
                              *
                               
                              // main procedure
                              /free
                              open detalle25
                              ;
                              setll *loval polel70a
                              read polel70a;         
                              dow not %eof;          
                               
                              CreateData25();
                               
                              key12.p12cdp p62cdp;            
                               
                              setll %kds(key12:1prolef12;     
                               
                              reade %kds(key12:1prolef12;     // for each record in PROLEF12,  i run the update on DETALLE25 file
                               
                              dow not %eof;                     
                                   
                              Update25();                   
                                   
                              CopyFile();                                // executes a CPYF command
                                   
                              reade %kds(key12:1prolef12
                               
                              enddo;         
                               
                              close detalle25;    
                               
                              ClearFile();                                // executes a CLRPFM command
                               
                              open detalle25;     
                               
                              read polel70a;  
                              enddo;                                  
                              /
                              end-free

                                 
                              // CreateData25 Procedure: writes DETALLE25 file with some records
                              P CreateData25    b          
                              D CreateData25    pi         
                               
                              /free                       
                                p25cdp 
                              p62cdp;
                                
                              p25pla p62pla;
                                
                              p25ram p62ram;
                                
                              p25pol p62pol;
                                
                              p25end p62end;
                                
                              p25cop p62cop;
                                
                              write det25r
                              /
                              end-free
                              P CreateData25    e          

                                 
                              // Update25 Procedure: Updates DETALLE25 file
                              P Update25        b      
                              D Update25        pi     
                               
                              /free                   
                                 setll 
                              *loval detalle25
                                 
                              read detalle25;         
                                 
                              dow not %eof;           
                                    
                              p25pla new_p62pla;
                                    
                              p25pol new_p62pol;
                                    
                              p25end new_p62end;
                                     
                              update det25r;  
                                     
                              read detalle25
                                 
                              enddo;              
                              /
                              end-free
                              P Update25        e 
                              file DETALLE25 dds:
                              PHP Code:
                              A                                      UNIQUE                    
                              A          R PROLF25R                                            
                              A
                              Informacion General de la poliza                              
                              A            P25CDP         3S 0       TEXT
                              ('Producto')          
                              A                                      COLHDG('Producto')        
                              A            P25PLA         6A         TEXT('Plan')              
                              A                                      COLHDG('Plan')            
                              A            P25RAM         2S 0       TEXT('Ramo')              
                              A                                      COLHDG('Ramo')            
                              A            P25POL         7S 0       TEXT('Poliza')            
                              A                                      COLHDG('Poliza')          
                              A            P25END         5S 0       TEXT('Endoso')            
                              A                                      COLHDG('Endoso')          
                              A            P25CER         8S 0       TEXT('Certificado')       
                              A                                      COLHDG('Certificado')     
                              A            P25COP         2S 0       TEXT('Codigo transaccion')
                              A                                      COLHDG('Codigo Transaccion')
                              A            P25PLR         7S 0       TEXT('Poliza Referencia')  
                              A                                      COLHDG('Poliza Referencia')
                              A            P25EDR         5S 0       TEXT('Endoso Referencia')  
                              A                                      COLHDG('Endoso Referencia')
                              A            P25EDE         5S 0       TEXT('Endoso Emision')     
                              A                                      COLHDG('Endoso Emision')   
                              A            P25NCT        20A         TEXT('Nro Solicitud')      
                              A                                      COLHDG('Nro Solicitud')    
                              A          K P25CDP
                              A          K P25RAM
                              A          K P25POL
                              A          K P25END
                              A          K P25CER
                              A          K P25COP 
                              i think with those data may be enough.
                              Could happen something strange when i do the CPYF command after each update? in this case after the first update i do the CPYF, could this affect something to the second update?

                              Comment

                              Working...
                              X