|
Hello Antonio, > If, in a RPG pgm, I manage to have in a field (let's call it FieldName) > the name of a real field from an externally described file, and in > another field, call it "FieldValue", a value (either alfa or numeric), > is there a way to write something as: > Eval FieldName(??) = FieldValue It's relatively easy to get a list of fields in an externally defined file, and their positions in a record. It's possible to use the ILE C record i/o functions to read/write/update a database without knowing any of the details of the database at compile time. And thanks to the design of the ILE environment, it's possible to use these ILE C routines from an ILE RPG program. But you've still got the task of taking generic data and reformatting it to fit exactly the right way into the record buffer. For example, if you've got a field called "FieldValue" what's in it? Most likely, it's going to be an alphanumeric field with data formatted in a human-readable format, because that allows it to be used for any possible scenario. Then, you've got to write routines that convert from that human-readable format to the specific format, binary, packed, date, time, timestamp, etc. that the database field is in. And you have to be able to do that based on the ability to look the fieldname up in the external definition at run-time. If FieldName is "Amount" and "FieldValue" contains "123.45", what do you need to do? You need to call an API to get the list of fields for the database, scan through it for a field called "Amount". Now you can find out that "Amount" is an "11P 2" field in the database, so you have to convert "123.45" to x'00000012345F' and store it into the record buffer at the right position, and then save the record back to disk. Is that possible? Sure. Is it easy? No. Remember, you know nothing about the data at compile time -- so it's not easy at all. There are some MI functions that can assist with this -- most notably _LBCPYNV which will convert a numeric value from one format to another based on pointers in memory. That way, you can use a routine like %DEC() to convert the character string to a very large (maybe 30P 9) numeric field, and use _LBCPYNV to convert it to the correct field, copy that into the record buffer, and then save the data. Carsten Flensburg did a sample of parsing external record buffers in one of his "APIs by Example" columns in my newsletter. You can read it at the following link (requires a free membership to the iSeries Network): http://www.iseriesnetwork.com/resources/clubtech/index.cfm?fuseaction=ShowNewsletterIssue&ID=17380
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.