× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Scott

Doesn't the %replace limit what will get changed as well as the %subst
limits what gets changed in F1?

John

----- Original Message -----
From: "Scott Klement" <klemscot@klements.com>
To: <rpg400-l@midrange.com>
Sent: Tuesday, November 26, 2002 11:36 AM
Subject: Re: Passing By Reference


>
>
> On Tue, 26 Nov 2002, JJW wrote:
> >
> > Dow (%scan(C1:F1) > *Zeros)  AND  (%scan(C1:F1) <= InLen);
> >     %subst(F1:1:InLen) = %replace('':F1:%scan(C1:F1):1);
> >
> >     F1 = %replace(' ':F1:InLen:1);
> >
> > endDO;
> >
>
>
> Any time you have a 'F1 = <anything>' in your subprocedure, and F1 is a
> *VARSIZE parameter, you will have problems.
>
> Why is that?  Okay, I'll explain.
>
> The 'eval' op-code (Which is what you're using here, it's implied in
> a free form statement that has no op-code) always sets every character
> when you do an assignment.
>
> For example, if you have a 25A variable, and you do:
>
>               My_25A = 'X';
>
> The eval op-code not only sets the first character to an X, it also sets
> the other 24 characters to spaces.
>
> That's a problem with a *VARSIZE variable, because the compiler doesn't
> actually know the length of the variable.   If you have a 32766A which
> is *VARSIZE, then the compiler ALWAYS treats it as if it's 32766 bytes
> long.   It doesn't matter that you only passed 10 bytes, it still thinks
> it's 32766 bytes long.
>
> So, if you've passed a 10A as a 32766A *VARSIZE, and do a
>
>         F1 = 'X';
>
> It sets the first byte to an X.  It also sets the other 32765 bytes to
> blanks.   Since you only passed 10 bytes, you are overwriting 32755 bytes
> with blanks which don't belong to you.   Those bytes could be ANYTHING.
> It might end up having no effect, but then again, it might end up
> causing mass chaos, including program crashes that are extremely difficult
> to track down.
>
> Therefore, I'll say it again.   If you use *VARSIZE, don't EVER do an
>     F1 = <anything>
>
> That's why you need to use
>     %subst(F1:1:InLen) = <anything>
>
> That way, you're telling the compiler 'ONLY work with InLen bytes of
> my variable!'
>
>
> _______________________________________________
> This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
> To post a message email: RPG400-L@midrange.com
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/cgi-bin/listinfo/rpg400-l
> or email: RPG400-L-request@midrange.com
> 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 thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.