本文介绍了分两列打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们应该形成一个出现108次的名称数组。我们应该在左栏中有名称1-54,在右栏中有名称55-108。在一页中有108个名称之后,我们初始化数组并重新开始。我的代码的输出显示的是打印的名称1-54,而不是在同一页上且在名称1-54旁边,而是在右列中但在名称1-54之后显示名称55-108。任何想法都将不胜感激。

We are supposed to form an array of names that occur 108 times. We are supposed to have name 1-54 in a left column and names 55-108 in a right column. After there have been 108 names for one page, we initialize our array and start over again. The output for my code is showing names 1-54 printed and, instead of being on the same page and beside names 1-54, names 55-108 in the right column but after names 1-54. Any thoughts would be greatly appreciated.

这是我的一些代码:

       PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
           READ NAMELIST-FILE-IN
               AT END
                   MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
               NOT AT END
                   PERFORM 200-PROCESS-ONE-RECORD
           END-READ
       END-PERFORM
       CLOSE NAMELIST-FILE-IN
       CLOSE NAMELIST-FILE-OUT
       STOP RUN.

   200-PROCESS-ONE-RECORD.
       ADD 1 TO NAME-SUB
       MOVE NAME-IN TO NAME-1 (NAME-SUB)
       PERFORM 220-MOVE-RECORDS.


   220-MOVE-RECORDS.
       IF NAME-SUB <= 54
           MOVE NAME-1 (NAME-SUB) TO LEFT-LABEL
           MOVE SPACES TO RIGHT-LABEL
       END-IF
       IF NAME-SUB >= 55
           MOVE NAME-1 (NAME-SUB) TO RIGHT-LABEL
           MOVE SPACES TO LEFT-LABEL
       END-IF
       MOVE DETAIL-LINE TO NAMELIST-RECORD-OUT
       WRITE NAMELIST-RECORD-OUT
           AFTER ADVANCING 1 LINE
       IF NAME-SUB >= 108
           MOVE SPACES TO DETAIL-LINE
           MOVE ZERO TO NAME-SUB
           PERFORM 300-WRITE-HEADING
       END-IF.

我已经对所有适当的WORKING-STORAGE条目进行了编码,以容纳这些信息。您知道我编写详细信息线的方式是否有问题还是我处理数据的方式吗?

I have coded all the proper WORKING-STORAGE entries to accommodate the information. Do you know if there is something wrong with the way I am writing the detail-line or is it the way I am processing my data?

推荐答案

您的逻辑错误。假设(为了简单起见)您有216个名称,则需要读取108个名称并将它们存储在NAME-1数组中。

Your logic is wrong. Lets say (just to make things easy) you have 216 names, you will need to read in 108 of them and store them in your NAME-1 array.

然后可以遍历54条线,将NAME-1 [n]放入LEFT-LABEL,将NAME-1 [n + 54]放入RIGHT-LABEL,然后移动明细行并写入输出;对第n行重复n = 1

Then you can loop over the 54 lines placing NAME-1[n] into LEFT-LABEL and NAME-1[n+54] into RIGHT-LABEL, Then move your detail-line and write to output; repeating for lines n = 1 <= 54

现在阅读您的下108行并重复。有两个循环;读取108个名称,打印54行。

Now read in your next 108 lines and repeat. So two loops; Read 108 names, print 54 lines.

显然,您需要保护其余部分,即,如果您不完全是108个名称的倍数,则类似

Obviously you will need to guard for your remainder, ie if you don't have exactly a multiple of 108 names, something like

if n <= name-sub
    move NAME-1[n] to LEFT-LABEL
else
    move spaces to LEFT-LABEL
endif

if n+54 <= name-sub
    move NAME-1[n+54] to RIGHT-LABEL
else
    move spaces to RIGHT-LABEL
endif

我意识到您将必须正确设置变量(n + 54不是正确的cobol),并且对大小写混合感到抱歉,但是很久以前,编写COBOL并现在使用小写。 ;)

I realise you will have to set the variables properly (n+54 is not proper cobol) and sorry for the mix of case, but long time ago writing COBOL and used to lower case now. ;)

这篇关于分两列打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 16:25