Function OV@P937 OV_DATETIME_DIFF

LANSA

Function OV@P937 OV_DATETIME_DIFF

********** COMMENT(=======================================================);
********** COMMENT(Process ........: SET_165);
********** COMMENT(Function .......: OV@P937);
********** COMMENT(Created on .....: 21/01/00 at 14:43:32);
********** COMMENT(Created using template BBRDMLBIF);
********** COMMENT(Description ....: Date-Time difference );
********** COMMENT(Version.........: 1);
**********;
********** COMMENT(Full Description: The purpose of this function is to);
********** COMMENT(calculate the difference between two );
********** COMMENT(date-times in seconds));
**********;
********** COMMENT(Disclaimer: The following material is supplied as);
********** COMMENT(sample material only. No warranty concerning the);
********** COMMENT(material or its use in any way whatsoever is);
********** COMMENT(expressed or implied.);
**********;
********** COMMENT(Minimum LANSA release: 8.0);
**********;
********** COMMENT(=======================================================);
FUNCTION OPTIONS(*DIRECT *NOMESSAGES *LIGHTUSAGE *MLOPTIMISE *BUILTIN);
********** COMMENT(=======================================================);
********** COMMENT(Special field to name the Built-In Function);
********** COMMENT(=======================================================);
DEFINE FIELD(#BIF_NAME) TYPE(*CHAR) LENGTH(20) DESC('Date Time Difference') DEFAULT(OV_DATETIME_DIFF);
********** COMMENT(=======================================================);
********** COMMENT(Built-In Function Arguments);
********** COMMENT(=======================================================);
********** COMMENT(Argument 01, from Date );
DEFINE FIELD(#BIF_ARG01) TYPE(*DEC) LENGTH(8) DECIMALS(0) DESC('from Date ');
********** COMMENT(Argument 02, Format of from-Date );
DEFINE FIELD(#BIF_ARG02) TYPE(*CHAR) LENGTH(20) DESC('Format of from-Date ');
********** COMMENT(Argument 03, from Time (HHMMSS) );
DEFINE FIELD(#BIF_ARG03) TYPE(*DEC) LENGTH(6) DECIMALS(0) DESC('from Time (HHMMSS) ');
********** COMMENT(Argument 04, to Date);
DEFINE FIELD(#BIF_ARG04) TYPE(*DEC) LENGTH(8) DECIMALS(0) DESC('to Date');
********** COMMENT(Argument 05, format of to-Date);
DEFINE FIELD(#BIF_ARG05) TYPE(*CHAR) LENGTH(20) DESC('format of to-Date');
********** COMMENT(Argument 06, to Time (HHMMSS));
DEFINE FIELD(#BIF_ARG06) TYPE(*DEC) LENGTH(6) DECIMALS(0) DESC('to Time (HHMMSS)');
********** COMMENT(=======================================================);
********** COMMENT(Built-In Function Return Values);
********** COMMENT(=======================================================);
********** COMMENT(Return Value 01, Time difference in seconds);
DEFINE FIELD(#BIF_RET01) TYPE(*DEC) LENGTH(15) DECIMALS(0) DESC('Time difference in seconds');
********** COMMENT(Return Value 02, Return Code (OK or ER));
DEFINE FIELD(#BIF_RET02) TYPE(*CHAR) LENGTH(2) DESC('Return Code (OK or ER)') DEFAULT(*BLANK);
********** COMMENT(=======================================================);
********** COMMENT(Working fields, lists and groups);
********** COMMENT(=======================================================);
********** COMMENT(=======================================================);
********** COMMENT(Function Mainline : SET165M);
********** COMMENT(=======================================================);
********** COMMENT(internal work fields);
DEFINE FIELD(#S_165SECF) TYPE(*DEC) LENGTH(15) DECIMALS(0);
DEFINE FIELD(#S_165SECT) TYPE(*DEC) LENGTH(15) DECIMALS(0);
DEFINE FIELD(#S_165SEC) TYPE(*DEC) LENGTH(15) DECIMALS(0);
DEFINE FIELD(#S_165TIM) TYPE(*DEC) LENGTH(6) DECIMALS(0);
DEFINE FIELD(#S_165DAYS) TYPE(*DEC) LENGTH(8) DECIMALS(0);
DEFINE FIELD(#S_165SIGN) TYPE(*CHAR) LENGTH(1);
DEFINE FIELD(#S_FORMAT) TYPE(*CHAR) LENGTH(20) DESC('Long date format');
DEFINE FIELD(#S_FMT) TYPE(*CHAR) LENGTH(1) DESC('Single character date format');
DEFINE FIELD(#S_165FFM1) TYPE(*CHAR) LENGTH(1) DESC('From-date format');
DEFINE FIELD(#S_165TFM1) TYPE(*CHAR) LENGTH(1) DESC('To-date format');
**********;
CHANGE FIELD(#BIF_RET02) TO(OK);
EXECUTE SUBROUTINE(SECONDS) WITH_PARMS(#BIF_ARG03 #S_165SECF);
EXECUTE SUBROUTINE(SECONDS) WITH_PARMS(#BIF_ARG06 #S_165SECT);
**********;
EXECUTE SUBROUTINE(TRANSLATE) WITH_PARMS(#BIF_ARG02 #S_165FFM1);
EXECUTE SUBROUTINE(TRANSLATE) WITH_PARMS(#BIF_ARG05 #S_165TFM1);
**********;
USE BUILTIN(DATEDIFFERENCE) WITH_ARGS(#BIF_ARG01 #S_165FFM1 #BIF_ARG04 #S_165TFM1) TO_GET(#S_165DAYS #S_165SIGN #S_RETCDA1);
IF COND('#S_RETCDA1 *NE Y');
CHANGE FIELD(#BIF_RET02) TO(ER);
CHANGE FIELD(#BIF_RET01) TO(0);
ELSE;
CHANGE FIELD(#BIF_RET01) TO('(#S_165DAYS * 24 * 3600) + (#S_165SECT - #S_165SECF)');
ENDIF;
RETURN;
SUBROUTINE NAME(SECONDS) PARMS((#S_165TIM *RECEIVED) (#S_165SEC *RETURNED));
DEFINE FIELD(#S_165H) TYPE(*DEC) LENGTH(2) DECIMALS(0);
DEFINE FIELD(#S_165M) TYPE(*DEC) LENGTH(2) DECIMALS(0);
DEFINE FIELD(#S_165S) TYPE(*DEC) LENGTH(2) DECIMALS(0);
CHANGE FIELD(#S_165H) TO('#S_165TIM / 10000');
CHANGE FIELD(#S_165M) TO('#S_165TIM / 100');
CHANGE FIELD(#S_165S) TO(#S_165TIM);
CHANGE FIELD(#S_165SEC) TO('(#S_165H * 3600) + (#S_165M * 60) + (#S_165S)');
ENDROUTINE;
SUBROUTINE NAME(TRANSLATE) PARMS((#S_FORMAT *RECEIVED) (#S_FMT *RETURNED));
CASE OF_FIELD(#S_FORMAT);
WHEN VALUE_IS('= SYSTEM' '= SYSFMT' '= A');
CHANGE FIELD(#S_FMT) TO(A);
WHEN VALUE_IS('= DDMMYY' '= B');
CHANGE FIELD(#S_FMT) TO(B);
WHEN VALUE_IS('= YYMMDD' '= D');
CHANGE FIELD(#S_FMT) TO(D);
WHEN VALUE_IS('= MMDDYY' '= F');
CHANGE FIELD(#S_FMT) TO(F);
WHEN VALUE_IS('= DDMMYYYY' '= H');
CHANGE FIELD(#S_FMT) TO(H);
WHEN VALUE_IS('= YYYYMMDD' '= J');
CHANGE FIELD(#S_FMT) TO(J);
WHEN VALUE_IS('= MMDDYYYY' '= L');
CHANGE FIELD(#S_FMT) TO(L);
WHEN VALUE_IS('= SYSTEM8' '= SYSFMT8' '= V');
CHANGE FIELD(#S_FMT) TO(V);
OTHERWISE;
CHANGE FIELD(#BIF_RET02) TO(ER);
ENDCASE;
ENDROUTINE;