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

A beginner ? about an error, Thanks

Status
Not open for further replies.

NateUNI

MIS
Jan 3, 2002
132
US
When i run the following code it it gives me the following error: illegal character in numeric field. This program is a validation program, here an example of the incoming records:

Hhhhhhh 0BEEOOlOOO9995556OOlOO
Aaaaaaa lBAN012340O122220054320000

Can you please give me a hint on how to fix this, Thanks A lot

IDENTIFICATION DIVISION.
PROGRAM-ID. Project8-8stubs.
AUTHOR. Nathan.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT STOCK-FILE ASSIGN TO 'C:\cobol\prj08-08.dat'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT ERROR-FILE ASSIGN TO 'C:\cobol\error.txt'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT VALID-FILE ASSIGN TO 'C:\cobol\valid.txt'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD STOCK-FILE
RECORD CONTAINS 34 CHARACTERS
DATA RECORD IS STOCK-RECORD-IN.
01 STOCK-RECORD-IN.
05 STOCK-INFO.
10 STOCK-NAME PIC X(8).
10 STOCK-EXCHANGE-CODE PIC 9.
88 VALID-EXCHANGE-CODE VALUES 1 THRU 4.
10 STOCK-INDUSTRY-CODE PIC X(3).
88 VALID-INDUST-CODE VALUES 'AIR' 'AUT' 'BAN' 'BEE' 'CMP' 'DRU' 'ELE' 'F&L' 'FOO' 'OIL' 'RET' 'S&L' 'TEL'.
05 STOCK-CURRENT-INFO.
10 STOCK-PRICE PIC 999V999.
10 STOCK-PE PIC 9(3).
10 STOCK-DIVIDEND PIC 9V99.
05 STOCK-PROJECTION-INFO.
10 STOCK-RISK-CODE PIC 9.
88 VALID-RISK-CODE VALUES 1 THRU 5.
10 STOCK-GROWTH-RATE PIC 9V9(4).
88 VALID-GROWTH-RATE VALUES .01 THRU 1.
10 STOCK-SHARES-TO-BUY PIC 9(4).

FD ERROR-FILE
RECORD CONTAINS 132 CHARACTERS
DATA RECORD IS ERROR-RECORD-OUT.
01 ERROR-RECORD-OUT PIC X(132).

FD VALID-FILE
RECORD CONTAINS 132 CHARACTERS
DATA RECORD IS VALID-RECORD-OUT.
01 VALID-RECORD-OUT PIC X(132).

WORKING-STORAGE SECTION.
01 NO-DATA-REMAINS-SWITCH PIC X(3) VALUE SPACES.
01 STOCK-PURCHASE-PRICE PIC 9(10) VALUE ZEROS.

PROCEDURE DIVISION.
100-PREPARE-PROGRAMMER-REPORT.
OPEN INPUT STOCK-FILE
OUTPUT ERROR-FILE
VALID-FILE.
PERFORM 200-PROCESS-CUST-RECORDS
UNTIL NO-DATA-REMAINS-SWITCH = 'YES'.
CLOSE STOCK-FILE
ERROR-FILE
VALID-FILE.
STOP RUN.

200-PROCESS-CUST-RECORDS.
READ STOCK-FILE
AT END
MOVE 'YES' TO NO-DATA-REMAINS-SWITCH
NOT AT END
PERFORM 210-PROCESS-EACH-RECORD
END-READ.


210-PROCESS-EACH-RECORD.
IF STOCK-NAME = SPACES
MOVE 'ERROR1' TO ERROR-RECORD-OUT
END-IF

IF STOCK-EXCHANGE-CODE NOT NUMERIC
MOVE 'ERROR2' TO ERROR-RECORD-OUT
END-IF

IF NOT VALID-EXCHANGE-CODE
MOVE 'ERROR3' TO ERROR-RECORD-OUT
END-IF

IF NOT VALID-INDUST-CODE
MOVE 'ERROR4' TO ERROR-RECORD-OUT
END-IF

IF STOCK-PE NOT NUMERIC
MOVE 'ERROR5' TO ERROR-RECORD-OUT
END-IF

IF STOCK-DIVIDEND NOT NUMERIC
MOVE 'ERROR6' TO ERROR-RECORD-OUT
END-IF

IF STOCK-PRICE NOT NUMERIC
MOVE 'ERROR7' TO ERROR-RECORD-OUT
ELSE
IF STOCK-PRICE IS ZERO
MOVE 'ERROR9' TO ERROR-RECORD-OUT
END-IF

IF STOCK-SHARES-TO-BUY NOT NUMERIC
MOVE 'ERROR8' TO ERROR-RECORD-OUT
ELSE
IF STOCK-SHARES-TO-BUY = ZEROS
MOVE 'ERROR10' TO ERROR-RECORD-OUT
END-IF

COMPUTE STOCK-PURCHASE-PRICE = STOCK-PRICE *
STOCK-SHARES-TO-BUY

IF STOCK-PURCHASE-PRICE > 25000
MOVE 'ERROR11' TO ERROR-RECORD-OUT
END-IF

IF STOCK-RISK-CODE NOT NUMERIC
MOVE 'ERROR12' TO ERROR-RECORD-OUT
END-IF

IF STOCK-GROWTH-RATE NOT NUMERIC
MOVE 'ERROR13' TO ERROR-RECORD-OUT
END-IF

IF NOT VALID-RISK-CODE
MOVE 'ERROR14' TO ERROR-RECORD-OUT
END-IF

IF NOT VALID-GROWTH-RATE
MOVE 'ERROR15' TO ERROR-RECORD-OUT
END-IF

WRITE ERROR-RECORD-OUT.
 
Nate,

Hhhhhhh 0BEEOOlOOO9995556OOlOO
Aaaaaaa lBAN012340O122220054320000

must fit

01 STOCK-RECORD-IN.

The first problem for example will be the STOCK-PRICE PIC 999V999: OOlOOO does not fit and will result in an error (S0C7?)

You can solve this problem with (for example and understandable) the following:

rewrite
>cut
>10 STOCK-PRICE PIC 999V999.
>uncut

in

10 STOCK-PRICE-VALIDATION.
15 STOCK-PRICE PIC 999V999.


Because STOCK-PRICE-VALIDATION does not have a (direct) picture clause, you can ask if it's numeric.

The code can be like this:

IF STOCK-PRICE-VALIDATION NOT NUMERIC
MOVE 'ERROR7' TO ERROR-RECORD-OUT
ELSE
IF STOCK-PRICE IS ZERO
MOVE 'ERROR9' TO ERROR-RECORD-OUT.

Your job is to find the other ones.

suc6,


M.
BigMag, The Netherlands.
someone@euronet.nl (no kidding!)
 
BigMag,

you can test the numeric field directly, as long as you don't do any numeric processing on it if it turns out to be not numeric. Your solution does make it possible to display the contents or something.

NateUNI,

check those records; it seems they contain wrong values in many places. You can't expect a prgram to execute correctly if the input is full of errors, and checking for every possible mistake here doesn't make much sense.

Regards,
Ronald.
 
Ive seen files that use fields for 2 or more purposes depending if a flag is set or not on a specific one char field.

If you think you have bad data make a program to list the key and the bad data field for every record that contains invalid data (or maybe just the first 50 items).

Be warned that bad logic is just as likely to occur as bad data.

That is an awful lot of errors to check for if the first item checked has an error. If you have 10 errors you will only see one of them.

When you say: "IF NOT VALID-EXCHANGE-CODE"

How do you know if it is valid? I didn't know you could use thru and a list of items for a single condition?? If you do not like my post feel free to point out your opinion or my errors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top