Decide variable name based on value in RPGLE

1215 pts.
Display File
I want to move some values to variable in RPGLE Program. I want to decide the Variable name based on the value which i received. Eg: If i am getting '' from my calling program, i want to move to DEmail Field. All the Fields are available in Display File. How will i achieve this. In my display File, I am having 100 Fields. I want to display only 50 Fields based on the input. I am getting only 50 Values from my calling program. Here i dont want to repeat the code to move values.  

Answer Wiki

Thanks. We'll let you know when a new response is added.

I think, You are about to move the data from one Record format(Display File) to Data Structure(In RPGLE) with out actually moving varaiable by varaible.
If So, You can try the EVAL-CORR opcode.
But, Atleast One of the two Data Structures must be Qualifed.
Refer the sample code below.
* Physical file EVALCORRPF
A IDNO 10P 0
* Display file EVALCORRDF
A 3 2’Name’
A NAME 25A O 3 15
A 4 2’City’
* RPG program
Fevalcorrpfuf e disk
Fevalcorrdfcf e workstn

D pf_ds e ds extname(evalcorrpf : *input)
D qualified
D pf_save_ds ds likeds(pf_ds)
D dspf_in_ds e ds extname(evalcorrdf : *input)
D qualified
D dspf_out_ds e ds extname(evalcorrdf : *output)
D qualified
read pfrec pf_ds;
dow not %eof;
// Assign all subfields with the same name and type
// to the data structure for the write operation
// to the display file (NAME and CITY)
eval-corr dspf_out_ds = pf_ds;
// Write and read the display file record format
// (WRITE+READ is equivalent to EXFMT)
write dspfrec dspf_out_ds;
read dspfrec dspf_in_ds;
// Save the original physical file record
// and assign the display file subfields to the
// physical file data structure. Then compare
// the physical file data structure to the saved
// version to see if any fields have changed.
eval pf_save_ds = pf_ds;
eval-corr pf_ds = dspf_in_ds;
if pf_ds <> pf_save_ds;
// Some of the fields have changed
update pfrec pf_ds;
read pfrec pf_ds;
*inlr = ‘1’;



Discuss This Question: 5  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • TomLiotta
    Here i dont want to repeat the code to move values. Why not? It's possibly the most efficient way of getting it done, and it's likely to be the clearest code you can put in place. A direct SELECT/WHEN group seems reasonable. Are the fields all of the same type and size? Can they be arranged in program memory as an array? Tom
    125,585 pointsBadges:
  • TomLiotta
    If you really really want to do something like this, study the Retrieve Display File Description (QDFRTVFD) API, in particular the Row-Column Table (QDFFRCTB), Row-Column Table Entry (QDFFRCTE) and Field Name Table (QDFFNTB) sub-topics. Also, study the ILE RPG EXTNAME(file-name{:format-name}{:*ALL| *INPUT|*OUTPUT|*KEY}) topic for data structures. From those, it should be seen that you can have some control over how fields are placed in program memory, and that you can determine data types and sizes of fields along with their names at run-time. If you can determine that a field named DEmail exists and that it's some number of bytes in length at a known offset in a data structure, you should be able to place data in it. I still think a SELECT/WHEN group will be a better choice. (Maybe not as fun.) Tom
    125,585 pointsBadges:
  • TomLiotta
    Technically, I suppose you could ignore standard display files and do the display work with the Dynamic Screen Manager APIs or even using the USRDFN (User-Defined) keyword for display files. With those, you could code your displays to work just about any way you wanted. Tom
    125,585 pointsBadges:
  • Yorkshireman
    I've tried various ways of achieving this over the years, and eventually I've arrived at the clear winner, which aligns with Tom's first comment. Lots of lines of boring but crystal clear code. - If 'x' then move y if 'w' then move m If I'm likely to repeat it, I'll encapsulate it into reusable code - /copy returning the fastest execution , or if it's going to end up in multiple functions, use a service program or such. And for trhe benefit of whoever maintains it I usually add a comment along the lines of 'this is long winded code, and I know it, but YOU can see exactly what it does, and it will execute as fast as all get out, because there is one route through, however many lines of code there are. The key is to make it readable, and encapsulate the boring parts. then who cares?
    6,085 pointsBadges:
  • Bigmac46
    How bout lookup search array with all field names in it and move to specific element of a data structure with all the field names defined in with dim(50) using return value of lookup??? might be somwhat old fashioned but I bet it would work .
    1,000 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: