suppressing leading zeros

I have this book that explains you can suppress leading zeros in a variable like this         01    THE-NUMBER           PIC ZZ99.

but i get an error operand should be numeric error  cobch0034 error

It says you can put Z's in front and suppress them this i think came from a 85 cobol standard book

  • Sure, you can specify a numeric edited field with zero suppression and you can even add the blank when zero clause so that only spaces will be displayed when the value is zero.

    These numeric-edited fields are used for display only on the screen or in a print file, etc. but they are not numeric so you can not do arithmetic operations on them. Doing so will result in the error that you are experiencing.

    id division.                                    
    program-id.   testzerosupp.                      
    data division.                                  
    working-storage section.                        
    01 THE-EDITED-NUMBER      PIC ZZ99.                    
    01 THE-EDITED-NUMBER2     PIC ZZ99 BLANK WHEN ZERO.    
    01 THE-NUMBER                     PIC 9999 VALUE ZEROES.
    procedure division.                              

       *> So the following is supported
     
         move 10 to the-edited-number, the-edited-number2            
         display "number = " the-edited-number                
         display "number2 = " the-edited-number2              
         move 0 to the-edited-number, the-edited-number2              
         display "number = " the-edited-number                
         display "number2 = " the-edited-number2              

      *> The following is not

        *>  add 1 to the-edited-number2                

       *> use this instead

         add 1 to the-number
         move the-number to the-edited-number
         display the-edited-number

         stop run.                                    

  • I still don't understand what I'm doing wrong here's my code

          IDENTIFICATION DIVISION.

          PROGRAM-ID. GOOTOO.

          ENVIRONMENT DIVISION.

          DATA DIVISION.

          WORKING-STORAGE SECTION.

          01 THE-NUMBER       PIC ZZ99.

          01 THE-MULTIPLIER   PIC ZZ99.

          01 THE-PRODUCT      PIC 9999.

          PROCEDURE DIVISION.

          PROGRAM-BEGIN.

              PERFORM PROGRAM-INITIALIZATION.

              PERFORM GET-TABLE-NUMBER.

              PERFORM DISPLAY-THE-TABLE.

          PROGRAM-DONE.

          PROGRAM-INITIALIZATION.

              MOVE 0 TO THE-MULTIPLIER.

          GET-TABLE-NUMBER.

              DISPLAY "Which multiplication table (01-99)?"

              ACCEPT THE-NUMBER.

          DISPLAY-THE-TABLE.

              DISPLAY "The " THE-NUMBER "'S table is:".

              PERFORM CALCULATE-AND-DISPLAY.

          CALCULATE-AND-DISPLAY.

              ADD 1 TO THE-MULTIPLIER.

              COMPUTE THE-PRODUCT = THE-NUMBER * THE-MULTIPLIER.

              DISPLAY

                  THE-NUMBER " * " THE-MULTIPLIER " = " THE-PRODUCT.

              IF THE-MULTIPLIER <= 12

                  GO TO CALCULATE-AND-DISPLAY.

  • ok if you cannot do operations on the THE-NUMBER AND THE-MULTIPLIER how can I  format  my code where there are no zeros in front of it and do computations. from what you said I think anyway I can't do this  in cobol

    COMPUTE THE-PRODUCT = THE-NUMBER * THE-MULTIPLIER

  • In your example the result field, THE-PRODUCT can be numeric-edited, i.e. PIC ZZ99 but the fields used in the computation cannot be.

    They need to be numeric, i.e., PIC 9999.

    Likewise in a non-COMPUTE arithmetic statement like ADD, SUBTRACT, MULTIPLY and DIVIDE you can use the numeric-edited field in the GIVING phrase of the operation.

    01 THE-PRODUCT      PIC ZZ99  VALUE 0.

    01 THE-NUMBER        PIC 9999  VALUE 2.

    01 THE-MULTIPLIER  PIC 9999 VALUE 3.

       COMPUTE THE-PRODUCT = THE-NUMBER * THE-MULTIPLIER

    or

       MULTIPLY THE-NUMBER BY THE-MULTIPLIER GIVING THE-PRODUCT

       DISPLAY THE-PRODUCT