|
On Tue, 2005-12-20 at 13:57 -0700, Mohammad Tanveer wrote: > Any idea if we can use dynamic variable names in RPGLE? > > Something like this > > fldvalue = %value(&var1); > > Once we chain to a file or create cursor program knows what fields are > available. Is there any API or Userspace stuff to get the value of the > fields using a dynamic variable name? > > > Thanks > > > No. However, you can roll your own to an extent. In the case of a record buffer, such as results from a chain or read, you can find out the column name, type, offset and length at run time via DSPFFD to an outfile, the list fields API, the SQL catalog, and others. Once you know the column from positions and length for a particular record, you could do fldvalue = %subst(input_buffer: from_pos: length); You will probably need some special handling for field types other than alphanumeric. Years ago, we had need to allow users to define their own validation rules for any of about one hundred different fields contained on a set of five screens. Users needed to do simple validation against lists, and also needed the capability to do rudimentary if-then-else logic, as well as to compare one field to another field. The rules change frequently, and special cases are routinely added. Initially, we though about generating a piece of code and compiling it each time they changed the file maintenance, but we were concerned about how cpu intensive that would be. Instead, we loaded the fields at run time into an array. Once there, it was easy to write generic code to compare (for example) array(15) to array(10) or validate array(27) against a list. The only hard-coded portion of the program was that to move the fields from the record into the array. The rules were stored in a file, and the 'engine' worked from the rules. As usual, it depends on what problem you are trying to solve as to the best way to go about it. Regards, Rich
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.