Cobol-日期循环

时间:2018-09-04 16:58:55

标签: loops date cobol

我如何实现一个循环,该循环将显示随后的几个月(01/01 / 2018、01 / 02/2018等)x次?另外,如何将日,月,年设置为变量?顺便说一下,我是Cobol的新手。 这是我到目前为止编写的代码

 01  YYYYMMDD         Pic 9(8).
 01  Integer-Form     Pic S9(9).
 Move Function Current-Date(1:8) to YYYYMMDD
 Compute Integer-Form = Function Integer-of-Date(YYYYMMDD)
 Add 12 to Integer-Form
 Compute YYYYMMDD = Function Date-of-Integer(Integer-Form)
 Display 'Date: ' YYYYMMDD.

编辑!

            PERFORM VARYING Number-Periods FROM 0 BY 1 UNTIL Number-Periods > 36
            DISPLAY ws-current-day, "/", ws-current-month, "/", ws-current-year
            ADD 1 TO  WS-current-month
                IF ws-current-month > 12 THEN
                   COMPUTE ws-current-month = 1
                   ADD 1 TO WS-current-year
                   END-IF
            END-PERFORM

1 个答案:

答案 0 :(得分:0)

最好使用重新定义并使用88来检查月份:

01  YYYYMMDD         PIC 9(8).
01  YYYYMMDD-R REDEFINES YYYYMMDD.
    05  YYYY         PIC 9(4).
    05  MM           PIC 9(2).
        88 VALID-MONTH VALUE 1 2 3 4 5 6
                             7 8 9 10 11 12.
    05  DD           PIC 9(2).

然后,您可以在支票中使用88(在您发现的PERFORM VARYING中):

  IF NOT VALID-MONTH
     ... increment year