9 Replies - 1189 Views - Last Post: 19 February 2009 - 01:27 AM Rate Topic: -----

#1 tigerfan88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 16-January 09

Keep getting an error with this Cobol program

Posted 18 February 2009 - 01:34 PM

I have most of this program done, but for some reason, I keep getting an illegal character in numeric field error. Here's my code:

			  identification division.
			  program-id. assignment2.
			  environment division.
			  input-output section.
			  file-control.
				  select file-in assign to disk "h:data2.txt"
				   organization is line sequential.
				  select file-out assign to printer, "con".
			  data division.
			  file section.
			  fd file-in label records are standard.
			  01 record-in.
				  05 desc-in   pic x(14).
				  05 unit-in   pic 999v999.
				  05 cargo-in  pic x(3).
				  05 price-in  pic 99v99.
				  05 qty-in	pic 99999.

			  fd file-out label records are omitted.
			  01 record-out pic x(80).
			  working-storage section.
			  01 more-records pic x value 'y'.
			  01 total-cost pic 99999v99.
			  01 line1-out.
				  05 filler pic x(30) value spaces.
				  05 filler pic x(6) value 'output'.
				  05 filler pic x(30) value spaces.
			  01 line2-out.
				  05 filler pic x(6) value spaces.
				  05 filler pic x(10) value 'Ship Name'.
				  05 filler pic x(6) value spaces.
				  05 filler pic x(5) value 'Units'.
				  05 filler pic x(6) value spaces.
				  05 filler pic x(5) value 'Cargo'.
				  05 filler pic x(6) value spaces.
				  05 filler pic x(14) value 'Units Price'.
				  05 filler pic x(6) value spaces.
				  05 filler pic x(12) value 'Cargo Value'.
			  01 print-line-out.
				  05 filler	pic x(10) value spaces.
				  05 desc-out  pic x(14).
				  05 filler	pic x(3).
				  05 cargo-out pic x(14).
				  05 filler	pic x(10) value spaces.
				  05 price-out pic $z,z99.99.
				  05 filler	pic x(8) value spaces.
				  05 unit-out   pic 999v999.
				  05 filler	pic x(8) value spaces.
				  05 qty-out   pic 9999.
				  05 filler	pic x(10) value spaces.
				  05 total-cost-out  pic $zzz,999.99.
				  05 filler	pic x(13) value spaces.
			  procedure division.
			  100-main.
			   perform 300-open.
			   perform 400-headings.
			   read file-in at end move 'n' to more-records.
			   perform 200-process until more-records = 'n'.
			   perform 500-close.
			   stop run.
			  200-process.
			   compute total-cost = price-in * qty-in.
			   perform 600-move.
			   write record-out from print-line-out after advancing 1
			   line.
			   read file-in at end move 'n' to more-records.
			  300-open.
			   open input file-in.
			   open output file-out.
			  400-headings.
			   write record-out from line1-out after advancing 5 lines.
			   write record-out from line2-out after advancing 2 lines.
			   write record-out from print-line-out after advancing 2
			   lines.
			  500-close.
			   close file-in.
			   close file-out.
			  600-move.
			   move desc-in to desc-out.
			   move unit-in to unit-out.
			   move cargo-in to cargo-out.
			   move price-in to price-out.
			   move qty-in to qty-out.
			   move total-cost to total-cost-out.



And this is the contents of Data2:

Quote

BLUENOSE 240000OIL 04312
IRONSIDE 150500ORE 07550
DALSOHN 064400WHEAT 00980
BALOCHSIDE 330000COPPER 00145
SANTA MARIA 175000OATS 00326
HIGHLAND 180000ALUMINUM11050


I should be getting this output:

Quote

Ship Cargo Units Unit Cargo
Name Price Value

Bluenose Oil 240,000 88.50 $21,240,000.00
Balochside Ore 150,500 75.50 $ 3,837,750.00


What am I doing wrong? Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Keep getting an error with this Cobol program

#2 bsaunders  Icon User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: Keep getting an error with this Cobol program

Posted 18 February 2009 - 04:06 PM

The contents of the input file (h:data2.txt) do not correspond to the picture clauses defined in the FD of the FILE SECTION.

In the first entry of the FD, you declared an alphanumeric field with a width of 14 characters.

When the first record of the input file is read into memory, this is what it will look like:

BLUENOSE 240000OIL 04312
IRONSIDE 150500ORE 07550
DALSOHN 064400WHEAT 00980
BALOCHSIDE 330000COPPER 00145
SANTA MARIA 175000OATS 00326
HIGHLAND 180000ALUMINUM11050


It read a bit more than it was supposed to, I assume.

Then, when it reads the next field, which is defined as a numeric field with three digits preceding the decimal point followed by three more digits (999v999), this is what is in memory:

