Monday, April 02, 2007

RPG on the AS/400 - /FREE?

Do you /FREE? If you are doing RPG IV, you should be.

Tired of the C specs and MOVE commands? Itching to create your own commands? Then FREE is for you.

Ever get frustrated moving a 5 character field into a 6 character one and realize you didn't justify it to the left? No more need for MOVEL vs MOVE or MOVER. If you want to set one string equal to another how about String1 = String2?

Sweet yes? Can you tell I've got a thing about my programming?

Working through your code and suddenly realize you an account number from the order you have? Don't want to do the series of three chains and etc in the middle of your current logic? Write your own procedure and stow its code away somewhere else:

getAccount(order);

Just declare and define the code behind getAccount somewhere else. So where can that somewhere else be? Heck, at the bottom of your current code or even in another source file, that can be /COPY in or better yet, called directly from the other program or module.

It's as easy as:

D getAccount PR
D orderNum 10 0

There, you've just declared the getAccount procedure. Want to stick that at the bottom of your source?

P getAccount B
D getAccount PI
D order 10 0

... your code here ...

P getAccount E

There you have it, all you need to put getAccount where it belongs, out of the way of your core logic. The great thing if you can /FREE procedures or code in regular C specs, whichever is most convenient.

But, if you are going to do CHAIN commands, are you still using indicators? RPG IV supports BIF (built in functions) such as %Found.

Instead of CHAIN with an indicator, how about this:

Chain (keyField) fileFormat;
If %Found;
... your logic here ...
EndIf;

Good stuff I say. And it makes your logic easier to read.

Enough for tonight, but go try this out, come back and tell me about it.

More RPG IV and FREE to come.

Your programmer nerd buddy,
Tojosan

No comments: