微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 RPGLE 的一行中移动或合并不同的字段到子文件中

如何解决如何在 RPGLE 的一行中移动或合并不同的字段到子文件中

我被困在如何在一行中移动或显示来自不同字段的不同值。

我的输出应该是这样的

Real Output

但现在,我的输出是这样的

Recent Output

这是我的物理文件

CUREXG file

我在物理文件中有三个字段:

  • EXGDAT = 日期和关键字段
  • EXGCOD = 交换代码
  • EXGRAT = 汇率

我有 2 个日期,基本上我需要输出只有 2 行,其中一个是 5 月 31 日,第二个是 6 月 1 日。 我试图通过执行 if 条件将它们分组,但没有奏效。我该怎么办?请帮帮我

提前致谢

解决方法

//Add a logical for the table by date,exchange code
fcurexg2   if   e           k disk   

**---------------------- start of your code
*LOVAL setll curexg
       read curexg
       dou  %eof(curexg);

c       eval @@date =  exgdat
c       exsr $GetVals         

        eval rrn = rrn + 1
        write sfl01

   // move to the next date
exgdat  setgt curexg
        read curexg
        enddo

**------------------------
Begsr  $GetVals;  // runs for each code -- usd,eur,etc
  @@gcod = 'USD'
  exsr $GetGrat;
  move   @@grat   USD

  @@gcod = 'GBP'
  exsr $GetGrat;
  move   @@grat   GBP

  @@gcod = 'EUR'
  exsr $GetGrat;
  move   @@grat   EUR

  @@gcod = 'AUD'
  exsr $GetGrat;
  move   @@grat   AUD

  @@gcod = 'SGD'
  exsr $GetGrat;
  move   @@grat   SGD

Endsr;
**------------------------
Begsr $GetGrat;  //find the rate for that date and code
*like  define curexg   @@date
*like  define exgcod   @@gcod
*like  define exgrat   @@grat


  clear @@grat
  Chain (@@date: @@gcod) curexg2;  //the new logical 
  if %found(curexg2);
    @@grat = exgrat
  endif
Endsr;
**------------------------
,

考虑一个 SQL 函数。这是一个返回特定兑换代码和日期的汇率的 SQL 函数。

CREATE or replace function curexg_exchangeRate(
inDate       date,inCurrency   char(3))                          
returns      decimal(7,2)                      
language sql                                   
                                               
begin                                          
                                               
declare      Sqlcode int ;                     
declare      vSqlcode DECIMAL(5,0) default 0 ; 
declare      vExgrat decimal(7,2) default 0 ;  
                                               
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION      
SET  vSqlcode = SQLCODE ;                      
                                               
select       a.exgrat                          
into         vExgrat                           
from         curexg a                          
where        a.exgdat <= inDate                
             and a.exgcod = inCurrency         
order by     a.exgdat desc                     
fetch first row only ;
 
return       coalesce( vExgrat,0 ) ;
end                                  

调用exchangeRate sql函数的RPG代码:

d usdRate         s              7p 2                                  
d gbpRate         s              7p 2                                  
d eurRate         s              7p 2                                  
 /free                                                                 
  // get exchange rate,of each exchange code,as of the specified date
      exec sql                                                         
      set         :usdRate =  curexg_exchangeRate( :exgdat,'USD' ) ;  
      exec sql                                                         
      set         :gbpRate =  curexg_exchangeRate( :exgdat,'GBP' ) ;  
      exec sql                                                         
      set         :eurRate =  curexg_exchangeRate( :exgdat,'EUR' ) ;  

此代码读取每个交换日期的汇率:

  // list exchange rates for each exchange date.                       
      exec sql                                                         
      declare c1 cursor for                                            
      with t1 as (                                                     
      select distinct  a.exgdat                                        
      from             curexg a                                        
      order by         a.exgdat )    
      select      a.exgdat,curexg_exchangeRate( a.exgdat,'USD' ) usdRate,'GBP' ) gbpRate,'EUR' ) eurRate  
      from        t1 a                                            
      order by    a.exgdat ;                                      
                                                                  
      exec sql                                                    
      open        c1 ;                                            
                                                                  
      exec sql                                                    
      fetch       c1                                              
      into        :exgdat,:usdRate,:gbpRate,:eurRate ;         
      if          sqlcode <> 0 ;                                  
      leave ;                                                     
      endif ;                                                     
                                                                  
  // write to subfile                                             
      sfExgdat    = exgdat ;                                      
      sfUsdRate   = usdRate ;                                     
      sfGbpRate   = gbpRate ;                                     
      sfEurRate   = eurRate ;  
      write       sflrcd ; 
                           
      enddo ;              
                           
      exec sql             
      close       c1 ;     
                           
      *inlr       = '1' ;  
      return ;             
 /end-free                 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。