BLUENOSE 240000OIL 04312
IRONSIDE 150500ORE 07550
DALSOHN 064400WHEAT 00980
BALOCHSIDE 330000COPPER 00145
SANTA MARIA 175000OATS 00326
HIGHLAND 180000ALUMINUM11050


The O in oil is definitely not a digit, hence the numeric field error.

In short, I think you need to reformat the input record file to reflect the pictures clauses the COBOL program expects.

This post has been edited by bsaunders: 18 February 2009 - 04:09 PM

Was This Post Helpful? 0
  • +
  • -

#3 tigerfan88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 16-January 09

Re: Keep getting an error with this Cobol program

Posted 18 February 2009 - 04:52 PM

So wait, I should edit data2.txt to reflect what I'm trying to do with the fd section?
Was This Post Helpful? 0
  • +
  • -

#4 bsaunders  Icon User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: Keep getting an error with this Cobol program

Posted 18 February 2009 - 05:32 PM

I think that should work. Did you create the data2.txt file yourself, or was the data set given to you by the instructor?
Was This Post Helpful? 0
  • +
  • -

#5 tigerfan88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 16-January 09

Re: Keep getting an error with this Cobol program

Posted 18 February 2009 - 07:25 PM

It was given to me by my professor, but I do not think he would have a problem if I edited it.

EDIT: Here's what I have now, still getting the same error:

			  identification division.
			  program-id. assignment2.
			  environment division.
			  input-output section.
			  file-control.
				  select file-in assign to disk "j:data2.txt"
				   organization is line sequential.
				  select file-out assign to printer, "con".
			  data division.
			  file section.
			  fd file-in label records are standard.
			  01 record-in.
				  05 desc-in   pic x(14).
				  05 cargo-in  pic x(6).
				  05 unit-in   pic 999v999.
				  05 price-in  pic 99v99.

			  fd file-out label records are omitted.
			  01 record-out pic x(80).
			  working-storage section.
			  01 more-records pic x value 'y'.
			  01 total-cost pic 99999v99.
			  01 line1-out.
				  05 filler pic x(30) value spaces.
				  05 filler pic x(6) value 'output'.
				  05 filler pic x(30) value spaces.
			  01 line2-out.
				  05 filler pic x(6) value spaces.
				  05 filler pic x(10) value 'Ship Name'.
				  05 filler pic x(6) value spaces.
				  05 filler pic x(5) value 'Units'.
				  05 filler pic x(6) value spaces.
				  05 filler pic x(5) value 'Cargo'.
				  05 filler pic x(6) value spaces.
				  05 filler pic x(14) value 'Units Price'.
				  05 filler pic x(6) value spaces.
				  05 filler pic x(12) value 'Cargo Value'.
			  01 print-line-out.
				  05 filler	pic x(10) value spaces.
				  05 desc-out  pic x(8).
				  05 filler	pic x(10).
				  05 cargo-out pic x(3).
				  05 filler	pic x(10) value spaces.
				  05 price-out pic $z,z99.99.
				  05 filler	pic x(8) value spaces.
				  05 unit-out   pic 999v999.
				  05 filler	pic x(8) value spaces.
				  05 total-cost-out  pic $zzz,999.99.
				  05 filler	pic x(13) value spaces.
			  procedure division.
			  100-main.
			   perform 300-open.
			   perform 400-headings.
			   read file-in at end move 'n' to more-records.
			   perform 200-process until more-records = 'n'.
			   perform 500-close.
			   stop run.
			  200-process.
			   compute total-cost = price-in * unit-in.
			   perform 600-move.
			   write record-out from print-line-out after advancing 1
			   line.
			   read file-in at end move 'n' to more-records.
			  300-open.
			   open input file-in.
			   open output file-out.
			  400-headings.
			   write record-out from line1-out after advancing 5 lines.
			   write record-out from line2-out after advancing 2 lines.
			   write record-out from print-line-out after advancing 2
			   lines.
			  500-close.
			   close file-in.
			   close file-out.
			  600-move.
			   move desc-in to desc-out.
			   move unit-in to unit-out.
			   move cargo-in to cargo-out.
			   move price-in to price-out.
			   move total-cost to total-cost-out.



The error occurs with this line:

compute total-cost = price-in * unit-in.


Here's my DATA file now:

Quote

BLUENOSE OIL 240000 04312
IRONSIDE ORE 150500 07550
DALSOHN WHEAT 064400 00980
BALOCHSIDE COPPER 330000 00145
SANTA MARIAOATS 175000 00326
HIGHLAND ALUMINUM 180000 11050


This post has been edited by tigerfan88: 18 February 2009 - 07:45 PM

Was This Post Helpful? 0
  • +
  • -

#6 bsaunders  Icon User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: Keep getting an error with this Cobol program

Posted 18 February 2009 - 08:36 PM

