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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Illegal character in Numeric Field

Status
Not open for further replies.

lostso

Technical User
Oct 22, 2002
13
US
In my progarm When I compile it I keep getting illegal character in Numeric Field. MOVE QUANTITY-SOLD TO QUANTITY-SOLD-OUT is where it happens and I can't see why Can someone help?

IDENTIFICATION DIVISION.
PROGRAM-ID. ASSGN-03.
AUTHOR. Jessica Bennett.
DATE-WRITTEN. 10-29-02.


*REMARKS. This program calculates Net-Sales.


ENVIRONMENT DIVISION.

CONFIGURATION SECTION.

SPECIAL-NAMES. C01 IS NEXT-PAGE.

INPUT-OUTPUT SECTION.

FILE-CONTROL.
SELECT DATA-FILE ASSIGN TO "A:Chdata04.DAT".
SELECT PRINT-FILE ASSIGN TO "A:Calc.cbl".

DATA DIVISION.

FILE SECTION.

FD DATA-FILE.

01 IN-DATA-RECORD.
05 ITEM-NUMBER PIC X(9).
05 ITEM-DESCRIP PIC X(20).
05 PIC X(10) VALUE SPACES.
05 QUANTITY-SOLD PIC 999.
05 UNIT-PRICE PIC 999V99.
05 SALESMAN PIC X(2).
05 PIC X.

FD PRINT-FILE.

01 PRINT-RECORD PIC X(80).

WORKING-STORAGE SECTION.

01 HEADING-1.
05 HEADER-DATE PIC X(8) VALUE "11/05/02".
05 PIC X(23) VALUE SPACES.
05 PIC X(18) VALUE "KITCHEN INDUSTRIES".
05 PIC X(23) VALUE SPACES.
05 PIC X(5) VALUE "PAGE".
05 PAGE-NUMBER-OUT PIC Z9.

01 HEADING-2.
05 PIC X(12) VALUE "ITEM NUMBER".
05 PIC X(2) VALUE SPACES.
05 PIC X(13) VALUE "QUANTITY SOLD".
05 PIC X(1) VALUE SPACES.
05 PIC X(10) VALUE "UNIT PRICE".
05 PIC X(1) VALUE SPACES.
05 PIC X(11) VALUE "GROSS SALES".
05 PIC X(2) VALUE SPACES.
05 PIC X(8) VALUE "DISCOUNT".
05 PIC X(1) VALUE SPACES.
05 PIC X(9) VALUE "NET SALES".
05 PIC X(2) VALUE SPACES.
05 PIC X(9) VALUE "SALESMAN".

01 DETAIL-LINE.
05 PIC X(1) VALUE SPACES.
05 ITEM-NUMBER-OUT PIC X(9).
05 PIC X(8) VALUE SPACES.
05 QUANTITY-SOLD-OUT PIC ZZ9.
05 PIC X(8) VALUE SPACES.
05 UNIT-PRICE-OUT PIC ZZ9.99.
05 PIC X(5) VALUE SPACES.
05 GROSS-SALES-OUT PIC Z(7).99.
05 PIC X(3) VALUE SPACES.
05 DISCOUNT-OUT PIC Z(4).99.
05 PIC X(1) VALUE SPACES.
05 NET-SALES-OUT PIC Z(7).99.
05 PIC X(5) VALUE SPACES.
05 SALESMAN-OUT PIC X(2).

01 NAME-RECORD.
05 PIC X(60) VALUE SPACES.
05 PIC X(30) VALUE "Jessica Bennett".

01 TOTAL-PRINT-RECORD.
05 PIC X(40) VALUE SPACES.
05 TOTAL-GROSS-SALES-OUT PIC $$$,$$$.99.
05 PIC X(3) VALUE SPACES.
05 TOTAL-DISCOUNT-OUT PIC $$$$.99.
05 PIC X(1) VALUE SPACES.
05 TOTAL-NET-SALES-OUT PIC $$$,$$$.99.
05 UNUSED PIC X(9) VALUE SPACES.

01 COUNTERS.
05 PAGE-NUMBER PIC S99 VALUE ZERO packed-decimal.
05 LINE-COUNT PIC S99 VALUE ZERO packed-decimal.
05 WS-TOTAL-GROSS-SALES PIC S9(7)V99 VALUE ZERO.
05 WS-TOTAL-DISCOUNT PIC S9(3)V99 VALUE ZERO.
05 WS-TOTAL-NET-SALES PIC S9(7)V99 VALUE ZERO.
05 WS-GROSS-SALES PIC S9(7)V99 VALUE ZERO.
05 WS-DISCOUNT PIC S9(3)V99 VALUE ZERO.
05 WS-NET-SALES PIC S9(7)V99 VALUE ZERO.


01 FLAGS.
05 MORE-DATA-FLAG PIC X(3) VALUE "YES".
88 NO-MORE-DATA VALUE "NO".

PROCEDURE DIVISION.

100-MAIN-LINE-ROUTINE.
PERFORM 200-INITIALIZATION-ROUTINE.
PERFORM 300-PROCESS-ROUTINE
UNTIL NO-MORE-DATA.
PERFORM 500-FINAL-ROUTINE.
STOP RUN.

200-INITIALIZATION-ROUTINE.
OPEN INPUT DATA-FILE
OUTPUT PRINT-FILE.
MOVE SPACES TO DETAIL-LINE
PERFORM 600-HEADER-ROUTINE.
READ DATA-FILE AT END MOVE "NO"
TO MORE-DATA-FLAG.

