【问题标题】:How to write merge files with keys having duplicate values in cobol如何使用在cobol中具有重复值的键编写合并文件
【发布时间】:2021-07-24 13:11:56
【问题描述】:

请帮助编写具有重复记录的键的合并 2 个文件。

我的要求是

         Key1.       Key2
          015.        015
          015.        015
          017.        017
         019.        017
         019.        019
         019.        019

        Op file needs to check
             Key1=key2
          If so,my op will be
               015
               015
              017
              017
              019
              019
              019 like this..
         I have written like this.But it is working for 015 and 
           017..not helping for 019
           Process para.
              If eof-input1 = 'N'
                 If key1 = key2
                    Move details from file2
                      to op1
                    Write op1
                    Read file2
                 Else
                    If key1<key2
                       Read file1 until eof1
                        or key1>=key2
                        If key1=key2
                         Move details
                          Write op1
                         Read file2
                        End-if
                      End-if
                    End-if
                  End-if.

如果我尝试像这样为 cond key1>key2 编写它不起作用..我不知道如何获得完整的操作。 请帮忙。 提前致谢!!

【问题讨论】:

    标签: file merge key match cobol


    【解决方案1】:

    关键点:

    • 您需要确保两个文件排序到相同的顺序。查找Cobol Sort verb
    • 最新版本的 Cobol 有一个 merge 语句。您可能可以使用取决于
      • 程序逻辑
      • 如果您的编译器支持。
    • Cobol SortCOBOL Merge 上已经有很多 Stackoverflow 问题

    通用合并逻辑

    我发现带有 EVALUATE 语句的以下逻辑最容易阅读/调试。假设升序键,基本上你读取具有最低键的文件,当它们相等时你有匹配

    if (key-file1 > key-file2)
        read file2
    else if (key-file1 < key-file2)
        read file1
    else
        /* what you do here is determined by the file structure
           * one to one match -> read both files
           * one to many relationship read the `may` file */
       read both files ?
    

    either 文件达到 eof 时,您将停止循环。然后分别处理剩下的

    更多的 Cobol 形式

           perform  r100-read-file-1
           perform  r200-read-file-2
           
           perform until eof-file-1 or eof-file-2
              evaluate true
              when key-File-1 > key-file-2
                 ...  what ever
                 perform r200-read-file-2
              when key-File-1 < key-file-2
                  ...  what ever
                 perform r100-read-file-1
              when key-File-1 = key-file-2
                 perform process-match
                 perform r100-read-file-1 and/or perform r200-read-file-2
             end-evaluate
          end-perform
          
          perform until eof-file-1
             ...  what ever
             perform r100-read-file-1
          end-perform
          
          
          perform until eof-file-2
             ...  what ever
             perform r200-read-file-2
          end-perform          
    

    【讨论】:

    • 谢谢布鲁斯!!我的文件已经整理好了。我已经像上面的方法一样测试过。我没有得到所需的输出..
    • 代码采用升序键。在问题中,键未按排序顺序列出。这是它们在文件中出现的顺序吗???
    • 我的代码给出了 sec1 count = sec2 count 的成功结果。和 sec2 count > sec1 count ..但不适用于 sec1 count > sec2count。
    • If in1>in2 (我必须检查 in2 键是否等于 prev 键并且需要执行循环直到它等于 prev 键)来写 op.. 我不知道怎么写..请帮忙。
    • 你也不需要第二个循环。确保在每个 when 子句中读取正确的文件。还可以尝试将显示放入代码中以查看发生了什么。如果你不能得到什么是错的问第二个问题
    猜你喜欢
    • 1970-01-01
    • 2015-08-17
    • 2019-12-15
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-22
    相关资源
    最近更新 更多