Doing a 'date' compare that has worked in the past. It is:
if mpatpmrc-LineOfBusiness = 'HOM' or 'DWF'
and w-compare-date-two >= w-auto-renewal-date
next sentence
The value in w-compare-date-two is '20170729'
The value in w-auto-renewal-date is '20171001'
nevertheless, it goes to next sentence!
w-compare-date-two is a group field and w-auto-renewal-date is not. I tried changing both to group fields, and got the same result. Then I changed them both to primary fields, and got the same result.
The values in hex look also show the w-auto-renewal-date is larger
w-compare-date-two H"3230313730373239"
w-auto-renewal-date H"3230313731303031"
I have changed w-auto-renewal-date to '99999999', it still goes to Next Sentence
I have changed w-compare-date-two to '00000000' with the same result. It is almost as if the compare does not care what is in the variables!
We are at MF Visual Cobol 2.3 and Visual Studio 2013.
What is the Else clause that accompanies the IF then ....? If there is none, the logic proceeds to the NEXT SENTENCE.
Doing a 'date' compare that has worked in the past. It is:
if mpatpmrc-LineOfBusiness = 'HOM' or 'DWF'
and w-compare-date-two >= w-auto-renewal-date
next sentence
The value in w-compare-date-two is '20170729'
The value in w-auto-renewal-date is '20171001'
nevertheless, it goes to next sentence!
w-compare-date-two is a group field and w-auto-renewal-date is not. I tried changing both to group fields, and got the same result. Then I changed them both to primary fields, and got the same result.
The values in hex look also show the w-auto-renewal-date is larger
w-compare-date-two H"3230313730373239"
w-auto-renewal-date H"3230313731303031"
I have changed w-auto-renewal-date to '99999999', it still goes to Next Sentence
I have changed w-compare-date-two to '00000000' with the same result. It is almost as if the compare does not care what is in the variables!
We are at MF Visual Cobol 2.3 and Visual Studio 2013.
What is the Else clause that accompanies the IF then ....? If there is none, the logic proceeds to the NEXT SENTENCE.
Doing a 'date' compare that has worked in the past. It is:
if mpatpmrc-LineOfBusiness = 'HOM' or 'DWF'
and w-compare-date-two >= w-auto-renewal-date
next sentence
The value in w-compare-date-two is '20170729'
The value in w-auto-renewal-date is '20171001'
nevertheless, it goes to next sentence!
w-compare-date-two is a group field and w-auto-renewal-date is not. I tried changing both to group fields, and got the same result. Then I changed them both to primary fields, and got the same result.
The values in hex look also show the w-auto-renewal-date is larger
w-compare-date-two H"3230313730373239"
w-auto-renewal-date H"3230313731303031"
I have changed w-auto-renewal-date to '99999999', it still goes to Next Sentence
I have changed w-compare-date-two to '00000000' with the same result. It is almost as if the compare does not care what is in the variables!
We are at MF Visual Cobol 2.3 and Visual Studio 2013.
This is to do with the precedence of AND and OR in COBOL. The rules are particularly confusing in the context of abbreviated conditions (as in this example), and I've seen very many examples of this sort of problem. The solution is to make use of parentheses to make the meaning unambiguous.
The following (correctly though counter-intuitively) displays "True" (though it would display "False if the first data item contained "DWF"):
01 mpatpmrc-LineOfBusiness pic xxx value "HOM".
01 w-compare-date-two pic x(10) value "20170729".
01 w-auto-renewal-date pic x(10) value "20171001".
if mpatpmrc-LineOfBusiness = 'HOM' or 'DWF'
and w-compare-date-two >= w-auto-renewal-date
display "True"
else
display "False"
end-if
...whereas the following displays "False" as expected.
01 mpatpmrc-LineOfBusiness pic xxx value "HOM".
01 w-compare-date-two pic x(10) value "20170729".
01 w-auto-renewal-date pic x(10) value "20171001".
if (mpatpmrc-LineOfBusiness = 'HOM' or 'DWF')
and w-compare-date-two >= w-auto-renewal-date
display "True"
else
display "False"
end-if
The IF statement in the first example:
if mpatpmrc-LineOfBusiness = 'HOM' or 'DWF'
and w-compare-date-two >= w-auto-renewal-date
...is actually parsed as:
if mpatpmrc-LineOfBusiness = 'HOM' or( mpatpmrc-LineOfBusiness = 'DWF'
and w-compare-date-two >= w-auto-renewal-date)
Doing a 'date' compare that has worked in the past. It is:
if mpatpmrc-LineOfBusiness = 'HOM' or 'DWF'
and w-compare-date-two >= w-auto-renewal-date
next sentence
The value in w-compare-date-two is '20170729'
The value in w-auto-renewal-date is '20171001'
nevertheless, it goes to next sentence!
w-compare-date-two is a group field and w-auto-renewal-date is not. I tried changing both to group fields, and got the same result. Then I changed them both to primary fields, and got the same result.
The values in hex look also show the w-auto-renewal-date is larger
w-compare-date-two H"3230313730373239"
w-auto-renewal-date H"3230313731303031"
I have changed w-auto-renewal-date to '99999999', it still goes to Next Sentence
I have changed w-compare-date-two to '00000000' with the same result. It is almost as if the compare does not care what is in the variables!
We are at MF Visual Cobol 2.3 and Visual Studio 2013.
This is the more comprehensive answer. Another measure would be to produce a condition value along the lines of
88 mpatpmrc-LineofBusiness-common Value "HOM", "DWF". If I remember correctly. Then test
If mpatpmrc-LIneOfBusiness-common And ....