抑制COBOL中的前导零

时间:2014-03-29 01:04:31

标签: cobol leading-zero

我试过在线查找,但找不到符合我情况的任何内容。我需要抑制输出中的前导零,但我无法使其正常工作。我需要压制的数字是PR-PAY-RATE。

  ******************************************************************
   ID DIVISION.
      PROGRAM-ID. LAB5
      AUTHOR. asdf.
      DATE-WRITTEN. March 25, 2014.
      DATE-COMPILED. CURRENT-DATE.
  ******************************************************************
   ENVIRONMENT DIVISION.
     INPUT-OUTPUT SECTION.
     FILE-CONTROL.
       SELECT PAYROLL-FILE ASSIGN TO PAYIN
       ORGANIZATION IS SEQUENTIAL.

   DATA DIVISION.
     FILE SECTION.
     FD PAYROLL-FILE.

  **** Payroll Record Length 360 characters ************************
   01  PAYROLL-RECORD.
       05  PR-EMPLOYEE-ID         PIC  X(07).
       05  PR-LAST-NAME           PIC  X(26).
       05  PR-FIRST-NAME          PIC  X(15).
       05  PR-DIVISION            PIC  X(10).
       05  PR-GROUP               PIC  X(10).
       05  PR-DEPARTMENT          PIC  X(10).
       05  PR-TITLE               PIC  X(20).
       05  PR-ADDRESS1            PIC  X(30).
       05  PR-ADDRESS2            PIC  X(30).
       05  PR-CITY                PIC  X(30).
       05  PR-STATE               PIC  X(2).
       05  PR-PROVINCE            PIC  X(20).
       05  PR-COUNTRY             PIC  X(20).
       05  PR-ZIP-POSTAL          PIC  X(09).
       05  PR-PAY1-STATUS         PIC  X(01).
           88  PR-STAT-ACTIVE         VALUE 'A'.
           88  PR-STAT-TERMINATED     VALUE 'T'.
           88  PR-STAT-RETIRED        VALUE 'R'.
           88  PR-STAT-DISCHARGED     VALUE 'D'.
       05  PR-START-DT            PIC  9(08).
       05  PR-TERM-DT             PIC  9(08).
       05  PR-TERM-REASON         PIC  X(30).
       05  PR-PAY-RATE            PIC  9(9)V99.
       05  PR-PAY-CYCLE           PIC  X(01).
           88  PR-HOURLY              VALUE 'H'.
           88  PR-BIWEEKLY            VALUE 'B'.
           88  PR-YEARLY              VALUE 'R'.
       05  PR-LAST-INCREASE-DT    PIC  9(08).
       05  PR-LAST-EVAL-DT        PIC  9(08).
       05  PR-LAST-EVAL-RATING    PIC  X(01).
           88  PR-RATE-A              VALUE 'A'.
           88  PR-RATE-B              VALUE 'B'.
           88  PR-RATE-C              VALUE 'C'.
           88  PR-RATE-D              VALUE 'D'.
           88  PR-RATE-N              VALUE 'N'.
       05  PR-BENEFIT-FLAG        PIC  X(01).
           88  PR-BENEFIT-YES         VALUE 'Y'.
           88  PR-BENEFIT-NO          VALUE 'N'.
       05  PR-MEDICAL-FLAG        PIC  X(01).
           88  PR-MEDICAL-YES         VALUE 'Y'.
           88  PR-MEDICAL-NO          VALUE 'N'.
       05  PR-DENTAL-FLAG         PIC  X(01).
           88  PR-DENTAL-YES          VALUE 'Y'.
           88  PR-DENTAL-NO           VALUE 'N'.
       05  PR-VISION-FLAG         PIC  X(01).
           88  PR-VISION-YES          VALUE 'Y'.
           88  PR-VISION-NO           VALUE 'N'.
       05  PR-BENEFIT-COST-YR     PIC  9(9)V99.
       05                         PIC  X(30).
  **** End of Payroll Record ***************************************


    WORKING-STORAGE SECTION.
    01  WS-NAMED-MEMORY-LOCATIONS.
       05 EOF-SWITCH               PIC X        VALUE 'N'.
          88 EOF                                VALUE 'Y'.
          88 NOT-EOF                            VALUE 'N'.

       05 PAYROLL-COUNT            PIC 9(5).
       05 EMP-SELECTED             PIC 9(9)V99.
       05 TOTAL-PAY                PIC 9(9)V99.
       05 AVG-PAY                  PIC 9(9)V99.


  ******************************************************************
    PROCEDURE DIVISION.

    100-MAIN-PROGRAM.
       PERFORM 200-DISPLAY-SPLASH-PAGE.
       PERFORM 300-OPEN-FILES.
       PERFORM 400-READ-PAYROLL-FILE UNTIL EOF.
       PERFORM 700-END-PROGRAM.
       STOP RUN.

    200-DISPLAY-SPLASH-PAGE.
       DISPLAY '**************************************************'.
       DISPLAY '* asdf   ENTERPRISE TECHNOLOGIES LAB5            *'.
       DISPLAY '* asdf                                           *'.
       DISPLAY '* March 25, 2014                                 *'.
       DISPLAY '**************************************************'.

    300-OPEN-FILES.
       OPEN INPUT PAYROLL-FILE.

    400-READ-PAYROLL-FILE.
        READ PAYROLL-FILE
            AT END MOVE 'Y' TO EOF-SWITCH.

        IF EOF
            THEN PERFORM 700-END-PROGRAM.
        IF NOT-EOF
            PERFORM 500-PROCESS-PAYROLL-RECORDS
        END-IF.

     500-PROCESS-PAYROLL-RECORDS.

        ADD 1 TO PAYROLL-COUNT.

        IF PR-PAY1-STATUS = 'A' AND PR-PAY-CYCLE = 'B'
            THEN PERFORM 600-DISPLAY-PAYROLL-DATA.




     600-DISPLAY-PAYROLL-DATA.
       DISPLAY 'Employee ID        : ' PR-EMPLOYEE-ID.
       DISPLAY 'Employee First Name: ' PR-FIRST-NAME.
       DISPLAY 'Employee Last  Name: ' PR-LAST-NAME.
       DISPLAY 'Pay Status         : ' PR-PAY1-STATUS.
       DISPLAY 'Pay Cycle          : ' PR-Pay-Cycle.
       DISPLAY 'Pay Rate           : ' PR-Pay-Rate.
       DISPLAY '******************************************'.
        ADD 1 TO EMP-SELECTED.
        ADD PR-PAY-RATE TO TOTAL-PAY GIVING TOTAL-PAY.
        COMPUTE AVG-PAY = TOTAL-PAY / EMP-SELECTED.


     700-END-PROGRAM.


       DISPLAY 'Total Payroll Recs : ' PAYROLL-COUNT.
       DISPLAY 'Employees Selected : ' EMP-SELECTED.
       DISPLAY 'Total Pay          : ' TOTAL-PAY.
       DISPLAY 'Average Pay        : ' AVG-PAY.
       DISPLAY '******************************************'.
       DISPLAY '* End of LAB5                            *'.
       DISPLAY '******************************************'.
       CLOSE PAYROLL-FILE.
       STOP RUN.

1 个答案:

答案 0 :(得分:4)

在W-S

       05 FORMATTED-INTEGER          PIC Z(04)9.
       05 FORMATTED-CURRENCY         PIC Z(08)9.99.

在700

   DISPLAY 'Total Payroll Recs : ' PAYROLL-COUNT.

变为

   MOVE PAYROLL-COUNT TO FORMATTED-INTEGER.
   DISPLAY 'Total Payroll Recs : ' FORMATTED-INTEGER.

并按照弹跳球显示其他显示项目。

如果合适的话,移动/显示格式化的货币。

(当然,标识符名称是您的选择)。如果您想要千位分隔符逗号,也可以选择使用PIC Z(02),Z(03),Z(02)9.99.

顺便说一句 - 你拨打700两次 - 一次是在文件结尾,然后再从主线发出。这将显示两次,也可能是错误,你将试图关闭一个已关闭的文件。