RPG IV 编程问题百解(5)引用外部DS(2)
提问:
Jmasak
Trying to do a lookup and/or build on a data stucture array. not usre if I set
this up correctly.
DNonBill_Jobs ds dim(100) Qualified Inz
D NB_Job# 5A overlay(NonBill_Jobs)
D NB_JNme 23A overlay(NonBill_Jobs:*next)
D NB_JobHrs 9P 2 overlay(NonBill_Jobs:*next)
dIndex s 4 0
dJob#In s 5
d hoursin s 9P 2
d namein s 23
d x s like(index) inz(0)
Trying to build the array. Doing a lookup to see if NB_Job# is present, if it
is, add new hourin to NB_JobHRs. If not there add one to arrary index and
populate the fields.
/free
index = %lookup(job#in:nb_job#);
if index = *zero;
X +=1;
NB_Job#(x) = Job#in;
NB_Jname(x) = something;
NB_JobHrs(x) = something;
x += 1;
elsif index <> *zero;
NB_JobHRs(index) += hoursin;
endif;
/End-Free
回答1:
passthru
If DS is referenced by Qualified, can't limited by DIM keyword.
回答2:
passthru
Jmasak, If you really want to reference a data structure that is already definded in an external pgm, module or procedure and the DS maybe contain numbers of recodes like data in an array. I think it's right way following below source codes:
DNonBill_Jobs ds qualified
DNonBill_jobsIn likeds(ds_NonBill_jobs_in) dim(100)
DNonBill_jobsOut likeds(ds_NonBill_jobs_Out) dim(100)
DPubPtr *
*
/free
//Main
ExSr Init;
ExSr MvDataIn;
Exsr CallRatePro;
Exsr ContDataOut;
Exsr Exit;
//move conditional data into the DS of NonBill_jobsIn
begsr MvDataIn;
//process ps/lf(s) for data that will be moved into the
// DS of NonBill_jobsIn
NonBill_jobsIn.fld1 = fld1;
NonBill_jobsIn.fld2 = fld2;
......
endsr;
begsr CallRatePro ;
PubPtr = %Addr(NonBill_Jobs);
Callp RateCSPgm(Ds_Project:Ds_ReturnCode:PubPtr);
//process Ds_ReturnCode
....
endsr;
begsr ContDataOut;
//%lookup for NonBill_jobsOut
......
endsr;
......
/end-free
阅读(854) | 评论(0) | 转发(0) |