COBOL 程序不会在我的报告中输出详细信息行

COBOL program won't output the detail lines in my report

编辑: 搞清楚了。我需要在 A420-COUNT-MARKS

结束时再次调用读取

编辑: 在我通过 Vista TN3270 访问的 z/OS 大型机上工作。使用老师提供的JCL提交程序。

我在学校学习编程,我有一个 COBOL 作业,我的程序读取一个包含主题名称和代码的文件以及一个包含学生分数和相关主题代码的文件。它必须使用此信息创建一份报告,其中列出所有科目并计算每个科目获得 A、B、C、D 或 F 等级的学生人数。然后它会将底部每个等级的数量相加。

报告示例:

01         ABC COLLEGE TESTING CENTER
02         TEST RESULTS SUMMARY           DATE: yyyy/mm/dd
03
04 SUBJECT NAME                  A           B            C           D        F
05
06 xxxxxxxxxxxxxxxxxxxx        9,999       9,999        9,999       9,999    9,999
07 xxxxxxxxx                   9,999       9,999        9,999       9,999    9,999
19
20 TOTAL                      99,999      99,999       99,999      99,999   99,999

问题是我的程序只输出 header 行,但不会输出详细信息行或总计行。我已经编写了执行这些操作的函数,但它们没有出现任何错误,所以我不知道出了什么问题。

这是我的文件控制和文件部分:

FILE-CONTROL.                               
    SELECT F01-SUBJ-FILE ASSIGN TO F01SUBJ. 
    SELECT F02-MARK-FILE ASSIGN TO F02MARK. 
    SELECT F03-REPT-FILE ASSIGN TO F03REPT. 

FILE SECTION.                      
FD  F01-SUBJ-FILE                  
    RECORDING MODE IS F            
    RECORD CONTAINS 80 CHARACTERS  
    DATA RECORD IS F01-SUBJ-RECORD.
01  F01-SUBJ-RECORD.               
    05  F01-SUBJ-CODE  PIC X(6).   
    05  F01-SUBJ-NAME  PIC X(20).  
    05                 PIC X(54).  

FD  F02-MARK-FILE                 
    RECORDING MODE IS F           
    RECORD CONTAINS 80 CHARACTERS 
    DATA RECORD IS F02-MARK-RECORD
01  F02-MARK-RECORD.              
    05  F02-STUD-NAME  PIC  X(20).
    05  F02-SUBJ-CODE  PIC  X(6). 
    05                 PIC  X.    
    05  F02-DATE-TEST  PIC  X(8). 
    05  F02-STUD-MARK  PIC  9(3). 
    05                 PIC  X(42).

FD  F03-REPT-FILE                  
    RECORDING MODE IS F            
    RECORD CONTAINS 120 CHARACTERS 
    DATA RECORD IS F03-REPT-RECORD.
01  F03-REPT-RECORD.               
    05                 PIC X(120). 

这是工作存储空间:

WORKING-STORAGE SECTION.                   
01  W01-EOF-SWITCH.                        
    05  W01-MARK-EOF       PIC X VALUE 'N'.
    05  W01-SUBJ-EOF       PIC X VALUE 'N'.

01  W02-TEST-TABLE.                               
    05  W02-SUBJ-COUNT     PIC 99 VALUE 0.        
    05  W02-SUBJ-MAX       PIC 99 VALUE 50.       
    05  W02-TEST-ROW OCCURS 1 TO 50               
        DEPENDING ON W02-SUBJ-COUNT               
        ASCENDING KEY IS W02-SUBJ-CODE            
        INDEXED BY W02-IDX.                       
        10  W02-SUBJ-CODE  PIC X(6)  VALUE SPACES.
        10  W02-SUBJ-NAME  PIC X(20) VALUE SPACES.
        10  W02-A-CTR      PIC 9999  VALUE 0.     
        10  W02-B-CTR      PIC 9999  VALUE 0.     
        10  W02-C-CTR      PIC 9999  VALUE 0.     
        10  W02-D-CTR      PIC 9999  VALUE 0.     
        10  W02-F-CTR      PIC 9999  VALUE 0.     

