Search code examples
moverpgle

How to MOVE VALUE OF A NEW RECORD ADDED from subfile to physical file in RPGLE?


How to move value of a new record added from SUBFILE into physical file?

The value are as shown in picture below:

CREATE

CUREXG are name of my physical file(pf), CURREC is my record name. My pf look like this :

PF

How to make the value separated into the pyhsical file? What should I do? Please help me. Thanks in advance


Solution

  • The brute force method suggested by RockBoro will work, though with a lot of duplicate code. One way to reduce the duplicate code (DRY principle) is to redefine the display file record structure using an array. Though you didn't give us the DDS for the display file record, I am guessing the record format looks something like this:

    dcl-f DSPF    Workstn Qualified;
    dcl-ds rec    LikeRec(DSPF.screen: *all) Inz;
    

    Where the 5 rates fall one after another. You can overlay an array on that like this:

    dcl-s rates   Like(rec.usd3) dim(5) based(pRates);
    dcl-s pRates  Pointer Inz(%addr(rec.usd3));
    

    After reading the screen just loop through the rates and write to the physical file:

    exfmt DSPF.screen rec;
    for ix = 1 to %elem(rates);
      exgdat = rec.date;
      exgcod = exccd(ix);
      exgrat = rates(ix);
      write currec;
    endfor;
    

    You would also need a compile time array exccd to hold the exchange codes in the order that they appear in the display file to make this work.