Dave,

On 12/9/2013 12:44 PM, Dave Shaw wrote:

So would this be preferable?

num4 = %dec(%subst(%char(num6):1:4):4:0);



This code is wrong. %char() will remove leading zeros, and trim the resulting blanks. So if the input was '000111' the MOVEL example results in '0001', but your %CHAR() technique would result in '111 '

If you want to use %dec() and %subst() you'll need to also use %EDITC to preserve the leading zeros.

num4 = %dec(%subst(%editc(num6:'X'):1:4):4:0);

Personally, my vote would be %div(num6:100) which is every bit as valid and self-documenting as MOVEL. With both MOVEL and %DIV you have to be familiar with how the feature (meaning the MOVEL opcode or the %DIV BIF) works. If you're not familiar with MOVEL, then it won't be self-explanatory. Likewise, if you're not familiar with %DIV, it won't be self explanatory, either. The difference here is that RPGers tend to be more familiar with old obsolete things than they are with things released in the past 15 years... but I refuse to use THAT as a reason not to use new things.

Using %DIV is NOT 'magic' like the old "use mult to flip dates" technique, as %DIV is documented to always return an integer, so there's no question that it'll always strip the decimal places.


This thread ...

Replies:

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

This mailing list archive is Copyright 1997-2026 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.