COBOL 如何对两个无序文件进行排序和合并?

发布于 2025-01-08 09:21:07 字数 875 浏览 4 评论 0原文

我正在做一项作业,但我有点碰壁了。我将使这个问题变得非常笼统,因为我主要是在寻找一些技巧并推动正确的方向。我要获取两个记录没有特定顺序的输入文件,将它们排序到一个输出文件中,同时排除某些条目。到目前为止,我已经发现我需要对排序语句进行编码,例如:

SORT ORDERS-FILE-SORT                          
ON ASCENDING REQUEST-DATE-S                
   ASCENDING CUST-NUMBER-S                 
   ASCENDING CUST-ORDER-NUMBER-S           
   ASCENDING PART-NUMBER-S                 
   USING INPUT PROCEDURE 200-SORT-AND-MERGE
   GIVING ORDERS-OUT                       

我还没有弄清楚在输入过程中要编码什么。

PS 还有一件事我还没弄清楚。这是一种旁注,我不想对这个特定问题提供任何具体信息,只是一个提示。我们应该排除 REQUEST-DATE 不在 6 个月内的记录。起初我以为这很简单:

01 WS-DATE
    05 RUN-YEAR            PIC 99.
    05 RUN-MONTH           PIC 99.
    05 RUN-DAY             PIC 99.

300-TEST-DATE
    ADD 6 TO RUN-MONTH
    IF REQUEST-DATE > WS-DATE

但是,如果将月份添加 6 导致它超过 12,则这是行不通的。我一直为这个问题头疼。感谢您的任何帮助,我将非常感激。

I'm working on an assignment and I've sort of hit a wall. I'm going to make the question very generic as I'm mainly looking for some tips and a shove in the right direction. I am to take two input files who's records are in no particular sequence, sort both of them into one output file while excluding certain entries. So far I've figured out that I need to code the sort statements like:

SORT ORDERS-FILE-SORT                          
ON ASCENDING REQUEST-DATE-S                
   ASCENDING CUST-NUMBER-S                 
   ASCENDING CUST-ORDER-NUMBER-S           
   ASCENDING PART-NUMBER-S                 
   USING INPUT PROCEDURE 200-SORT-AND-MERGE
   GIVING ORDERS-OUT                       

I haven't figured out what to code in the input procedure.

P.S. There is one other thing I haven't figured out. This is kind of a side notE and I don't want anything specific with this particular question, just a tip. We're supposed to exclude records with a REQUEST-DATE that is not within 6 months. At first I was thinking it was as simple as:

01 WS-DATE
    05 RUN-YEAR            PIC 99.
    05 RUN-MONTH           PIC 99.
    05 RUN-DAY             PIC 99.

300-TEST-DATE
    ADD 6 TO RUN-MONTH
    IF REQUEST-DATE > WS-DATE

However in the event that adding 6 to the month causes it to go over 12 this will not work. I've been getting a headache over this one. Thanks for any help I will really appreciate it.

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

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

发布评论

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

评论(1

顾铮苏瑾 2025-01-15 09:21:07

查看此链接。它提供了几个示例来说明如何使用 COBOL 排序动词。这个链接应该会给你很多提示。至于测试日期范围,请考虑在输入过程中进行。请参阅链接中的 MaleSort.cbl 示例,其中根据特定性别代码包含/排除记录。

在日期上加上 6 个月可能有点小技巧。 COBOL 中有许多固有的日期操作函数,但使用它们可能有点超出您现在的范围,但请查看:整数日期日期整数 或许还有 日期。另一方面,您可能会发现自己做算术很容易。

如果您选择自己进行日期数学计算,请尝试以下操作:

             ADD 6 TO RUN-MONTH
             DIVIDE RUN-MONTH BY 12 
                 GIVING WS-YEAR-ROLLOVER
                 REMAINDER IN RUN-MONTH
             END-DIVIDE
             COMPUTE RUN-YEAR = RUN-YEAR + WS-YEAR-ROLLOVER

由于您的 RUN-YEAR 只有 2 位数字长,因此如果 WS-DATE 早于 2000 年,您可能必须处理世纪翻转(我不能相信在当今时代,任何人仍然会使用 2 位数日期)。另一件需要注意的事情是天数——8 月 31 日加上 6 个月,你就到了……2 月,只有 28 或 29 天。

玩得开心。

Check out this link. It gives several examples illustrating how to use the COBOL sort verb. This link should give you plenty of hints. As for testing date ranges, consider doing it within the INPUT PROCEDURE. See the MaleSort.cbl example from the link where records are included/excluded based on having a specific gender code.

Adding 6 months to a date can be a bit of a trick. There are a number of intrinsic date manipulation functions in COBOL but using them may be a bit beyond where you are at right now, but have a look at: date-of-integer and integer-of-date and maybe dateval. On the other hand, you might find it just a easy to do the arithmetic yourself.

If you choose to do your own date math, try something along the lines of:

             ADD 6 TO RUN-MONTH
             DIVIDE RUN-MONTH BY 12 
                 GIVING WS-YEAR-ROLLOVER
                 REMAINDER IN RUN-MONTH
             END-DIVIDE
             COMPUTE RUN-YEAR = RUN-YEAR + WS-YEAR-ROLLOVER

Since your RUN-YEAR is only 2 digits long, you might have to deal with century rollover if WS-DATE is prior to year 2000 (I can't believe that anybody would still be using 2 digit dates in this day and age). Another thing to watch out for are the number of days - August 31 plus 6 months gets you to... February which only has 28 or 29 days.

Have fun.

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