4 years ago I started the RFE 89289 about "eval-corr using a record format from a file".
Unfortunately it was declined recently.
What I wanted to do was this (from the RFE):
Description and use case
Many times I need to move the contents of the fields in a record into a data structure or vice versa.
because that very often the fields from the file are defined in other data structures or referred to
in the program it is not possible to use PREFIX with a data structure name. Therefore it would be nice
if it is possible to use EVAL-CORR instead using a record format name as either the result or the expression.
- - - - - - - - - - - - - - - - - -- - - - - - - - -- - - - - - - - -- - - - - - - - -- - - - - - - - -- - - - - - - - -- - - - - - - - -- - - - - - - - -
The solution.
I have thought a long time how to solve this. All I needed was to get access to the I/O-buffer of the file.
And suddenly I found the answer. OPEN ACCESS was the solution.
It only needed the implementation of an Open Access file defined by the handler keyword.
The fields in MyFileP1 and MyFileP1_h share the same storage. Normal RPG behaviour.
This means that after reading MyFileP1 I only need to write to MyFileP1_h thus calling the handler.
In the handler I have made it so that when writing to MyFileP1_h the outputbuffer is saved in the data
structure MyFileRec. And when reading from it the data in MyFileRec are returned in the inputbuffer or
more correctly - it acts as the inputbuffer. And all the fields in MyFileP1_h and MyFileP1 are then populated
with the content of MyFileRec.
Unfortunately it was declined recently.
What I wanted to do was this (from the RFE):
Description and use case
Many times I need to move the contents of the fields in a record into a data structure or vice versa.
because that very often the fields from the file are defined in other data structures or referred to
in the program it is not possible to use PREFIX with a data structure name. Therefore it would be nice
if it is possible to use EVAL-CORR instead using a record format name as either the result or the expression.
Code:
FMyFileP1 IF E K DISK include(MyFileR1) D MyFileRec ds likerec(MyFileR1 : *INPUT) read Myfile; eval-corr MyFileRec = MyFileR1; eval-corr MyFileR1 = MyFileRec; *inlr = '1'; return;
The solution.
I have thought a long time how to solve this. All I needed was to get access to the I/O-buffer of the file.
And suddenly I found the answer. OPEN ACCESS was the solution.
It only needed the implementation of an Open Access file defined by the handler keyword.
The fields in MyFileP1 and MyFileP1_h share the same storage. Normal RPG behaviour.
This means that after reading MyFileP1 I only need to write to MyFileP1_h thus calling the handler.
In the handler I have made it so that when writing to MyFileP1_h the outputbuffer is saved in the data
structure MyFileRec. And when reading from it the data in MyFileRec are returned in the inputbuffer or
more correctly - it acts as the inputbuffer. And all the fields in MyFileP1_h and MyFileP1 are then populated
with the content of MyFileRec.
Code:
FMyFileP1 IF E K DISK include(MyFileR1) FMyFileP1_hIF A E K DISK block(*no) F extdesc('MYFILEP1') F RENAME(MYFILER1:MYFILER1_h) F HANDLER(MYFILE_handle) F usropn D MyFileRec ds likerec(MyFileR1 : *INPUT) D* Standard IBM supplied Open Access definitions D/copy qoar/qrpglesrc,qrnopenacc open MyFileP1_h; read Myfile; write MyFileP1_h; // eval-corr MyFileRec = MyFileR1; read MyFileP1_h; // eval-corr MyFileR1 = MyFileRec; *inlr = '1'; return; C******************************************************************** P MYFILE_handle B D MYFILE_handle PI D info likeds(QrnOpenAccess_T) D* D* D outBuffer s 32767 based(pOutBuffer) select; when info.rpgOperation = QrnOperation_WRITE; pOutBuffer = info.outputBuffer; MyFileRec = outBuffer; when info.rpgOperation = QrnOperation_READ; info.inputBuffer = %addr(MyFileRec); info.inputBufferLen = %size(MyFileRec); endsl; return; P MYFILE_handle E
Comment