record-line/output-line 中的第一个计算记录在 COBOL 的输出中变为空白

First calculated records in record-line/output-line becomes BLANK in output in COBOL

我的计算是正确的。但是输出文件的 ONLY first calculated 记录变为 BLANK 并影响所有记录。

在输出文件 [A5-SalaryReport-5A.out] 中,您可能会看到第一条记录的位置为空白.

这是我的输入文件 [A5.dat]

030ALLDREN RUTH   21G202000002200000
185DONNEMAN THOMAS06G042300900460000
004ACHER WILLIAM  01N072600500720000
325HATFIELD MARK  01G112200201100000
730REEDE OWEN     09G055501000620000
111CARTOLER VIOLET02G099800701000000
590NEIL CLARENCE  07N006500900100000
801SCHEIBER HARRY 01N100000001000000
956WANGLEY THEO   01N099999101000000
999BAKER RON      03G300001403500000
181DELBERT EDWARD 12G065901300770000
311GROLER GRACE   23N064302000770000
318HANEY CAROL    09G500001405500000
487KING MILDRED   18N091996301000000
834TRAWLEY HARRIS 05N732600507700000
027ALHOUER ELAINE 01G257300202500000
171COSTA NAN      15N035600500400000
317HANBEE ALETA   03G500000305500000
739RIDEL ROBERT   05N019400800200000
806STOCKTON NORMAN06G250700704300000
122CENNA DICK     03N577700406000000
207EBERHARDT RON  05G400700904500000
308GLEASON JAMES  01G500000305000000
568LYNNF GERALD   09N448701304500000
909UDSON DORIS    01N449900304500000
100BATES TONY     08N106602001000000
179DAMSON ERIC    03N250201802500000
292EVERLEY DONNA  03G200001702500000
409ICK MICK       25G999999910500000
607ODELLE NICK    10G250701803000000
825TILLMAN DON    12N044401900500000
214EDMONSON RICK  02N100000001000000
310GORMALLY MARIE 03N302200603000000
332HELD ANNA      02G400000204000000
689OWNEY REED     04N317460303500000
802SHEA MICHAEL   06G203300802300000
102BELLSLEY ART   08G300000903500000
282ESTABAN JUAN   19G405500004500000
322HARLETON JEAN  07N089901201000000
505LAMBERT JERRY  01G400100404000000
921ULL GEORGE     18N229885102500000
105BOYLE RALPH    08N804401407800000
215EDSON WILBUR   06G705000808000000
315HALE ALAN      12N400001604500000

这是我的 COBOL 项目文件 .cbl [A5-SalaryReport-5A.cbl]

    identification division.
       program-id. A5-SalaryReport-5A.
       author. Nirmal Patel.
       date-written. 11 March 2021.

*      NOTE: I could have finished this, I just had too much for 
*            this week so I couldn not give this enough time. And I 
*            started this assignment on the day it it was due, 5th 
*            March.

       environment division.
       input-output section.
       file-control.
       
                  select input-file
                      assign to "../../../data/A5.dat"
                      organization is line sequential.

                  select output-file
                      assign to "../../../data/A5-SalaryReport-5A.out"
                      organization is line sequential.
      *
                   select outputdat-file
                       assign to 
                       "../../../data/A5-SalaryData-NonGrad.dat"
                       organization is line sequential. 
       data division.
       file section.
              fd input-file
                  data record is input-rec
                  record contains 36 characters.
       01 input-rec.
         05 in-emp-no          pic 9(3).
         05 in-name            pic x(15).
         05 in-yrs-serv        pic 9(2).
         05 in-edu-code        pic x(1).
           88 il-88-type-K value "N".
         05 in-prsnt-sly       pic 9(5)V99.
         05 in-bgt-est         pic 9(6)V99.

       fd output-file
           data record is output-file
           record contains 120 characters.
*     
       01 output-line          pic x(120).

       fd outputdat-file
           data record is outputdat-line
           record contains 55 characters.

       01 outputdat-line       pic x(55).

       working-storage section.

       01 ws-eof-flag          pic x           value 'n'.
*
       01 ws-heading-info-line.
         05 filler             pic x(26)
           value "Nirmal Patel, Assignment 4".
