There is no equivalent to the MOVE/MOVEL operations in /FREE syntax. In fact, there is no equivalent to the MOVE/MOVEL operations when using the EVAL operation.
This has led to numerous problems when attempting to move existing code to RPG IV's /FREE syntax. If you notice, the conversion tools do not convert MOVE/MOVEL operations to /FREE syntax, simply because they cannot.
Each individual MOVE/MOVEL operation (hereinafter referred to as "MOVE") must be individually evaluated for conversion and converted by hand.
For me, the biggest problem area is converting between numeric and character data. EVAL just doesn't do it.
In previous articles, I have explained how to convert character fields containing numeric data into true numeric. In traditional, fixed-format syntax, you would use the MOVE operation code, and it would just work. With the EVAL operation, there are three options:
If no decimal positions exist in the field, you can use the C runtime function atoll() to convert from character to numeric.
- If you are on V5R2 or later, you can use the %INT built-in function to do the same thing.
- If the value contains decimal positions, you need to use the CharToNum() function in the RPG ToolKit; if you are on V5R2 or later, the %DEC built-in function will do a similar job to CharToNum, but it's not as good in all situations.
But today, I'm talking about going the other way around: converting a numeric value to a character field. Believe it or not, there is a fairly easy solution to this problem: the %EDITC built-in function.
You can use the little-known "X" edit code to convert numeric fields to character and retain the leading zeros on the value. Then, when used in conjunction with the EVAL operation or the assignment (equals sign) on /FREE syntax, it converts a number to character and zero fills the result.
The following example illustrates three styles for implementing the techniques described in this week's tip: (1) The MOVE operation, (2) the EVAL operation in traditional RPG IV, and (3) the assignment statement in /FREE syntax.
D AcctNbr S 7P 0 Inz(5678)
D szAcct1 S 7A
D szAcct2 S 7A
D szAcct3 S 7A
C MOVE AcctNbr szAcct1
C eval szAcct2 = %EditC(AcctNbr: 'X')
szAcct3 = %EditC(AcctNbr: 'X');
C eval *INLR = *ON
Bob Cozzi has been programming in RPG since 1978. Since then, he has written many articles and several books, including The Modern RPG Language--the most widely used RPG reference manual in the world. Bob is also a very popular speaker at industry events such as RPG World and is the author of his own Web site and of the RPG ToolKit, an add-on library for RPG IV programmers.