On 8/17/2010 1:56 PM, hockchai Lim wrote:
How/what would be the best way to handle above if I prefer to always use
result-field DS when performing file IO opcode?
"best" is a highly subjective term. But here's one way:
if customer# <> 0;
chain (customer#) CUSTL1 myCustL1;
eval-corr myCust = myCustL1;
elseif creditcard# <> 0;
chain (creditcard) CUSTL2 myCustL2;
eval-corr myCust = myCustL2;
elseif ssn <> 0;
chain (ssn) CUSTL3 myCustL3;
eval-corr myCust = myCustL3;
. . .
endif;
ScreenField_CustName = myCust.CUSTNAM;
exfmt mainScreen;
myCust.CustNam = ScreenField_CustName;
chain (CUST#) CUSTL0 tmpCUST;
update CUSTL0 myCust;
This assumes that you declared DSes for each LF like this (where
CUSTL0REC is the record format for CUSTL0, CUSTL1REC is the record
format for CUSTL1, etc)
D MyCust ds likerec(CUSTL0REC:*OUTPUT)
D MyCustL1 ds likerec(CUSTL1REC:*INPUT)
D MyCustL2 ds likerec(CUSTL2REC:*INPUT)
D MyCustL3 ds likerec(CUSTL3REC:*INPUT)
D tmpCUST ds likerec(CUSTL0REC:*INPUT)
Or if you're _sure_ that all LFs will always have the same record format
(which is a dangerous assumption) and that these record formats will
_never_ have input-only or output-only fields in them, then you could
potentially do it this way:
D MyCust ds likerec(CUSTL0REC:*OUTPUT)
D myCustPtr s * inz(%addr(MyCust))
D MyCustL1 ds likerec(CUSTL1REC:*INPUT)
D based(myCustPtr)
D MyCustL2 ds likerec(CUSTL2REC:*INPUT)
D based(myCustPtr)
D MyCustL3 ds likerec(CUSTL3REC:*INPUT)
D based(myCustPtr)
D tmpCust ds likerec(CUSTL0REC:*OUTPUT)
I suppose overlaying in a DS might also work. But, hopefully you get
the idea... anyway... with this, all the DSes occupy the same memory,
so they all access the same data, and you could eliminate the EVAL-CORR
in the code example.
Eval-Corr is definitely safer, though. Is it worth it to save 3 lines
of code, and a millisecond or two of execution time?
As an Amazon Associate we earn from qualifying purchases.