On 14-Aug-2015 15:25 -0600, Vinay Gavankar wrote:

I was looking for way to retrieve number of fields in a file. I wrote
a CL program to do a DSPFFD to a file, and then read the first record
in that file to get number of fields.

That usage of the Display File Field Description (DSPFFD) request would give the number of columns in the /first/ format. That is because the number of fields is an attribute of the Record Format (RCDFMT), rather than of the database file.

An externally described Physical File (PF) has only one Record Format [and despite what various interfaces may present, and are likely to continue unchanged, a program-described file has zero fields]. Thus, if the DSPFFD requests were limited to only externally-described PFs, then the current method is sufficient and accurate.

The Display File Description (DSPFD) request to generate information about the Record Formats [using the TYPE(*RCDFMT) specification and] as output file records, the same information as given in the DSPFFD is given in the column RFFLDN [of model file QAFDRFMT in QSYS and RcdFmt QWHFDFMT]. However that request limits the output to one row per [implicitly duplicate or explicit] record format; a PF with 300 fields, for example, would result in just one row showing RFFLDN=300.

I also saw that there is an API to retrieve File Description, which
has the number of fields "somewhere".

The FILD0200 of Retrieve Database File Description (QDBRTVFD) API allows obtaining information about the record formats, including the number of fields for each. See also RCDL0200 of List Record Formats (QUSLRCD) API.

Since I am not too familiar with writing API's I was wondering if
someone has some code using that API, or whether the CL I have would
be good enough?

An example that should help progress a reader quite close to what is stated as required [most easily when restricted to a PF] using the aforementioned API with the format FILD0200:

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 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].