ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Free Code

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

  • Free Code

    I have two files DAILYF and MASTERF
    Both are Non-keyed PF.

    I want to compare Family# of MASTERF with Family# of DAILYF , if there is a match
    I want to replcae the values in column1, column2 of MASTERF with column1, column2 of DAILYF respectively.
    Please suggest me code in Free RPG, is it necessary to define a LF with Family# as key over MASTERF?

    Donna.

  • #2
    Re: Free Code

    its not required that you create a logical -- but -- if you dont you will re-read file two for every record in file one. so which way do you want to see it?

    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


    • #3
      Re: Free Code

      Originally posted by jamief View Post
      its not required that you create a logical -- but -- if you dont you will re-read file two for every record in file one. so which way do you want to see it?

      jamie


      Obviously reading two times might take longer time and no efficient right?
      what do you think

      Donna

      Comment


      • #4
        Re: Free Code

        I would agree and it wouldnt be 2 times it would be read all records in file two for every one record you read in file one.......you could use datastructures to get around the multiple reads...but a key would be the best way to code this.
        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


        • #5
          Re: Free Code

          Originally posted by jamief View Post
          I would agree and it wouldnt be 2 times it would be read all records in file two for every one record you read in file one.......you could use datastructures to get around the multiple reads...but a key would be the best way to code this.
          Any sample code available using DS as suggested?

          Donna

          Comment


          • #6
            Re: Free Code

            i wrote without DS cause its the better way to go = this requires a logical to be
            created.

            PHP Code:
                 H dftactgrp(*no)
                 
            H actgrp(*caller)
                  *
                  *  
            I want to compare Family# of MASTERF with Family# of DAILYF , if there is 
                      
            match
                  *  
            I want to replcae the values in column1column2 of MASTERF with column1
                      
            column2 of DAILYF
                  
            *  respectively.
                  *  
            Please suggest me code in Free RPGis it necessary to define a LF with Family
                      
            as key over
                  
            *  MASTERF?
                  *
                 
            FMASTERF   UF   E             DISK
                 FDAILYF    
            IF   E           K DISK

                 D what            s              1    inz
            ('R')

                  *=============================================================
                  *  
            M A I N     L I N E
                  
            *=============================================================

            12345 /free

                      
            // read the masterf file

                       
            setll *start ARACUSTD;
                       
            read  ARACUSTD;
                        
            dow not%eof(ARACUSTD);
                         
            chain (Family#) DAILYF;
                          
            if %found(DAILYF);

                            
            // i prefixed the column1 and 2 with the file name because i dont know
                            // the real names.... I made up format ARACUSTD on update

                            
            arcustd.column1 dailyf.column1;
                            
            arcustd.column2 dailyf.column2;
                            
            update ARACUSTDR  %fields(arcustd.column1:arcustd.column2)
                          endif;
                         
            read  ARACUSTD;
                        
            enddo;

                       *
            inlr = *on;
                  /
            end-free 
            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: Free Code

              Jamie wrote . . . .

              PHP Code:
              setll *start ARACUSTD;
              read  ARACUSTD;
              dow not%eof(ARACUSTD);
                   
              chain (Family#) DAILYF;
                   
              if %found(DAILYF);
                      
              arcustd.column1 dailyf.column1;
                      
              arcustd.column2 dailyf.column2;
                      
              update ARACUSTDR  %fields(arcustd.column1:arcustd.column2)
                   endif;
                   
              read  ARACUSTD;
              enddo
              I am no expert on RPG/Free and may be missing something here . . . . .

              but this seems to be reading every record in MASTERF (ARACUSTD), and checking to see if there are updates in DAILYF. If I am guessing correctly the number of records in DAILYF will only be a small subset of MASTERF. So would it be better to reverse this, and read every record in DAILYF and then chain to a logical created on MASTERF and then update it. This would eliminate a number of reads etc.

              Depends on the sizes of the 2 files on a daily basis.

              GC
              Greg Craill: "Life's hard - Get a helmet !!"

              Comment


              • #8
                Re: Free Code

                It would depend on what the detail file is and if there can be multiple records in the detail for the master file.
                Based on the information given we can't tell.

                Comment


                • #9
                  Re: Free Code

                  Personally I would do it the other way around. I would:
                  1. read the daily file
                  2. chain to the master file
                  3. update the master record
                  4. read the next daily record


                  This way, you are updating only the master files that need updating, this will make the program run quicker.
                  Never trust a dog to watch your food.

                  Comment

                  Working...
                  X