2 Replies - 737 Views - Last Post: 08 September 2013 - 12:41 PM Rate Topic: -----

#1 Cliftron  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 27-April 11

COBOL - Illegal char in numeric field

Posted 08 September 2013 - 11:27 AM

I'm trying to get a total of all purchases made and display the amount at the end of the record. When I try to run it however I get error 163 Illegal character in numeric field. Can anyone explain why it's throwing this error and help me understand what I'm doing wrong or how to fix it? I know that it's telling me that it contains a non numeric character but this is the first program I've attempted in COBOL, so I'm at a loss. I'm using Net Express for my compiler. The code and contents of the input file are below.

Code
 IDENTIFICATION DIVISION.
       PROGRAM-ID. CH6PPB.
      *****************************************************************
      *    This program creates a purchase report of customers and
      *    their amount of purchase and also prints the total amount
      *    of purchases for all customers at the end of the report.
      *****************************************************************
       AUTHOR. anonymous.
       INSTALLATION. .
       DATE-WRITTEN. SEP. 08, 2013.
       DATE-COMPILED.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT PURCHASE-TRANS ASSIGN TO 'CH6PPB.DAT'
               ORGANIZATION IS LINE SEQUENTIAL.
           SELECT PURCHASE-REPORT ASSIGN TO 'CarterCA2.RPT'
               ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  PURCHASE-TRANS
                  RECORD CONTAINS 32 CHARACTERS.
       01  TOTAL                               PIC 9(5)V99
                VALUE ZERO.
       01  TRANS-REC-IN.
           05 CUST-NO-IN                       PIC X(5).
           05 CUST-NAME-IN                     PIC X(20).
           05 AMT-OF-PUR-IN                    PIC 9(5)V99.
       FD  PURCHASE-REPORT
           RECORD CONTAINS 80 CHARACTERS.
       01  PRINT-REC                           PIC X(80).
           WORKING-STORAGE SECTION.
       01  WORK-AREAS.
           05  ARE-THERE-MORE-RECORDS          PIC XXX
                  VALUE 'YES'.
           05  WS-DATE.
               10  WS-YEAR                     PIC 9999.
               10  WS-MONTH                    PIC 99.
               10  WS-DAY                      PIC 99.
           05  WS-PAGE-CT                      PIC 99
                  VALUE ZERO.
           05  WS-LINE-CT                      PIC 99
                  VALUE ZERO.
       01  HDR1-OUT.
           05                                  PIC X(40)
                  VALUE SPACES.
           05                                  PIC X(20)
                  VALUE 'PURCHASE REPORT'.
           05  DATE-OUT.
               10  MONTH-OUT                    PIC 99.
               10                               PIC X
                  VALUE '/'.
               10  DAY-OUT                      PIC 99.
               10                               PIC X
                  VALUE '/'.
               10  YEAR-OUT                    PIC 9999.
           05                                  PIC X(2)
                  VALUE SPACES.
           05                                  PIC X(5)
                  VALUE 'PAGE'.
           05  PAGE-OUT                        PIC Z9.
       01  HDR2-OUT.
           05                                  PIC X(10)
                  VALUE SPACES.
           05                                  PIC X(27)
                  VALUE 'CUSTOMER NO   CUSTOMER NAME'.
           05                                  PIC X(13)
                  VALUE SPACES.
           05                                  PIC X(18)
                  VALUE 'AMOUNT OF PURCHASE'.
       01  HDR3-0UT.
           05                                  PIC X(10)
                  VALUE SPACES.
           05                                  PIC X(27)
                  VALUE 'TOTAL PURCHASE AMOUNT'.
           05                                  PIC X(13)
                  VALUE SPACES.
       01  DETAIL-REC-OUT.
           05                                  PIC X(13)
                  VALUE SPACES.
           05  CUST-NO-OUT                     PIC X(5).
           05                                  PIC X(6)
                  VALUE SPACES.
           05  CUST-NAME-OUT                   PIC X(20).
           05                                  PIC X(11)
                  VALUE SPACES.
           05  AMT-OF-PUR-OUT                  PIC Z(5).99
                  VALUE SPACES.
       PROCEDURE DIVISION.
      *****************************************************************
      *    All program logic is controlled by
      *        100-MAIN-MODULE
      *****************************************************************
       100-MAIN-MODULE.
            OPEN INPUT  PURCHASE-TRANS
                 OUTPUT PURCHASE-REPORT
            MOVE FUNCTION CURRENT-DATE TO WS-DATE
            MOVE WS-MONTH TO MONTH-OUT
            MOVE WS-DAY TO DAY-OUT
            MOVE WS-YEAR TO YEAR-OUT
            PERFORM 200-HDG-RTN.
            PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
               READ PURCHASE-TRANS
                    AT END
                       MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
                    NOT AT END
                       PERFORM 300-REPORT-RTN
               END-READ
            END-PERFORM
            PERFORM 400-FTR-RTN.
            CLOSE PURCHASE-TRANS
                  PURCHASE-REPORT
            STOP RUN.
      *****************************************************************
      *    200-HDG-RTN is executed once from the main module
      *         and then again after 25 detail lines print
      *****************************************************************
       200-HDG-RTN.
           ADD 1 TO WS-PAGE-CT
           MOVE WS-PAGE-CT TO PAGE-OUT
           WRITE PRINT-REC FROM HDR1-OUT
                AFTER ADVANCING PAGE
           WRITE PRINT-REC FROM HDR2-OUT
                AFTER ADVANCING 2 LINES
           MOVE ZEROS TO WS-LINE-CT.
      *****************************************************************
      *    300-REPORT-RTN is executed form the main module
      *       until all input records have been processed
      *****************************************************************
       300-REPORT-RTN.
           IF WS-LINE-CT >=25
               PERFORM 200-HDG-RTN
           END-IF
           MOVE CUST-NO-IN TO CUST-NO-OUT
           MOVE CUST-NAME-IN TO CUST-NAME-OUT
           COMPUTE TOTAL = TOTAL + AMT-OF-PUR-IN
           MOVE AMT-OF-PUR-IN TO AMT-OF-PUR-OUT
           WRITE PRINT-REC FROM DETAIL-REC-OUT
               AFTER ADVANCING 2 LINES
           ADD 1 TO WS-LINE-CT.
      *****************************************************************
      *    400-FTR-RTN is exectued after all records are processed.
      *****************************************************************
       400-FTR-RTN.
           WRITE PRINT-REC FROM HDR3-0UT
               AFTER ADVANCING 2 LINES
           WRITE PRINT-REC FROM TOTAL




