Midrange News for the IBM i Community


Posted by: Chris Proctor
Programmer Analyst
Columbia Sports Company
Portland, OR
Recommendation for changing a key???
has no ratings.
Published: 09 May 2012
Revised: 23 Jan 2013 - 4104 days ago
Last viewed on: 19 Apr 2024 (4770 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Recommendation for changing a key??? Published by: Chris Proctor on 09 May 2012 view comments(7)

Good afternoon. I have a need to write a process that will take a changed sales transaction and change the sequence numbers in another file to line up with the new values in the transaction. The sequence number is part of the key to the file and obviously, since records cann be added or removed from the transaction, I can't just chain with the old number and update it with the new value because then we could have a dup key error.

I was playing with the idea of loading a mult occur data structure with all the records in the transaction, deleting the tran and rewriting it with the new seq#, but it appears that I can't have an external data structure defined with dim or occur.

Does anyone have a suggestion as to a simple way to handle this? Any help would be greatly appreciated!

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: neilrh
Premium member *
Jackson, MI
Comment on: Recommendation for changing a key???
Posted: 11 years 11 months 10 days 23 hours 15 minutes ago

 

d dsRec           ds                  likerec(FileRec) dim(50)

 

Posted by: chrisp
Premium member *
Portland, OR
Comment on: Recommendation for changing a key???
Posted: 11 years 11 months 10 days 22 hours 57 minutes ago

Interesting. I've never used likerec. Thanks, Neil.

Posted by: Ringer
Premium member *
Comment on: Recommendation for changing a key???
Posted: 11 years 11 months 10 days 22 hours 32 minutes ago

I've had cases like this where I set the numeric values negative so avoid the duplicate keys and then go back ASAP and update them all to positive. Not sure if that helps you or not. And you have to make sure the same program is not running twice (or that could cause a dup key).

Chris R

Posted by: chrisp
Premium member *
Portland, OR
Comment on: Recommendation for changing a key???
Posted: 11 years 11 months 10 days 22 hours 23 minutes ago

Good suggestion, Chris. Thanks!

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Recommendation for changing a key???
Posted: 11 years 11 months 10 days 20 hours 45 minutes ago

 You can have a DIM on an EXTNAME DS, just not the original... use it as a "template" and you're done!

D myExtDS     E DS      EXTNAME(PICKLES) QUALIFIED
D myArray       DS      LIKEDS(myExtDS) DIM(100) 

 

Posted by: neilrh
Premium member *
Jackson, MI
Comment on: Recommendation for changing a key???
Posted: 11 years 11 months 10 days 6 hours 24 minutes ago

Ah yes update with negatives, I forgot about that, used that solution when I had the same problem about 15 years ago.... never had a need to do it since then.

Posted by: Ringer
Premium member *
Comment on: Recommendation for changing a key???
Posted: 11 years 11 months 10 days 2 hours 23 minutes ago

You could have the program lock a data area (of the same name) before changing the key values, so if another copy of the program is running, it has to wait its turn. I use something similar but I call it proxy locking (where I can logically flag anything as in use).