|
Hi Jerry, Yes, this is a fine technique (generally known as abstraction), that can greatly simplify the interface to a procedure. In general, you would want to abstract data elements that are commonly used together, then apply that abstraction across all routines that work with that data-type. Not only does this technique save you the headache of typing in all those parms every time you call a procedure, it also allows you to change the contents of that abstract datatype as you need to. You might want to use qualified naming on the DS definition, so that you can create copies of this abstract data type wherever you need. Using qualified DS mimics the object.attribute reference that is so common in OO languages, and generally makes your programs much easier to understand. An easy to understand example of this is Address.... D t_Address DS qualified D Attn 30 D Street 30 D City 20 D State 2 D PostalCd 10 D l_BillingAddr likeds(t_Address) D l_ShipToAddr likeds(t_Address) D l_ShipFromAddr likeds(t_Address) I have been recommending to my colleagues to pick up a copy of Steve McConnell's "Code Complete" Second Edition. Don't be scared off because it's published by Microsoft Press.... It's an excellent compendium of programming best-practices, many of which are applicable to ILE on the iSeries. In general, ILE developers can learn a great deal from this book. hth, Eric DeLong Sally Beauty Company MIS-Project Manager (BSG) 940-297-2863 or ext. 1863 -----Original Message----- From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of Jerry Adams Sent: Wednesday, October 04, 2006 7:50 AM To: RPG Midrange Subject: Passing a data structure as a parm I have a whole mess of data elements that I need to pass to another program so I thought that using a data structure would be more concise than something like: PGM(parm1:parm2:...parm13); . I think Bob's book (4th ed.) explained how to do this with prototypes, but, since it'll be awhile before I can actually get around to testing this, I thought perhaps someone might have suggestions or criticisms (both willingly accepted) of how I implemented it. Code samples are below. D SIPROTO DS D #End 1A D blitm# D blsqty D bltxcd D bllc01 D bllc02 D bllc03 D blcust D blref# D dlspst D dlsp01 D dlsp02 D dlsp03 D SIU002 PR ExtPgm('SIU002') D SIUAddr Like(SiProto) Later the actual "call": SIU002(SiProto); SIU002 (the humble callee) has this as the prototype: D SIU002 PR D Parms Like(SiProto) D SIU002 PI D InParms Like(SiProto) D SiProto DS Based(pSiProto) D #End 1A D #Item 5S 0 D #Qty 5P 0 D #TaxCode 5A D #Local1 5A D #Local2 5A D #Local3 5A D #Cust 5S 0 D #Ref 6S 0 D #StStamps 5P 0 D #Lc1Stamps 5P 0 D #Lc2Stamps 5P 0 D #Lc3Stamps 5P 0 Then, as the first step in the program: pSiProto = %Addr(inParms); Am I doing this right? Thanks.
As an Amazon Associate we earn from qualifying purchases.
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.