Search code examples
cobol

Why do we check if empty before we move?


I see a lot of codes like this:

if WA > SPACES
  move WA to WA2
end-if

What are the advantages that this is checked? Is it more efficient to check if it is empty than to just move it anyways?

Additional information:

WA and WA2 can be simple structures (without fillers) but also just simple attributes. They are not redifined and typed as chars or structures of chars. They can be either low-values (semantically NULL) or have alphanumeric content.


Solution

  • Nobody can tell you what the actual reason is except for the people who coded it, but here is a very probable reason:

    Usually this is accompanied with an ELSE that would cover what happens if the value is less than spaces, but in this case I would assume that what every happens to this data later is relying on that field NOT being LOW-VALUES or some funky non-displayable control character.

    If I had to guess, I would assume that WA2 is initialized to spaces. So doing this check before the move ensures that nothing lower than spaces would be moved to that variable. Remember, less than spaces does not mean empty, it just means that hex values of that string are less than X'40' (so for example is the string was full of low values, it would be all X'00'. So I would guess that its more about ensuring that the data is valid than efficiency.