I've never completely understood this, but in having a file name on a
D-spec assuming the definition of the file (instead of explicitly
restating the definition), you have to be careful with zoned vs packed
fields. I've been bit by this before.
Field1 = 3s 0 on file.
D Field1 // equates to 3p 0 for the program.
Then if I pass Field1 by reference to a procedure (not Const) that has a
parameter that is "Like( Field1 )", I get an error since the program
says I'm passing a 3s 0 into a 3p 0 parameter.
So to fix it, I do this on my D spec:
D Field1 3s 0 // so the program doesn't change it to 3p 0
Kurt Anderson
Application Developer
Highsmith Inc
-----Original Message-----
From: rpg400-l-bounces+kjanderson=highsmith.com@xxxxxxxxxxxx
[mailto:rpg400-l-bounces+kjanderson=highsmith.com@xxxxxxxxxxxx] On
Behalf Of Rory Hewitt
Sent: Friday, August 31, 2007 2:06 PM
To: RPG programming on the AS400 / iSeries
Subject: Re: Defining datastructure with ExtName/LikeRec
Scott,
<snip>
LIKEREC defines a data structure to be like a record format. That
record format must have already been brought into your program via an
F-spec at the top of the program.
LIKEREC guarantees that the data structure is identical to the input or
output buffer that the RPG program will be using to interact with the
database, that's important when you want to read a raw record into the
structure (which is what happens when you list the DS in the result
field of a RPG I/O opcode, or if you use something like the _Rreadx()
APIs.) </snip>
This has always puzzled me - if you need to have defined a LIKEREC's
file in an F-spec, why would you want to use the _R* API's to access the
file, rather than RPG's built-in file I/O opcodes?
As far as reading into a data-structure, one thing that lots of people
seem to forget (or just be unaware of!) is that if you specify an
unqualified, unprefixed EXTNAME data-structure, every file read/chain
will *automatically
* populate it, e.g.:
D FileDS E DS Extname(YELMCST00L)
...
/free
read(e) YELMCST00L;
/end-free
After the read, the FileDS data-structure contains the record data. You
can then copy the entire DS into a separate (qualified) data-structure
if you want. True, it's not as 'obvious' as coding a LIKEREC
data-structure on the READ opcode itself, but that's effectively what
you've done...
One benefit of using EXTNAME is where you have a program which might
want to read a number of different files - you simply define a
program-described file in the F-specs (complete with the EXTFILE
keyword), override to the file you want, read the file into a generic
data-structure and then copy that data-structure into the EXTNAME'd
data-structure.
I also make use of the ability to add additional fields and/or provide
overlays of exisitng fields, e.g.:
* Subfile record data-structure
D SFLRCDDS E DS Extname(YELMCST00L) Prefix(Z_)
D Z_CstID1 1A Overlay(Z_CstID:1)
D Z_CstInf47 47A Overlay(Z_CstInf:1)
D Z_CstInf48 3A Overlay(Z_CstInf:48)
D SflSel 1A
D Z_DspInf 50A
<snip>
Also, if a file has fields that are input-only or output-only, EXTNAME's
format might not match the layout of the record.
</snip>
With the exception of display file record formats, these aren't an issue
with the vast majority of files, are they?
Rory
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing
list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.