Tuesday, April 03, 2007

More RPG IV /FREE

So speaking of the MOVE command. How many of you used that to transfer between character and numeric fields? Probably everyone of us has done that.

And you say, wait in RPG IV, there is no MOVE command, and EVAL doesn't do conversions. Well you'd be right, but better tools there be now.

Let's take just character to number. Let's say we have "123456789" and want to turn that into the number 123456789. Previously you'd have just done

MOVE STRING NUMBER

Now, let's see the RPGIV command ...

NUMBER = %Dec(STRING) or NUMBER = %Dec(STRING: 9: 0)

There, that wasn't painful was it?

The huge flexibility is to be able to convert that string to any formatted number type, even with decimals. The 9 and 0 represent the standard decimal declaration for numerics.

Now to go the other way, we have a couple of options ...

STRING = %Char(NUMBER)
this left justifies in the string and trims leading zeros.

Or...

STRING = %EditC(NUMBER: 'X')
this right justifies and keeps leading zeros.

Both are excellent choices and I was able to make use of both just this last week in a program where I had to do conversions.

The above covers just two aspects of MOVE replacement. RPGIV also includes some new DATE BIF (built in functions).

More later, happy programming,
Tojosan

No comments: