Chain function to find a specific record

20 pts.
Tags:
AS/400
AS/400 Records
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

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

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • BigKat
    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
    8,100 pointsBadges:
    report
  • CharlieBrowne
    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.
    41,380 pointsBadges:
    report
  • GiuGia
    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 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following