Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I get the value of this field in a rpg program?

Status
Not open for further replies.

joestone

Programmer
Aug 5, 2003
2
US
I am trying to put the value of a field in a text string. Simple enough, but I want the field name to come from an array. I do not have the value of the field in the array, only the name.

I fill an array from reading the QDDSSRC into my RPG program. The array is called FieldNames: CustNo, Addr, City, State, Zip

I read the physical file and want to put the values for CustNo into a text string. When I run the program I don't know the name of the fields. They are in the array.

Does anybody have a clue? Is this even possible?


 
I've never encountered this before but if I had to do it, I'd look into pointers. With the latest versions of RPG I think you can set a field to a value based on its address.
I've never tried it and I only have a small exmaple in one of my RPG books but I think this may be possible:-


D MyPointer S *
D MyString S 10 BASED(MyPointer)
*
* Sets MyString to the value pointed to via MyPointer
EVAL MyPointer = %ADDR(ArrayFieldName)


Hope it helps.


Dazed and confused
 
Skittle
If you have defined ArrayFieldName as an array with (for example) five elements, setting MyPointer to
%ADDR(ArrayFieldName) will make MyString point to the same bit of memory as ArrayFieldName and it will therefore have the same value (ie the actual characters "CustNo", "Addr", "City", "State" or "Zip") so I don't think that will do what joestone wants.

joestone
I'm a bit confused - what are you actually trying to do here? You don't know what the field name is but you do have a list of the names in the DDS which it could be? If so, how is your RPG going to compile since it needs to know what the input file looks like? Have a look at this link


to show you how to use QM queries. It will let you run an SQL statment which you could build on the fly and output it to a workfile which you previously created with one field called FIELD1. If you create the SQL statment like
Code:
C          Close    WorkFile
C          Eval     CmdString = "SELECT "         +
C                      Array(x) + " AS FIELD1 FROM " +
C                       "your_file_name"
C          Call     'QMQRYPGM'
C          Parm                 CmdString      80
C          Open     WorkFile
and pass it to your program to populate the workfile. Your program could then use field FIELD1 which will have the value of the field name in Array(x). I have a working version of the QM query stuff in my utility library. If it would be of any help I'll mail it to you. It has a few helpfull bits and also has a better way of getting the field names from a file than reading the DDS.

PeteJ
(Contract Code-monkey)

It's amazing how many ways there are to skin a cat
(apologies to the veggies)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top