evaluate true. when false but code is executed



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

evaluate true. when false but code is executed

Postby tivrfoa » Mon Feb 29, 2016 6:34 pm

Hello everyone,

Please help me with the problem below.
I don’t understand why it entered the WHEN FUN-BNC AND NOT EVT-BNC code when both FUN-BNC and EVT-BNC are false.
I think it is related with the compilations warnings, that I didn’t understand as well. :/

000218        01 FUN-INCORPORADO        PIC  9(001) VALUE 0.
000219           88 FUN-NAO-INCORPORADO VALUE 0.            
000220           88 FUN-BESC            VALUE 1.            
000221           88 FUN-BEP             VALUE 2.            
000222           88 FUN-BNC             VALUE 3.            

000224        01 EVT-INCORPORADO        PIC  9(001) VALUE 0.
000225           88 EVT-NAO-INCORPORADO VALUE 0.            
000226           88 EVT-BESC            VALUE 1.            
000227           88 EVT-BEP             VALUE 2.            
000228           88 EVT-BNC             VALUE 3.  

001102            DISPLAY 'FUN-INCORPORADO ' FUN-INCORPORADO
001103            DISPLAY 'EVT-INCORPORADO ' EVT-INCORPORADO
001104            EVALUATE TRUE                                                
001105              WHEN FUN-NAO-INCORPORADO AND NOT EVT-NAO-INCORPORADO      
001106                MOVE 'some text
001107       -             '
more text.' TO TX-ERROR                        
001108                PERFORM GRAVAR-ERRO-E-ENCERRAR                          
001109              WHEN FUN-BESC AND NOT EVT-BESC                            
001110                MOVE '
some text
001111       -             'more text.' TO TX-ERROR                      
001112                PERFORM GRAVAR-ERRO-E-ENCERRAR                          
001113              WHEN FUN-BEP AND NOT EVT-BEP                              
001114                MOVE 'some text
001115       -             '
more text.' TO TX-ERROR                      
001116                PERFORM GRAVAR-ERRO-E-ENCERRAR                          
001117              WHEN FUN-BNC AND NOT EVT-BNC                              
001118                MOVE '
it displays this message
001119       -             'more text.' TO TX-ERROR                      
001120                PERFORM GRAVAR-ERRO-E-ENCERRAR
001121       * Incorporados Optantes                                          
001122              WHEN NOT (EVT-BESC OR EVT-BEP OR EVT-BNC)                  
001123                MOVE 'some text
001124       -             '
more text.' TO TX-ERROR                      
001125                PERFORM GRAVAR-ERRO-E-ENCERRAR                          
001126            END-EVALUATE                


Output of the two displays above:
FUN-INCORPORADO 0
EVT-INCORPORADO 0
GRAVAR-ERRO-E-ENCERRAR displays the message in TX-ERROR and exits the program.

The compilation gave me these warnings:
0 WHEN FUN-BNC AND NOT EVT-BNC
0 MOVE '...
W CODE FROM "MOVE (LINE 1902.01)" TO "MOVE (LINE 1902.01)" CAN NEVER BE
EXECUTED AND WAS THEREFORE DISCARDED.

It gave this warning for all WHEN conditions, except for the first and last one.
tivrfoa
 
Posts: 84
Joined: Wed Aug 22, 2012 6:35 pm
Has thanked: 60 times
Been thanked: 0 time

Re: evaluate true. when false but code is executed

Postby tivrfoa » Mon Feb 29, 2016 7:35 pm

sorry folks.
it actually goes to the last WHEN condition. The text was the same ... copy/paste problem :oops: :oops: :oops:

But I still don't understand the compilation warnings.
I tried to replace MOVE with STRING, but I got the same warning messages.
tivrfoa
 
Posts: 84
Joined: Wed Aug 22, 2012 6:35 pm
Has thanked: 60 times
Been thanked: 0 time

Re: evaluate true. when false but code is executed

Postby BillyBoyo » Mon Feb 29, 2016 8:33 pm

Are you using the OPT(imizer) compile option?

These users thanked the author BillyBoyo for the post:
tivrfoa (Mon Feb 29, 2016 9:04 pm)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: evaluate true. when false but code is executed

Postby tivrfoa » Mon Feb 29, 2016 9:09 pm

BillyBoyo wrote:Are you using the OPT(imizer) compile option?

I searched for "OPT" in the JCL that compiled the program and the only time I found was:
XXLKED EXEC PGM=IEWL,
XX PARM='OPTIONS=OPTS'

But you are right, it's some optimization that the compiler is doing.
I changed the code to set a value to the FUN-INCORPORADO variable before the EVALUATE, and the warnings disappeared.

Thank you. =)
tivrfoa
 
Posts: 84
Joined: Wed Aug 22, 2012 6:35 pm
Has thanked: 60 times
Been thanked: 0 time

Re: evaluate true. when false but code is executed

Postby BillyBoyo » Mon Feb 29, 2016 9:51 pm

Have a look at the first page of the compile listing, it shows you all the values. The optimizer spotted that nothing was being set for one of your fields, so knew which WHENs were possible and which were impossible.

These users thanked the author BillyBoyo for the post:
tivrfoa (Mon Feb 29, 2016 10:05 pm)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post