01  W03-REPT.                                        
    05  W03-HEADER-ROW1.                             
        10                 PIC X(9)  VALUE SPACES.   
        10                 PIC X(3)  VALUE 'ABC'.    
        10                 PIC X     VALUE SPACES.   
        10                 PIC X(7)  VALUE 'COLLEGE'.
        10                 PIC X     VALUE SPACES.   
        10                 PIC X(7)  VALUE 'TESTING'.
        10                 PIC X     VALUE SPACES.   
        10                 PIC X(6)  VALUE 'CENTER'. 
        10                 PIC X(85) VALUE SPACES.   
    05  W03-HEADER-ROW2.                             
        10                 PIC X(9)  VALUE SPACES.   
        10                 PIC X(4)  VALUE 'TEST'.   
        10                 PIC X     VALUE SPACES.   
        10                 PIC X(7)  VALUE 'RESULTS'.
        10                 PIC X     VALUE SPACES.   
        10                 PIC X(7)  VALUE 'SUMMARY'.
        10                 PIC X(11) VALUE SPACES.   
        10                 PIC X(5)  VALUE 'DATE:'.  
        10                 PIC X     VALUE SPACES.   
        10  W03-YEAR       PIC 9999.                 
        10                 PIC X     VALUE '/'.      
        10  W03-MONTH      PIC 99.                   
        10                 PIC X     VALUE '/'.      
        10  W03-DAY        PIC 99.                   
        10                 PIC X(64) VALUE SPACES. 
    05  W03-HEADER-ROW3.                              
        10                 PIC X     VALUE SPACES.    
        10                 PIC X(7)  VALUE 'SUBJECT'. 
        10                 PIC X     VALUE SPACES.    
        10                 PIC X(4)  VALUE 'NAME'.    
        10                 PIC X(15) VALUE SPACES.    
        10                 PIC X     VALUE 'A'.       
        10                 PIC X(7)  VALUE SPACES.    
        10                 PIC X     VALUE 'B'.       
        10                 PIC X(7)  VALUE SPACES.    
        10                 PIC X     VALUE 'C'.       
        10                 PIC X(7)  VALUE SPACES.    
        10                 PIC X     VALUE 'D'.       
        10                 PIC X(7)  VALUE SPACES.    
        10                 PIC X     VALUE 'F'.         
        10                 PIC X(59) VALUE SPACES.
    05  W03-DETAIL-ROW.                            
        10                 PIC X     VALUE SPACES. 
        10  W03-SUBJ-NAME  PIC X(20).              
        10                 PIC XXX   VALUE SPACES. 
        10  W03-A-CTR      PIC Z,ZZ9.              
        10                 PIC XXX   VALUE SPACES. 
        10  W03-B-CTR      PIC Z,ZZ9.              
        10                 PIC XXX   VALUE SPACES. 
        10  W03-C-CTR      PIC Z,ZZ9.              
        10                 PIC XXX   VALUE SPACES. 
        10  W03-D-CTR      PIC Z,ZZ9.              
        10                 PIC XXX   VALUE SPACES. 
        10  W03-F-CTR      PIC Z,ZZ9.              
        10                 PIC X(59) VALUE SPACES. 

01  W04-SYS-DATE.                       
    05  W04-YEAR           PIC 9999.    
    05  W04-MONTH          PIC 99.      
    05  W04-DAY            PIC 99.      

01  W05-TOTALS.                               
    05  W05-TOTAL-A        PIC 99999 VALUE 0. 
    05  W05-TOTAL-B        PIC 99999 VALUE 0. 
    05  W05-TOTAL-C        PIC 99999 VALUE 0. 
    05  W05-TOTAL-D        PIC 99999 VALUE 0. 
    05  W05-TOTAL-F        PIC 99999 VALUE 0. 

这里是程序划分

PROCEDURE DIVISION.              
    PERFORM A100-OPEN-FILES      
    PERFORM A200-WRITE-HEADINGS  
    PERFORM A300-PROCESS-SUBJECTS
    PERFORM A400-PROCESS-MARKS   
    PERFORM A500-WRITE-TOTALS    
    PERFORM A600-CLOSE-FILES     
    STOP RUN                     
    .                           

 A100-OPEN-FILES.              
