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 - 1767 days ago
Last viewed on: 24 Nov 2017 (3169 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: 5 years 6 months 18 days 14 hours 4 minutes ago

 

d dsRec           ds                  likerec(FileRec) dim(50)

 

Posted by: chrisp
Premium member *
Portland, OR
Comment on: Recommendation for changing a key???
Posted: 5 years 6 months 18 days 13 hours 46 minutes ago

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

Posted by: Ringer
Premium member *
Comment on: Recommendation for changing a key???
Posted: 5 years 6 months 18 days 13 hours 21 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: 5 years 6 months 18 days 13 hours 12 minutes ago

Good suggestion, Chris. Thanks!

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Recommendation for changing a key???
Posted: 5 years 6 months 18 days 11 hours 34 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: 5 years 6 months 17 days 21 hours 14 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: 5 years 6 months 17 days 17 hours 12 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).