Menu

Use Syntax Cobol

M_D
2021-09-16
2021-09-16
  • M_D

    M_D - 2021-09-16

    Hi everyone,

    What 's the difference between this to syntax?
    A bad use of this statement can create bugs?

    « MOVE 3 TO INDICE »
    « ADD  3 TO INDICE »
    

    Thanks for your help

     
    • Brian Tiffin

      Brian Tiffin - 2021-09-16

      ?? 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

       
  • Emmad

    Emmad - 2021-09-16

    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.

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.