Midrange News for the IBM i Community


Posted by: Chris Proctor
Programmer Analyst
Columbia Sports Company
Portland, OR
CHAIN Operation question...
has no ratings.
Published: 18 Nov 2011
Revised: 23 Jan 2013 - 4111 days ago
Last viewed on: 25 Apr 2024 (5555 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.

CHAIN Operation question... Published by: Chris Proctor on 18 Nov 2011 view comments(6)

Good morning. This may be a stupid question, especially after being a IBM midrange programmer for about 30 years, but I'm going to ask anyway.

When coding a chain operation I have always had the chain and the %found()  with the file name. For example:

 

chain (fla:fldb) filea;

if %found(filea);

blah, blah

endif;

 

Some other developers here tend to use the record format name in the chain and the file name in the %found(). I guess I was always under the impression that they had to be the same. Am I wrong???

 

Thanks for any input and have a great weekend.

Chris

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: CHAIN Operation question...
Posted: 12 years 5 months 9 days 2 hours 53 minutes ago
Edited: Fri, 18 Nov, 2011 at 15:51:22 (4543 days ago)

Originally the CHAIN preferred the Record Format name, and the %FOUND always required the File name.

IBM has be relaxing some restrictions in the language in order to allow you to consistently use one or the other. The preference is for File name only, however some RPGers tend to habitually use record name. But %FOUND, %EOF, etc. all require a file name.

[EDIT] Okay Paul. Foot in mouth the word "require" was misguided. I should have said, "%FOUND, %EOF, etc. accept only a file name or no name"

Posted by: neilrh
Premium member *
Jackson, MI
Comment on: CHAIN Operation question...
Posted: 12 years 5 months 9 days 1 hours 53 minutes ago

I typically CHAIN FILE, the only time this annoys me is when I am doing READC SFL.

Posted by: Paulster
Premium member *
Sweden and The Netherlands
Comment on: CHAIN Operation question...
Posted: 12 years 5 months 8 days 23 hours 54 minutes ago

Hi,

Quite sure %found() would be enough... 

Have a nice weekend,

Paulster

Posted by: DaleB
Premium member *
Reading, PA
Comment on: CHAIN Operation question...
Posted: 12 years 5 months 6 days 8 hours 18 minutes ago

If your file has only one format, makes no difference. But, here's the rub, if you always use file name on your Chain (Read, etc.), you're going to get a warning at the bottom of the compiler output about format names not being referenced. It's only a warning, but there you go. (Possibly this was relaxed at 7.1?)

As for Paulster's comment, %FOUND and %EOF with no name refer to the most recent, relevant file operation. Better to specify an unneeded %FOUND(name) than to omit and wind up doing test for the wrong file. Be especially wary if there are any ExSR or (possibly implied) CallP in between.

If %FOUND is in the next line after Chain, I don't specify the file parameter. If it's more than a few lines away, certainly more than what will fit on same page of viewed source, always include the file.

Posted by: neilrh
Premium member *
Jackson, MI
Comment on: CHAIN Operation question...
Posted: 12 years 5 months 6 days 7 hours 58 minutes ago

I recall back around 2003/4 some of our technical guys were panicking one day because they'd installed a ptf that they claimed had hosed how unqualified %found and %eof worked.  Since they had installed the ptf for some other critical problem, we spent the day editting all of our source to make the %found/%eof's qualified.

I just qualify them out of habit since then.

Posted by: rgilsdor
Premium member *
Wayne, Michigan
Comment on: CHAIN Operation question...
Posted: 12 years 5 months 4 days 3 hours 47 minutes ago

I rarely use a file name with a %Found. I usually code the %found immediately after the chain operation so it makes little difference and my files usually have only 1 format so I can get away with that.