I would like to build a function that calculate a date.
I have a CL program that calls a RPG program with a parameter The calculation i want to do is if i send in the parm 00000000 (yearmonthdays) nothing happends. the function returns todays date in ISO. If i send in 00050000 the function returns 2017-02-15 (todays date - 5 years) If i send in 00020100 the function returns 2020-01-15 (today date - 2 years - 1 month)
The results i need to be set in the variable VALUE in the CL program.
PGM PARM(&RTNDATE)
DCL VAR(&VALUE) TYPE(*CHAR) LEN(50)
DCL VAR(&RTNDATE) TYPE(*CHAR) LEN(8)
CALL PGM(B91RKI/RCVRPG) PARM(&RTNDATE)
SNDPGMMSG MSG(&RTNDATE)
CHGVAR VAR(&VALUE) VALUE(&RTNDATE)
ENDPGM
RPGLE :
hoption(*srcstmt:*nodebugio)
dRCVRPG PR extpgm('RCVCALL')
C *ENTRY PLIST
C PARM RTNDATE
dRTNDATE 8a
dyear1 4a
dmonth1 2a
dday1 2a
/free
year1 = %subst(RTNDATE:1:4) ;
month1 = %subst(RTNDATE:5:2) ;
day1 = %subst(RTNDATE:7:2) ;
RTNDATE = %date() ;
RTNDATE = RTNDATE - %years(year1) ;
RTNDATE = RTNDATE - %months(month1) ;
return ;
/end-free
c SETON LR