[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how does CHAIN statment work? rpgle as400

Posted on 2011-10-25
5
Medium Priority
?
1,327 Views
Last Modified: 2012-06-21
Hi,
How does CHAIN work?
in particular, if I have 10 records: 1,2,3,4,..,10
if I have just read the 10th record (10).
if I execute this statment:2 chain file
Does the program auto-return to the top of the file in order
to find my 2th record,
or instead it returns NOT FOUND value??
thanks



0
Comment
Question by:bobdylan75
  • 3
5 Comments
 

Author Comment

by:bobdylan75
ID: 37024225
ps:
the key is obviously the only field I have, the value 1,2,3..10
thanks
0
 
LVL 14

Expert Comment

by:daveslater
ID: 37024421
Hi
chain gets the a rcord basewd on the index on the file along with other criteria.
It return a single record.

if you have the 10 recors in an indexed file

chain 2 will reset the pointer, if you then did a read you would ger record 3.

Dave
0
 

Author Comment

by:bobdylan75
ID: 37024441
SORRY,
I don't mean 2, but the key=2 like the value of the 2th record.
eval key= 2
key chain filename

the key of the file if the field VALUE. (1,2,3,..10)
0
 
LVL 36

Accepted Solution

by:
Gary Patterson earned 2000 total points
ID: 37024447
CHAIN can operate on file opened in Keyed sequence, or in Arrival sequence.

If the file is opened in Keyed mode, then CHAIN causes a single-record lookup by key.  The position of the file pointer before the CHAIN operation does not matter.  CHAIN causes the system to search the index of the file and locate the first record with a matching key.  If a matching record is found, the record is retrieved into the program's input buffer, and the file pointer is positioned at the next record in keyed sequence, so a subsequent READ operation would retrieve the next record in keyed sequence.

Let's use a different example, since the numeric keys can be confusing when discussing relative record numbers.

Given this file (on arrival sequence)

RRN   Key
1       Jerrold
2       Ladonne
3       Gary
4       John
5       Mark

File1 opened in arrival sequence:

REC=2
REC CHAIN FILE1 <- RRN2 is retrieved
READ FILE1 <- RRN3 (next in arrival sequence) is retrieved

Keyed order would be:

Key        RRN
Gary       3
Jerrold    1
John       4
Ladonne 2
Mark       5

File1 opened "K"eyed":

KEY="John"
KEY CHAIN FILE1 <- RRN4 is FOUND, and retrieved.
READ FILE1 <- RRN 2 (next in keyed sequence) is retrieved

- Gary Patterson
0
 

Author Closing Comment

by:bobdylan75
ID: 37024499
thank you very clear explanation.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exchange administrators are always vigilant about Exchange crashes and disasters that are possible any time. It is quite essential to identify the symptoms of a possible Exchange issue and be prepared with a proper recovery plan. There are multiple…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question