Since no one else has replied, I'll tell you a couple of things I'd try... 1. I think you might be able do it with pointers. Somehow... 2. You could use SQL to extract the value.
Since no one else has replied, I'll tell you a couple of things I'd try... 1. I think you might be able do it with pointers. Somehow... 2. You could use SQL to extract the value.
As you read the QDDSSRC file keep track of the location of the fields and their data type in the record (along with the names); or alternatively use the QUSLFLD (List Fields) API to determine file field names, types, and locations. Read the customer record into a data structure or single large field and then use the substring capability of RPG to substring out the CustNo value (based on its location within the record) from the data structure/field. If CustNo is character based (or zoned decimal) then you've got what you want. If CustNo happens to be packed decimal, binary, etc. then you need to convert the value you substringed out to a zoned decimal or character definition. This can be done using various sized and typed fields within your program as the target of your substring (redefined as character) and then setting a zoned decimal field to the value (this could be a real pain if you have great variety in the number of decimal positions to the right of the decimal point -- assuming you are after a general solution and not just CustNo)); or more directly by using the Copy Numeric Value MI instruction within your program (assuming you are using ILE based RPG).
bvining: One way to solve the packed problem in your method would be to use an array for the characters and overlay only the number of bytes needed onto a large packed field, padded on the left with 0s.
> I am trying to put the value of a field in a text string. There is an explanation of how to do this with SQL in the FAQ at http://faq.midrange.com The search link is at the lower left. I think it's under 'indirect'. --buck
That is what I had in mind but I'm thinking that getting the decimal point right means a few redefinitions (though I must admit I haven't given this a great deal of thought).
I don't see a quick solution for the decimal point, either. Buck's suggestion is actually a robust method for this, but since joestone already knows the field name, I'm thinking a simple dynamic SQL would be the way to go, unless it's being done thousands of times. (Note, the method Buck pointed out uses dynamic SQL, and it also includes code to make sure the field is valid, that it indeed contains data, etc.)
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?