300-PROCESS-ROUTINE.
IF LINE-COUNT > 56
PERFORM 600-HEADER-ROUTINE
ELSE
NEXT SENTENCE.

MOVE ITEM-NUMBER TO ITEM-NUMBER-OUT
MOVE QUANTITY-SOLD TO QUANTITY-SOLD-OUT
MOVE UNIT-PRICE TO UNIT-PRICE-OUT
COMPUTE WS-GROSS-SALES = UNIT-PRICE * QUANTITY-SOLD

IF WS-GROSS-SALES >=500.00
PERFORM 400-CALC-ROUTINE
ELSE
MOVE 0 TO DISCOUNT-OUT, WS-DISCOUNT
MOVE WS-GROSS-SALES TO GROSS-SALES-OUT
MOVE GROSS-SALES-OUT TO NET-SALES-OUT
MOVE NET-SALES-OUT TO WS-NET-SALES
END-IF

MOVE SALESMAN TO SALESMAN-OUT
WRITE PRINT-RECORD FROM DETAIL-LINE
AFTER ADVANCING 1 LINE.
ADD WS-GROSS-SALES TO WS-TOTAL-GROSS-SALES.
ADD WS-DISCOUNT TO WS-TOTAL-DISCOUNT.
ADD WS-NET-SALES TO WS-TOTAL-NET-SALES.
ADD 1 TO LINE-COUNT.
READ DATA-FILE AT END MOVE "NO"
TO MORE-DATA-FLAG.

400-CALC-ROUTINE.
MULTIPLY WS-GROSS-SALES BY .02 GIVING WS-DISCOUNT
SUBTRACT WS-DISCOUNT FROM WS-GROSS-SALES
GIVING WS-NET-SALES.
MOVE WS-GROSS-SALES TO GROSS-SALES-OUT
MOVE WS-DISCOUNT TO DISCOUNT-OUT
MOVE WS-NET-SALES TO NET-SALES-OUT.

500-FINAL-ROUTINE.
MOVE WS-TOTAL-GROSS-SALES TO TOTAL-GROSS-SALES-OUT.
MOVE WS-TOTAL-DISCOUNT TO TOTAL-DISCOUNT-OUT.
MOVE WS-TOTAL-NET-SALES TO TOTAL-NET-SALES-OUT.
MOVE TOTAL-PRINT-RECORD TO PRINT-RECORD.
WRITE PRINT-RECORD AFTER ADVANCING 2 LINES.
CLOSE DATA-FILE, PRINT-FILE.

600-HEADER-ROUTINE.
MOVE NAME-RECORD TO PRINT-RECORD.
ADD 1 TO PAGE-NUMBER.
MOVE PAGE-NUMBER TO PAGE-NUMBER-OUT.
WRITE PRINT-RECORD AFTER ADVANCING NEXT-PAGE.
MOVE HEADING-1 TO PRINT-RECORD.
WRITE PRINT-RECORD AFTER ADVANCING 2 LINES.
MOVE HEADING-2 TO PRINT-RECORD.
WRITE PRINT-RECORD AFTER ADVANCING 2 LINES.
MOVE SPACES TO PRINT-RECORD.
WRITE PRINT-RECORD AFTER ADVANCING 2 LINES.
MOVE 8 TO LINE-COUNT.
 
Hi lostso,

I don't see how the compiler 'knows' there is an illegal character in a numeric field. When you write " When I compile it ", do you mean to say " When I run it "?

Dimandja
 
Yeah when I run it. Sorry about that not thinking right now.
 
Well then, it looks like you have bad data.

To find out if my assumption is true, you should either:

1. Look at at the input file. QUANTITY-SOLD could contain invalid numeric data.

2. Check the definition of IN-DATA-RECORD. It may be incorrect.

Dimandja
 
Hi Jessica,

There are a number of ways to look at the invalid data, 2 of which are:

1) Print a portion of the input file and determine the position and length of the field in question and take a look.

2) Use the DISPLAY verb to show the field on your terminal. I use DISPLAY '>' WS-my-field '<' so that the brackets show the start/end of the field in the event it contains blanks or other unprintable chars.

Regards, Jack.
 
try

IF QUANTITY-SOLD NOT NUMERIC DISPLAY IN-DATA-RECORD.

If there is a non-numeric character that will display enough identifying info so you can look at the actual record.
 
MOVE WS-GROSS-SALES TO GROSS-SALES-OUT
MOVE GROSS-SALES-OUT TO NET-SALES-OUT
MOVE NET-SALES-OUT TO WS-NET-SALES

First move is a numeric to a formatted field. OK.
Next is a formated character field moving to a formatted field.

You likely meant MOVE WS-xxxx to NET-xxx format in every case.

Lesson: Make sure you only move to formatted fields and not from them unless they are to PIC X fields.

 
Hi DD,

With the latest COBOL compilers you can move numerid edited fields to numeric fields. They call it de-editing.

Regards, Jack.
 
Hi Lostso,

Just one other thing you might want to look out for!
You may have received Low values.
These will probably show up as &quot;@&quot; in any diplays or trace prints.

You can get over this as follows.

If QUANTITY-SOLD < zero
MOVE 0 TO QUANTITY-SOLD-OUT
else
MOVE QUANTITY-SOLD TO QUANTITY-SOLD-OUT.

Good Luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top