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.
如何修复此代码收到的错误消息:
错误讯息:
执行错误:文件' prog2.int' 错误代码:163,pc = 5AB,call = 1,seg = 0 163数字字段中的非法字符
有没有找到非法字符在数字字段中的确切位置?我在试图找到问题的罪魁祸首时遇到了麻烦。
答案 0 :(得分:2)
您正在运行Micro Focus COBOL的某些变体。您遇到了一个运行时错误,上面写着“源数据被破坏(某处)或者我已经完成的事情被破坏了,非数字数据是一个数字字段”。
为此,数字字段是USAGE DISPLAY
数字或数字编辑字段,或压缩十进制字段(尽管您没有任何这些字段,我不完全确定'我会给你一个163)。
USAGE
和DISPLAY
(在USAGE的上下文中)都是可选字词,您不会经常看到它们。所以,举个例子:
02 Zip-Out Pic 9(5).
如果您碰巧使用Zip-Out,那么如果程序包含除数字以外的任何内容,您的程序将会刻录。
第一个提示:只是因为某个东西是“数字”,除非您的处理需要,否则不要将其设为数字。帐号,客户编号,部件号,邮政编码都可以是简单的PIC X字段。您(几乎)永远不会将它们用于计算或将它们用作下标,那么为什么要将它们数字化为无用目的?其他示例包括天,月,年,小时,分钟,秒等。
第二个提示:了解编译选项/指令。可以“关闭”163(在每个引用之前进行数字测试,这不是那么有效)并且还有其他可以修改处理的东西。你可能想要的是“告诉我它失败的行号”,我怀疑这是可能的。阅读实际编译器的选项/指令。
第三提示:在PROCEDURE DIVISION中仅使用最小的全停/周期。例如,目前,您的所有IF报表都以全站/期间终止。删除它们,并用END-IF替换。找出您应该在程序中使用的其他范围终止符,并替换它们。然后删除除终止PROCEDURE DIVISION标头和标签(段落名称)之外的所有句号/句点。然后,在另一行中,在第12列中说明,使用单个句号/句号终止每个段落。
一个例子。你有:
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.
你可以:
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
.
第四提示:除非是索引(在OCCURS上由INDEXED BY
定义),否则不要在数据名中使用“index”。如果它只是您用作下标的数字字段,请不要使用“index”命名。数据名称的目的是准确地记录字段。这不包括误导。
第五提示:如果您需要“编号”段落/ SECTIONS,我建议首先设计/编写/测试程序,当它完成时,进行编号。如果它们不是按顺序排列,则数字没有意义,而你的数字则没有。由于设计的缺点,你不得不修理一些东西,因此重新编号不是没有意义的。
第五提示:对于数据定义,在级别数中留下“空白”。如果必须重组数据只是因为在更高级别的定义中没有“差距”,那么你将会被下一个人所憎恨。通常留下五个左右的间隙(01,05,10,15 ......)。这样做没有真正的缺点,它将保留你的名字,以及将来查看你的程序的其他人(可能包括你的标记)。
第六提示:使用88s。你使用的是88s,但你仍然在PROCEDURE DIVISION中有文字,所以你并不真正理解其中的好处。您还使用MOVE
设置“标记”。如果你使用88s,你可以SET
一个88到TRUE
,比MOVE更清晰。
第七提示:在过去四年中,请查看COBOL问题。您甚至可以看到相同课程的示例:-)您将从该过程中获得更多提示。
答案 1 :(得分:1)
您可以采取多种方法来确定"非法角色的原因"错误:
如果错误导致系统产生程序转储,请检查转储以查看它是否提供任何有用的信息。
转储通常会提供以下信息:
但是,如果您没有幸运地拥有包含特定于COBOL的详细信息的转储,那么您将只获得下一个汇编语言的地址,而不是COBOL程序中的行号。要执行的指令。
而且,您可能只获得工作存储部分的存储转储,而不是COBOL程序变量的内容。
然后,您需要使用COBOL编译器列表来显示生成的汇编语言代码,以便将汇编语言指令映射到相应的COBOL语句,并将任何感兴趣的COBOL变量映射到存储中的相应地址。对于没有经验的开发人员而言,这样做可能会非常困难且耗时。
如果您的开发环境包含交互式调试器,则可以在调试器中执行程序,直到发生错误,然后记下导致错误的程序语句和数据。
通过在程序中添加代码以验证数字字段的内容,您不仅可以识别错误原因,还可以从中恢复。
您可能要考虑添加的验证包括:
(1)针对Input-Rec
中的数字内容测试以下其他2100-Validate-record
字段:
Zip
Sale-Day
Sale-Hr
Sale-Min
Sale-Sec
Latitude
Longitude
(2)在将数字内容Rate-Table
移至Multi-Rate(City-Index)
之前测试字段Bedrooms
。
(3)在更新Bed-Bath-Accum(Bedrooms,Bathrooms)
,Table-Bedroom-Price(bedrooms)
和Table-Num-Bedrooms(bedroom-index)
之前,验证Bathrooms
的值是< = 6,因为会产生大于6的值在数组索引超出范围。
(4)在更新Bed-Bath-Accum(Bedrooms,Bathrooms)
之前,验证{{1}}的值是< = 5,原因与上述相同。
答案 2 :(得分:0)
无论如何都要找到非法角色的确切位置 数字字段?
使用MicroFocus®Animator®。选择'Z'进行'缩放'(或任何菜单选择可用于'缩放')。当错误发生时,Animator将停止并突出显示错误的语句。当数据项用作算术语句中的发送字段时,通常会发生此类错误。例如,
program-id. err-163.
data division.
working-storage section.
1 163-data pic 9(5).
procedure division.
add 1 to 163-data
stop run
.
系列add 1 to 163-data
突出显示,同时显示错误Illegal character in numeric field (Error 163)
。
在这种情况下,程序试图将1添加到空格,因为未初始化数据的默认值是空格。字段163-data
既是发送字段又是接收字段(以COBOL标准术语表示)。它将其值(空格)发送到ADD statement
,这被检测为错误,并且根据编译器选项处理或忽略错误。
对于任何符合2002的实现,TURN
的适当EC-DATA-INCOMPATIBLE
指令和内在函数EXCEPTION-LOCATION
都可以提供该信息。