When I've done projects like this, I used the system APIs to get the
record layouts. (Other ways are to use DSPFFD to an *OUTFILE, or use
the system catalogs... but I go for APIs for efficiency purposes.)
Here's where I'd start looking:
You'll notice there are APIs to get a list of the record formats in a
table, and a list of fields in a record format. There's also a
(difficult to use, but very powerful) API called QDBRTVFD that gives you
basically everything you might want to know about a table.
What I've done is have an 'open' type of procedure that gets the list of
fields, buffer positions, and data types... I put that in a lookup table
in my program. And, of course, call the _Ropen() API to open the table.
(though, you could also use dynamic SQL which would be easier, but, in
my case I was trying to make something that worked the same as native I/O)
Then when they call your CRUD operation procedure, it'd retrieve the row
from the table (using a routine like _Rreadk, for example, or fetch from
a dynamic SQL) and then look up the buffer positions of the field, and
substring (or memcpy) the data from the record buffer in that position,
convert the data type to whatever the caller expects, and return it.
On 6/23/2022 4:45 PM, Mohammad Tanveer wrote:
Thanks. Just wondering how does OA get name/value pairs of the fields from
a record, I always dreamed of looping through fields and their values in a
generic way without using field names.
Following article is very old but this gave me this crazy thought :)
As an Amazon Associate we earn from qualifying purchases.