John,
A couple of things:
First, why are you defining the subfields as being overlays of another
subfield? Why not simply define them as e.g.:
D RCVM0100 DS 65535 Qualified
D BytesRtn 10I 0
D BytesAvail 10I 0
D MsgSeverity 10I 0
D MsgID 7A
D MsgType 2A
D MsgKey 4A
D 7A
D CCSIDCvtSts 10I 0
D RplDtaCCSID 10I 0
D RplDtaLenRtn 10I 0
D RplDtaLenAvl 10I 0
It's a lot simpler and easier to read, I think. There's no reason to use
overlays (just like there isn't really a reason to name reserved fields in
RPGLE, so I leave them blank). It's all just style, though, since both
methods work fine.
Second, if you're going to use a template structure and then refer to
another LIKEDS structure in your program, then you should base the template
structure on a dummy pointer, otherwise you're simply defining two
structures (both of which take up memory). In fact, in my example above, I
didn't define a separate based-on-dummy template - I simply use the RCVM0100
structure in my program - it's not (in my opinion) significantly less
readable to refer to RCVM0100.MsgID than it is to refer to MsgInfo.MsgID.
Again, just a style thing. Although the likes of Bob Cozzi and Scott Klement
would probably chastize me for it, I *very* rarely use template structures
and LIKEDS, unless there are likely to be multiple copies of the same
structure in the same procedure (or module) which need to be used at the
same time.
As far as your actual question goes, I typically define several large
stand-alone variables and load them, as Charles suggests. However,
I typically define a fixed-length constant field which refers to the offset
of the variable-length data and use that:
D RplDta S 3000A Inz
D RCVM0100DataOS C Const(49)
RplDta = %subst( RCVM0100 : RCVM0100DataOS : RplDtaLenRtn );
or maybe if I'm being lazy, I just use:
RplDta = %subst( RCVM0100 : 49 : RplDtaLenRtn );
Yes, I know it's 'bad' to use hard-coded 'magic' numbers, but since IBM's
not going to change the layout of any existing API formats (they'll just
create new ones), they're pretty much cast in stone.
HTH,
Rory
On 6/26/07, johnking@xxxxxxx <johnking@xxxxxxx> wrote:
All,
Q) How to define a DS to retrieve variable-length data from an API? The
goal is
to define an /include member that can be used in V5R3 RPGLE.
As an Amazon Associate we earn from qualifying purchases.