gpt4 book ai didi

cobol - cobol 中的 "copy corresponding"是什么,它是如何工作的?

转载 作者:行者123 更新时间:2023-12-04 19:43:56 25 4
gpt4 key购买 nike

在罕见的情况下,人们 say nice things about cobol, they often mention "copy corresponding" (and "move corresponding")

我真的很想更多地了解这些——它们的语义是什么?是否与以下相同:

(Perl)

for my $key (keys %foo) {
$bar{key} = $foo{key} if exists $bar{key};
}

或者还有比这更深的东西吗? Cobol 记录是强类型的,对吗?这是如何运作的?

最佳答案

根据 AcuCOBOL 文档(我使用的):

When the CORRESPONDING phrase is used, selected elementary items in source-group are moved to corresponding items in dest-group. This is treated as a series of Format 1 MOVE statements, one for each corresponding pair of data items.



格式 1 移动如下所示:

MOVE source-item TO {dest-item}



给定以下文件和工作存储定义
DATA DIVISION.
FILE SECTION.
FD PRODUCT-INFO-FILE.
01 PRODUCT-INFO-RECORD.
03 PI-HOLD-PROD PIC x(12).
03 PI-HOLD-DESC PIC x(30).
03 PI-HOLD-DISC PIC 9(01).
03 PI-HOLD-TOTAL PIC 9(08)V99.

WORKING-STORAGE SECTION.
01 HOLD-FIELDS-DEST.
03 WS-HOLD-PROD PIC x(12).
03 WS-HOLD-DESC PIC x(30).
03 WS-HOLD-DISC PIC 9(01).
03 WS-HOLD-TOTAL PIC 9(08)V99.

这样做:
MOVE CORRESPONDING PRODUCT-INFO-RECORD TO HOLD-FIELDS-DEST.

将与这样做相同:
MOVE PI-HOLD-PROD  TO WS-HOLD-PROD.
MOVE PI-HOLD-DESC TO WS-HOLD-DESC.
MOVE PI-HOLD-DISC TO WS-HOLD-DISC.
MOVE PI-HOLD-TOTAL TO WS-HOLD-TOTAL.

这节省了 3 行代码。许多文件都比这更宽。

编辑:
这也来自同一组文档......

The following table outlines the combinations of source-item and dest-item that are allowed by the MOVE statement. The numbers in the table are the "General Rules" numbers in this section where each combination is described:


Sending Category:   Receiving Item Category:
Alphabetic Alphanumeric/Alphanumeric Edited Numeric /Numeric Edited
Alphabetic Yes (12) Yes (13) No (15)
Alphanumeric Yes (12) Yes (13) Yes (14)
Alphanumeric Edited Yes (12) Yes (13) No (15)
Numeric Integer No (15) Yes (13) Yes (14)
Numeric
Non-integer No (15) No (15) Yes (14)
Numeric Edited No (15) Yes (13) Yes (14)

'12. When dest-item is alphabetic, justification and space filling occur according to the standard alignment rules.

'13. When dest-item is alphanumeric or alphanumeric edited, justification and space filling occur according to the standard alignment rules. If source-item is signed numeric, the operational sign is not moved. If the sign occupies a separate character position, that sign character is not moved, and the size of source-item is treated as being one less.

'14. When dest-item is numeric or numeric edited, decimal point alignment and zero filling occur according to the standard alignment rules. If source-item is unsigned, it is treated as being positive. If dest-item is unsigned, the absolute value of source-item is moved. If dest-item is signed, its sign is set to the sign of source-item. If source-item is numeric edited, it is "de-edited" first such that dest-item receives the same numeric value.

'15. The following moves are illegal: An alphabetic or alphanumeric edited data item may not be moved to a numeric or numeric edited data item. A numeric or numeric edited data item may not be moved to an alphabetic item. A non-integer numeric data item cannot be moved to an alphanumeric or alphanumeric edited data item.

关于cobol - cobol 中的 "copy corresponding"是什么,它是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1440120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com