从COBOL创建.RPT文件

时间:2014-02-12 23:43:56

标签: cobol

我需要在COBOL中为作业创建一个报告文件。 .rpt文件很简单,但现在我必须在屏幕分区时执行此操作。使用,我在砖墙。我知道我必须做一些事情来适应屏幕部分,但我不知道我需要做什么。所以任何帮助都会很棒!

       IDENTIFICATION DIVISION.
  ************************

   PROGRAM-ID.          EX3-2R.
   AUTHOR.              NOLAN ARCHER.
   INSTALLATION.        MSCTC.
   DATE-WRITTEN.        FEBRUARY 12, 2014.
   DATE-COMPILED.
  ******************************************************************
  *                      PROGRAM NARRATIVE                         *
  *                                                                *
  *                                                                *
  *    THIS PROGRAM READS ALL THE RECORDS IN THE CUSTOMER PURCHASE *
  *    FILE FOR ABC DEPARTMENT STORE.  ONE DETAIL LINE CONTAINING  *
  *    THE ACCOUNT NUMBER, CUSTOMER NAME, BALANCE, PURCHASES, AND  *
  *    CREDIT LIMIT.  A COUNT OF THE RECORDS PROCESSED IS DISPLAYED*
  *    AT THE END OF THE REPORT.                                   *
  *                                                                *
  *        INPUT:     CUSTOMER.DAT - CUSTOMER FILE                 *
  *                                                                *
  *        OUTPUT:    SCREEN       - CUSTOMER PURCHASE REPORT      *
  ******************************************************************

   ENVIRONMENT DIVISION.
  **********************

   INPUT-OUTPUT SECTION.
  **********************

   FILE-CONTROL.

       SELECT CUSTOMER-FILE
           ASSIGN TO "C:\data\cobol-1\Data\Data\CUSTOMER.DAT".
       SELECT REPORT-FILE
           ASSIGN TO "C:\solution\cobol-1\EX3-2R.RPT".

  /
   DATA DIVISION.
  ***************

   FILE SECTION.
  **************

  ******************************************************************
  *                                                                *
  *    INPUT-FILE - CUSTOMER FILE                                  *
  *                                                                *
  ******************************************************************

   FD  CUSTOMER-FILE.

   01  CUSTOMER-RECORD.
       02                                  PIC X(8).
       02  CR-ACCOUNT-NUMBER               PIC X(6).
       02  CR-CUSTOMER-NAME                PIC X(20).
       02                                  PIC X(21).
       02  CR-BALANCE                      PIC S9(4)V99.
       02  CR-PURCHASES                    PIC 9(4)V99.
       02  CR-CREDIT-LIMIT                 PIC 9(5).
       02                                  PIC XX.


  ******************************************************************
  *                                                                *
  *    REPORT-FILE                                                 *
  *                                                                *
  ******************************************************************
   FD  REPORT-FILE.

       01  REPORT-LINE-OUT      PIC X(80).
  /
   WORKING-STORAGE SECTION.
  ************************

  ******************************************************************
  *                                                                *
  *                        SWITCHES                                *
  *                                                                *
  ******************************************************************

   01  SWITCHES.

       02  SW-END-OF-FILE                  PIC X.
           88  END-OF-FILE                             VALUE "Y".

  ******************************************************************
  *                                                                *
  *                      ACCUMULATORS                              *
  *                                                                *
  ******************************************************************

   01  ACCUMULATORS.

       02  AC-LINE-COUNT                   PIC 999.
       02  AC-PAGE-COUNT                   PIC 999.
       02  AC-RECORD-COUNT                 PIC 9(5).
  /
  ******************************************************************
  *                                                                *
  *                     Work Area Fields                           *
  *                                                                *
  ******************************************************************

   01  WORK-AREA.

       02  WA-TODAYS-DATE-TIME.
           03  WA-TODAYS-DATE.
               04  WA-TODAYS-YEAR          PIC 9(4).
               04  WA-TODAYS-MONTH         PIC 99.
               04  WA-TODAYS-DAY           PIC 99.
           03  WA-TODAYS-TIME.
               04  WA-TODAYS-HOUR          PIC 99.
               04  WA-TODAYS-MINUTES       PIC 99.
           03                              PIC X(9).

       02  WA-DATE.
           03  WA-MONTH                    PIC 99.
           03  WA-DAY                      PIC 99.
           03  WA-YEAR                     PIC 9(4).

       02  WA-RUN-DATE REDEFINES
           WA-DATE                         PIC 9(8).

       02  WA-SCREEN-HOLD                  PIC X.
       02  WA-HYPHENS                      PIC X(20) VALUE ALL "-".
       02  WA-SATISFACTION-RATING          PIC X(12).
  /
   SCREEN SECTION.
  ***************

  ******************************************************************
  *                                                                *
  *    Report Headings for the Customer Purchase Report            *
  *                                                                *
  ******************************************************************

   01  HEADING-LINES.
       02  BLANK SCREEN.
       02    LINE 1 COLUMN 1  VALUE "DATE: ".
       02           COLUMN 7  PIC Z9/99/9999 FROM WA-RUN-DATE.
       02           COLUMN 25 VALUE "ABC DEPARTMENT STORE".
       02           COLUMN 58 VALUE "PAGE ".
       02           COLUMN 63 PIC ZZ9  FROM AC-PAGE-COUNT.
       02    LINE 2 COLUMN 1  VALUE "NOLAN ARCHER".
       02           COLUMN 23 VALUE "CUSTOMER PURCHASES REPORT".
       02    LINE 4 COLUMN 1  VALUE "ACCOUNT".
       02           COLUMN 54 VALUE "CREDIT".
       02    LINE 5 COLUMN 1  VALUE "NUMBER".
       02           COLUMN 11 VALUE "CUSTOMER NAME".
       02           COLUMN 32 VALUE "BALANCE".
       02           COLUMN 43 VALUE "PURCHASES".
       02           COLUMN 54 VALUE "LIMIT".
       02    LINE 6 COLUMN 1  PIC X(8)  FROM WA-HYPHENS.
       02           COLUMN 11 PIC X(20) FROM WA-HYPHENS.
       02           COLUMN 32 PIC X(10) FROM WA-HYPHENS.
       02           COLUMN 43 PIC X(10) FROM WA-HYPHENS.
       02           COLUMN 54 PIC X(12) FROM WA-HYPHENS.
  /
  ******************************************************************
  *                                                                *
  *    Detail Line for the Customer Purchase Report                *
  *                                                                *
  ******************************************************************

   01  DETAIL-LINE.

       02  LINE AC-LINE-COUNT.
       02           COLUMN 1  PIC X(6)       FROM CR-ACCOUNT-NUMBER.
       02           COLUMN 11 PIC X(20)      FROM CR-CUSTOMER-NAME.
       02           COLUMN 31 PIC $$$,$$$.99 FROM CR-BALANCE.
       02           COLUMN 43 PIC $$$,$$$.99 FROM CR-PURCHASES.
       02           COLUMN 54 PIC Z,ZZ9.99   FROM CR-CREDIT-LIMIT.
  /
  ******************************************************************
  *                                                                *
  *         Summary Lines for the Customer Purchase Report         *
  *                                                                *
  ******************************************************************

   01  SUMMARY-LINES.

       02  SL-LINE-1.
           03  LINE AC-LINE-COUNT.
           03       COLUMN 13 VALUE
               "TOTAL NUMBER OF CUSTOMERS LISTED = ".
           03       COLUMN 49 PIC ZZZZ9 FROM AC-RECORD-COUNT.

       02  SL-LINE-2.
           03  LINE AC-LINE-COUNT.
           03       COLUMN 26 VALUE "END OF REPORT".
  /
   PROCEDURE DIVISION.
  *******************
  ******************************************************************
  *                                                                *
  *  MAIN-PROGRAM - THIS IS THE MAIN PARAGRAPH OF THIS PROGRAM     *
  *                                                                *
  ******************************************************************

   MAIN-PROGRAM.

       PERFORM A-100-INITIALIZATION.
       PERFORM B-100-PROCESS-FILE.
       PERFORM C-100-WRAP-UP.
       STOP RUN.

  ******************************************************************
  *                                                                *
  *               THE INITIALIZATION PARAGRAPH FOLLOWS             *
  *                                                                *
  ******************************************************************

   A-100-INITIALIZATION.

       MOVE ZERO TO AC-PAGE-COUNT
                    AC-LINE-COUNT
                    AC-RECORD-COUNT.

       MOVE FUNCTION CURRENT-DATE TO WA-TODAYS-DATE-TIME.
       MOVE WA-TODAYS-MONTH TO WA-MONTH.
       MOVE WA-TODAYS-DAY TO WA-DAY.
       MOVE WA-TODAYS-YEAR TO WA-YEAR.

       OPEN INPUT   CUSTOMER-FILE
            OUTPUT  REPORT-FILE.
  /
  ******************************************************************
  *                                                                *
  *             FILE PROCESSING CONTROL PARAGRAPH                  *
  *                                                                *
  ******************************************************************

   B-100-PROCESS-FILE.

       MOVE "N" TO SW-END-OF-FILE.
       READ CUSTOMER-FILE
           AT END MOVE "Y" TO SW-END-OF-FILE.
       PERFORM B-200-PROCESS-RECORD
           UNTIL END-OF-FILE.
       ADD 1 TO AC-LINE-COUNT.
       DISPLAY SL-LINE-1.
       WRITE REPORT-LINE-OUT FROM SL-LINE-1
           AFTER ADVANCING 2 LINES.
       ADD 1 TO AC-LINE-COUNT.
       DISPLAY SL-LINE-2.
       WRITE REPORT-LINE-OUT FROM SL-LINE-2
           AFTER ADVANCING 1 LINE.
       DISPLAY " ".


  ******************************************************************
  *                                                                *
  *          DISPLAY HEADINGS AND DETAIL LINES                     *
  *                                                                *
  ******************************************************************

   B-200-PROCESS-RECORD.

       IF AC-LINE-COUNT = 0
           ADD 1 TO AC-PAGE-COUNT
           DISPLAY HEADING-LINES
           MOVE 7 TO AC-LINE-COUNT.


       DISPLAY DETAIL-LINE.
       WRITE REPORT-LINE-OUT FROM DETAIL-LINE
           AFTER ADVANCING 1 LINE.
       ADD 1 TO AC-LINE-COUNT.
       ADD 1 TO AC-RECORD-COUNT.


       IF AC-LINE-COUNT > 20
           DISPLAY " "
           DISPLAY "PLEASE PRESS THE ENTER KEY TO CONTINUE"
           ACCEPT WA-SCREEN-HOLD
           MOVE ZERO TO AC-LINE-COUNT.

       READ CUSTOMER-FILE
           AT END MOVE "Y" TO SW-END-OF-FILE.

  /
  ******************************************************************
  *                                                                *
  *                 END OF JOB PARAGRAPH                           *
  *                                                                *
  ******************************************************************

   C-100-WRAP-UP.

       DISPLAY " ".
       DISPLAY " ".
       DISPLAY "PLEASE PRESS THE ENTER KEY TO CONTINUE".
       ACCEPT WA-SCREEN-HOLD.
       CLOSE CUSTOMER-FILE
           REPORT-FILE.
       DISPLAY " ".
       DISPLAY "CUSTOMER PURCHASE REPORT PROGRAM HAS TERMINATED".
       DISPLAY " ".

  ******************************************************************
  *                END OF PROGRAM                                  *
  ******************************************************************
  /

