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.