Cobol-导入带实十进制的带符号数字 [英] Cobol - Importing a signed numeric with real decimal

查看:212
本文介绍了Cobol-导入带实十进制的带符号数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让批处理正确解释正在读取的文件中的值。

I'm having trouble getting my batch to correctly interpret the values in a file I'm reading.

这些值具有单独的前导符号和实数十进制,例如:

The values have a separate leading sign and a real decimal, eg:

;+000000123.99;+123456789.99;

但是以下内容给了我编译错误:

But the following just gives me compilation errors:

10 FILLER     PIC X(1).
10 VALUE1     PIC S9(9),9(2) SIGN LEADING SEPARATE.
10 FILLER     PIC X(1).
10 VALUE2     PIC S9(9),9(2) SIGN LEADING SEPARATE.
10 FILLER     PIC X(1).

在这家商店中,他们使用DECIMAL POINT IS COMMA

In this shop, they use DECIMAL POINT IS COMMA

我认为我可以像上面那样定义一个数字,并且无需任何额外的工作即可读取文件,但是似乎无法使其正常工作。

I thought I'd be able to just define a numerical as above and just read the file without any extra work, but can't seem to get it to work.

如果我使用隐含的十进制数,不会出现错误。

If I use a implied decimal I don't get an error.

是否不能将符号前导和实数十进制混合使用?

Isn't it possible to mix sign leading separate and real decimal?

推荐答案

这一点非常重要。

首先,我将展示如何我做这个我这样做是因为我想知道应该具有特定值的所有内容都具有该特定值。

Firstly, I'll show how I do this. I do it this way, because I like to know that everything which should have a particular value does have that particular value.

       05  VALUE-TO-DE-EDIT. 
           10  VTDE-SIGN                   PIC X. 
               88  VTDE-SIGN-VALID         VALUE "-" "+". 
               88  VTDE-NEGATIVE           VALUE "-". 
           10  VTDE-INTEGER-PART           PIC X(9). 
           10  VTDE-DEC-POINT              PIC X. 
               88  VTDE-DEC-POINT-VALID    VALUE ".". 
           10  VTDE-DECIMAL-PART           PIC XX. 
   01  THE-NUMBER                          PIC S9(9)V99. 
   01  FILLER REDEFINES THE-NUMBER. 
       05  TN-INTEGER-PART                 PIC X(9). 
  * The S in the PICture is required, to get correct sign for a
  * positive edited value, unless you do it a different way.
  * 
       05  TN-DECIMAL-PART                 PIC S99.

然后在程序部门中,当然,细节可能会有所不同,这只是一个简短而又简短的示例:

And then in the PROCEDURE DIVISION, the details, of course, can vary, this is only an example keeping it short and minimum:

       IF ( VTDE-SIGN-VALID 
        AND VTDE-DEC-POINT-VALID 
        AND VTDE-INTEGER-PART NUMERIC 
        AND VTDE-DECIMAL-PART NUMERIC ) 
           PERFORM                  DE-EDIT-NUMBER 
           DISPLAY THE-NUMBER 
       ELSE 
           PERFORM                  BUSTED-NUMBER 
       END-IF 
       IF ( VTDE-SIGN-VALID 
        AND VTDE-DEC-POINT-VALID 
        AND VTDE-INTEGER-PART NUMERIC 
        AND VTDE-DECIMAL-PART NUMERIC ) 
           PERFORM                  DE-EDIT-NUMBER 
           DISPLAY THE-NUMBER 
       ELSE 
           PERFORM                  BUSTED-NUMBER 
       END-IF 
       ... 
   DE-EDIT-NUMBER. 
       MOVE VTDE-INTEGER-PART       TO TN-INTEGER-PART 
       MOVE VTDE-DECIMAL-PART       TO TN-DECIMAL-PART 
       IF VTDE-NEGATIVE 
           SUBTRACT THE-NUMBER      FROM ZERO 
             GIVING                 THE-NUMBER 
       END-IF 
       . 
   BUSTED-NUMBER. 
       do what you feel
       .

好,为什么在您接受答案后为什么现在显示呢?

OK, why am I showing that now after you Accepted the Answer?

您正在尝试使用分隔符号进行解决,而没有验证数据。在不验证数据的情况下,最简单的方法是取消编辑已编辑的号码。编译器为您完成了所有工作,您只需编写一个MOVE。如果符号为错误,则会出现运行时错误。如果小数点值错误,则不会发生任何事情。如果您的数字元素不是数字,则会得到一些乱码。为此,您必须100%信任数字。我始终验证的来自外部文件和报告的数据。

You were attempting your solution with a SEPARATE SIGN and without validating the data. Without validating the data, the easiest thing to do is to "de-edit" the edited number. The compiler does it all for you, you just code one MOVE. If the sign is "wrong", you'll get a run-time error. If the decimal-point value is "wrong" nothing will happen. If your elements of the number are not numeric, you'll get some slightly-garbled version of them. To do it that way, you have to 100% trust the numbers. Data from external files and from reports I always validate.

好,您是 DECIMAL POINT IS ...

将S(不是数字编辑字段的符号)更改为+,并删除 SIGN LEADING Separate

Change the S, which is not a sign for a numeric-edited field, to + and drop the SIGN LEADING SEPARATE. You should be good to go.

除非您使用 DECIMAL POINT IS COMMA ,否则COBOL使用句号/句点/ dot表示小数点。

Unless you use DECIMAL POINT IS COMMA COBOL uses a full-stop/period/dot for a decimal-point.

您的数据包含COBOL将产生的小数点,因此只需更改数据定义以使用而不是

Your data contains what COBOL would produce as a decimal-point, so just change your data-definitions to use . rather than ,.

如果要使用数据,您可以可以将经过数字编辑的字段(即具有显式小数点的字段)移动到具有隐式小数位的字段。

If you want to use the data, you can MOVE the numeric-edited field (that is what you have by having an explicit decimal-point) to a field with an implied decimal place.

您的定义将按以下方式工作只要数据在固定位置即可。如果一列中的宽度有所不同,那么您使用不同的解决方案就会遇到另一个问题。

Your definition will work as long as the data is in fixed positions. If the "widths" vary within a column, you will have a different problem with a different solution.

这篇关于Cobol-导入带实十进制的带符号数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