the loop within a loop would be too complicated for me. An RPG procedure which returns each exchange rate of a specific exchange date would help simplify.
** ------------------------ curexg_readExchangeRates --------------
pcurexg_readExchangeRates...
p b
dcurexg_readExchangeRates...
d pi
d outUsd 5p 2
d outGbp 5p 2
d outEur 5p 2
d outAud 5p 2
d outSgd 5p 2
d inExgDat d const
/free
outUsd = 0 ;
outGbp = 0 ;
outEur = 0 ;
outAud = 0 ;
outSgd = 0 ;
setll ( inExgDat ) curexg ;
dow 1 = 1 ;
reade ( inExgDat ) curexg ;
if %eof ;
leave ;
endif ;
if exgcod = 'USD' ;
outUsd = exgrat ;
elseif exgcod = 'GBP' ;
outGbp = exgrat ;
elseif exgcod = 'EUR' ;
outEur = exgrat ;
elseif exgcod = 'AUD' ;
outAud = exgrat ;
elseif exgcod = 'SGD' ;
outSgd = exgrat ;
endif ;
enddo ;
return ;
/end-free
p e
then you can have a simple loop that reads exchange rate dates from a starting date:
dow 1 = 1 ;
setll ( startDate ) curexg ;
read curexg ;
if %eof ;
leave ;
endif ;
cur_date = exgdat ;
curexg_readExchangeRates( usd: gbp: eur: aud: sgd:
cur_date ) ;
// write exchange rates of current date to subfile.
write sflrec ;
// advance to next exchange rate date
setgt ( cur_date ) curexg ;
read curexg ;
if %eof ;
leave ;
endif ;
startDate = exgdat ;
enddo ;