Input
12345CHARLES NEWTON,INC. 0031500
23456HARWOOD ASSOCIATES  5187975
34567LEMON AUTOMOTIVE    0950000
54321BISTRO BROTHERS     0134565



Is This A Good Question/Topic? 0
  • +

Replies To: COBOL - Illegal char in numeric field

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4319
  • View blog
  • Posts: 12,101
  • Joined: 18-April 07

Re: COBOL - Illegal char in numeric field

Posted 08 September 2013 - 12:31 PM

Well it has been awhile since I had done COBOL but one thing that is popping out at me is where you put in spaces into a numeric field...

05  AMT-OF-PUR-OUT                  PIC Z(5).99
    VALUE SPACES.



If you set this to ZERO does it correct the problem?

If not, you have to do the classic COBOL debugging.... start commenting out large pieces of code until the error disappears and then slowly uncomment pieces to narrow down the line giving you issues.

This post has been edited by Martyr2: 08 September 2013 - 12:34 PM

Was This Post Helpful? 0
  • +
  • -

#3 Cliftron  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 27-April 11

Re: COBOL - Illegal char in numeric field

Posted 08 September 2013 - 12:41 PM

Managed to fix it myself but I figured I'd post how in case anyone else stumbled across it.
01  TOTAL                               PIC 9(5)V99
025
               VALUE ZERO.

Needed to be moved down to past the description of the file that was accepted as an input. Otherwise the variable would read the wrong information from the file and initialize it to that instead of being a Zero or blank. Really goofs it up.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1