ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Compare two PF

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

  • Compare two PF

    I have two files that I am writing two. Both files have the same field definitions as one is a live file and one is a history file. So the history file will be built up and the live file cleared each day.

    When I write to the live file I first need to check if the record exists in the history file, if it does, I need to check if anything has changed by checking each field against the incoming data.

    So, is there an easy way to compare lets say two record formats rather than checking field by field.

    Hope this is not a silly question. Been away from RPG for a bit.

    Thanks

  • #2
    Re: Compare two PF

    Just a theory, and I'm honestly not sure it will work, but have you tried creating a flat data structure for the records and then comparing the entire data structures to each other? Not at my system at the moment, so can't give this a whirl.

    Comment


    • #3
      Re: Compare two PF

      Create a Data Structure with the EXTNAME of the files being read. Read a record into each and then compare the DS values.

      PHP Code:
      LiveFileDS    DS       ExtName(LiveFile)
      HistFileDS    DS       ExtName(HistFile)

      Read LiveFile;
      Read HistFile;

      If 
      LiveFileDS <> HistFileDS;
         Do 
      something when it doesn't match;
      EndIF; 
      Not tested.. but, it should be some sort of pseudo code to start by...

      Comment


      • #4
        Re: Compare two PF

        Thanks guys for you help. Just what I needed.

        Just forgot about that one.....

        Comment


        • #5
          Re: Compare two PF

          nice Rick! That almost exactly what I would have written....only I would have used about 40 more lines of code...
          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


          • #6
            Re: Compare two PF

            Ah, I have a slight problem. I explain.

            The history file is written to so that history is built up. The live file fields are filled within the program and prior to writing to the live file I make the compare of the data structures.

            I figured that if I build the fields then the data structure for the live file will be ok to test against a record in the history file as I chain into this file.

            So LIVEds fields pre filled with data. HIST is chained which pulls in the record format When compare HIST with LIVE it always returns a changed record even though nothing has changed. but if I chain into the live file then it works.

            It almost like the LIVE record format has to be properley initialised first. So this is a problem......

            Not sure what I can do

            Comment


            • #7
              Re: Compare two PF

              Originally posted by RPGguy View Post
              Ah, I have a slight problem. I explain.

              The history file is written to so that history is built up. The live file fields are filled within the program and prior to writing to the live file I make the compare of the data structures.

              I figured that if I build the fields then the data structure for the live file will be ok to test against a record in the history file as I chain into this file.

              So LIVEds fields pre filled with data. HIST is chained which pulls in the record format When compare HIST with LIVE it always returns a changed record even though nothing has changed. but if I chain into the live file then it works.

              It almost like the LIVE record format has to be properley initialised first. So this is a problem......

              Not sure what I can do
              post your code maybe there's a little surprise in there you aren't seeing...
              I'm not anti-social, I just don't like people -Tommy Holden

              Comment


              • #8
                Re: Compare two PF

                either there's a slight surprise, or there's possibly an extra field in the history file that you're not taking into account (possibly a sequence number or something along those lines?). If so, you can manually build the data structures instead of using ExtName so that they both match up.

                Better yet, if the field names are the same in the history file as they are in the Live file (even if there are extra fields in History), use ExtName(LiveFile) for BOTH data structures and then eval-corr to move only those history fields that exist in the live file to your "history" data structure.

                Comment


                • #9
                  Re: Compare two PF

                  Originally posted by RPGnoobie View Post
                  Better yet, if the field names are the same in the history file as they are in the Live file (even if there are extra fields in History), use ExtName(LiveFile) for BOTH data structures and then eval-corr to move only those history fields that exist in the live file to your "history" data structure.

                  if filed name are same in both file and you are using EXTNAME will give you compile time error..

                  So field name should be diffrent if same then you can use PREFIX keyworld at file level.

                  I would like to see his code to see what happening ..


                  Pramendra Pandeya
                  Young people knows how to run fast but old people knows the way..

                  Comment


                  • #10
                    Re: Compare two PF

                    Originally posted by RPGnoobie View Post
                    either there's a slight surprise, or there's possibly an extra field in the history file that you're not taking into account (possibly a sequence number or something along those lines?). If so, you can manually build the data structures instead of using ExtName so that they both match up.

                    Better yet, if the field names are the same in the history file as they are in the Live file (even if there are extra fields in History), use ExtName(LiveFile) for BOTH data structures and then eval-corr to move only those history fields that exist in the live file to your "history" data structure.

                    Your second idea of creating two data structures from the LIVEFILE, and then performing the eval-corr from the HISTFILE data structure into the second LIVEFILE data structure would solve the problems with additional fields in the history file rather nicely. If there are extra fields in the history file, this method would ensure that the common fields between the files are the ones being compared.

                    If the field names are the same between the files, simply qualify the data structures. That way, the eval-corr can easily be used to transfer and compare the two structures.
                    Michael Catalani
                    IS Director, eCommerce & Web Development
                    Acceptance Insurance Corporation
                    www.AcceptanceInsurance.com
                    www.ProvatoSys.com

                    Comment

                    Working...
                    X