Not considering code readability, performance and operating system version,
what's the difference between MOVE
opcode and a C API such as ATOI
?
How does MOVE
internally works?
Example:
MOVE ALPHAFLD NUMRCFLD
EVAL NUMRCFLD = ATOI(ALPHAFLD)
In old O.S. (< V3R7) when should I use MOVE
and when should I use C APIs?
atoi() and atof() have "always" been available. But RPG programmers have been able to use %INT/%INTH or %DEC/%DECH to convert strings to numerics since V5R2, around the year 2002. %DECH and %INTH do rounding.
MOVE sometimes handles numerics in a bizarre way. For example, let's say you have a variable with 5 digits and 1 decimal position with a current value of 9876.5. Now you MOVE the value '123' to that variable. Try this code to see what bizarre result is in variable "num". Hint: It's not 123.
D num s 5p 1 inz(9876.5)
D msg s 20
C move '123' num
C eval msg = %char(num)
C msg dsply
C return