× 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.



Subject: Re: Alternative to MOVEA?
To: rpg400-l@midrange.com
Date: Mon, 14 Jan 2002 12:48:32 -0500
Reply-To: rpg400-l@midrange.com

Mike wrote:
>I'm trying to join the twentieth century here and replace all my MOVEs
>with EVALs, but this one has me stuck. If I have a 9-element array  RA and
>I want to fill the last three elements with, say, "X", I can code:
>
>MOVEA          *ALL('X')           RA(7)
>
>Is there a way I can do the same thing  using EVAL?

Barbara wrote:
>Here's one way:
>
>C           for     i = 7 to %elem(RA)
>C           eval    RA(i) = *all'X'
>C           endfor
>
>Here's another way that will probably perform somewhat better,
>if the number of elements is very large (which it's not in
>your case):
>
>D data      s             65535a    based(pData)
>D pData     s                  *
>C           eval    pData = %addr(RA(7))
>C           eval    numElems = %elem(RA) - 7 + 1
>C           eval    %subst(data : 1 : %size(RA) * numElems)
>C                       = *ALL'X'
>
>Mike, in an earlier thread, I made the bold claim that MOVEA was
>a useless opcode, now that the string builtins are so powerful.
>I challenged the mailing list to come up with a reasonable use
>for MOVEA.  Do we have a candidate here?  What's the problem
>being solved by setting those elements to 'X'?

Technically, the using a FOR loop is not the same as using
opcode MOVEA.  For *ALL'X', there's no problem.  But consider
MOVEA *ALL'abc' ARR(7), where ARR is defined as, say, 10A.
In this case, using a FOR loop to initialize elements
individually is clearly not the same.  Barbara's proposed
solution using %SUBST would work properly for the general
case, but it's not a pretty piece of coding.  (And of course
it fails for arrays larger than 64K bytes.)

If you always know that you just want to set the last three
array elements, I'd probably just code it as:

     RA(%elem(RA)-2) = *all'X';
     RA(%elem(RA)-1) = *all'X';
     RA(%elem(RA)  ) = *all'X';

Anyways, personally, I don't think this qualifies as a
"reasonable" use of MOVEA.  For most "normal" situations,
the FOR loop is a good alternative.

Cheers!  Hans

Hans Boldt, ILE RPG Development, IBM Toronto Lab, boldt@ca.ibm.com



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.