Focal Point
[CLOSED] Previous Working Day

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/3631053642

September 11, 2007, 09:03 AM
SG
[CLOSED] Previous Working Day
Hello,

My previous working day suddenly stopped working.
I am using the following syntax over a month.
-SET &PRIBUSDAY = DATEMOV(&YYMD, 'PWD');
it is setting to 20070908 instead of 20070910.

Thanks,
SG.

This message has been edited. Last edited by: Kerry,


Webfocus 7.6.8
PDF,HTML & EXCEL
September 11, 2007, 09:18 AM
Francis Mariani
I've been led to believe that Date functions will only work with Date fields, in Dialogue Manager &YYMD is an alphanumeric value, not a Date field. You can use Date functions in Dialogue Manager if you convert the date to a Date field before applying the function.

-SET &PRIBUSDAY =
-  DATECVT((DATEMOV((DATECVT(&YYMD,'I8YYMD','YYMD')),'PWD')),'YYMD','I8YYMD');
-TYPE &PRIBUSDAY


The inner DATECVT function converts &YMMD to a Date field, then DATEMOV is applied, then the outer DATECVT converts the result back to an alphanumeric field.

Ridiculous, non?


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
September 11, 2007, 09:30 AM
SG
Thank You Francis for the explanation and its working now.

SG.


Webfocus 7.6.8
PDF,HTML & EXCEL
April 29, 2009, 10:34 AM
mark66
Hi guys,

We have a problem with Previos Work Day calculation. I am using Francis's example to convert the text to date then doing DATEMOV etc.

This works fine, however someone has noticed that the previous working day calulcation for 1st Feb 2009 is Thursday 29th Jan and not Friday 30th Jan?


-SET &PRIBUSDAY = DATECVT((DATEMOV((DATECVT('20090201','I8YYMD','YYMD')),'PWD')),'YYMD','I8YYMD');
-TYPE &PRIBUSDAY
-EXIT


Any ideas? Is this a holiday in the States?

Thanks

Mark


WebFocus 765. iSeries v5r4
April 29, 2009, 12:48 PM
j.gross
There seems to be a consistent bug, when the argument date is not a weekday:

DATECVT(date,'PWD'), for a Saturday or Sunday date, returns the prior Thursday.

-REPEAT :DATES: FOR &Z FROM 0 TO 27;
-SET &Z1 = 20090201+&Z;
-SET &Z2 = DATECVT(&Z1,'I8YYMD','YYMD');
-SET &Z3 = DATEMOV(&Z2,'PWD');
-SET &Z4 = DATECVT(&Z3,'YYMD','I8YYMD');
-SET &ZW1=DOWK(&Z1,'A3');
-SET &ZW4=DOWK(&Z4,'A3');
-TYPE * &ZW1 &Z1 : &Z2 : &Z3 : &ZW4 &Z4 *
-:DATES:

 * SUN 20090201 : 39479 : 39476 : THU 20090129 *
 * MON 20090202 : 39480 : 39477 : FRI 20090130 *
 * TUE 20090203 : 39481 : 39480 : MON 20090202 *
 * WED 20090204 : 39482 : 39481 : TUE 20090203 *
 * THU 20090205 : 39483 : 39482 : WED 20090204 *
 * FRI 20090206 : 39484 : 39483 : THU 20090205 *
 * SAT 20090207 : 39485 : 39483 : THU 20090205 *
 * SUN 20090208 : 39486 : 39483 : THU 20090205 *
 * MON 20090209 : 39487 : 39484 : FRI 20090206 *
 * TUE 20090210 : 39488 : 39487 : MON 20090209 *
 * WED 20090211 : 39489 : 39488 : TUE 20090210 *
 * THU 20090212 : 39490 : 39489 : WED 20090211 *
 * FRI 20090213 : 39491 : 39490 : THU 20090212 *
 * SAT 20090214 : 39492 : 39490 : THU 20090212 *
 * SUN 20090215 : 39493 : 39490 : THU 20090212 *
 * MON 20090216 : 39494 : 39491 : FRI 20090213 *
 * TUE 20090217 : 39495 : 39494 : MON 20090216 *
 * WED 20090218 : 39496 : 39495 : TUE 20090217 *
 * THU 20090219 : 39497 : 39496 : WED 20090218 *
 * FRI 20090220 : 39498 : 39497 : THU 20090219 *
 * SAT 20090221 : 39499 : 39497 : THU 20090219 *
 * SUN 20090222 : 39500 : 39497 : THU 20090219 *
 * MON 20090223 : 39501 : 39498 : FRI 20090220 *
 * TUE 20090224 : 39502 : 39501 : MON 20090223 *
 * WED 20090225 : 39503 : 39502 : TUE 20090224 *
 * THU 20090226 : 39504 : 39503 : WED 20090225 *
 * FRI 20090227 : 39505 : 39504 : THU 20090226 *
 * SAT 20090228 : 39506 : 39504 : THU 20090226 *

And similarly, 'NBD' returns the following Tuesday for a weekend argument date.

-- Apparently the DATECVT function first adjusts a non-business-day argument date in the indicated direction to a business day, and then continues to the adjusted argument date's prior or next business day.


- Jack Gross
WF through 8.1.05
April 30, 2009, 09:23 AM
PBrightwell
And the work around is:

