Page 1 of 1

COBOL declaration and value of variable.

Posted: Fri Feb 17, 2023 7:25 pm
by HajiAmida
Hello,

Suppose i am declaring

Code: Select all

05 temp-a.
     10 temp-b pic x(1)
      10 temp-c pic x(1)

If I give if temp-a = '1' , means it is equivalent to if temp-b = 1 right? Anyone please confirm.

Re: COBOL declaration and value of variable.

Posted: Fri Feb 17, 2023 7:53 pm
by Robert Sample
Actually, you are not quite correct. COBOL compares equal sizes of variables, so saying

Code: Select all

IF TEMP-A = '1'
is really comparing TEMP-A to '1 ' -- COBOL will add the blank after the one so the comparison values are the same size. So depending upon the value of temp-c, the IF TEMP-A = '1' statement you posted may or not work the same as IF TEMP-B = '1'.