I recently found a bug in a pgm where I had coded the following:
========================================================
/***** Program Variables */
DCL &Pfx1 *CHAR 1
DCL &Pfx2 *CHAR 2
DCL &Pfx4 *CHAR 4
RCVF
MonMsg MsgID(CPF0864) Exec(Goto End_Delete) /* E.O.F. */
ChgVar &Pfx1 %SST(&Package 1 1)
ChgVar &Pfx2 %SST(&Package 1 2)
ChgVar &Pfx4 %SST(&Package 1 4)
If ((&Library *NE 'QRECOVERY ') +
*OR (&Library *EQ 'QRECOVERY ' +
*AND (Pfx2 *EQ 'OW' *OR &Pfx1 *EQ 'T' *OR &Pfx4 *EQ 'JDBJ'))) DO
/* Alloc. first to chk for locks */
AlcObj Obj((&Library/&Package *SQLPKG *EXCL)) Wait(5)
MonMsg MsgID(CPF1002 CPF1085) Exec(GoTo CmdLbl(AllocErr)) /*Alloc. err.*/
/* Delete */
DltSqlPkg &Library/&Package
EndDo
========================================================
The problem was that I had inadvertantly left out the ampersand on var. Pfx2 in "*AND (Pfx2 *EQ 'OW' *OR &Pfx1 *EQ 'T' *OR &Pfx4"
The editor did not complain (though it did if I did this to a *Dec field that was used in a comparison) and there was no error in the compiler.
When the program ran it would not ever recognize the Pfx2 value as having "OW" in it. When I put it back in all was fine.
Can anyone tell me why this is happening and/or how to prevent it from happening again? I do not see any options on the compiler to test for var. declarations. My concern is: if i had coded it diff. (If &Library = 'QRECOVERY' *AND Pfx2 *NE "OW") it would have deleted things that shouldn't have.
I am on V5R2 but have found that it worked that way on our old V4R3 system too.
========================================================
/***** Program Variables */
DCL &Pfx1 *CHAR 1
DCL &Pfx2 *CHAR 2
DCL &Pfx4 *CHAR 4
RCVF
MonMsg MsgID(CPF0864) Exec(Goto End_Delete) /* E.O.F. */
ChgVar &Pfx1 %SST(&Package 1 1)
ChgVar &Pfx2 %SST(&Package 1 2)
ChgVar &Pfx4 %SST(&Package 1 4)
If ((&Library *NE 'QRECOVERY ') +
*OR (&Library *EQ 'QRECOVERY ' +
*AND (Pfx2 *EQ 'OW' *OR &Pfx1 *EQ 'T' *OR &Pfx4 *EQ 'JDBJ'))) DO
/* Alloc. first to chk for locks */
AlcObj Obj((&Library/&Package *SQLPKG *EXCL)) Wait(5)
MonMsg MsgID(CPF1002 CPF1085) Exec(GoTo CmdLbl(AllocErr)) /*Alloc. err.*/
/* Delete */
DltSqlPkg &Library/&Package
EndDo
========================================================
The problem was that I had inadvertantly left out the ampersand on var. Pfx2 in "*AND (Pfx2 *EQ 'OW' *OR &Pfx1 *EQ 'T' *OR &Pfx4"
The editor did not complain (though it did if I did this to a *Dec field that was used in a comparison) and there was no error in the compiler.
When the program ran it would not ever recognize the Pfx2 value as having "OW" in it. When I put it back in all was fine.
Can anyone tell me why this is happening and/or how to prevent it from happening again? I do not see any options on the compiler to test for var. declarations. My concern is: if i had coded it diff. (If &Library = 'QRECOVERY' *AND Pfx2 *NE "OW") it would have deleted things that shouldn't have.
I am on V5R2 but have found that it worked that way on our old V4R3 system too.