How does the program run if you remove the compute statement?
Was This Post Helpful? 0
  • +
  • -

#7 tigerfan88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 16-January 09

Re: Keep getting an error with this Cobol program

Posted 18 February 2009 - 10:24 PM

It then gives me the same error, except with this line:

move unit-in to unit-out.
Was This Post Helpful? 0
  • +
  • -

#8 bsaunders  Icon User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: Keep getting an error with this Cobol program

Posted 18 February 2009 - 11:19 PM

I don't think the input file's records match the picture clauses declared in the FD section:

01 record-in.
				  05 desc-in   pic x(14).
				  05 cargo-in  pic x(6).
				  05 unit-in   pic 999v999.
				  05 price-in  pic 99v99.
.

For the first record, this is how it works:

desc-in is an alphanumeric field with a width of 14:

BLUENOSE OIL 240000 04312

This is desc-in when the input file is read: BLUENOSE OIL 2.

cargo-in is an alphanumeric field with a width of 6 characters:

BLUENOSE OIL 240000 04312

This is cargo-in after the input file is read: 40000 .

unit-in is a nine-digit numeric field with a decimal point after the third digit:

BLUENOSE OIL 240000 04312

This is unit-in after a read operation: 04312.

price-in is a four-digit numeric field with a decimal point after the second digit:

BLUENOSE OIL 240000 04312
IRONSIDE ORE 150500 07550


This is the value of price-in after a read operation: IRON.

When you call compute with price-in and unit-in:

compute total-cost = price-in * unit-in.
,

these are the values that are being substituted:

compute total-cost = IRON * 04312.
.

That will definitely not work.

What happens if you try with this data set (everything inside the quotation marks, not including the quotation marks)?

WARNING: DO NOT ADD NEW LINES BETWEEN RECORDS.

"This is a testTest120123451234This is a testTest120123451234This is a testTest120123451234"

This post has been edited by bsaunders: 18 February 2009 - 11:19 PM

Was This Post Helpful? 0
  • +
  • -

#9 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Keep getting an error with this Cobol program

Posted 19 February 2009 - 01:05 AM

View Postbsaunders, on 18 Feb, 2009 - 10:19 PM, said:

I don't think the input file's records match the picture clauses declared in the FD section:

01 record-in.
				  05 desc-in   pic x(14).
				  05 cargo-in  pic x(6).
				  05 unit-in   pic 999v999.
				  05 price-in  pic 99v99.
.

For the first record, this is how it works:

desc-in is an alphanumeric field with a width of 14:

BLUENOSE OIL 240000 04312

If you reply to the first post tigerfan88 made and check the quote block for the data2.txt file you will see that the field length is 15 characters, not 14. The forum software has the unfortunate practice of compressing spaces.

You're still right about about the picture not matching the data. :)

Here is the original data2 data with spaces removed:

Quote

BLUENOSE-------240000OIL-----04312
IRONSIDE-------150500ORE-----07550
DALSOHN--------064400WHEAT---00980
BALOCHSIDE-----330000COPPER--00145
SANTA-MARIA----175000OATS----00326
HIGHLAND-------180000ALUMINUM11050

This post has been edited by n8wxs: 19 February 2009 - 01:23 AM

Was This Post Helpful? 0
  • +
  • -

#10 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Keep getting an error with this Cobol program

Posted 19 February 2009 - 01:27 AM

View Posttigerfan88, on 18 Feb, 2009 - 09:24 PM, said:

It then gives me the same error, except with this line:

move unit-in to unit-out.

You may have some other problem. I've compiled your original posting code on two different systems: OpenVMS with the HP COBOL compiler, and windows using Fujitsu's COBOL'97. Both produced executables without any errors.

Here is what I get when using your second code block, with the four fields in the data record instead of the original five. The only changes I made to your code were 1) to handle OpenVMS file input/output, and 2) 05 desc-in pic x(15).

Quote

Welcome to OpenVMS ™ Alpha Operating System, Version V8.3 on node PWS600
Last interactive login on Thursday, 19-FEB-2009 01:07:37.12
Last non-interactive login on Thursday, 29-JAN-2009 18:42:55.70

$ cobo dic
$ link dic
$ run dic
$ type console.dat

output

Ship Name Units Cargo Units Price Cargo Value

000000
BLUENOSE 240 $ 00.04 OIL--- $ 78,434
IRONSIDE 150 $ 00.07 ORE--- $ 3,235
DALSOHN- 064 $ 00.00 WHEAT- $ 9,755
BALOCHSI 330 $ 00.00 COPPER $ 7,720
SANTA-MA 175 $ 00.00 OATS-- $ 46,929
HIGHLAND 180 $ 04.11 ALUMIN $ 64,630
$

This post has been edited by n8wxs: 19 February 2009 - 01:51 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1