Troubleshooting
Problem
This document illustrates the use, in ILE CL, of three CEE APIs: CEEDAYS, CEEDATE, CEEDYWK.
Resolving The Problem
This document illustrates the use, in ILE CL, of three CEE APIs: CEEDAYS, CEEDATE, CEEDYWK. These APIs rely on the Lilian date representation, which is the integer number of days since October 14, 1582.
Example:
October 14, 1582 = Lilian date 0
October 15, 1582 = Lilian date 1
.......
January 1, 2000 = Lilian date 152,385
.......
The upper bound on the Lilian date range as implemented is:
December 31, 9999 = Lilian date 3,074,324
The Lilian date format is especially well-suited to such date arithmetic operations as adding/subtracting days to/from a date or calculating the number of days between two dates.
The functionality of each API is as follows:
Three sample ILE CL programs are included in this document in the order and with the functionality's shown below:
Note: These programs will not compile as OPM CL because CEE APIs are only callable from ILE languages.
Example:
October 14, 1582 = Lilian date 0
October 15, 1582 = Lilian date 1
.......
January 1, 2000 = Lilian date 152,385
.......
The upper bound on the Lilian date range as implemented is:
December 31, 9999 = Lilian date 3,074,324
The Lilian date format is especially well-suited to such date arithmetic operations as adding/subtracting days to/from a date or calculating the number of days between two dates.
The functionality of each API is as follows:
o | CEEDAYS converts a date from Gregorian to Lilian representation. The input's date format is selected by specifying a picture string, for example, 'MMDDYYYY' for *USA0 format. |
o | CEEDATE converts dates from Lilian to Gregorian representation. The output's date format is selected by specifying a picture string, for example, 'MMDDYYYY' for *USA0 format. |
o | CEEDYWK determines the day-of-week corresponding to a given Lilian date. This API returns: 1 = Sunday 2 = Monday 3 = Tuesday 4 = Wednesday 5 = Thursday 6 = Friday 7 = Saturday |
o | Add a positive or negative integer to a Gregorian date, return the result as a Gregorian date. |
o | Find the number of days between two Gregorian dates. |
o3 | Determine the day-of-week corresponding to a Gregorian date. |
Note: These programs will not compile as OPM CL because CEE APIs are only callable from ILE languages.
Caution: This is an example only. IBM® accepts no responsibility for its correctness. |
/********************************************************************/ /* This program adds a given number of days to a date and returns */ /* the resulting date as a message at the bottom of the screen. */ /* Usage example: */ /* */ /* CALL program_name PARM('12311999' 7) */ /* */ /* will return: */ /* */ /* 20000107 */ /* */ /* Input format is: MMDDYYYY */ /* Output format is: YYYYMMDD */ /* */ /* The operation is accomplished by conversion to Lilian date, */ /* addition and reconversion to Gregorian date; this is done using */ /* CEE API routines documented in Chapter 4 of: */ /* */ /* OS/400 Integrated Language Environment® (ILE) CEE APIs V3R7 */ /* SC41-4861-01 */ /* */ /* */ /* */ /********************************************************************/ PGM PARM(&USAINPUT &ADDDAYSDEC) DCL &USAINPUT *CHAR 8 DCL &ADDDAYSDEC *DEC (15 5) DCL &YMDOUTPUT *CHAR 8 DCL &PICTURE *CHAR 8 DCL &LILIANBIN *CHAR 4 DCL &LILIANDEC *DEC (10 0) /* The following variable is used to receive API's feedback codes */ DCL &FC *CHAR 12 /**/ /* Define input format */ CHGVAR &PICTURE 'MMDDYYYY' /* Convert to Lilian date (returned as a 32-bit binary integer) */ /* This API call may also be made without a feedback code variable: */ /* CALLPRC PRC(CEEDAYS) PARM(&USAINPUT &PICTURE &LILIANBIN *OMIT) */ CALLPRC PRC(CEEDAYS) PARM(&USAINPUT &PICTURE &LILIANBIN &FC) /* Convert binary Lilian to decimal Lilian */ CHGVAR &LILIANDEC %BINARY(&LILIANBIN) /* Add days to decimal Lilian */ CHGVAR &LILIANDEC VALUE(&LILIANDEC + &ADDDAYSDEC) /* Convert decimal Lilian to binary Lilian */ CHGVAR %BINARY(&LILIANBIN) &LILIANDEC /* Define output format */ CHGVAR &PICTURE 'YYYYMMDD' /* Convert to Gregorian date */ /* This API call may also be made without a feedback code variable: */ /* CALLPRC PRC(CEEDATE) PARM(&LILIANBIN &PICTURE &YMDOUTPUT *OMIT) */ CALLPRC PRC(CEEDATE) PARM(&LILIANBIN &PICTURE &YMDOUTPUT &FC) /* Display result */ SNDPGMMSG MSG(&YMDOUTPUT) ENDPGM /********************************************************************/ /* This program finds the number of days between two dates and */ /* returns the result as a message at the bottom of the screen. */ /* Usage example: */ /* */ /* CALL program_name PARM('12311999' '01012000') */ /* */ /* will return: */ /* */ /* 00000000000000000001 */ /* */ /* Input format is: MMDDYYYY */ /* */ /* The operation is accomplished by converting the two dates to */ /* binary Lilian format, then to decimal Lilian and finally */ /* subtracting the two resulting integers. */ /* This is done using CEE API routines documented in Chapter 4 of: */ /* */ /* OS/400 Integrated Language Environment (ILE) CEE APIs V3R7 */ /* SC41-4861-01 */ /* */ /* */ /* */ /********************************************************************/ PGM PARM(&USAINPUT1 &USAINPUT2) DCL &USAINPUT1 *CHAR 8 DCL &USAINPUT2 *CHAR 8 DCL &DURDEC *DEC (10 0) DCL &DURCHAR *CHAR 20 DCL &PICTURE *CHAR 8 DCL &LILIANBIN1 *CHAR 4 DCL &LILIANBIN2 *CHAR 4 DCL &LILIANDEC1 *DEC (10 0) DCL &LILIANDEC2 *DEC (10 0) /* The following variable is used to receive API's feedback codes */ DCL &FC *CHAR 12 /**/ /* Define input format */ CHGVAR &PICTURE 'MMDDYYYY' /* Convert to Lilian date (returned as a 32-bit binary integer) */ /* This API call may also be made without a feedback code variable: */ /* CALLPRC PRC(CEEDAYS) PARM(&USAINPUT1 &PICTURE &LILIANBIN1 *OMIT) */ /* CALLPRC PRC(CEEDAYS) PARM(&USAINPUT1 &PICTURE &LILIANBIN2 *OMIT) */ CALLPRC PRC(CEEDAYS) PARM(&USAINPUT1 &PICTURE &LILIANBIN1 &FC) CALLPRC PRC(CEEDAYS) PARM(&USAINPUT2 &PICTURE &LILIANBIN2 &FC) /* Convert binary Lilian to decimal Lilian */ CHGVAR &LILIANDEC1 %BINARY(&LILIANBIN1) CHGVAR &LILIANDEC2 %BINARY(&LILIANBIN2) /* Find number of days between the two dates */ CHGVAR &DURDEC VALUE(&LILIANDEC2 - &LILIANDEC1) /* Convert result to CHAR for messaging to the screen */ CHGVAR VAR(&DURCHAR) VALUE(&DURDEC) /* Display result */ SNDPGMMSG MSG(&DURCHAR) ENDPGM /********************************************************************/ /* This program determines the day of the week given a Gregorian */ /* date and displays the result as a message at the bottom of the */ /* screen. */ /* Usage example: */ /* */ /* CALL program_name PARM('12311999') */ /* */ /* will return: */ /* */ /* THIS DATE IS A FRIDAY */ /* */ /* Input format is: MMDDYYYY */ /* */ /* The operation is accomplished by conversion to Lilian date */ /* and day-of-week computation; this is done using CEE API */ /* routines documented in Chapter 4 of: */ /* */ /* OS/400 Integrated Language Environment (ILE) CEE APIs V3R7 */ /* SC41-4861-01 */ /* */ /* */ /* */ /********************************************************************/ PGM PARM(&USAINPUT) DCL &MESSAGE *CHAR 78 'THIS DATE IS A ' DCL &USAINPUT *CHAR 8 DCL &LILIANBIN *CHAR 4 DCL &LILIANDEC *DEC (10 0) DCL &DOWBIN *CHAR 4 DCL &DOWDEC *DEC (5 0) DCL &DOW *CHAR 9 DCL &PICTURE *CHAR 8 /* The following variable is used to receive API's feedback codes */ DCL &FC *CHAR 12 /**/ /* Define input format */ CHGVAR &PICTURE 'MMDDYYYY' /* Convert to Lilian date (returned as a 32-bit binary integer) */ /* This API call may also be made without a feedback code variable: */ /* CALLPRC PRC(CEEDAYS) PARM(&USAINPUT &PICTURE &LILIANBIN *OMIT) */ CALLPRC PRC(CEEDAYS) PARM(&USAINPUT &PICTURE &LILIANBIN &FC) /* Compute day-of-week (returned as a 32-bit binary integer) */ /* This API call may also be made without a feedback code variable: */ /* CALLPRC PRC(CEEDYWK) PARM(&LILIANBIN &DOWBIN *OMIT) */ CALLPRC PRC(CEEDYWK) PARM(&LILIANBIN &DOWBIN &FC) /* Convert binary day-of-week to decimal day-of-week */ CHGVAR &DOWDEC %BINARY(&DOWBIN) /* Select name of day */ IF (&DOWDEC = 1) THEN(CHGVAR &DOW 'SUNDAY ') IF (&DOWDEC = 2) THEN(CHGVAR &DOW 'MONDAY ') IF (&DOWDEC = 3) THEN(CHGVAR &DOW 'TUESDAY ') IF (&DOWDEC = 4) THEN(CHGVAR &DOW 'WEDNESDAY') IF (&DOWDEC = 5) THEN(CHGVAR &DOW 'THURSDAY ') IF (&DOWDEC = 6) THEN(CHGVAR &DOW 'FRIDAY ') IF (&DOWDEC = 7) THEN(CHGVAR &DOW 'SATURDAY ') /* Paste name of day into message */ CHGVAR VAR(%SUBSTRING(&MESSAGE 16 9)) VALUE(&DOW) /* Display message */ SNDPGMMSG MSG(&MESSAGE) ENDPGM
[{"Type":"MASTER","Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Platform":[{"code":"PF012","label":"IBM i"}],"Version":"7.1.0"}]
Historical Number
15543023
Was this topic helpful?
Document Information
Modified date:
18 December 2019
UID
nas8N1018101