在提到在线资源时,我不太确定 Stack Overflow 和家庭作业,但 GnuCOBOL FAQ 有一个合并行顺序文件的示例。
希望这个小样本仍然让您有机会了解 MERGE,而不是剥夺您的任何机会。
https://open-cobol.sourceforge.io/faq/index.html#merge
请注意语法轨道图中的 ON ... KEY 短语如何在每个文件中重复,并带有多个文件。
避免链接腐烂;这是代码,但这应该始终可以通过在 MERGE 保留字条目中搜索“GnuCOBOL FAQ”来找到。
GCobol >>SOURCE FORMAT IS FIXED
*> ***************************************************************
*> Author: Brian Tiffin
*> Date: 20140610
*> Purpose: Demonstrate a merge pass
*> Tectonics: cobc -x gnucobol-merge-sample.cob
*> ***************************************************************
identification division.
program-id. gnucobol-merge-sample.
environment division.
configuration section.
repository.
function all intrinsic.
io input-output section.
file-control.
select master-file
assign to "master-sample.dat"
organization is line sequential.
select eastern-transaction-file
assign to "east-transact-sample.dat"
organization is line sequential.
select western-transaction-file
assign to "west-transact-sample.dat"
organization is line sequential.
select merged-transactions
assign to "merged-transactions.dat"
organization is line sequential.
select working-merge
assign to "merge.tmp".
data data division.
file section.
fd master-file.
01 master-record pic x(64).
fd eastern-transaction-file.
01 transact-rec pic x(64).
fd western-transaction-file.
01 transact-rec pic x(64).
fd merged-transactions.
01 new-rec pic x(64).
sd working-merge.
01 merge-rec.
02 master-key pic 9(8).
02 filler pic x.
02 action pic xxx.
02 filler PIC x(52).
code *> ***************************************************************
*> not much code
*> trick. DEP, CHQ, BAL are action keywords. They sort
*> descending as DEP, CHQ, BAL, so do all deposits, then
*> all withdrawals, then balance reports.
*> ***************************************************************
procedure division.
merge working-merge
on ascending key master-key
descending key action
using eastern-transaction-file, western-transaction-file,
master-file
giving merged-transactions
done goback.
end program gnucobol-merge-sample.
数据样本看起来像
11111111 CHQ 0001111.11 withdrawal from account one
33333333 DEP 0333333.33 third of a million in, pocket change
33333333 CHQ 0000333.33 payroll
33333333 CHQ 0000333.33 payroll
33333333 CHQ 0000333.33 payroll
55555555 DEP 0000555.55 deposit to new record five
55555555 CHQ 0000055.55 withdrawal from account five
东方
11111111 CHQ 0001111.11 withdrawal from account one
44444444 DEP 0000044.44 deposit to account four
66666666 BAL balance request for account six
西等。
GnuCOBOL 使得处理 LINE SEQUENTIAL 部分变得非常容易。
您的问题还有更多问题,这里没有提到,因为这个列表只是为了演示 MERGE with LINE SEQUENTIAL,而不是担心爆头。