*    OPENS FILES               
     OPEN INPUT  F01-SUBJ-FILE 
                 F02-MARK-FILE 
     OPEN OUTPUT F03-REPT-FILE 
     .                         

 A200-WRITE-HEADINGS.                                 
*    WRITES HEADERS TO THE REPORT FILE                
     MOVE W03-HEADER-ROW1 TO F03-REPT-RECORD          
     WRITE F03-REPT-RECORD                            

     MOVE FUNCTION CURRENT-DATE (1:8) TO W04-SYS-DATE 
     MOVE W04-YEAR  TO W03-YEAR                       
     MOVE W04-MONTH TO W03-MONTH                      
     MOVE W04-DAY   TO W03-DAY                        

     MOVE W03-HEADER-ROW2 TO F03-REPT-RECORD          
     WRITE F03-REPT-RECORD                            

     MOVE W03-HEADER-ROW3 TO F03-REPT-RECORD          
     WRITE F03-REPT-RECORD                            
     .

 A300-PROCESS-SUBJECTS.                                     
*    MOVES SUBJECT NAMES AND CODES INTO W02-TEST-TABLE      
     PERFORM A310-READ-RECORD                               
     PERFORM UNTIL W01-SUBJ-EOF = 'Y'                       
         IF W02-SUBJ-COUNT < W02-SUBJ-MAX                   
             ADD 1 TO W02-SUBJ-COUNT                        
             SET W02-IDX TO W02-SUBJ-COUNT                  
             MOVE F01-SUBJ-CODE TO W02-SUBJ-CODE(W02-IDX)   
             MOVE F01-SUBJ-NAME TO W02-SUBJ-NAME(W02-IDX)   
         ELSE                                               
             DISPLAY "ERROR - SUBJECT FILE EXCEEDS MAX OF " 
                 W02-SUBJ-MAX " RECORDS, RECORD IGNORED"                       
         END-IF                                             
         PERFORM  A310-READ-RECORD                          
     END-PERFORM
     .          

 A310-READ-RECORD.                                      
*    READS FROM THE SUBJECT FILE INTO THE SUBJECT RECORD
     READ F01-SUBJ-FILE                                 
         AT END MOVE 'Y' TO W01-SUBJ-EOF                
     END-READ                                           
     .                                                  

 A400-PROCESS-MARKS.             
     PERFORM A410-READ-RECORD    
     PERFORM A420-COUNT-MARKS    
         UNTIL W01-MARK-EOF = 'Y'
     .                           

 A410-READ-RECORD.                                  
*    READS FROM THE MARK FILE INTO THE MARK RECORD  
     READ F02-MARK-FILE                             
         AT END MOVE 'Y' TO W01-MARK-EOF            
     END-READ                                       
     .                                              

 A420-COUNT-MARKS.                                               
*    COUNTS GRADE TOTALS                                         
     SET W02-IDX TO 1                                            
     SEARCH ALL W02-TEST-ROW                                     
         AT END DISPLAY 'INVALID INPUT RECORD: ' F02-MARK-RECORD 
         WHEN W02-SUBJ-CODE(W02-IDX) = F02-SUBJ-CODE             
             EVALUATE F02-STUD-MARK                              
                 WHEN "80" THRU "100"                            
                    ADD 1 TO W05-TOTAL-A                         
                    ADD 1 TO W02-A-CTR(W02-IDX)                  
                 WHEN "70" THRU "79"                             
                    ADD 1 TO W05-TOTAL-B                         
                    ADD 1 TO W02-B-CTR(W02-IDX)                  
                 WHEN "60" THRU "69"               
                    ADD 1 TO W05-TOTAL-C           
                    ADD 1 TO W02-C-CTR(W02-IDX)    
                 WHEN "50" THRU "59"               
                    ADD 1 TO W05-TOTAL-D           
                    ADD 1 TO W02-D-CTR(W02-IDX)    
                 WHEN OTHER                        
                    ADD 1 TO W05-TOTAL-F           
                    ADD 1 TO W02-F-CTR(W02-IDX)    
             END-EVALUATE                          
     END-SEARCH                                    
     .                                             

 A500-WRITE-TOTALS.                         
     PERFORM A510-WRITE-SUBJ-GRADE-TOTALS   
     PERFORM A520-WRITE-GRADE-GRAND-TOTALS  
     .                                      

 A510-WRITE-SUBJ-GRADE-TOTALS.              
     PERFORM VARYING W02-IDX FROM 1 BY 1  
     UNTIL W02-IDX > W02-SUBJ-COUNT       
          MOVE W02-SUBJ-NAME(W02-IDX) TO W03-SUBJ-NAME  
          MOVE W02-A-CTR(W02-IDX) TO W03-A-CTR          
          MOVE W02-B-CTR(W02-IDX) TO W03-B-CTR          
          MOVE W02-C-CTR(W02-IDX) TO W03-C-CTR          
          MOVE W02-D-CTR(W02-IDX) TO W03-D-CTR          
          MOVE W02-F-CTR(W02-IDX) TO W03-F-CTR          
          MOVE W03-DETAIL-ROW TO F03-REPT-RECORD        
          WRITE F03-REPT-RECORD                            
     END-PERFORM   
     .               

 A520-WRITE-GRADE-GRAND-TOTALS.                       
