Search code examples
moverpglerpg

How to MOVE or MERGE different fields into the subfile in ONE LINE in RPGLE


i'm stuck on how to move or display different value from different field in one line.

My output supposed to look like this

Real Output

but for now, my output is look like this

Recent Output

This is my physical file

CUREXG file

I have three field in physical file which are :

  • EXGDAT = date And the key field
  • EXGCOD = exchange code
  • EXGRAT = exchange rate

I have 2 dates, and basically i need the output to only have 2 line which one is 31 May, and the second one is 1 june. I tried to group them by doing the if condition but it didnt work. How I'm supposed to do? Please help me

Thanks in advance


Solution

  • //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;
    **------------------------