1 个答案:

答案 0 :(得分:2)

参见Gary Cutler的程序员指南。除了对关键字的完整描述外,Gary还包括面向屏幕的编译器控件和源交叉引用程序列表。 OCic.cbl

OCic中的屏幕比下面的示例更复杂。

http://opencobol.add1tocobol.com/GNU%20Cobol%202.0%20Programmers%20Guide.pdf

为了避免成为链接答案,这里有一个GNU Cobol FAQ的小片段。定义屏幕布局,非常类似于使用FROM(读取),VALUE(文字)和USING(读/写字段)的报表布局。然后在01记录上使用ACCEPT和DISPLAY。

OCOBOL >>SOURCE FORMAT IS FIXED
      *> ***************************************************************
      *> Author:    Brian Tiffin
      *> Date:      20110806
      *> Purpose:   RELATIVE file organization
      *> Tectonics: cobc -g -debug -W -x relatives.cob
      *> ***************************************************************
       identification division.
       program-id. relatives.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       input-output section.
       file-control.
           select optional relatives
               assign to "relatives.dat"
               file status is filestatus
               organization is relative
               access mode is dynamic
               relative key is nicknum.

       data division.
       file section.
       fd relatives.
          01 person.
             05 firstname      pic x(48).
             05 lastname       pic x(64).
             05 relationship   pic x(32).

       working-storage section.
       77 filestatus pic 9(2).
          88 ineof value 1 when set to false is 0.

       77 satisfaction pic 9.
          88 satisfied value 1 when set to false is 0.

       77 nicknum   pic 9(2).

       77 title-line pic x(34).
          88 writing-names value "Adding, Overwriting.  00 to finish".
          88 reading-names value "Which record?         00 to quit".
       77 problem   pic x(80).

       screen section.
       01 detail-screen.
          05           line 1 column 1  from title-line erase eos.
          05           line 2 column 1  value "Record: ".
          05 pic 9(2)  line 2 column 16 using nicknum.
          05           line 3 column 1  value "First name: ".
          05 pic x(48) line 3 column 16 using firstname.
          05           line 4 column 1  value "Last name: ".
          05 pic x(64) line 4 column 16 using lastname.
          05           line 5 column 1  value "Relation: ".
          05 pic x(32) line 5 column 16 using relationship.
          05 pic x(80) line 6 column 1  from problem.

       01 show-screen.
          05           line 1 column 1  from title-line erase eos.
          05           line 2 column 1  value "Record: ".
          05 pic 9(2)  line 2 column 16 using nicknum.
          05           line 3 column 1  value "First name: ".
          05 pic x(48) line 3 column 16 from firstname.
          05           line 4 column 1  value "Last name: ".
          05 pic x(64) line 4 column 16 from lastname.
          05           line 5 column 1  value "Relation: ".
          05 pic x(32) line 5 column 16 from relationship.
          05 pic x(80) line 6 column 1  from problem.

      *> -*********-*********-*********-*********-*********-*********-**
       procedure division.
       beginning.

      *> Open the file and find the highest record number
      *> which is a sequential read operation after START
           open input relatives

           move 99 to nicknum
           start relatives key is less than or equal to nicknum
               invalid key
                   move concatenate('NO START' space filestatus)
                     to problem
                   move 00 to nicknum
               not invalid key
                   read relatives next end-read
           end-start

      *> Close and open for i-o
           close relatives
           open i-o relatives

      *> Prompt for numbers and names to add until 00
           set writing-names to true
           set satisfied to false
           perform fill-file through fill-file-end
               until satisfied

           close relatives

      *> Prompt for numbers to view names of until 00
           open input relatives

           set reading-names to true
           set satisfied to false
           perform record-request through record-request-end
               until satisfied

           perform close-shop
       .
       ending.
           goback.

      *> get some user data to add
       fill-file.
           display detail-screen end-display.
           accept detail-screen end-accept.
           move spaces to problem
           if nicknum equal 0
               set satisfied to true
               go to fill-file-end
           end-if.
       .
       write-file.
           write person
               invalid key
                   move concatenate("overwriting: " nicknum) to problem
                   rewrite person
                       invalid key
                           move concatenate(
                               exception-location() space nicknum
                               space filestatus)
                           to problem
                   end-rewrite
           end-write.
           display detail-screen end-display

       .
       fill-file-end.
       .

      *> get keys to display
       record-request.
           display show-screen end-display
           accept show-screen end-accept
           move spaces to problem
           if nicknum equals 0
               set satisfied to true
               go to record-request-end
           end-if
       .

      *> The magic of relative record number reads
       read-relation.
           read relatives
               invalid key
                   move exception-location() to problem
               not invalid key
                   move spaces to problem
           end-read
           display show-screen end-display
       .

       record-request-end.
       .

      *> get out <*
       close-shop.
           close relatives.
           goback.
       .
       end program relatives.