*    WRITES THE GRADE GRAND TOTALS TO THE REPORT FILE 
*    AFTER INSERTING A BLANK ROW                      
     MOVE SPACES TO F03-REPT-RECORD                   
     WRITE F03-REPT-RECORD                            

     MOVE W05-TOTAL-A TO W03-TOTAL-A                  
     MOVE W05-TOTAL-B TO W03-TOTAL-B                  
     MOVE W05-TOTAL-C TO W03-TOTAL-C                  
     MOVE W05-TOTAL-D TO W03-TOTAL-D                  
     MOVE W05-TOTAL-F TO W03-TOTAL-F                  

     MOVE W03-TOTAL-ROW TO F03-REPT-RECORD            
     WRITE F03-REPT-RECORD                            
     .                                                

 A600-CLOSE-FILES.        
*    CLOSES THE FILES     
     CLOSE F01-SUBJ-FILE  
           F02-MARK-FILE  
           F03-REPT-FILE  
     .                    

汤姆,很高兴你明白了。

我希望你没有被关闭并且会进一步探索。仅供参考,虽然 ISPF、TSO/E 和其他经典用户界面仍然可用(有些人仍然喜欢它们,并且它们会继续工作 "forever"),但现在开发人员经常使用并更喜欢图形用户界面。有一些免费的,例如 z/OS 的 IBM Explorer 及其远程系统资源管理器 (RSE):

https://developer.ibm.com/mainframe/products/zosexplorer/

这在 Mac 或 PC(Linux 或 Windows)上运行良好,如您所愿(RSE 部分在 z/OS 上) .全部免费。或者,如果您愿意,可以添加更多 "COBOL aware" 编辑器(以及其他几个功能),前提是您添加了 IBM Z Open Development 插件:

https://developer.ibm.com/mainframe/products/ibm-z-open-development/

这也行,免费使用 90 天。在 90 天结束时,您可以支付现行价格以保留这些插件,也可以卸载它们并仅使用 base/free 资源管理器实现 z/OS 功能。

也许这是对您 instructor/professor 的良好反馈?是的,您对任何编程语言的初次体验 都可以是 (例如)通过 emacs 和终端仿真器。是的,您可以使用 emacs、ISPF 或 vi 编写 Apple Swift 代码(例如)。然而,这些经典的用户界面并不是每个人都喜欢的第一个。同样,如果您喜欢某个特定的 UI,并且它适合您,没问题!但从教学的角度来看,最好从观众更熟悉的内容开始。

关于编辑:再举一个例子,如果您碰巧更喜欢 Microsoft Visual Studio Code, then you can add IBM Z Open Editor 免费而不是 IDE。

我通过在每个函数的开头放置一个 DISPLAY 来找出我的程序出了什么问题,它输出什么函数 运行。我看到它在 A420-COUNT-MARKS 中处于无限循环中,我忘记在它的末尾添加 PERFORM A410-READ-RECORD。