Cobol not numeric name

2.9k Views Asked by At

I am having some trouble with some cobol code. In the following code bellow it causes these two errors. The compiler does not like when I try and do the addition.

CH7PPB.CBL:158: Error: 'NEW-DUES' is not numeric name
CH7PPB.CBL:161: Error: 'NEW-INSURANCE' is not numeric name
   MOVE UNION-DUES TO OLD-DUES
   MULTIPLY UNION-DUES BY .04 GIVING NEW-DUES
   ADD UNION-DUES TO NEW-DUES
   MOVE INSURANCE TO OLD-INSURANCE
   MULTIPLY INSURANCE BY .03 GIVING NEW-INSURANCE
   ADD INSURANCE TO NEW-INSURANCE

NEW-DUES and NEW-INSURANCE are defined as follows.

       05   NEW-DUES                       PIC Z9(4).99.
       05   NEW-INSURANCE                  PIC Z9(4).99.

Thank you for any help.

3

There are 3 best solutions below

2
On

Resolved this by useing two temp variables not sure if this is the way to do it but it worked.

           MOVE ANNUAL-SALARY TO OLD-SALARY
           MULTIPLY ANNUAL-SALARY BY .07 GIVING TEMP
           ADD ANNUAL-SALARY,TEMP TO TEMP2
           MOVE TEMP2 TO NEW-SALARY
           MOVE ZEROS TO TEMP, TEMP2
           MOVE UNION-DUES TO OLD-DUES
           MULTIPLY UNION-DUES BY .04 GIVING TEMP
           ADD UNION-DUES,TEMP TO TEMP2
           MOVE TEMP2 TO NEW-DUES
           MOVE ZEROS TO TEMP, TEMP2
           MOVE INSURANCE TO OLD-INSURANCE
           MULTIPLY INSURANCE BY .03 GIVING TEMP
           ADD INSURANCE,TEMP TO TEMP2
           MOVE TEMP2 TO NEW-INSURANCE
           MOVE ZEROS TO TEMP, TEMP2
0
On

I'm glad you already solved the issue.

Just for the record, you cannot use edited formats in computations. The character "Z" in the PICTURE string of both variables turns the variable to be not considered numeric by the compiler.

You indeed have to declare a full numeric variable (no formatting) and move its result value to the formatted variable after.

0
On

In addition to the COMPUTE suggested by NealB:

       MOVE ANNUAL-SALARY TO OLD-SALARY
       MULTIPLY ANNUAL-SALARY BY 1.07 GIVING NEW-SALARY
       MOVE UNION-DUES TO OLD-DUES
       MULTIPLY UNION-DUES BY 1.04 GIVING NEW-DUES
       MOVE INSURANCE TO OLD-INSURANCE
       MULTIPLY INSURANCE BY 1.03 GIVING NEW-INSURANCE

The use of TEMP2 in the code shown is particularly bad. It firstly relies on its initial value (presumably a VALUE clause) and for the second time through relies upon the 'MOVE ZEROS TO TEMP, TEMP2' at the end of the block. That's a bad way to do it. The repeated initialisation of TEMP is pointless, as TEMP is always the "target" of a GIVING, so its value at the time of the MULTIPLY is irrelevant.