Being holiday season most of the real COBOLlers are away leaving me - newish to COBOL - to pick up the pieces when a production program failed in testing (well, it was my new program that was proving a feed to this other program). What I eventually found was that a SUBTRACT seemed to be not being executed i.e. the variables involved were unchanged from before to after. This is replicated in the following snippet. Test A is how it is in production and test B is how I am going to fix it.
Can anyone explain WHY nothing appeared to happen? Just reading it all values should end up being 0. The answer could be in the assembler code but I have not gone there yet - I am not hot on assembler, in fact, just above zero!
working-storage section.
01 a-table.
05 number-1 occurs 2 pic 9999v99 comp-3.
77 i pic 9 comp.
77 j pic 9 comp.
*==========================================================
procedure division.
a000-mainline section.
move 2 to i j
* Test A
move +10 to number-1(2)
display 'I: >' number-1(i) '<; J: >' number-1(j) '<'
subtract number-1(i) from number-1(j)
number-1(i)
display 'I: >' number-1(i) '<; J: >' number-1(j) '<'
* Test B
move +10 to number-1(2)
display 'I: >' number-1(i) '<; J: >' number-1(j) '<'
subtract number-1(i) from number-1(j)
subtract number-1(i) from number-1(i)
display 'I: >' number-1(i) '<; J: >' number-1(j) '<'
01 a-table.
05 number-1 occurs 2 pic 9999v99 comp-3.
77 i pic 9 comp.
77 j pic 9 comp.
*==========================================================
procedure division.
a000-mainline section.
move 2 to i j
* Test A
move +10 to number-1(2)
display 'I: >' number-1(i) '<; J: >' number-1(j) '<'
subtract number-1(i) from number-1(j)
number-1(i)
display 'I: >' number-1(i) '<; J: >' number-1(j) '<'
* Test B
move +10 to number-1(2)
display 'I: >' number-1(i) '<; J: >' number-1(j) '<'
subtract number-1(i) from number-1(j)
subtract number-1(i) from number-1(i)
display 'I: >' number-1(i) '<; J: >' number-1(j) '<'
Output:
From test A:
I: >001000<; J: >001000< Before subtract
I: >001000<; J: >001000< After subtract
I: >001000<; J: >001000< After subtract
From test B:
I: >001000<; J: >001000< Before subtract
I: >000000<; J: >000000< After subtract
I: >000000<; J: >000000< After subtract
The key to the problem is that it is the same piece of storage being referred to for all variables involved.