× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



When executing file IO opcode, I usually prefer to use qualified
result-field DS as the way to fetch/update record of a file. Using
result-field DS is quite simple if there are no update-and-add on a file or
duplicate file (two or more files that point to the same physical file)
involve. But when the RPG program needs to perform update-and-add on a file
or duplicate files are invlove, thing seems to get a bit complicated to me.
This is because RPG requires the result-field DS to match the record format
of the file that the IO code is executing on and for the write opcode, the
result-field DS must be of a *output type. Below is how I normally handle
this type of situation. Is there a better way than this?

Note: Syntax might be write, did not try to compile it. Hopefully you get
the idea.

FAFILEL0 UF A E K DISK usropn
*
FAFILEL1 UF E K DISK usropn rename(AFILEFM :AFILEL1FM)

* Result-Field DS to overlay each possible IO combination on L0 and L1
* this make each of these DS interchangable
D AFILE e DS extname(AFILEPF :AFILEFM :*input)
D qualified
D AFILEL0 e DS extname(AFILEL0 :AFILEFM :*input)
D based(AFILE_p) qualified
D AFILEL0Output e DS extname(AFILEL0 :AFILEFM :*output)
D based(AFILE_p) qualified
D AFILEL1 e DS extname(AFILEL1 :AFILEFM :*input)
D based(AFILE_p) qualified
D AFILE_p s * inz(%addr(AFILE))

/free

// for example
if key1 <> 0;
chain (key1) AFILEL0 AFILEL0;
else;
chain (key2) AFILEL1 AFILEL1;
endif;

AFILE.data1 = 'ABC';
AFILE.data2 = 'DEF';

if %found(AFILEL0);
update AFILEL0 TESTL0;
elseif %found(AFILEL1);
update AFILEL0 TESTL0;
else;
AFILE.Key1 = 'NewKey1';
AFILE.Key2 = 'NewKey1';
write AFILEFM AFILEL0Output;
endif;

// is above crazy or normal...



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.