Home > Ask the AS/400 Experts > iSeries Application Development Questions & Answers > Comparing new records to existing records
Ask The iSeries 400 Expert: Questions & Answers
EMAIL THIS

Comparing new records to existing records

John Blenkinsop EXPERT RESPONSE FROM: John Blenkinsop

Pose a Question
Other iSeries 400 Categories
Meet all iSeries 400 Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 17 March 2005
I'm creating a new record and want to compare it with an existing record on file. If they are identical I drop the new one, otherwise I write the new one to the file. The file can have a duplicate key. Can it be done without comparing every field?

>
You can name a complete record from a database file by declaring an externally-defined data structure. Create two for the same file and use the PREFIX keyword on one of them:

 
D Rec1          E DS                  ExtName(WMETPCPF)                 
                                                                        
D Rec2          E DS                  ExtName(WMETPCPF) Prefix(D1:2) 

Now the fields in the file WMETPCPF are contained by name in structure REC1, and by a slightly different name in REC2. So you can refer to field TPVDRN (which is the field in REC1) or to field D1VDRN in structure REC2.

I use this to load screens from files. When you read a record from the file, its data will fill the fields in REC1. If you then do:

 C                   Eval      Rec2 = Rec1  

...both structures now contain the same data. The fields on the screen match the fields from the file.

This means that you can do your new record duplication detection in one compare operation. First, the fields containing your new data are in one structure, and the fields from the database record are in another. So, just compare REC1 with REC2 and you have compared ALL the fields.

BUT, you might not want to compare ALL the fields! Some fields, like timestamps, are not relevant. So, set those to a known value before comparing the structures:

 
C                   Eval      TPDATE = D1DATE 
C                   Eval      TPTIME = D1TIME 
C                   Eval      TPUSER = D1USER 

C                   If        Rec1 <> Rec2 
C                   Eval      Rec1  = Rec2 
C                   Write (E) TP 
C                   EndIf 

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Visit the ITKnowledge Exchange and get answers to your developing questions fast.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
iSeries Application Development
Monitoring escape messages and using RCVMSG for diagnostic messages
Listing contents of multiple FTP directories on AS/400
Chain operation error after converting RPG3 to ILE RPG (RPGIV)
Space offset X'0015FF00' or X'0000000000000000' is outside current limit for object QIGC2424C
Searching fields for values
iSeries application display subfiles with other program windows
Searching part of a name or address in AS/400
Passing parameters in an ILE RPG module
What's happening to my subfile?
What happening to my subfile?

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



iSeries Networking - Printing, Remote Access, TCP/IP
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts