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 'DEmail:xxxx@xxx.com' 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.
Software/Hardware used:
ASKED:
November 11, 2011 9:46 AM
UPDATED:
March 17, 2012 6:56 AM
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
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
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
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?
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 .