|
Scott, OF course passing by value on the first parameter would help, but not solve the issue at hand. We still need to use %ADDR as you pointed out. The other changes would have no impact on what I'm looking. I don't think there's a clear answer to this question.... something of an "anything" parameter is want I'd like to be able to specify, but without using %ADDR(). Bob Cozzi Cozzi Consulting www.rpgiv.com -----Original Message----- From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Scott Klement Sent: Thursday, October 09, 2003 6:22 PM To: RPG programming on the AS400 / iSeries Subject: Re: Help with parameter passing > .....D myFunct PI > D anytype * > D nLen 10I 0 > D nDec 10I 0 > D type 10I 0 > > Could I call myFunct and pass a characte field, or a numeric field > or a data field? If so, could I avoid using %ADDR to do it, or do I > need to wrap the variable in %ADDR? Actually the way you have this coded, you couldn't do either. Because your parms are passed by reference, you MUST pass a variable for each parameter. Like this: D myFunct PR D anytype * D nLen 10I 0 D nDec 10I 0 D type 10I 0 D ALPHAVAR C CONST(1) D ptr S * D myvar S 100A D len s 10I 0 D dec s 10I 0 D type s 10I 0 /free ptr = %addr(myvar); len = %len(myvar); dec = 0; type = ALPHAVAR; myFunct(ptr: len: dec: type); /end-free Personally, I think that's really ugly code. I don't see why you'd want to be able to change the address, length, dec or type parms... so why require them to be stored in variables? Instead, pass the parms by value: D myFunct PR D anytype * value D nLen 10I 0 value D nDec 10I 0 value D type 10I 0 value D ALPHAVAR C CONST(1) D myvar S 100A /free myFunct(%addr(myvar): %len(myvar): 0: ALPHAVAR); /end-free I think that code like this is much easier to read than the first example. Of course, that's only a matter of opinion. At any rate, you cannot avoid using %addr() unless you want to have a separate prototype for each data type. > My guess is that I would need to do pass %ADDR(CustNo), but is that > allowed when I may want to change the data in the called proc? > (i.e, I don't want to use CONST). Yes, in fact passing the %addr(MYVAR) by value results in the same underlying machine code as passing MYVAR by reference. In either case what's actually being passed from one procedure to another is an address. The procedure that you're calling uses this address to access an area of memory. Since it's the same area of memory as the caller uses, the changes are visible to the caller. Since I passed the "anytype" parameter by VALUE, the newly called procedure's changes to "anytype" won't be visible to the caller -- but remember, "anytype" is not the data we want to change! It's the ADDRESS of the data we want to change. We don't need to change the address. Just the data that's at that address. Maybe it helps to think of an address the same way you think of an RRN (relative record number) of a file. For example, if you call a subprocedure and pass an RRN of 76, and you protect that 76 so the procedure cannot change it... That doesn't prevent the procedure from updating the record #76! It just prevents it from being able to change the 76 to a 94. Memory addresses are the same basic idea... Anyway, the hard part about allowing "any" type of parameter to a procedure is not going to be the prototype :) It's going to be figuring out how to write RPG code that works with any possible variable type, with any possible length and any possible number of decimal places. That'll be a lot of work. It's doable though... I've done it.. _______________________________________________ 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.
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.