Reputation: 11
Identification Division.
Program-Id. Fifth-Assignment.
Author. Joanne Lin.
Date-Written. 04/12/2017.
Date-Compiled.
*Joanne Lin.
*Assignment #5.
Environment Division.
Input-Output Section.
File-Control.
Select City-File
assign to "/home1/c/a/acsi203/cityrates.dat".
Select Input-File
assign to "/home1/c/a/acsi203/realestate.dat".
Select Output-File
assign to "prog5out.dat"
Organization is line sequential.
Select Error-File
assign to "error5out.dat"
Organization is line sequential.
Data Division.
File Section.
FD City-File.
01 Input-City.
02 City-Table Pic a(15).
02 Rate-Table Pic v9(3).
02 Filler Pic x.
FD Input-File.
01 Input-Rec.
02 Street-Address Pic x(27).
02 City Pic a(15).
02 Zip Pic 9(5).
02 State Pic a(2).
88 Valid-State value "CA".
02 Bedrooms Pic 9.
02 Bathrooms Pic 9.
02 Square-Feet Pic 9(4).
02 Property-Type Pic x(8).
88 Valid-Property values
"Resident",
"Condo",
"Multi-fa".
02 Sale-Day-week Pic a(3).
02 Filler Pic x(1).
02 Sale-Month Pic x(3).
02 Filler Pic x(1).
02 Sale-Day Pic 9(2).
02 Filler Pic x(1).
02 Sale-Hr Pic 9(2).
02 Filler Pic x(1).
02 Sale-Min Pic 9(2).
02 Filler Pic x(1).
02 Filler Pic x(1).
02 Sale-Sec Pic 9(2).
02 Filler Pic x(1).
02 Time-Zone Pic a(3).
02 Filler Pic x(1).
02 Sale-Year Pic x(4).
02 Sale-Price Pic 9(6).
02 Latitude Pic 99V9(6).
02 Longitude Pic 99V9(7).
02 Filler Pic x.
FD Output-File
linage is 58 lines
with footing at 56
lines at top 5
lines at bottom 5.
01 Output-Rec Pic x(132).
FD Error-File.
01 Error-rec Pic x(132).
Working-Storage Section.
01 Report-Header.
02 Filler Pic x(48) value spaces.
02 Filler Pic x(43) value
"California Area Real Estate Transactions - ".
02 Current-Month Pic 99.
02 Filler Pic x value "/".
02 Current-Day Pic 99.
02 Filler Pic x value "/".
02 Current-Year Pic 9999.
01 Date-Header.
02 Year-head Pic 9999.
02 Month-head Pic 99.
02 Day-head Pic 99.
01 Column-Headers.
02 Filler pic x(27) value "Address".
02 Filler pic x(1) value spaces.
02 Filler pic x(16) value "City".
02 Filler pic x(6) value "Zip".
02 Filler pic x(3) value "St".
02 Filler pic x(6) value "BD".
02 Filler pic x(3) value "BT".
02 Filler pic x(4) value "SFt".
02 Filler pic x(10) value "Prop Type".
02 Filler pic x(4) value "Day".
02 Filler pic x(4) value "Mth".
02 Filler pic x(3) value "DD".
02 Filler pic x(3) value "HR".
02 Filler pic x(3) value "MN".
02 Filler pic x(3) value "SC".
02 Filler pic x(4) value "Zon".
02 Filler pic x(5) value "Year".
02 Filler pic x(6) value "Price".
02 Filler pic x(6) value spaces.
02 Filler pic x(9) value "Latitude".
02 Filler pic x(10) value "Longitude".
02 Filler pic x(7) value "$/Sq Ft".
02 Filler pic x(1) value spaces.
02 Filler pic x(9) value "Est Value".
01 Info-Line.
02 Street-Address-out Pic x(27).
02 Filler Pic x(1) value spaces.
02 City-out Pic a(15).
02 Filler Pic x(1) value spaces.
02 Zip-Out Pic 9(5).
02 Filler Pic x(1) value spaces.
02 State-out Pic a(2).
02 Filler Pic x(1) value spaces.
02 Bedrooms-out Pic x(5).
02 Filler Pic x(2) value spaces.
02 Bathrooms-out Pic 9(1).
02 Filler Pic x(1) value spaces.
02 Square-feet-out Pic 9(4).
02 Filler Pic x(1) value spaces.
02 Property-Type-out Pic x(8).
02 Filler Pic x(1) value spaces.
02 Sale-Day-week-out Pic x(3).
02 Filler Pic x(1) value spaces.
02 Sale-Month-out Pic x(3).
02 Filler Pic x(1) value spaces.
02 Sale-day-out Pic 9(2).
02 Filler Pic x value spaces.
02 Sale-hr-out Pic 9(2).
02 Filler Pic x value spaces.
02 Sale-min-out Pic 9(2).
02 Filler Pic x value spaces.
02 Sale-Sec-out pic 9(2).
02 Filler Pic x value spaces.
02 Time-Zone-out pic x(3).
02 Filler Pic x(1) value spaces.
02 Sale-Year-out Pic x(4).
02 Filler Pic x(1) value spaces.
02 Sale-price-out Pic $zzz,zz9.99.
02 Filler Pic x(1) value spaces.
02 Latitude-out Pic 9(8).
02 Filler Pic x value spaces.
02 Longitude-out Pic 9(9).
02 Filler Pic x(2) value spaces.
02 Price-Sq-Ft-Out Pic $zz9.99.
02 Filler Pic x(1) value spaces.
02 Estimate-Value-Out Pic $zzz,zz9.99.
01 WSMisc-fields.
02 WS-Price-Sq-Ft Pic 9(6)V99.
02 ws-Estimate-value Pic 9(6)V99.
02 Total-Bedrooms Pic 9(5) value zeros.
02 Total-Bathrooms Pic 9(5) value zeros.
02 Total-Square-Feet Pic 9(7) value zeros.
02 Total-Sale-Price Pic 9(9) value zeros.
02 Total-Records Pic 9(5) value zeros.
02 Avg-Bedrooms Pic 9(5)V99.
02 Avg-Bathrooms Pic 9(5)v99.
02 Avg-Square-Feet Pic 9(6)V99.
02 Avg-Sale-Price Pic 9(6)V99.
02 Row-Index Pic 9(2).
02 Bedroom-Index Pic 9.
02 Sale-Price-Temp Pic 9(8)v99 value zeros.
01 Error-out-line.
02 Filler Pic x(15) value
"Record Number: ".
02 Error-rec-number Pic z,zz9.
02 Filler Pic x(2) value spaces.
02 Error-message Pic x(30) value spaces.
02 Filler Pic xx value spaces.
01 WS-Error-line Pic x(114) value spaces.
01 Averages.
02 Filler Pic x(9) value "Averages:".
02 Filler Pic x(45) value spaces.
02 Bedroom-Average Pic zzz.
02 Filler Pic x(2) value spaces.
02 Bathroom-Average Pic zzz.
02 Filler Pic x(2) value spaces.
02 SqFt-Average Pic z,zzz,zz.
02 Filler Pic x(5) value spaces.
02 Sale-Price-Average Pic $$,$$$,$$9.99.
01 End-Report.
02 Filler Pic x(60) value spaces.
02 Filler Pic x(13) value
"End of Report".
02 Filler Pic x(59) value spaces.
01 Number-of-files-line.
02 Filler Pic x(29) value
"Number of records processed:".
02 Rec-count Pic 9(4) value 0.
02 Filler Pic x(99) value spaces.
01 eof-flag Pic xxx value "No".
01 Invalid-flag Pic xxx value "No".
01 eop-flag Pic x value "N".
01 eof-city-flag Pic x value "N".
01 match-flag Pic x value "N".
01 blank-line Pic x(132) value spaces.
01 Page-Footer.
02 Filler Pic x(80) value spaces.
02 Filler Pic x value "-".
02 Page-Num Pic 9 value 1.
02 Filler Pic x value "-".
01 Bedrooms-Heading.
02 Filller Pic x(18) value "Number of Bedrooms".
02 Filler Pic x(6) value spaces.
02 Filler Pic x(22) value
"Accumulated Sale Price".
01 WS-Num-Bedroom.
02 Filler Pic x(5) value "Zero".
02 Filler Pic x(5) value "One".
02 Filelr Pic x(5) value "Two".
02 Filler Pic x(5) value "Three".
02 Filler pic x(5) value "Four".
02 Filler Pic x(5) value "Five".
02 Filler Pic x(5) value "Six".
01 Ws-Num-Bedroom-Table redefines Ws-Num-Bedroom.
02 Table-Num-Bedrooms occurs 7 times Pic x(5).
01 Ws-Sale-Price-Table occurs 6 times.
02 Table-bedroom-price Pic 9(9)v99 value zeroes.
01 Total-Sale-Bedroom.
02 Filler Pic x(7) value spaces.
02 Num-bedrooms Pic 9(1).
02 Filler Pic x(18) value spaces.
02 Tot-Sale-Price Pic $zzz,zzz,zz9.99.
01 City-Index Pic 99 value 1.
01 City-Rate-Table occurs 22 times
ascending key is city-name
indexed by City-Table-Index.
02 City-Name Pic a(15).
02 Multi-Rate pic v9(3).
01 Bath-Header.
02 Filler Pic x(13) value spaces.
02 Filler Pic x(5) value "Baths".
02 Filler Pic x(15) value spaces.
02 Filler Pic x value "1".
02 Filler Pic x(18) value spaces.
02 Filler Pic x Value "2".
02 Filler Pic x(18) value spaces.
02 Filler Pic x Value "3".
02 Filler Pic x(18) Value spaces.
02 Filler Pic x Value "4".
02 Filler Pic x(18) Value spaces.
02 Filler Pic x Value "5".
01 Bedroom-Header.
02 Filelr Pic x(4) value spaces.
02 Filler Pic x(6) value "Bedrms".
01 Bed-Row occurs 6 times.
02 Bath-Col occurs 5 times.
03 Bed-Bath-Accum Pic 9(8)v99 value zeroes.
01 Bed-Bath-Row occurs 6 times.
02 Filler Pic x(15) value spaces.
02 Bed-Num-Out Pic zz9.
02 Filler Pic x(8) value spaces.
02 Bed-Bath-Sale-Out occurs 5 times.
03 Bed-Bath-Sale Pic zzz,zzz,zz9.99.
03 Filler Pic x(5) value spaces.
01 Column-Counter Pic 99 value 0.
Procedure Division.
*Main logic of the program.
0000-Main-Logic.
Perform 1000-Init.
Perform 2000-Main-Loop until Eof-Flag = "Yes".
Perform 3000-Calculate-Average.
Perform 4000-Finish.
Perform 5000-Write-Bedroom-Heading.
* Prints 1-dimensional table accumulated price
* per bedroom
Perform 6000-Print-Tot-Price-Bed
varying row-index from 1 by 1
until row-index > 6.
Perform 8000-Write-Ftr-Space-Line-Num.
Perform 6500-Write-Bed-Bath-Headings.
Perform 7000-Print-Bed-Bath-Sales-Tot
varying row-index from 1 by 1
until row-index > 6.
Perform 8000-Write-Footer.
Perform 9000-Close-Files.
Stop Run.
1000-init.
Open Input Input-File
Input City-File
output Output-File
output Error-File.
Perform 1500-Load-City-Rate until
Eof-City-Flag = "Y".
Close City-File.
Move Ws-Num-Bedroom to Ws-Num-Bedroom-Table.
Move Function Current-Date to Date-header.
Move Year-head to Current-year.
Move Month-head to Current-month.
Move Day-head to Current-day.
Write Output-Rec from Report-Header
after advancing 2 lines.
Write Output-Rec from Column-Headers
after advancing 2 lines.
Write output-Rec from blank-line.
Read Input-File at end move "Yes" to Eof-Flag.
1500-Load-City-Rate.
Read City-File at end move "Y" to Eof-City-Flag.
If Eof-City-Flag = "N"
Move City-Table to City-Name(City-Index)
Move Rate-Table to Multi-Rate(City-Index)
Add 1 to City-Index.
2000-Main-Loop.
Add 1 to Rec-count.
Perform 2100-Validate-Record.
If Invalid-Flag = "N"
Perform 2200-Write-Good-Record
else
Perform 2300-Write-Error-Record.
Read Input-File at end move "Yes" to Eof-Flag.
2100-Validate-record.
If Valid-State and
Valid-Property and
Bedrooms is Numeric and
Bathrooms is Numeric and
Square-feet is Numeric and
Sale-Price is Numeric
Move "N" to Invalid-Flag
Else
Move "Y" to Invalid-Flag.
2200-Write-Good-Record.
Move Street-Address to Street-Address-out.
Move City to City-out.
Move State to State-out.
Move Zip to Zip-out.
Move 1 to City-Index.
Move "Y" to Match-Flag.
Search all City-Rate-Table
at end
Move "N" to Match-Flag
When City-Name(City-Table-Index) = City
Compute Sale-Price-Temp = Sale-Price *
Multi-Rate(City-Table-Index).
If bedrooms > 0 and Bathrooms > 0 and
Match-Flag = "Y"
Add Sale-Price-Temp to
Bed-Bath-Accum(Bedrooms,Bathrooms).
If bedrooms > 0
Add Sale-Price-temp to Table-Bedroom-Price(bedrooms).
Compute bedroom-index = Bedrooms + 1.
Move Table-Num-Bedrooms(bedroom-index) to
Bedrooms-Out.
Move Bathrooms to Bathrooms-out.
Move Square-feet to Square-feet-out.
Move Property-Type to Property-Type-out.
Move Sale-Day-week to Sale-Day-week-out.
Move Sale-Month to Sale-Month-out.
Move Sale-day to Sale-day-out.
Move Sale-hr to Sale-hr-out.
Move Sale-min to Sale-min-out.
Move Sale-sec to Sale-sec-out.
Move Sale-Year to Sale-Year-out.
Move Sale-price-Temp to Sale-price-out.
Perform 2050-Calculation.
Write Output-Rec from Info-Line at eop
perform 2040-Write-Page-Footer.
Add 1 to Rec-Count.
2040-Write-Page-Footer.
Write Output-Rec from Page-Footer
after advancing 2 lines.
Add 1 to Page-Num.
Write Output-Rec from Report-Header
after advancing page.
Write Output-Rec from Column-Headers
after advancing 2 lines.
Write Output-Rec from Blank-Line.
2050-Calculation.
If Square-feet > 0
Compute WS-Price-Sq-Ft =
Sale-price-temp / Square-feet
Else
Move 0 to WS-Price-Sq-Ft.
Move WS-Price-Sq-Ft to Price-Sq-Ft-out.
If City = "SACRAMENTO" or "RIO LINDA"
Compute WS-Estimate-Value = Sale-price-temp * 1.18
Else
Compute WS-Estimate-Value = Sale-price-temp * 1.13.
Move WS-Estimate-Value to Estimate-Value-out.
If Square-feet > 0
Add Bedrooms to Total-Bedrooms
Add Bathrooms to Total-Bathrooms
Add Square-feet to Total-Square-Feet
Add Sale-Price-temp to Total-Sale-Price
Add 1 to Total-Records.
2300-Write-Error-Record.
Move Input-Rec to WS-Error-Line.
Write Error-Rec from WS-Error-Line.
Move Rec-count to Error-rec-number.
If not Valid-State
Move "State is invalid" to error-message
Write error-rec from Error-out-line.
If not Valid-Property
Move "Propery Type is invalid" to error-message
Write error-rec from Error-out-line.
If Bedrooms is not numeric
Move "Bedrooms is not numeric" to error-message
Write error-rec from Error-out-line.
If Bathrooms is not numeric
Move "Bathrooms is not numeric" to error-message
Write error-rec from Error-out-line.
If Square-Feet is not numeric
Move "Square feet is not numeric" to error-message
Write error-rec from Error-out-line.
If Sale-Price is not numeric
Move "Sale Price is not numeric" to error-message
Write error-rec from Error-out-line.
Write error-rec from blank-Line.
3000-Calculate-Average.
Compute Avg-Bedrooms =
Total-Bedrooms / Total-Records.
Compute Avg-Bathrooms =
Total-Bathrooms / Total-Records.
Compute Avg-Square-Feet =
Total-Square-Feet / Total-Records.
Compute Avg-Sale-Price =
Total-Sale-Price / Total-Records.
Move Avg-Bedrooms to Bedroom-Average.
Move Avg-Bathrooms to Bathroom-Average.
Move Avg-Square-Feet to SqFt-Average.
Move Avg-Sale-Price to Sale-Price-Average.
6000-Print-Tot-Price-Bed.
Move Table-Bedroom-Price(row-index) to
Tot-Sale-Price.
move row-index to Num-Bedrooms.
Write Output-Rec from Total-Sale-Bedroom.
4000-Finish.
Write Output-Rec from Averages
after advancing 2 lines.
Write Output-Rec from Number-of-files-line
after advancing 2 lines.
Perform 5500-Write-Blank-Lines until Eop-Flag = "Y".
5500-Write-Blank-Lines.
Write Output-Rec from blank-Line
at eop Write Output-Rec from Page-Footer
Move "Y" to Eop-Flag.
5000-Write-Bedroom-Heading.
Add 1 to Page-Num.
Write Output-Rec from Bedrooms-Heading
after advancing page.
Write Output-Rec from blank-Line.
6500-Write-Bed-Bath-Headings.
Add 1 to Page-Num.
Write Output-Rec from Bath-Header
after advancing page.
Write Output-Rec from Bedroom-Header.
Write Output-Rec from blank-Line.
7000-Print-Bed-Bath-Sales-Tot.
Move Row-Index to Bed-Num-Out(Row-Index).
Perform 7500-Print-Line varying
Column-Counter from 1 by 1
Until Column-Counter > 5.
Write Output-Rec from Bed-Bath-Row(Row-Index).
7500-Print-Line.
Move Bed-Bath-Accum(Row-Index,Column-Counter) to
Bed-Bath-Sale(Row-Index,Column-Counter).
8000-Write-Ftr-Space-Line-Num.
Move "N" to Eop-Flag.
Perform 5500-Write-Blank-Lines until Eop-Flag = "Y".
8000-Write-Footer.
Write Output-Rec from blank-line.
Write Output-Rec from End-Report.
Perform 8000-Write-Ftr-Space-Line-Num.
9000-Close-Files.
Close Output-File Input-File Error-File.
How would I go about fixing this error message received with this code:
Error message:
Execution error : file 'prog2.int' error code: 163, pc=5AB, call=1, seg=0 163 Illegal character in numeric field
Is there anyway to find exactly where the illegal character is in the numeric field? I'm having trouble attempting to find the culprit of the issue.
Upvotes: 1
Views: 2886
Reputation: 1
go to command prompt and type this command set cobsw=-f and press enter and try again
Upvotes: 0
Reputation: 4407
Is there anyway to find exactly where the illegal character is in the numeric field?
Use Micro Focus® Animator®. Select 'Z' for 'zoom' (or whatever menu selection is available to 'zoom'). When the error occurs Animator will stop and highlight the statement with the error. This type of error generally happens when the data item is used as a sending field in an arithmetic statement. For example,
program-id. err-163.
data division.
working-storage section.
1 163-data pic 9(5).
procedure division.
add 1 to 163-data
stop run
.
The line, add 1 to 163-data
, is highlighted with the error Illegal character in numeric field (Error 163)
also shown.
In this case, the program is attempting to add 1 to spaces, because the default for uninitialized data is spaces. The field 163-data
is both a sending and receiving field (in COBOL standard terms). It sends its value, spaces, to the ADD statement
, this is detected as an error, and the error is either processed or ignored, depending on compiler options.
With any conforming 2002 implementation, a suitable TURN
directive for EC-DATA-INCOMPATIBLE
and the intrinsic function EXCEPTION-LOCATION
could provide that information.
Upvotes: 0
Reputation: 13076
You are running some variant of Micro Focus COBOL. You have encountered a run-time error which says "either the source-data is busted (somewhere) or something I've done is busted, and non-numeric data is a in a numeric field".
For this purpose, a numeric field is a USAGE DISPLAY
numeric or numeric-edited field, or a packed-decimal field (although you don't have any of those, and I'm not completely sure that'll get you a 163).
Both USAGE
and DISPLAY
(in the context of USAGE) are optional words which you won't often see. So, an example:
02 Zip-Out Pic 9(5).
If you happen to use Zip-Out for something, then your program will burn if it contains anything other than numbers.
First Tip: just because something is a "number", don't make it numeric unless your processing requires it. Account-number, customer-number, part-number, zip-code can all be simple PIC X fields. You are (almost) never going to use those for calculations or use them as subscripts, so why make them numeric for no purpose? Other examples are days, months, years, hours, minutes, seconds, etc.
Second Tip: become aware of compile options/directives. The 163 can be "turned off" (the test for numeric is made before each reference, which is not so efficient) and there will be other things which can modify the processing. What you probably want here is "show me the line-number it failed at", which I suspect is possible. Read up on the options/directives for your actual compiler.
Third Tip: in the PROCEDURE DIVISION use only the minimum full-stops/periods. At the moment, for instance, all your IF statements are terminated by full-stops/periods. Delete those, and replace by END-IF. Find out what other scope-terminators you should be using in your program, and replace those. Then remove all full-stops/periods except that terminating the PROCEDURE DIVISION header and the labels (paragraph-names). Then, on a separate line, stating in column 12, terminate each paragraph with a single full-stop/period.
An example. You have:
1500-Load-City-Rate.
Read City-File at end move "Y" to Eof-City-Flag.
If Eof-City-Flag = "N"
Move City-Table to City-Name(City-Index)
Move Rate-Table to Multi-Rate(City-Index)
Add 1 to City-Index.
You could have:
1500-Load-City-Rate.
Read City-File
at end
move "Y" to Eof-City-Flag
End-read
If Eof-City-Flag = "N"
Move City-Table to City-Name
( City-Index )
Move Rate-Table to Multi-Rate
( City-Index )
Add 1 to City-Index
End-if
.
Fourth Tip: Don't use "index" in a data-name unless it is an index (defined by INDEXED BY
on an OCCURS). If it is simply a numeric field which you are using as a subscript, don't name it with "index". The purpose of data-names is to document, accurately, fields. That does not include misleading.
Fifth Tip: If you are required to "number" paragraphs/SECTIONS, I'd suggest desing/write/test the program first, and when it is complete, do the numbering. There is no point in numbers if they are not in sequence, and yours are not. There is no point in renumbering more than once just because you had to fix-up some things due to shortcomings with the design.
Fifth Tip: For data-definitions, leave "gaps" in the level-numbers. You will be hated by the next person along if the have to restructure your data just because there is no "gap" to put in a higher-level definition. It is common to leave gaps of five or so (01, 05, 10, 15...). There is no real downside in doing this and it will preserve your name amongst others who look at your program in the future (which will presumably include your marker).
Sixth Tip: Use 88s. You are using 88s, but you still have literals in the PROCEDURE DIVISION, so you don't really understand the benefits. You are also setting "flags" with MOVE
. If you use 88s, you can SET
an 88 to TRUE
, much clearer than a MOVE.
Seventh Tip: Look around at COBOL questions here from the last four years. You'll even see examples of the same course work :-) You'll get more Tips from that process.
Upvotes: 2
Reputation: 271
There are several approaches you can take to determine the cause of the "Illegal character" error:
If the error caused your system to produce a program dump, check the dump to see if it provides any useful information.
Dumps will normally provide information such as:
However, if you are not lucky enough to have a dump containing COBOL-specific details, then instead of a line number in your COBOL program, you will get only the address of the next assembly language instruction to be executed.
And, instead of the contents of your COBOL program variables, you may get only a storage dump of the Working-Storage Section.
You would then need to use a COBOL compiler listing that displays the generated assembly language code in order to map the assembly language instruction to the corresponding COBOL statement, and to map any COBOL variables of interest to the corresponding addresses in storage. Doing this would likely be difficult and time-consuming for an inexperienced developer.
If your development environment includes an interactive debugger, you can execute your program within the debugger until the error occurs, and then note the program statement and data that caused the error.
By adding code to your program to validate the contents of numeric fields before using them, you can not only identify the cause of the error, but also recover from it.
Validations you might want to consider adding include:
(1) Testing the following additional Input-Rec
fields for numeric content in 2100-Validate-record
:
Zip
Sale-Day
Sale-Hr
Sale-Min
Sale-Sec
Latitude
Longitude
(2) Testing field Rate-Table
for numeric content before moving it to Multi-Rate(City-Index)
.
(3) Verify that the value of Bedrooms
is <= 6 before updating Bed-Bath-Accum(Bedrooms,Bathrooms)
, Table-Bedroom-Price(bedrooms)
, and Table-Num-Bedrooms(bedroom-index)
, since a value greater than 6 would result in the array indexes being out-of-range.
(4) Verify that the value of Bathrooms
is <= 5 before updating Bed-Bath-Accum(Bedrooms,Bathrooms)
, for the same reason as above.
Upvotes: 1