Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CL *CHAR Variable undeclared

Status
Not open for further replies.

DonU

MIS
Jan 31, 2002
19
0
0
CA
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.
 
In CL, within a condition, an unquoted string is just a character literal (as if you had typed it in single quotes, and in uppercase). That is what CL requires the ampersand to precede variable names.

Feles mala! Cur cista non uteris? Stramentum novum in ea posui!

 
There are just some things that the compiler won't pick up on.

I once spent the better part of my day debugging an RPG/400 application, where I had a statement similar to:

*IN99 IFEQ '*ON'

instead of

*IN99 IFEQ *ON

 
I've seen CL programs that say:

Code:
IF COND(&A = *BLANKS) THEN(DO)

There is no such thing as the figurative constant *BLANKS in CL. What that;s doing is comparing &A to the literal string '*BLANKS'. Not going to fly. Perfect example of mixing up two languages (CL versus RPG).

Feles mala! Cur cista non uteris? Stramentum novum in ea posui!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top