?? One sets a field to 3, one increases the current value by 3. GnuCOBOL defaults to ZERO for numeric data items.
And yes, bad use can create bugs. ;-) It gets pretty easy to overflow a PIC 9(1) field for instance, when using ADD. MOVE in COBOL is right to left fill (high digits can end up truncated), which can be bad when you truncate off the billions but remain accurate in the pennies. ;-)
Although a simple MOVE 3 will always work actually, a PIC 9 numeric can always hold at least one digit, even a PIC 9(1) and PIC 9(0) won't compile.
Cheers,
Blue
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Add increases the value in a field if the value is numeric and can hold he size of the resulting arithmetic operation. Move, when the source and target are valid only replaces the value in the target field.
It is a good practice to always initialize the target in case of Add, there isn't a need to do so for the move.
If your addition results in a large number and you use a ON SIZE ERROR, the error will be caught but in case of a move, if the sending field is larger, truncation from left or right may occur.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everyone,
What 's the difference between this to syntax?
A bad use of this statement can create bugs?
Thanks for your help
?? One sets a field to 3, one increases the current value by 3. GnuCOBOL defaults to ZERO for numeric data items.
And yes, bad use can create bugs. ;-) It gets pretty easy to overflow a PIC 9(1) field for instance, when using ADD. MOVE in COBOL is right to left fill (high digits can end up truncated), which can be bad when you truncate off the billions but remain accurate in the pennies. ;-)
Although a simple MOVE 3 will always work actually, a PIC 9 numeric can always hold at least one digit, even a PIC 9(1) and PIC 9(0) won't compile.
Cheers,
Blue
Add increases the value in a field if the value is numeric and can hold he size of the resulting arithmetic operation. Move, when the source and target are valid only replaces the value in the target field.
It is a good practice to always initialize the target in case of Add, there isn't a need to do so for the move.
If your addition results in a large number and you use a ON SIZE ERROR, the error will be caught but in case of a move, if the sending field is larger, truncation from left or right may occur.