*                 ----+----1----+----2----+-
         05 filler             pic x(15)       value spaces.
         05 filler             pic x(8)        value "20210411".
         05 filler             pic x(23)       value spaces.
         05 filler             pic x(7)        value "1951043".

       01 ws-heading-line-1.
         05 filler             pic x(30)       value spaces.
         05 filler             pic x(22)
           value "EMPLOYEE SALARY REPORT".
         05 filler             pic x(14)       value spaces.
         05 filler             pic x(6)        value "PAGE  ".
         05 page-num           pic 9           value 1.

       01 ws-heading-line-2.
         05 filler             pic x(3)        value "EMP".
         05 filler             pic x(2)        value spaces.
         05 filler             pic x(3)        value "EMP".
         05 filler             pic x(32)       value spaces.
         05 filler             pic x(7)        value "PRESENT".
         05 filler             pic x(2)        value spaces.
         05 filler             pic x(8)        value "INCREASE".
         05 filler             pic x(5)        value spaces.
         05 filler             pic x(3)        value "PAY".
         05 filler             pic x(11)       value spaces.
         05 filler             pic x(3)        value "NEW".

       01 ws-heading-line-3.
         05 filler             pic x(3)        value "NUM".
         05 filler             pic x(2)        value spaces.
         05 filler             pic x(4)        value "NAME".
         05 filler             pic x(10)       value spaces.
         05 filler             pic x(5)        value "YEARS".
         05 filler             pic x(1)        value spaces.
         05 filler             pic x(8)        value "POSITION".
         05 filler             pic x(8)        value spaces.
         05 filler             pic x(6)        value "SALARY".
         05 filler             pic x(5)        value spaces.
         05 filler             pic x(1)        value "%".
         05 filler             pic x(7)        value spaces.
         05 filler             pic x(8)        value "INCREASE".
         05 filler             pic x(7)        value spaces.
         05 filler             pic x(6)        value "SALARY".

       01 ws-record-line.
         05 ws-emp-num         pic 9(3).
         05 filler             pic x(1)        value spaces.
         05 ws-emp-name        pic 9(15).
         05 filler             pic x(2)        value spaces.
         05 ws-years           pic Z9.
         05 filler             pic x(2)        value spaces.
         05 ws-position        pic x(12).
         05 filler             pic x(2)        value spaces.
         05 ws-salary          pic ZZ,ZZ9.99.
         05 filler             pic x(2)        value spaces.
         05 ws-inc-per         pic 9(2).9.
         05 filler             pic x(1)        value "%".
         05 filler             pic x(3)        value spaces.
         05 ws-pay-inc         pic $ZZ,ZZ9.99.
         05 filler             pic x(1)        value "+".
         05 filler             pic x(1)        value spaces.
         05 filler             pic x(1)        value "$".
         05 filler             pic x(1)        value spaces.
         05 ws-new-salary      pic ZZ,ZZZ,ZZ9.99.

       01 ws-blank-line.
         05 ws-blank-position  pic x(12).

       01 ws-totals-line-1.
         05 filler             pic x(15)       value "EMPLOYEE CLASS:".
         05 filler             pic x(8)        value spaces.
         05 filler             pic x(7)        value "Analyst".
         05 filler             pic x(4)        value spaces.
         05 filler             pic x(8)        value "Sen Prog".
         05 filler             pic x(4)        value spaces.
         05 filler             pic x(4)        value "Prog".
         05 filler             pic x(4)        value spaces.
         05 filler             pic x(7)        value "Jr Prog".
         05 filler             pic x(4)        value spaces.
         05 filler             pic x(12)       value "Unclassified".

       01 ws-totals-line-2.
         05 filler             pic x(15)       value "# ON THIS PAGE:".
         05 filler             pic x(14)       value spaces.
         05 ws-no-of-analyst   pic 9.
         05 filler             pic x(11)       value spaces.
         05 ws-no-of-sen-prog  pic 9.
         05 filler             pic x(7)        value spaces.
         05 ws-no-of-prog      pic 9.
         05 filler             pic x(10)       value spaces.
         05 ws-no-of-jr-prog   pic 9.
         05 filler             pic x(15)       value spaces.
         05 ws-no-of-unclassified
                               pic 9.

       01 ws-sub-total-line-1.
         05 filler             pic x(18)
           value "AVERAGE INCREASES:".
         05 filler             pic x(3)        value spaces.
         05 filler             pic x(8)        value "ANALYST=".
         05 filler             pic x(5)        value spaces.
         05 ws-analyst-avg-inc pic Z,ZZ9.99.
         05 filler             pic x(5)        value spaces.
         05 filler             pic x(9)        value "SEN PROG=".
         05 filler             pic x(3)        value spaces.
         05 ws-sen-prog-avg-inc pic Z,ZZ9.99.

       01 ws-sub-total-line-2.
         05 filler             pic x(21)       value spaces.
         05 filler             pic x(5)        value "PROG=".
         05 filler             pic x(8)        value spaces.
         05 ws-prog-avg-inc    pic Z,ZZ9.99.
         05 filler             pic x(5)        value spaces.
         05 filler             pic x(8)        value "JR PROG=".
         05 filler             pic x(4)        value spaces.
         05 ws-jr-prog-avg-inc pic Z,ZZ9.99.

       01 ws-oth-line.
           05 filler                     pic x(25)
               value "  Type NON-GRADS count = ".
           05 ws-oth-staff-count         pic zz9.
           05 filler                     pic x(7)
               value spaces.           
           05 filler                     pic x(26)
               value "  Type NON-GRADA Salary = ".
           05 ws-oth-salary              pic $$$,$$$,$.
           05 filler                     pic x(38)
               value spaces.
           05 ws-calc-position           pic x(12).

       01 ws-const-calc.
         05 ws-page-count      pic 99          value 0.
         05 ws-edu-code        pic x(1).
         05 ws-o-staff-count   pic 999         value 0.
         05 ws-o-salary        pic 9(10)       value 0.
         05 ws-s-staff-count   pic 999         value 0.
         05 ws-s-salary        pic 9(10)       value 0.

       77 ws-lines-per-page    pic 99          value 20.
       77 ws-line-count        pic 99          value 0.

       procedure division.

       000-main.

           open input  input-file.
           open output output-file
                       outputdat-file.
       
           write output-line               from ws-heading-info-line
