|
Hi Juris We have the same requirement for a number of files. We start by getting the next sequential number/value from a data area, then dip into code like yours to make sure it's unique. When a gap is found, the key is used for the WRITE, incremented (add one, or A --> B, etc) then the data area is updated with the new value (as the starting point next time). The only difference is we just use a SETLL, rather than a CHAIN, and check for the EQ indicator being *OFF rather than *ON. It's a bit quicker if the loop has to hit a lot of records before quiting. If you do find a better solution, please post it here - I could make good use of it :-) martin@mjrowe.prestel.co.uk (home) Martin_Rowe@Moores.co.uk (work) ICQ UIN# 2020537 - http://www.mirabilis.com -----Original Message----- From: Juris Krikis Jr. <juris.rfb@mail.bkc.lv> To: RPG/400 mailing list <RPG400-L@midrange.com> Date: 28 August 1997 13:21 Subject: Re: finding a suitable key >Reading the responses I figured out that I really was not making myself >clear the first time. I'll try again, if I may. Let's say we have an >externally described file. The DDS specification looks approximately >like this: >A R FIL_REC > FIL_KEY 4S TEXT('unique primary key') > FIL_DTA 80A TEXT('the data') > K FIL_KEY > >We do have some records already there: >FIL_KEY FIL_DTA >------- ------------------------------- > 1 'one' > 4 'record FOOBAR' > 0 'null record' > 99 'some record' > 2 'BAR' > >Now, let's suppose we need to insert a record... We want to find a >unused primary key for it. What I do now is approximately: > >FFil UF A E K DISK >DKey S 4S 0 >C DoW *In40 = *Off >C Add 1 Key >C Key Chain Fil_Rec 40 >C EndDo >C Move Key Fil_Key >C Move Data Fil_Dta >C Write Fil_Rec > >This kinda gets the job done and we happily add a record with key '3' >(we skipped the '1' and '2' here) there. I don't really like this code, >because it takes a few lines to write and has to chain through the whole >file to find the next unused key. It doesn't recognize keys of 0. And it >changes the buffers (whatever was in Fil_Dta is modified). I was just >wondering if this could be written easier/better/smarter? Any ideas? > > Kind regards, Juris. >* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * >* This is the RPG/400 Discussion Mailing List! To submit a new * >* message, send your mail to "RPG400-L@midrange.com". To unsubscribe * >* from this list send email to MAJORDOMO@midrange.com and specify * >* 'unsubscribe RPG400-L' in the body of your message. Questions should * >* be directed to the list owner / operator: david@midrange.com * >* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * > * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This is the RPG/400 Discussion Mailing List! To submit a new * * message, send your mail to "RPG400-L@midrange.com". To unsubscribe * * from this list send email to MAJORDOMO@midrange.com and specify * * 'unsubscribe RPG400-L' in the body of your message. Questions should * * be directed to the list owner / operator: david@midrange.com * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.