/**
* \brief CEE Date API : Calculate Weekstart and -end
*
* This example uses the ILE CEE Date API to convert the current date
* into a lilian date. The weekday is calculated through the API CEEDYWK
* (1 - 7, 1 = sunday). Then the weekstart and -end is calculated.
*
*
*
* The following APIs were used:
*
* - Convert Date to Lilian Format (CEEDAYS)
* - Convert Lilian Date to Character Format (CEEDATE)
* - Get Day Of Week (Numeric) (CEEDYWK)
*
*
* \author Mihael Schmidt
* \date 29.08.2007
*/
H dftactgrp(*no) actgrp(*caller)
*-------------------------------------------------------------------------
* PEP
*-------------------------------------------------------------------------
D main PR extpgm('CEEDATE01')
D date 8A
D main PI
D date 8A
*-------------------------------------------------------------------------
* Prototypes
*-------------------------------------------------------------------------
/copy CEEAPI_H
*-------------------------------------------------------------------------
* Variables
*-------------------------------------------------------------------------
D today S 7P 0
D todayLilian S 10I 0
D dayOfWeek S 10I 0
D weekstartL S 10I 0
D weekendL S 10I 0
D weekstart S 10A
D weekend S 10A
D errorcode S 100A
/free
// check the parameters
if (%parms() = 1);
monitor;
today = %dec(%date(date : *ISO0) : *longjul);
on-error *all;
dsply %trimr('No valid ISO date: ' + date);
*inlr = *on;
return;
endmon;
else;
// no parameter passed => take the current date
today = %dec(%date() : *longjul);
endif;
cee_getLilianDate(%char(today) : 'YYYYDDD' : todayLilian);
cee_getDayOfWeekNumeric(todayLilian : dayOfWeek : errorcode);
// calculate weekstart /-end
weekstartL = todayLilian - dayOfWeek + 1; // sunday
weekendL = weekstartL + 6; // saturday
cee_getDateFromLilian(weekstartL : 'YYYY-MM-DD' : weekstart);
cee_getDateFromLilian(weekendL : 'YYYY-MM-DD' : weekend);
dsply %trim('Weekstart: ' + weekstart);
dsply %trim('Weekend : ' + weekend);
*inlr = *on;
return;
/end-free