在cobol中显示一年中的某一天

时间:2017-10-31 05:50:18

标签: cobol

我试图在cobolol中显示一年中的某一天,但它不起作用。这段代码没有显示任何内容,我无法弄清楚原因。有人可以帮帮我吗?

IDENTIFICATION DIVISION.
   PROGRAM-ID. SAMPLE.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 T-MOFYEAR.
     05 T-M-LINE OCCURS 12.
       10 T-EL-MN         PIC 9(2).

这里我取了年月和日的价值

   01 YEAR                PIC 9(4) VALUE 2017. 
   01 MONTH               PIC 9(2) VALUE 01.
   01 DAYY                PIC 9(2) VALUE 04.
   01 I                   PIC 9(2).
   01 MN                  PIC 9(2).
   01 DOFY                PIC 9(3).

   PROCEDURE DIVISION.
   MAIN SECTION.
   MAINA.
       PERFORM INIT
       PERFORM
       VARYING I
       FROM 1 BY 1
       UNTIL I = MONTH 
       PERFORM LEAP
       END-PERFORM
       .
   MAINZ.
       STOP RUN.

我在这里建立一年中的月份

   INIT SECTION.
   INITA.
       MOVE 31               TO T-EL-MN(1)
       MOVE 28               TO T-EL-MN(2)
       MOVE 31               TO T-EL-MN(3)
       MOVE 30               TO T-EL-MN(4)
       MOVE 31               TO T-EL-MN(5)
       MOVE 30               TO T-EL-MN(6)
       MOVE 31               TO T-EL-MN(7)
       MOVE 31               TO T-EL-MN(8)
       MOVE 30               TO T-EL-MN(9)
       MOVE 31               TO T-EL-MN(10)
       MOVE 30               TO T-EL-MN(11)
       MOVE 31               TO T-EL-MN(12)
       .
   INITZ.
       EXIT.

在这里,我检查一年是否是一个飞跃

   LEAP SECTION.
   LEAPA.
       EVALUATE TRUE                                  
           WHEN FUNCTION MOD (YEAR 4)   NOT ZERO    
           WHEN FUNCTION MOD (YEAR 100)     ZERO    
           AND FUNCTION MOD (YEAR 400) NOT ZERO    
           ADD T-EL-MN(I), DAYY TO DOFY
           DISPLAY "DAY OF YEAR = " DOFY
           WHEN OTHER                                      
           DISPLAY 'IT IS A LEAP YEAR     ' YEAR
           MOVE 29 TO T-EL-MN(2)
           ADD T-EL-MN(I), DAYY TO DOFY
           DISPLAY "DAY OF YEAR = " DOFY
        END-EVALUATE      
       .
   LEAPZ.
       EXIT.

2 个答案:

答案 0 :(得分:4)

它没有显示任何内容,因为你告诉它永远不会DISPLAY。请参阅附录中的说明。

修复此代码部分的可能解决方案可能是将代码更改为

UNTIL I > MONTH

通常,检查编译器是否支持

可能是个好主意
01 small-yd.
   05 syd-year pic 9(02).
   05 syd-day  pic 9(03).
01 full-yd.
   05 fyd-year pic 9(04).
   05 fyd-day  pic 9(03).

ACCEPT small-yd FROM DAY
ACCEPT full-yd  FROM DAY YYYYDDD

附录:否DISPLAY因为:

01 MONTH               PIC 9(2) VALUE 01.

   PERFORM
   VARYING I
   FROM 1 BY 1
   UNTIL I = MONTH 
   PERFORM LEAP
   END-PERFORM

等于

   PERFORM
   VARYING I
   FROM 1 BY 1
   UNTIL I = 1

等于

   PERFORM
   UNTIL 1 = 1

等于

MAIN SECTION.
MAINA.
   PERFORM INIT
   .
MAINZ.
   STOP RUN.

DISPLAY中没有INIT SECTION

答案 1 :(得分:1)

如果您只想在中显示一年中的某一天,那么使用以下内容会更容易:

...
WORKING-STORAGE SECTION.
01  TESTDATE PIC 9(8).

...
PROCEDURE DIVISION.
MAIN SECTION.
MOVE FUNCTION CURRENT-DATE (1:8) TO TESTDATE.            
COMPUTE TESTDATE = FUNCTION DAY-OF-INTEGER(              
                  FUNCTION INTEGER-OF-DATE(TESTDATE) 
               ).                                    
DISPLAY "DAY OF YEAR " TESTDATE (6:3).
...

AFAIK这些内在函数可在所有cobol编译器中使用。