× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Pete,

Based on the prior posts from Booth, I thought I understood that the D spec for the data structure would hold a copy of the data read from
the file "automagically".

There's no magic to it, Pete. When you compile an RPG program that uses
an externally defined file, the compiler reads the file description and
generates input specs that are used under the covers.

The input specs reference the field names in the program that the data
should be read into.

So if (for example) your external definition has fields named CUSTNO,
NAME, CITY, STATE, then the data structure would have fields with those
names, and so would the input specs, since they're both based on the
same file. Consequently (assuming the data structure isn't qualified,
prefixed, etc) it "automagically" reads into the DS.

So either I misunderstood or I am doing something wrong (that
wouldn't surprise me).

You understood perfectly, however, when I recommended LIKEREC, I didn't realize that this is what you're trying to do. (Perhaps I came into the middle of the conversation?)

The thing is... LIKEREC automatically qualifies the data structure. So now your data structure field names are FileNameDS.CUSTNO, FileNameDS.Name, FileNameDS.ADDR, etc --- and they no longer match the file names that are CUSTNO, NAME, ADDR becaause they're qualified by a data structure name.

There are many fixes to the problem, and none of them are difficult. Here are the fixes that come to mind:

a) Use EXTNAME instead of LIKEREC (though, keep in mind that the EXTNAME must be based on the external file name)

b) Continue using LIKEREC, but tell the RPG op-codes (READ, CHAIN, WRITE, etc) to read into a data structure. For example:

chain key file01 FileNameDs;

The 4th parameter to the chain opcode (which is the result field in fixed-format) contains the DS you want to read into.

c) Use a PREFIX on the F-spec to tell it to add the 'FileNameDs.' prefix onto the input specs so you don't HAVE to read into the DS.

FPMYFILE UF A E K DISK RENAME(FMYFILE:FILE01)
F PREFIX('FILENAMEDS.')

In this case, it'll generate input specs that read directly into your DS, since the input specs will read fields name FILENAMEDS.CUSTNO and FILENAMEDS.NAME instead of simply CUSTNO and NAME. (For example, again)

I'm sure there are additional options that haven't come to mind yet. But, hey, how many solutions do you need?

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

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

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