-SET &WKDAY=DOWK(20090201,'A3');
-SET &ADDDAYS=IF '&WKDAY.EVAL' EQ 'SAT' OR 'SUN' THEN 1 ELSE 0;
-SET &PRIBUSDAY =  DATECVT((DATEMOV((DATECVT('20090201','I8YYMD','YYMD')),'PWD')),'YYMD','I8YYMD');
-SET &ADJBUSDAY = AYMD(&PRIBUSDAY,&ADDDAYS,'I8YYMD');
-TYPE &PRIBUSDAY &ADJBUSDAY
  



Pat
WF 7.6.8, AIX, AS400, NT
AS400 FOCUS, AIX FOCUS,
Oracle, DB2, JDE, Lotus Notes
April 30, 2009, 10:09 AM
Francis Mariani
Does anyone else think this is ridiculous?


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
April 30, 2009, 12:22 PM
j.gross
Let's just say it's disappointing that the functions were not properly QA'd.

Note that Patricia's work-around will fail if and when IBI fixes DATEMOV. Here's a safer workaround.
-* To compute &OUT = the weekday following &IN (both as simple +yyyymmdd integer values):
-SET &OUT1   = DATECVT( DATEMOV( DATECVT(&IN  ,'I8YYMD','YYMD') ,'NWD') ,'YYMD','I8YYMD');
-SET &OUT2   = DATECVT( DATEMOV( DATECVT(&OUT1,'I8YYMD','YYMD') ,'PWD') ,'YYMD','I8YYMD');
-SET &OUT    = IF (&OUT2 GT &IN) THEN &OUT2 ELSE &OUT1;

-* To compute &OUT = the weekday preceeding &IN:
-SET &OUT1   = DATECVT( DATEMOV( DATECVT(&IN  ,'I8YYMD','YYMD') ,'PWD') ,'YYMD','I8YYMD');
-SET &OUT2   = DATECVT( DATEMOV( DATECVT(&OUT1,'I8YYMD','YYMD') ,'NWD') ,'YYMD','I8YYMD');
-SET &OUT    = IF (&OUT2 LT &IN) THEN &OUT2 ELSE &OUT1;

&OUT1 is the weekday date returned by DATEMOV, and &OUT2 is its neighbor back in the direction of the original date. We test whether &OUT2 looks right (where it lies in relation to the input date):
- If &OUT2 looks wrong, &OUT1 is the correct result;
- If &OUT2 looks right, &OUT1 must have overshot the goal, and &OUT2 is the correct result.


- Jack Gross
WF through 8.1.05
May 01, 2009, 10:51 AM
PBrightwell
quote:
Does anyone else think this is ridiculous?

Yes, it's why I write some of my own functions as -INCLUDES at least then I know how they will operate.


Pat
WF 7.6.8, AIX, AS400, NT
AS400 FOCUS, AIX FOCUS,
Oracle, DB2, JDE, Lotus Notes
May 01, 2009, 11:26 AM
Glenda
And here we thought we were the only ones having problems. Here's our solution which also includes holidays since we were unable to get that to work either.

-SET &EDATE         = IF &TOD GT 17.00.00 THEN AYMD(&YYMD, 1, 'I8YYMD') ELSE &YYMD;
DDATE/YYMD = &EDATE;
T1/MDYY=DDATE;
T3/I2=IF '&W1' EQ 'MON' THEN 3 ELSE 1;
T4/MDYY=T1-T3;
T5/I8YYMD=T4;
T6/I8=T5;
-*
-*Looks at previous day to determine if that day was a holiday
-*If so, force it to look at the most recent work day
-*
TDATEI/I8 = DECODE T6(20060102 20051230
                      20060414 20060413
                      20060529 20060526
                      20060704 20060703
                      20060904 20060901
                      20061123 20061122
                      20061124 20061122
                      20061225 20061222
                      20061226 20061222
                      20070707 20071229
                      20070406 20070405
                      20070528 20070525
                      20070704 20070703
                      20070903 20070831
                      20071122 20071121
                      20071123 20071121
                      20071224 20071221
                      20071225 20071221
                      20080101 20071231
                      20080321 20080320
                      20080526 20080523
                      20080704 20080703
                      20080901 20080829
                      20081127 20081126
                      20081128 20081126
                      20081225 20081224
                      20081226 20081224
                      20090101 20081231
                      20090410 20090409
                      20090525 20090522
                      20090703 20090702
                      20090907 20090904
                      20091126 20091125
                      20091127 20091125
                      20091224 20091223
                      20091225 20091223);
TDATE/I8 = IF TDATEI EQ 0 THEN T6 ELSE TDATEI;


It's great to be able think outside of the box!!! Music


Glenda

In FOCUS Since 1990
Production 8.2 Windows
May 03, 2009, 05:40 AM
Baillecl
Focus Community, You are not dead, yet
"Don't you think it's ridiculous"
"Nice to think out of the box"
How nice to read, Real thanks.
Cordially and Focusely.
PS : When I learnt (and never mastered) APL, someone told me that you had turned into a langage when you came to feel as Natural, dirty tricks to reach your goal.
I have some "Focuseries" that I particularly cherish
Last : Come to think to the enormous amount of money that went around Year 2K. "Wasn't it ridiculous" or worse ?


Focus Mainframe 7.6.11
Dev Studio 7.6.11 and !!!
PC Focus, Focus for OS/2, FFW Six, MSO