gpt4 book ai didi

cobol - 抑制 COBOL 中的前导零

转载 作者:行者123 更新时间:2023-12-02 04:32:32 27 4
gpt4 key购买 nike

我尝试在网上查找此内容,但找不到任何符合我情况的内容。我需要抑制输出中的前导零,但无法使其正常工作。我需要抑制的数字是 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.

最佳答案

在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.

并跟随弹跳球寻找其他显示项目。

如果合适,请移至/显示格式化货币。

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

顺便说一句 - 您调用 700 两次 - 一次在文件末尾,然后再次从主线调用。这将使您显示两次,并且可能还会出现错误,因为您将尝试关闭一个已关闭的文件。

关于cobol - 抑制 COBOL 中的前导零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22725688/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com