Search code examples
loopsrpgle

How to do LOOP record by KEY FIELD DATE in RPGLE?


I'm stuck to get the full output.

Supposedly the output need to look like this : Actual output

And this is my physical file: CUREXG

I have three field in physical file which are :

  • EXGDAT = date
  • EXGCOD = exchange code
  • EXGRAT = exchange rate

My output look like this :

Output

My output displayed record for 1 June only and not both 31 May and 1 June. What should I do to get the exact output that I want? Please help me. Thanks in advance


Solution

  • the inner loop runs until %eof. Then you write to the subfile. The reade that follows the write to the subfile will return %eof because the cursor into the file has not been reset.

                write sfl01
        exgdat  reade curexg
    

    use SETGT and then READ to read to the EXGDAT of the next set of currency rate records.

                write sfl01
        exgdat  setgt curexg
                read  curexg
    
    

    to debug the problem where you are not reading the records you expect, try to write the results of every read to a print file. That way you have something you can look at after the program runs. Might help understand what was read and why.

    FQSYSPRT   o    f  132        printer OflInd(*inOf)    
    
    d lineData        s            132a     
    
          if          *inof = '1' ;                          
          except      newPage ;                              
          endif ;                                            
          lineData    = %eof + ' ' + exgcod + ' ' + 
                        %editc(exgrat:'J') +
                        ' ' + %char(exgdat:*iso) ;      
          except      detail ;                               
    
    OQsysprt   E            NewPage           1            
    O                       LineData           132         
                                                           
    O          E            Detail      1                  
    O                       LineData           132