-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetdatey.cbl
62 lines (62 loc) · 2.6 KB
/
getdatey.cbl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
identification division.
program-id. getdatey.
*************************************************
**** input argument will be subtracted from current date
**** returns date X days before run date.
**** compile: cobc -x getdatey.cbl -std=mf
**** run: getdatey 31
**** returns new date 31 days before current date
**** example for running on the current date of 20240212
**** execute example: getdatey 31
**** returns from sysout on next line: 20240112
**** ALWAYS Check return-code
**** Dedicated to the public domain.
*************************************************
environment division.
configuration section.
source-computer.
System76.
repository.
function all intrinsic.
data division.
working-storage section.
01 dx pic x(08).
01 dn redefines dx pic 9(08).
01 wi comp-x pic x(08).
01 arg-alph-in value spaces pic x(07).
01 arg-numeric value zeroes pic 9(07).
01 arg-knt comp-5 pic x(02).
01 num-ss comp-5 pic x(02).
01 alph-ss comp-5 pic x(02).
procedure division.
move current-date to dx
move integer-of-date(dn) to wi
accept arg-knt from argument-number
if arg-knt not = 1
display "usage: getdatey <arg list 1>"
upon syserr
display "enter number of days to subtract "
"from current date"
upon syserr
stop run returning -1
end-if
accept arg-alph-in from argument-value
move 7 to num-ss
perform test after varying alph-ss
from 7 by -1
until alph-ss = 1
if arg-alph-in(alph-ss:1) not = space
move arg-alph-in(alph-ss:1) to arg-numeric(num-ss:1)
subtract 1 from num-ss
end-if
end-perform
if arg-numeric not numeric
display "argument not numeric " upon syserr
stop run returning -3
end-if
subtract arg-numeric from wi
move date-of-integer(wi) to dn
display dx
move zeroes to return-code
goback
.