首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cobol - 163数值字段中的非法字符

Cobol - 163数值字段中的非法字符
EN

Stack Overflow用户
提问于 2017-04-15 04:00:19
回答 4查看 1.7K关注 0票数 1
代码语言:javascript
复制
   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.

如何修复使用此代码收到的此错误消息:

错误消息:

执行错误:文件‘age2.int’错误代码: 163,pc=5AB,call=1,seg=0 163数值字段中的非法字符

有没有办法准确地找到非法字符在数字字段中的位置?我很难找到这个问题的罪魁祸首。

EN

回答 4

Stack Overflow用户

发布于 2017-04-18 03:59:06

您正在运行Micro Focus COBOL的某个变体。你遇到了一个运行时错误,它说“要么是源数据被破坏(某处),要么是我做的某件事被破坏了,而非数值数据是数值字段中的a”。

为此,数字字段是USAGE DISPLAY数字字段或数字编辑字段,或者是压缩十进制字段(尽管您没有任何这些字段,我也不完全确定这是否会得到163)。

USAGEDISPLAY (在使用上下文中)都是可选的单词,您不会经常看到它们。所以,举个例子:

代码语言:javascript
复制
           02   Zip-Out                Pic 9(5).

如果你碰巧使用Zip-Out来做一些事情,那么如果你的程序包含了除数字以外的任何东西,那么它将会被烧毁。

第一个提示:不要因为某件事是一个“数字”,就把它变成数字,除非你的处理需要它。Account-number、customer-number、part-number、zip-code都可以是简单的PIC X字段。您(几乎)永远不会将它们用于计算或将它们用作下标,那么为什么要将它们变成无用的数字呢?其他示例有天、月、年、小时、分钟、秒等。

第二个提示:了解编译选项/指令。163可以被“关闭”(在每次引用之前对数字进行测试,这不是很有效),并且会有其他事情可以修改处理。您在这里可能需要的是“显示它失败的行号”,我怀疑这是可能的。请阅读您实际编译器的选项/指令。

第三个提示:在程序部分中,只使用最小句号/句号。例如,目前所有的IF语句都以句号/句点结尾。删除这些,并替换为END-IF。找出您应该在程序中使用的其他作用域终止符,并替换它们。然后删除除终止程序分部标题和标签(段落名称)之外的所有句号/句号。然后,在第12栏中的单独一行中,以句号/句号结束每一段。

举个例子。您必须:

代码语言:javascript
复制
   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.

你可以:

代码语言:javascript
复制
   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
       .

第四个提示:不要在数据名中使用“索引”,除非它是一个索引(在发生时由INDEXED BY定义)。如果它只是一个用来作为下标的数字字段,不要用"index“来命名它。数据名的目的是准确地记录字段。这不包括误导。

第五个提示:如果你需要“编号”段落/章节,我建议你首先设计/编写/测试程序,当它完成后,再进行编号。如果数字没有按顺序排列,那么它们就没有意义,而你的数字也不是。仅仅因为设计中的缺陷而不得不修复一些东西,就没有必要多次重新编号。

第五个提示:对于数据定义,在级别编号中留下“间隙”。如果仅仅因为没有更高级别的定义就必须重构数据,那么下一个人就会讨厌你。通常会留下五个左右的空格(01,05,10,15...)。这样做没有什么坏处,它会在将来查看你的程序的其他人中保留你的名字(可能会包括你的标记)。

第六个小贴士:使用88。您正在使用88,但过程部分中仍有文字,因此您并不真正了解其好处。您还可以使用MOVE设置“标志”。如果你使用88,你可以将88转到TRUE,这比SET要清楚得多。

第七个提示:看看这里过去四年的COBOL问题。你甚至会看到相同课程的例子:-)你会从这个过程中获得更多的提示。

票数 2
EN

Stack Overflow用户

发布于 2017-04-16 07:45:33

有几种方法可以用来确定“非法字符”错误的原因:

  • 分析程序转储。
  • 使用交互式调试器。
  • 将代码添加到程序中以验证数值字段的内容。

分析程序转储

如果错误导致您的系统产生程序转储,请检查转储是否提供了任何有用的信息。

转储通常会提供如下信息:

最后一次从程序变量的每个输入变量中读取错误变量记录时,

  • 正在执行程序的哪一行

但是,如果您不够幸运,没有一个包含COBOL语言特定细节的转储,那么您将只获得要执行的下一条汇编语言指令的地址,而不是COBOL程序中的行号。

而且,您可能只获得工作存储部分的存储转储,而不是COBOL程序变量的内容。

然后,您需要使用显示生成的汇编语言代码的COBOL编译器清单,以便将汇编语言指令映射到相应的COBOL语句,并将任何感兴趣的COBOL变量映射到存储器中的相应地址。对于没有经验的开发人员来说,这样做可能既困难又耗时。

使用交互式调试器

如果您的开发环境包括交互式调试器,则可以在调试器中执行程序,直到出现错误,然后记下导致错误的程序语句和数据。

将验证代码添加到程序中

通过在程序中添加代码以在使用数值字段之前对其内容进行验证,您不仅可以确定错误的原因,还可以从中恢复。

您可能需要考虑添加的验证包括:

(1)在2100-Validate-record中测试以下附加Input-Rec字段中的数字内容

代码语言:javascript
复制
Zip
Sale-Day
Sale-Hr
Sale-Min
Sale-Sec
Latitude
Longitude

(2)在将字段Rate-Table移至Multi-Rate(City-Index)之前,先测试字段中的数值内容。

(3)在更新Bed-Bath-Accum(Bedrooms,Bathrooms)Table-Bedroom-Price(bedrooms)Table-Num-Bedrooms(bedroom-index)之前,请确认Bedrooms的值为<= 6,因为大于6的值会导致数组索引超出范围。

(4)在更新Bed-Bath-Accum(Bedrooms,Bathrooms)之前,请确认Bathrooms的值为<= 5,原因同上。

票数 1
EN

Stack Overflow用户

发布于 2018-04-27 01:19:26

有没有办法准确地找到非法字符在数字字段中的位置?

使用Micro Focus®Animator®。为“缩放”选择“Z”(或任何可用于“缩放”的菜单选项)。发生错误时,Animator将停止并突出显示出现错误的语句。当数据项用作算术语句中的发送字段时,通常会发生这种类型的错误。例如,

代码语言:javascript
复制
   program-id. err-163.
   data division.
   working-storage section.
   1 163-data pic 9(5).
   procedure division.
       add 1 to 163-data
       stop run
       .

还会显示错误Illegal character in numeric field (Error 163),并突出显示add 1 to 163-data行。

在本例中,程序尝试将空格加1,因为未初始化数据的默认值是空格。字段163-data既是一个发送字段,也是一个接收字段(在COBOL语言标准术语中)。它将其值空格发送到ADD statement,这将被检测为错误,错误将被处理或忽略,具体取决于编译器选项。

对于任何符合2002标准的实现,适用于EC-DATA-INCOMPATIBLETURN指令和内部函数EXCEPTION-LOCATION都可以提供该信息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43418436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档