*
           read input-file
               at end
                   move "y"                to ws-eof-flag.
*
*      Process each input record and read in next record
*     
           perform 100-process-pages
             until ws-eof-flag equals "y".

           write output-line               from ws-sub-total-line-1
               after advancing 1 line.
           write output-line               from ws-sub-total-line-2.

           close input-file
                 output-file
                 outputdat-file.

           goback.

       100-process-pages.
      *
      *  Initialize detail calculation variables for page
      *
           move 0                          to ws-s-staff-count
                                              ws-s-salary
                                              ws-line-count.


           perform 110-print-headings.
*     
*       process input and output results until
*         current page has been filled
*         OR EOF has been encountered
*     
           perform 120-process-lines
             varying ws-line-count from 1 by 1
             until (ws-line-count > ws-lines-per-page
                                 OR ws-eof-flag = "y").
           perform 150-print-page-totals.
*


       110-print-headings.

*          Increase page count by 1
           add 1                           to ws-page-count.
           move ws-page-count              to page-num.
*
*       Write the report heading with a blank line before heading
*       and blank line after heading
*
           if (ws-page-count > 1) then
               write output-line
                 after advancing page
               write output-line           from ws-heading-line-1
                 after advancing 1 line
               write output-line           from ws-heading-line-2
                 after advancing 2 line
               write output-line           from ws-heading-line-3

           else
               write output-line           from ws-heading-line-1
                 after advancing 1 line
               write output-line           from ws-heading-line-2
                 after advancing 2 line
               write output-line           from ws-heading-line-3
           end-if.



       120-process-lines.
      * Decide whether to output to report or data file
      *
           if il-88-type-K
               perform 210-process-data-lines
           else
               add 1                       to ws-line-count
*              if ws-line-count = 1
*                  perform 120-print-headings
*              end-if
               perform 220-process-rpt-lines
               if   ws-line-count > ws-lines-per-page
                 or ws-eof-flag   = "y"
                   perform 230-print-page-totals 
               end-if
           end-if. 
