如何在cobol中应用闰年检查逻辑

时间:2015-09-18 17:28:17

标签: cobol

我是COBOL的新手,因此对所有控制逻辑都不熟悉,因为它与其他高级语言完全不同。在从给定输入文件中读取日期参数以查找闰年条件时,我无法检查日期参数。任何人都可以为此提供代码吗?

1 个答案:

答案 0 :(得分:1)

这里有一种方法WS-YYYY可以定义为9(4)DISPLAY,S9(4)DISPLAY或S9(4)COMP。其他变量都在WORKING-STORAGE中定义为S9(4)COMP。

DIVIDE WS-YYYY BY 4 GIVING YEAR-BY-4 REMAINDER YEAR-BY-4-REMAINDER. 
DIVIDE WS-YYYY BY 100 GIVING YEAR-BY-100 REMAINDER YEAR-BY-100-REMAINDER.
DIVIDE WS-YYYY BY 400 GIVING YEAR-BY-400 REMAINDER YEAR-BY-400-REMAINDER.

IF YEAR-BY-400-REMAINDER = 0
    // LEAP YEAR CODE
ELSE IF YEAR-BY-100-REMAINDER = 0 
    //  NON-LEAP YEAR CODE
ELSE IF YEAR-BY-4-REMAINDER = 0
    //  LEAP YEAR CODE
ELSE
    // NON-LEAP YEAR CODE
. (period)