× 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.



Hi Lim,

I do the same thing in regard to input & output data structures pointing to one spot in memory. I haven't run into the need for the same file twice as you are doing. My only concern would be if the Logical was ever defined with a subset of fields - that would mess you up. But I'm guessing that's not the case now, and if so, very unlikely that the file would change.

I last heard that in an upcoming release one data structure would be allowed to satisfy both input & output (maybe with a value of *all).

-Kurt

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of hockchai Lim
Sent: Monday, August 16, 2010 1:53 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: read/chain/write/update with *input/*output/*all DS

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 ...

Replies:

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.