Are MOVE and MOVEL Obsolete?
Published: July 15, 2009
by Ted Holt
I've been writing free-format RPG calculations for several years now, yet I still find myself missing a couple of old friends. No, I don't mean GOTO and TAG. I refer to MOVE and MOVEL. Usually I can find a way to avoid them, but occasionally, it gets a bit difficult.
For example, suppose I read an eight-digit numeric field that identifies a customer. Into this field are loaded two pieces of information. The first two digits are a company number. The last six digits contain a customer number. (This is by no means far-fetched; we have been doing this sort of thing since our industry was known as data processing.)
D AccountNumber s 8 0
D Company s 2 0
D Customer s 6 0
How do I split the field into two variables? Here's one way.
Company = %div(AccountNumber: 1000000);
Customer = %rem(AccountNumber: 1000000);
Company = AccountNumber / 1000000;
Customer = AccountNumber - Company * 1000000;
All this multiplication and division seems overly complicated to me. I can understand multiplying a quantity by a price in order to invoice a customer. But multiplying and dividing to get a customer number strikes me as inappropriate, unsuitable, inapt, improper, malapropos, incongruous, and out of place. And I fail to see how multiplication and division could ever perform as efficiently as memory-copy operations.
Let's complicate it somewhat by making the variables a tad larger.
D SomeNumber s 63 30
D Whole s 33 0
D Fraction s 30 0
Here I want to take a very large number and split it into two portions--the part left of the decimal point and the part right of the decimal point. Notice that both resulting variables have zero decimal places. Can you think of an easy, straightforward way to load WHOLE and FRACTION using multiplication and/or division?
This makes more sense to me.
C movel SomeNumber Whole
C move SomeNumber Fraction
Fortunately, I don't often encounter situations that I cannot avoid MOVE and MOVEL. But when I need them, I use them.
Today's tip: Free-format calculations are far better than fixed-format calcs, but like everything else on this planet, they're not perfect. When you need a fixed-format op code, don't be afraid to use it.
Post this story to del.icio.us
Post this story to Digg
Post this story to Slashdot