*********************************************************
* カレンダー ver 1.0
*********************************************************
identification division.
program-id. prog.
environment division.
data division.
working-storage section.
01 in-area.
03 in-nen.
05 in-nen-9 pic 9(04).
03 in-tsuki.
05 in-tsuki-9 pic 9(02).
01 wk-area.
03 wk-uru-area.
05 wk-a pic 9(07).
05 wk-b pic 9(07).
03 wk-uru.
05 wk-uru-nen pic 9(04).
05 wk-uru-kekka pic x(01).
03 wk-calc.
05 wk-nen pic 9(4).
05 wk-nisu pic 9(07).
05 wk-yobi pic 9(4).
05 wk-w1 pic 9(07).
01 ss-area.
03 ss-1 pic 9(03).
03 ss-2 pic 9(03).
01 ct-area.
03 ct-nen pic 9(04) value 2000.
03 ct-yobi pic 9(04) value 7.
03 ct-title pic x(21) value
" S M T W T F S".
01 tb-area.
03 tb-data pic x(24)
value "312831303130313130313031".
03 tb-data-r redefines tb-data.
05 tb-tsuki pic 9(02) occurs 12.
01 ot-area.
03 ot-data pic x(126).
03 ot-data-r redefines ot-data.
05 ot-tbl pic x(03) occurs 42.
03 ot-disp-r redefines ot-data.
05 ot-disp pic x(21) occurs 6.
03 ot-hi pic 9(03).
03 ot-hi-set pic zz9.
03 ot-ss1 pic 9(02).
03 ot-midashi.
05 filler pic x(02) value space.
05 ot-nen pic 9(4).
05 ot-sura pic x(03).
05 ot-tsuki pic x(02).
procedure division.
main-rtn.
perform s00-init.
accept in-nen.
accept in-tsuki.
if in-nen not numeric
display in-nen
display "not numeric"
go to main-rtn-ext
end-if.
if in-tsuki not numeric
display in-tsuki
display "not numeric"
go to main-rtn-ext
end-if.
if in-nen-9 >= ct-nen
perform c10-nencal
perform c11-tsukical
perform c12-yobi
else
perform c20-nencal
perform c21-tsukical
perform c22-yobi
end-if.
move in-nen-9 to ot-nen.
move " / " to ot-sura.
move in-tsuki-9 to ot-tsuki.
move in-nen to wk-uru-nen.
perform c00-uruchk.
if wk-uru-kekka = "1"
move 29 to tb-tsuki(2)
end-if.
perform c13-edit.
perform c14-disp.
main-rtn-ext.
stop run.
*********************************************************
* 初期処理
*********************************************************
s00-init.
initialize in-area wk-area ot-area.
s00-init-ext.
exit.
*********************************************************
* うるう年チェック
*********************************************************
c00-uruchk.
move zero to wk-uru-kekka.
compute wk-a = wk-uru-nen / 4.
compute wk-b = wk-a * 4.
if wk-b = wk-uru-nen
compute wk-a = wk-uru-nen / 100
compute wk-b = wk-a * 100
if wk-b = wk-uru-nen
compute wk-a = wk-uru-nen / 400
compute wk-b = wk-a * 400
if wk-b = wk-uru-nen
move "1" to wk-uru-kekka
end-if
else
move "1" to wk-uru-kekka
end-if
end-if.
c00-uruchk-ext.
exit.
*********************************************************
* 2000年から対象年の前年までに日数算出
*********************************************************
c10-nencal.
move in-nen-9 to wk-nen.
compute wk-nen = wk-nen - 1.
perform until wk-nen < ct-nen
move wk-nen to wk-uru-nen
perform c00-uruchk
if wk-uru-kekka = "1"
compute wk-nisu = wk-nisu + 366
else
compute wk-nisu = wk-nisu + 365
end-if
compute wk-nen = wk-nen - 1
end-perform.
c10-nencal-ext.
exit.
*********************************************************
* 対象年の翌年から1999年までの日数算出
*********************************************************
c20-nencal.
move in-nen-9 to wk-nen.
compute wk-nen = wk-nen + 1.
perform until wk-nen >= ct-nen
move wk-nen to wk-uru-nen
perform c00-uruchk
if wk-uru-kekka = "1"
compute wk-nisu = wk-nisu + 366
else
compute wk-nisu = wk-nisu + 365
end-if
compute wk-nen = wk-nen + 1
end-perform.
c20-nencal-ext.
exit.
*********************************************************
* 対象年の1/1から対象月の前月までの日数算出
**********************************************************
c11-tsukical.
move 1 to ss-1.
perform until ss-1 = in-tsuki-9
compute wk-nisu = wk-nisu + tb-tsuki(ss-1)
compute ss-1 = ss-1 + 1
end-perform.
c11-tsukical-ext.
exit.
*********************************************************
* 対象月から対象年の12月までの日数算出
**********************************************************
c21-tsukical.
move in-tsuki-9 to ss-1.
perform until ss-1 > 12
compute wk-nisu = wk-nisu + tb-tsuki(ss-1)
compute ss-1 = ss-1 + 1
end-perform.
c21-tsukical-ext.
exit.
*********************************************************
* 対象月の1日の曜日算出
**********************************************************
c12-yobi.
compute wk-w1 = wk-nisu / 7.
compute wk-yobi = wk-nisu - wk-w1 * 7.
compute wk-yobi = wk-yobi + ct-yobi.
if wk-yobi > 7
compute wk-yobi = wk-yobi - 7
end-if.
c12-yobi-ext.
exit.
*********************************************************
* 対象月の1日の曜日算出
**********************************************************
c22-yobi.
compute wk-w1 = wk-nisu / 7.
compute wk-yobi = wk-nisu - wk-w1 * 7.
compute wk-yobi = ct-yobi - wk-yobi.
c22-yobi-ext.
exit.
*********************************************************
* カレンダー編集
**********************************************************
c13-edit.
move wk-yobi to ot-ss1.
move 1 to ot-hi.
perform until ot-hi > tb-tsuki(in-tsuki-9)
move ot-hi to ot-hi-set
move ot-hi-set to ot-tbl(ot-ss1)
add 1 to ot-hi
add 1 to ot-ss1
end-perform.
c13-edit-ext.
exit.
*********************************************************
* カレンダー表示
**********************************************************
c14-disp.
display ot-midashi.
display "".
display ct-title.
move 1 to ot-ss1.
perform until ot-ss1 > 6
display ot-disp(ot-ss1)
add 1 to ot-ss1
end-perform.
c14-disp-ext.
exit.