Reputation: 39
I'm stuck to get the full output.
Supposedly the output need to look like this
And this is my physical file
New Currency exchange physical file
I have three field in physical file which are :
I try to use
read curexg
dow not %eof
exgdat reade curexg
eval date = exgdat
select
exgcod wheneq 'USD'
move exgrat usd
exgcod wheneq 'GBP'
move exgrat gbp
exgcod wheneq 'EUR'
move exgrat eur
exgcod wheneq 'AUD'
move exgrat aud
exgcod wheneq 'SGD'
move exgrat sgd
endsl
read curexg
eval rrn = rrn + 1
write sfl01
enddo
this is the output : Output
After compile, I compare the value in subfile with the value in physical file, for 1 june, EUR is the wrong value. And right now, supposedly both of 31 May and 1 June records should be displayed on subfile.
Do I have to do another loop for READE? What should I do? please help me
Upvotes: 0
Views: 1095
Reputation: 453
I would do this - we read the input file sequentially and track the change in the date until the date has changed, fill in the entry for the subfile, as soon as we see that the date has changed - we save the filled entry in the subfile and start filling in the next one Curexg is assumed to be a logical file by exgdat key field
dcl-s lastDte char(10) inz(*blanks);
rrn = 0;
setll *loval curexg;
read curexg;
dow not %eof(curexg);
// If it's new date
if lastDte <> exgdat;
// If previous date not blanks (it's not the first record in the file)
if lastDte <> *blanks;
// write filled record to subfile
rrn += 1;
write sfl01;
endif;
// start new date group
date = exgdat;
lastDte = date;
endif;
// fill currency rate
select;
when exgcod = 'USD';
usd = exgrat;
when exgcod = 'GBP';
gbp = exgrat;
when exgcod = 'EUR';
eur = exgrat;
when exgcod = 'AUD';
aud = exgrat;
when exgcod = 'SGD';
sgd = exgrat;
endsl;
read curexg;
enddo;
// write last filled record to subfile
rrn += 1;
write sfl01;
Upvotes: 0
Reputation: 45
just move this
eval rrn = rrn + 1
write sfl01
outside of your loop and you should be good
Upvotes: 1
Reputation: 3674
First, when you compare EXGCOD to values like 'usd', the comparison is case-sensitive. The actual value in the file is 'USD', so you need to code 'USD' in your WHENEQ opcode.
But I think the main problem is that you are not doing the SELECT for every record that you get with READ or READE.
The first READ gets the record with 'USD'. Then, at the beginning of the DOW loop, you do a READE which would get the 'GBP' record. So you would do the first SELECT with the 'GBP' record, and your code would not see the 'USD" record. Then at the end of the loop, you do another READ operation which gets the 'EUR' record, but you don't process this record because the next thing that happens is the READE at the top of the loop, which gets the 'AUD' record. The READ at the end of the loop gets the 'SGD' record, and then the READE at the top of the loop attempts to get another record, but it would get end of file. But you don't check for end of file after the READE, so it would process the 'SGD' record. Finally, it would do another READ at the end of the loop, and %EOF would be *ON at the DOW so the loop would end.
At the end of the loop, you would have processed GBP, AUD, and SGD, but not USD or EUR.
Upvotes: 1