Making Dollars and Cents of Free-Format RPGLE
by Stephen West
Originally published in System iNEWS Magazine, December 2010
About half the companies I work with as a consultant want to keep all their application development in fixed-format RPG. Most of the time it's because the shop's programmers already know the language and are immediately productive.
When learning free-format RPGLE, programmers spend a fair amount of time figuring out how to do tasks that were easy in fixed format. An example of this is splitting a dollar amount into the whole dollar value and the cents value and storing them as separate fields.
The following example shows just how simple it is in [old] fixed-column RPG:
D DLRAMT S 10s 2 Inz(876.54)
D DOLLARS S 4p 0
D CENTS S 2p 2
C Z-ADD DLRAMT DOLLARS
C Z-ADD DLRAMT CENTS
Now, DOLLARS contains the value 876, and CENTS contains the value .54.
That was easy!
Now for the [new] free-format RPGLE version. Zero and Add (Z-ADD) is no longer supported; so that's out. We could do it with MOVE, but that's gone, too. What's a programmer to do? Well, the best course of action would be to figure it out once and then reuse it whenever necessary. Here goes ...
D DLRAMT S 10s 2 Inz(876.54)
D DOLLARS S 4p 0
D CENTS S 2p 2
/free
DOLLARS = getDollars(DLRAMT);
CENTS = getCents(DLRAMT);
/end-free
Again, DOLLARS = 876, and CENTS = .54.
But okay, something's missing. How about the logic behind the getDollars and getCents procedures? That code is in Figure 1. Figure 2 and Figure 3. Figure 1 contains the procedure prototypes that need to be included near the top of the code. Figure 2 contains the getDollars procedure. Figure 3 contains the getCents procedure.
(WARNING: shameless, corny humor to follow.) Now you are one step closer to being free.
Figure 1. Calling the getDollars and getCents procedures
Figure 2. getDollars procedure
Figure 3. getCents procedure
|