如何从具有小数字段的文件更新表?

发布于 2024-10-08 05:24:11 字数 159 浏览 0 评论 0原文

我正在编写一个 cobol 程序来读取 PS 文件并根据 PS 文件中设置的标志更新 DB2 表。文件中的字段之一在 cobol 程序中被声明为十进制字段。但是当我尝试更新表中的该字段时,它显示错误。我应该在表中声明什么相同的字段以及如何编写该字段的更新语句?

字段名称是有小数点的工资。

i'm writing a cobol program to read a PS file and update a DB2 table based on the flag set in the PS file. One of the fields in the file is declared as a decimal field in the cobol program. But when i try to update that field in the table,its showing error. What should i declare the same field in the table and how should i write the update statement for the field?

The field name is salary which has a decimal point.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡忘如思 2024-10-15 05:24:11

如果您发布 PICTURE/USAGE 子句,将会更有帮助
输入文件记录中的数据项以及 DB/2 列定义。

然而,这看起来很像数据转换问题。需要检查的事项包括:

  • 输入文件记录是否具有类似于 PIC 9(5).99 的 PICTURE/USAGE。关键点
    是声明中有一个明确的小数点。如果你看一下
    使用文本编辑器(例如 ISPF 编辑器)输入文件,您会看到一些数字
    例如12345.67。这些数字采用显示格式。将它们视为文本。

  • DB/2 列定义。 DB/2 中的十进制数通常声明为:
    DECIMAL(7,2)。以这种方式声明的数字由 DB/2 以压缩十进制存储
    格式。

显示格式数字(可能存在于输入文件中)与
压缩十进制数(苹果和橙子)。

为了说明这一点,请考虑以下 COBOL 小程序:

IDENTIFICATION DIVISION.                          
PROGRAM-ID. EXAMPLE.                              
DATA DIVISION.                                    
WORKING-STORAGE SECTION.                          
01  A                  PIC 9(6).99.               
01  B                  PIC 9(6)V99 PACKED-DECIMAL.
PROCEDURE DIVISION.                               
    MOVE 123456.78 TO A                           
    DISPLAY 'A=' A                                
    MOVE A TO B                                   
    ADD 1 TO B                                    
    DISPLAY 'B=' B                                
    MOVE B TO A                                   
    DISPLAY 'A=' A                                
    GOBACK.                                       

变量 A 采用显示格式,带有明确的小数点。你能做的一切
为它分配一个值以用于显示目的。尝试执行类似 ADD 1 TO A 的操作会导致
在编译错误中。

诀窍是将显示格式的数字转换为与 DB/2 兼容的格式(例如 Packed Decimal)。
COBOL MOVE 动词可以完成这项工作。声明一个数据类型兼容的新变量
DB/2 使用的。上面的变量B就是这样一个变量。移动显示器
格式化变量到 Packed Decimal 变量,如下所示:MOVE A TO B。 COBOL 运行时执行此转换。

请注意,您现在可以向 B 添加一些内容。显示B(哎呀小数点消失了 -
我会让你弄清楚为什么)。然后再移回显示格式,嘿嘿,小数点
回来了。

DB/2 直接采用主变量,无需进行转换。如果该主变量没有
正确的数据格式你会得到一个错误。

你可能需要做类似的事情:

  Read Record
  MOVE record display data (eg. `A`) to a DB/2 compatible field (eg. `B`)
  EXEC SQL
     INSERT INTO table (
         ...
         SALARY,
         ...)
       VALUES (
         ...
         :B,
         ...)
  END-EXEC.

It would be much more helpful if you were to post the PICTURE/USAGE clauses for
the data item in your input file record as well as the DB/2 column definition.

However, this looks a lot like a data conversion issue. Things to check out are:

  • Does the input file record have a PICTURE/USAGE something like PIC 9(5).99. The key point
    is that there is an explicit decimal point in the declaration. If you look at the
    input file with a text editor (eg. the ISPF editor) you would see a number something
    like 12345.67. These numbers are in display format. Think of them as being text.

  • DB/2 column definition. Decimal numbers in DB/2 are commonly declared as something like:
    DECIMAL(7,2). Numbers declared in this way are stored by DB/2 in packed decimal
    format.

Display format numbers, as probably exist in the input file, are not compatible with
Packed Decimal numbers (apples and oranges).

To illustrate this point consider the following little COBOL program:

IDENTIFICATION DIVISION.                          
PROGRAM-ID. EXAMPLE.                              
DATA DIVISION.                                    
WORKING-STORAGE SECTION.                          
01  A                  PIC 9(6).99.               
01  B                  PIC 9(6)V99 PACKED-DECIMAL.
PROCEDURE DIVISION.                               
    MOVE 123456.78 TO A                           
    DISPLAY 'A=' A                                
    MOVE A TO B                                   
    ADD 1 TO B                                    
    DISPLAY 'B=' B                                
    MOVE B TO A                                   
    DISPLAY 'A=' A                                
    GOBACK.                                       

Variable A is in display format, with an explicit decimal point. All you can do
is assign it a value for display purposes. Trying to do something like ADD 1 TO A will result
in a compile error.

The trick is to get numbers in display format into something that is a compatible with DB/2 (eg. Packed Decimal).
The COBOL MOVE verb does this job. Declare a new variable with a data type compatible
to that used by DB/2. Variable B above is such a variable. Move the display
formatted variable to the Packed Decimal variable as in: MOVE A TO B. The COBOL run-time does this conversion.

Notice that you can now add something to B. Display B (woops the decimal point disappeared -
I will let you figure out why). Then move it back to display format, hey, the decimal point
came back.

DB/2 takes host variables as they come without conversion. If that host variable does not have the
correct data format you will get an error.

You probably need to do something like:

  Read Record
  MOVE record display data (eg. `A`) to a DB/2 compatible field (eg. `B`)
  EXEC SQL
     INSERT INTO table (
         ...
         SALARY,
         ...)
       VALUES (
         ...
         :B,
         ...)
  END-EXEC.
月依秋水 2024-10-15 05:24:11

小数字段类型以与 DB2 不兼容的格式保存值,需要在将新值发布到数据库之前进行转换(假设您具有记录的写入或更新权限)。您可能需要将其移至 PIC 9(6)V.99 字段或类似字段,然后更新 DB2 记录。 COBOL 是一种编程语言,具有用于操作的不同数据表示形式,而数据库用于将数据存储在记录中,并且可用的格式可能较少。

The decimal field type holds the value in a format which is not compatible with DB2 and needs to be converted before releasing the new value to the database (assuming you have write or update permissions for the record). You may need to move it to a PIC 9(6)V.99 field or similar then update the DB2 record. COBOL is a programming language with different data representaions for manipulation while the database is for storing away the data in a record and may have less formats available.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文