Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CHAIN Operation results in more than 1 row

Status
Not open for further replies.

Ju5

Programmer
May 25, 2007
85
PH
I've come up against situations where records were not processed because there were more than 1 result to a chain operation.

The program I'm working on now generates an error report when records are not processed. The program doesn't catch the error when a Chain operation results in 2 or more rows. I need some way to catch this error. Any ideas?

Thanks in advance and Merry Christmas!
 
you could change the logic, to do a SETLL do a READE, and process the records until the READE returns an error,,
 
There can't be more than one record returned with a chain. By definition is gets a single record by key. If there are multiple records by key, then do as jmd said. Use a loop to read thru the records using READE. Use SETLL to set the file at the first record that meets the key and use READE to read them by key.

 
How does the CHAIN operation behave when there are more than 1 record that meets the key? If there are 2 records that meet the key will the CHAIN just ignore the record and move to the next?

I've encountered this a few times now where the users put in a record with a key that already exists. I usually have to delete the duplicate record then rerun the job.

 
Ju5 said:
...the users put in a record with a key that already exists. I usually have to delete the duplicate record...
To avoid that the users can write duplicates in the table, you can create unique index on the table - for example:
Code:
CREATE UNIQUE INDEX [i]my_lib[/i]/[i]my_lfidx[/i] ON [i]my_lib[/i]/[i]my_pf[/i]
([i]my_key1[/i] ASC, [i]my_key2[/i] ASC, [i]my_key3[/i] ASC)
 
How does the CHAIN operation behave when there are more than 1 record that meets the key? If there are 2 records that meet the key will the CHAIN just ignore the record and move to the next?
If you do NOT specify FIFO, FCFO or LIFO no guaranteed order is specified for retrieving records with duplicate keys.

I've encountered this a few times now where the users put in a record with a key that already exists. I usually have to delete the duplicate record then rerun the job.
You should specify an indicator in positions 71-72 that is set on if no record in the file matches the search argument or use the %FOUND built-in function, which returns ’0’ if no record is found, and ’1’ if a record is found. If the indicator is off or FOUND BIF is on then proceed to update the current record otherwise ignore or write the new record.

Philippe
 
How does the CHAIN operation behave when there are more than 1 record that meets the key? If there are 2 records that meet the key will the CHAIN just ignore the record and move to the next?

A CHAIN operation does not ignore records. It simply gets one record. As MERCURY2 stated, without specifying LIFO, FIFO, or FCFO, there's no telling which of the duplicate records will be retrieved.

A SETLL and READE combiation is what will read duplicate records. I agree with mikrom. The file should have unique keys if duplicates are not allowed. You can then test for an error message when an attempt is made to add a duplicate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top