0
votes

How to search or go to the position by field in RPGLE?

This is my screen :

enter image description here

Let say, I want to go to position of date 02/06/2016, and enter at the 'Position to..' field, supposedly the cursor will go to 02/06/2021 and the record after that.

But seems like I have an infinite loop. When I debug, I realize that the Date is 02/06/2021 and didn't go to the next date after that. What should I do? Please help me. Thanks in advance :)

2

2 Answers

0
votes
Date       reade   curexg
            dou     %eof   
            
            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  
    Date    reade curexg 

            enddo

This looks like an infinite loop to me. You read your file with a reade(read equal) but you never update your Date variable, you read the same record over and over again, not reaching %eof.

0
votes

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 ;