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.
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
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. the word "require" was misguided. I should have said, "%FOUND, %EOF, etc. accept only a file name or no name"
I typically CHAIN FILE, the only time this annoys me is when I am doing READC SFL.
Hi,
Quite sure %found() would be enough...
Have a nice weekend,
Paulster
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.
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.
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.