*
*          Logic to calculate the POSITION based on years of xp..
*      
           if in-yrs-serv > 15
               then
               move "ANALYST"              to ws-calc-position
           else
**
               if in-yrs-serv > 7 and in-yrs-serv < 15
                 then
                   move "SEN PROG"         to ws-calc-position
               else
***
                   if in-yrs-serv > 2 and in-yrs-serv < 7
                     then
                       move "PROG"         to ws-calc-position
                   else
****
                       if in-yrs-serv < 2
                         then
                           move "UNCLASSIFIED"
                                           to ws-calc-position
*                                ----+----1--
                       end-if
****
                   end-if
***
               end-if
**
           end-if
*
*         Read next input record for the next iteration of perform loop
*     
           read input-file
               at end
                   move "y"                to ws-eof-flag.
*
*
       

       150-print-page-totals.
      *
*          PRINT TOTAL LINES
           write output-line               from ws-totals-line-1
              after advancing 2 line.
           write output-line               from ws-totals-line-2.
      *
*
 
       210-process-data-lines.
*
           add 1                           to ws-o-staff-count.
           add in-prsnt-sly                to ws-o-salary.
           move ws-position                to ws-blank-position.
      *
           write outputdat-line            from input-rec.

       220-process-rpt-lines.
*
*
      *  Count staff and accumulate salary for page subtotals
      *
           add 1                           to ws-s-staff-count.
           add in-prsnt-sly                to ws-s-salary.
*
*
*        Output Salesperson Detail Line
*
*         Clear the detail line
           move spaces                     to ws-record-line.
*
*
*         Move input lines(sales-file) to output lines(report-line)
*
           move in-emp-no                  to ws-emp-num.
           move in-name                    to ws-emp-name.
           move in-yrs-serv                to ws-years.
           move in-prsnt-sly               to ws-salary.
           move ws-page-count              to page-num.
           move ws-o-staff-count           to ws-oth-staff-count.
           move ws-calc-position           to ws-position.
*
           write output-line               from ws-record-line.

       230-print-page-totals.
      *  Move subtotals to subtotal line and write to output file
      *  with blank line after subtotal line
      *
      *
           write outputdat-line            from ws-record-line.
      *
      *
           move 0                          to   ws-s-staff-count
                                                ws-s-salary. 
      *  
*
       end program A5-SalaryReport-5A.

这是我的输出文件 [A5-SalaryReport-5A.out ]

Nirmal Patel, Assignment 4               20210411                       1951043

                              EMPLOYEE SALARY REPORT              PAGE  1

EMP  EMP                                PRESENT  INCREASE     PAY           NEW
NUM  NAME          YEARS POSITION        SALARY     %       INCREASE       SALARY
030 ALLDREN RUTH     21                20,200.00
185 DONNEMAN THOMAS   6  ANALYST        4,230.09
325 HATFIELD MARK     1  UNCLASSIFIED  11,220.02
730 REEDE OWEN        9  UNCLASSIFIED   5,550.10
111 CARTOLER VIOLET   2  SEN PROG       9,980.07
999 BAKER RON         3  UNCLASSIFIED  30,000.14
181 DELBERT EDWARD   12  PROG           6,590.13
318 HANEY CAROL       9  ANALYST       50,000.14


EMPLOYEE CLASS:        Analyst    Sen Prog    Prog    Jr Prog    Unclassified
# ON THIS PAGE:
# ON THIS PAGE:
                              EMPLOYEE SALARY REPORT              PAGE  2

EMP  EMP                                PRESENT  INCREASE     PAY           NEW
NUM  NAME          YEARS POSITION        SALARY     %       INCREASE       SALARY
027 ALHOUER ELAINE    1  PROG          25,730.02
317 HANBEE ALETA      3  UNCLASSIFIED  50,000.03
806 STOCKTON NORMAN   6  PROG          25,070.07
207 EBERHARDT RON     5  PROG          40,070.09
308 GLEASON JAMES     1  PROG          50,000.03
292 EVERLEY DONNA     3  PROG          20,000.17


