20 pts.
 Chain function to find a specific record
Hi everyone. I need to use CHAIN function to find a specific record. The key is composed from 4 field but I know only two of them. It is possible? Thanks a lot (and sorry for my bad english!! :-( )

Software/Hardware used:
AS400
ASKED: April 11, 2012  11:41 AM
UPDATED: April 11, 2012  8:08 PM
  Help
 Approved Answer - Chosen by GiuGia (Question Asker)

you can chain by partial keys, but they must be the first fields in the key. That is, if the key consists of: fld1, fld2, fld3, fld4
you can chain with:

  • fld1, fld2, fld3, fld4
  • fld1, fld2, fld3
  • fld1, fld2
  • fld1
ANSWERED:  Apr 11, 2012  12:42 AM (GMT)  by GiuGia

 
Other Answers:

I forgot to mention that CHAINing with a partial key will always get you the <b>FIRST </b>record (according to the full key sequence) that matches the partial key. That is, if the file consists of the following records (as the full key would sequence them):
<pre>
fld1a, fld2a, fld3a, fld4a
fld1a, fld2a, fld3b, fld4a
fld1a, fld2b, fld3a, fld4a
fld1b, fld2a, fld3a, fld4a</pre>
CHAINing by: fld1a, fld2a will always get you the record: fld1a, fld2a, fld3a, fld4a

Last Wiki Answer Submitted:  April 11, 2012  6:22 pm  by  BigKat   7,185 pts.
Latest Answer Wiki Contributors:  BigKat   7,185 pts.
To see other answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

You said you want a specific record, but only know 2 of the 4 key fields, how will you know if you have the correct record.
If the 1st two fields of the key are unique, BigKats answer is correct.
If they are not, then are the two fields you want to use unique to the file. If so, create a new access path using those fields.

 32,905 pts.

 

Thanks a lot to both of you (is it correct english?!?!?! I hope so!)
I resolved with the BigKat’s solution! In this case the 1st two fields was enaugh for found my record!

 20 pts.

 

Again, be aware that CHAIN will only find one record that matches the two keys. In order to check other records that also match the same two key values, you can issue READ or READE statements in a loop. The CHAIN will position to the first record that matches; the reads will retrieve records that follow the first.

Your program would test each record to ensure that you process only the ones you want.

Tom

 108,175 pts.