What is the difference between EVAL and MOVE in RPGLE

I recently got into the world of IBM RPG, so by writing code and looking at the code of other people, I found that some use Eval and some others use Move to perform the same tasks. Is there a difference between the two?

Thanks.

+6
source share
2 answers

Yes! There is a big difference between these opcodes. The RPG Reference Guide is a good place to start.

It is important to understand that RPG is a strongly typed language. This variable is declared a certain type with a certain size and is constant until the program is compiled. For character variables, only character operations are allowed. For numeric variables, only numeric operations are allowed. The compiler prohibits operations that are not of the type of the variable.

MOVE (and the MOVEL and MOVEA variants) are intended for moving (copying) bytes in memory. The intentional side effect of some MOVE operations is the conversion between a character data type and a numeric one. A book will be required to describe the use of the myriads that MOVEx has, but each of them is closely related to the fact that it moves (copies) bytes from this memory cell to this memory cell.

EVAL has a completely different core function: EVAL is designed to evaluate expression. Most languages ​​accept an expression like BASIC LET N = X^2 + Y + Z There were no expressions in the old (very old) RPG. Each line of code performed one and only one calculation. One could add this number to this or map this variable to this. If we had to implement the above calculation in a (very old) RPG, we would need something like:

 CX MULT XN CN ADD YN CN ADD ZN 

We can do this with EVAL N = X*X + Y + Z : EVAL N = X*X + Y + Z It is imperative to understand that this evaluation requires the compiler to create some internal working variables in order to hold intermediate results. it is important to understand the numerical accuracy of these intermediate fields before converting the old code perforce. This is because operations with a fixed code format MULT and ADD may very well be truncated, but EVAL will signal an overflow.

Why did I spend so much time on expressions and EVAL? Because one of the possible expressions is "copy this variable into this." EVAL will NOT convert between data types. If you need to convert, you need to specify a code like %dec() or %editc() to do this.

This is why you will see that MOVE is used even in the latest code; someone would rather have the compiler do implicit type conversions with MOVE rather than write explicit expressions for using them with EVAL.

Aside, even EVAL is dated. The current version (7.1) of RPG allows full use of free-form specifications. There is no "specification type" in column 6, no / free or / end-free: but a completely free form file, data and calculation descriptions. Older versions, such as 5.4, allow free form calculations after the / free statement. I did not write a fixed form calculation line after 10 years. EVAL is (mainly) optional in any current compiler.

+15
source

I like Buck's answer, but explaining it a little differently ...

MOVE results can only be known by examining the attributes of the source and target variables; along with a deep knowledge of how MOVE works in various scenarios. There's a lot of implications for MOVE.

While EVAL works mainly in one way. You can get the same results as in MOVE, but you will have to explicitly use various built-in functions (e.g. BIF) such as $ dec (),% char (),% subst (),

In terms of maintainability, EVAL wins. So the reason IBM left MOVE is that it's free format siblings.

+6
source

All Articles