EMPLOYEE CLASS:        Analyst    Sen Prog    Prog    Jr Prog    Unclassified
# ON THIS PAGE:
# ON THIS PAGE:
                              EMPLOYEE SALARY REPORT              PAGE  3

EMP  EMP                                PRESENT  INCREASE     PAY           NEW
NUM  NAME          YEARS POSITION        SALARY     %       INCREASE       SALARY
409 ICK MICK         25  PROG          99,999.99
607 ODELLE NICK      10  ANALYST       25,070.18
332 HELD ANNA         2  PROG          40,000.02
802 SHEA MICHAEL      6  PROG          20,330.08
102 BELLSLEY ART      8  PROG          30,000.09
282 ESTABAN JUAN     19  SEN PROG      40,550.00
505 LAMBERT JERRY     1  ANALYST       40,010.04


EMPLOYEE CLASS:        Analyst    Sen Prog    Prog    Jr Prog    Unclassified
# ON THIS PAGE:
# ON THIS PAGE:
                              EMPLOYEE SALARY REPORT              PAGE  4

EMP  EMP                                PRESENT  INCREASE     PAY           NEW
NUM  NAME          YEARS POSITION        SALARY     %       INCREASE       SALARY
215 EDSON WILBUR      6  SEN PROG      70,500.08


EMPLOYEE CLASS:        Analyst    Sen Prog    Prog    Jr Prog    Unclassified
# ON THIS PAGE:

AVERAGE INCREASES:   ANALYST=                  SEN PROG=
                     PROG=                     JR PROG=

我知道这不是一件容易的事,我很感激你提供的任何答案。

干杯!

我看到的问题是 ws-position 的正确值显示在下一条记录上;发生这种情况是因为 ws-calc-position 是在打印该行之后确定的。这导致第一条记录出现空白,随后的打印行出现错误值。

我建议将确定 ws-calc-position 的代码移到需要它之前。 120-process-lines220-process-rpt-lines 采纳了这些建议。

IF 代码不应包含最初表达的 AND。它会导致某些值丢失,其中 in-yrs-serv150702。这些特定值导致(或将导致)先前确定的位置出现在输出中。该更改已在下面进行。

另外,这一行

         05 ws-emp-name        pic 9(15).

应该是

         05 ws-emp-name        pic x(15).

       120-process-lines.
      * Decide whether to output to report or data file
      *
           if il-88-type-K
               perform 210-process-data-lines
           else
               add 1                       to ws-line-count
*              if ws-line-count = 1
*                  perform 120-print-headings
*              end-if
               perform 220-process-rpt-lines
               if   ws-line-count > ws-lines-per-page
                 or ws-eof-flag   = "y"
                   perform 230-print-page-totals 
               end-if
           end-if. 

*  NOTE: Moved code to determine position to 225-determine-position

*
*         Read next input record for the next iteration of perform loop
*     
           read input-file
               at end
                   move "y"                to ws-eof-flag.

       220-process-rpt-lines.
*
*
      *  Count staff and accumulate salary for page subtotals
      *
           add 1                           to ws-s-staff-count.
           add in-prsnt-sly                to ws-s-salary.
*
*
*        Output Salesperson Detail Line
*
*         Clear the detail line
           move spaces                     to ws-record-line.
*
*
*         Move input lines(sales-file) to output lines(report-line)
*
           move in-emp-no                  to ws-emp-num.
           move in-name                    to ws-emp-name.
           move in-yrs-serv                to ws-years.
           move in-prsnt-sly               to ws-salary.
           move ws-page-count              to page-num.
           move ws-o-staff-count           to ws-oth-staff-count.
           perform 225-determine-position.
           move ws-calc-position           to ws-position.
*
           write output-line               from ws-record-line.


       225-determine-position. 
*
*          Logic to calculate the POSITION based on years of xp..
*      
           if in-yrs-serv > 15
               then
               move "ANALYST"              to ws-calc-position
           else
**
               if in-yrs-serv > 7
                 then
                   move "SEN PROG"         to ws-calc-position
               else
***
                   if in-yrs-serv > 2
                     then
                       move "PROG"         to ws-calc-position
                   else
****
                       move "UNCLASSIFIED" to ws-calc-position
****
                   end-if
***
               end-if
**
           end-if.