Build Customer Calendar Pattern using WebFOCUS Data Functions and Dialogue Manager Commands
The Actual Code:
-* The below code can be accessed using a –INCLUDE across various reports.
-IF &RPT_TYPE EQ 'CUS' THEN GOTO CUS_CAL ;
-CUS_CAL
-* WEEKFIRST with 1 determines SUNDAY as the start of the Week
SET WEEKFIRST = 1
-* FIX_DAY is a constant as January 1 2012 was a Sunday.
-SET &FIX_DAY = '20120101' ;
-* CAL_BOY begin of the year initially set to January 1 2012.
-SET &CAL_BOY = '20120101' ;
-* P_YEAR previous year set to 2012.
-SET &P_YEAR = '2012' ;
-*C_YEAR gets the current year value from the current date'
-SET &C_YEAR = HPART(HGETC(8, 'HYYMD'), 'YY', 'I3');
-TYPE C_YEAR &C_YEAR ;
-* Branching based on the Year
-IF &C_YEAR GT &P_YEAR THEN :1_LOOP ELSE :SKP_LOOP ;
-:1_LOOP
-* This section works if CUS_DOY < 365
-SET &Y_DIFF = (&C_YEAR - &P_YEAR) ;
-SET &DAYS_TO_ADD = &Y_DIFF * 364 ;
-TYPE &DAYS_TO_ADD &DAYS_TO_ADD ;
-SET &1STDAY = AYMD(&FIX_DAY, &DAYS_TO_ADD, 'I8YYMD') ;
-TYPE 1STDAY &1STDAY;
-SET &CAL_BOY = DATECVT(DATEMOV(DATECVT(&YYMD, 'I8YYMD', 'YYMD'), 'BOY'), 'YYMD', 'I8YYMD');
-TYPE CAL_BOY &CAL_BOY;
-SET &REM_DYS = DATEDIF('&1STDAY','&CAL_BOY','D') ;
-TYPE REM_DYS &REM_DYS;
-SET &CUR_DOY = HPART(HGETC(8, 'HYYMD'), 'DY', 'I3');
-TYPE CUR_DOY &CUR_DOY;
-SET &CUS_DOY = &CUR_DOY + &REM_DYS ;
-TYPE CUS_DOY &CUS_DOY ;
-IF &CUS_DOY GE 365 GOTO :365_LOOP ELSE GOTO :NEXT_STEP ;
-:365_LOOP
-* This section works if CUS_DOY >= 365
-SET &Y_DIFF = (&C_YEAR - &P_YEAR) + 1 ;
-SET &DAYS_TO_ADD = &Y_DIFF * 364 ;
-TYPE &DAYS_TO_ADD &DAYS_TO_ADD ;
-SET &1STDAY = AYMD(&FIX_DAY, &DAYS_TO_ADD, 'I8YYMD') ;
-SET &LAST_DOY = DATECVT(DATEMOV(DATECVT(&YYMD, 'I8YYMD', 'YYMD'), 'EOY'), 'YYMD', 'I8YYMD');
-TYPE LAST_DOY &LAST_DOY ;
-SET &CAL_BOY = AYMD(&LAST_DOY, 1, 'I8YYMD');
-SET &REM_DYS = DATEDIF('&1STDAY','&CAL_BOY','D') ;
-TYPE REM_DYS &REM_DYS;
-SET &P_DAY = &YYMD ;
-SET &CUR_DOY = IF &CUS_DOY GE 365 THEN DATEDIF('&CAL_BOY','&YYMD','D') ELSE HPART(HGETC(8, 'HYYMD'), 'DY', 'I3');
-TYPE CUR_DOY &CUR_DOY;
-SET &CUS_DOY = (&CUR_DOY + &REM_DYS) + 1 ;
-TYPE CUS_DOY &CUS_DOY ;
-GOTO :NEXT_STEP
-:SKP_LOOP
-* This section works only initially in year 2012
-SET &1STDAY = &FIX_DAY ;
-SET &REM_DYS = DATEDIF('&1STDAY','&CAL_BOY','D') ;
-TYPE REM_DYS &REM_DYS;
-SET &CUR_DOY = HPART(HGETC(8, 'HYYMD'), 'DY', 'I3');
-TYPE CUR_DOY &CUR_DOY;
-SET &CUS_DOY = &CUR_DOY + &REM_DYS ;
-TYPE CUS_DOY &CUS_DOY ;
-IF &CUS_DOY GE 365 THEN GOTO :365_LOOP ELSE GOTO :NEXT_STEP ;
-:NEXT_STEP
-* The section determines if the custom day of the year is in 4 week bucket or 5 week bucket.
-* The numbers below are the start day of each month .Ex 4 weeks contains 28 days so 29th day will be the 1st day of next month.
-IF (&CUS_DOY GE -&REM_DYS AND &CUS_DOY LT 29) OR (&CUS_DOY GE 365) THEN GOTO P_4_01 ELSE
-IF (&CUS_DOY GE 29 AND &CUS_DOY LT 57) THEN GOTO P_4_02 ELSE
-IF (&CUS_DOY GE 57 AND &CUS_DOY LT 92) THEN GOTO P_5_03 ELSE
-IF (&CUS_DOY GE 92 AND &CUS_DOY LT 120) THEN GOTO P_4_04 ELSE
-IF (&CUS_DOY GE 120 AND &CUS_DOY LT 148) THEN GOTO P_4_05 ELSE
-IF (&CUS_DOY GE 148 AND &CUS_DOY LT 183) THEN GOTO P_5_06 ELSE
-IF (&CUS_DOY GE 183 AND &CUS_DOY LT 211) THEN GOTO P_4_07 ELSE
-IF (&CUS_DOY GE 211 AND &CUS_DOY LT 239) THEN GOTO P_4_08 ELSE
-IF (&CUS_DOY GE 239 AND &CUS_DOY LT 274) THEN GOTO P_5_09 ELSE
-IF (&CUS_DOY GE 274 AND &CUS_DOY LT 302) THEN GOTO P_4_10 ELSE
-IF (&CUS_DOY GE 302 AND &CUS_DOY LT 330) THEN GOTO P_4_11 ELSE
-IF (&CUS_DOY GE 330 AND &CUS_DOY LT 365) THEN GOTO P_5_12 ELSE GOTO P_CONT ;
-P_4_01
-TYPE "Period 01" ;
-SET &FROMDATE = AYMD(&1STDAY, -35, 'I8YYMD');
-SET &TODATE = AYMD(&1STDAY, 0, 'I8YYMD');
-GOTO P_CONT
-P_4_02
-TYPE "Period 02" ;
-SET &FROMDATE = AYMD(&1STDAY, 0, 'I8YYMD');
-SET &TODATE = AYMD(&1STDAY, 28, 'I8YYMD');
-GOTO P_CONT
-P_5_03
-TYPE "Period 03" ;
-SET &FROMDATE = AYMD(&1STDAY, 28, 'I8YYMD');
-SET &TODATE = AYMD(&1STDAY, 56, 'I8YYMD');
-GOTO P_CONT
-P_4_04
-TYPE "Period 04" ;
-SET &FROMDATE = AYMD(&1STDAY, 56, 'I8YYMD');
-SET &TODATE = AYMD(&1STDAY, 91, 'I8YYMD');
-GOTO P_CONT
-P_4_05
-TYPE "Period 05" ;
-SET &FROMDATE = AYMD(&1STDAY, 91, 'I8YYMD');
-SET &TODATE = AYMD(&1STDAY, 119, 'I8YYMD');
-GOTO P_CONT
-P_5_06
-TYPE "Period 06" ;
-SET &FROMDATE = AYMD(&1STDAY, 119, 'I8YYMD');
-SET &TODATE = AYMD(&1STDAY, 147, 'I8YYMD');
-GOTO P_CONT
-P_4_07
-TYPE "Period 07" ;
-SET &FROMDATE = AYMD(&1STDAY, 147, 'I8YYMD');
-SET &TODATE = AYMD(&1STDAY, 182, 'I8YYMD');
-GOTO P_CONT
-P_4_08
-TYPE "Period 08" ;
-SET &FROMDATE = AYMD(&1STDAY, 182, 'I8YYMD');
-SET &TODATE = AYMD(&1STDAY, 210, 'I8YYMD');
-GOTO P_CONT
-P_5_09
-TYPE "Period 09" ;
-SET &FROMDATE = AYMD(&1STDAY, 210, 'I8YYMD');
-SET &TODATE = AYMD(&1STDAY, 238, 'I8YYMD');
-GOTO P_CONT
-P_4_10
-TYPE "Period 10" ;
-SET &FROMDATE = AYMD(&1STDAY, 238, 'I8YYMD');
-SET &TODATE = AYMD(&1STDAY, 273, 'I8YYMD');
-GOTO P_CONT
-P_4_11
-TYPE "Period 11" ;
-SET &FROMDATE = AYMD(&1STDAY, 273, 'I8YYMD');
-SET &TODATE = AYMD(&1STDAY, 301, 'I8YYMD');
-GOTO P_CONT
-P_5_12
-TYPE "Period 12" ;
-SET &FROMDATE = AYMD(&1STDAY, 301, 'I8YYMD');
-SET &TODATE = AYMD(&1STDAY, 329, 'I8YYMD');
-GOTO P_CONT
-P_CONT
-TYPE "Continue" ;
-TYPE FROMDATE &FROMDATE TODATE &TODATE ;
-IF &CUS_DOY IN (1,29,57,92,120,148,183,211,239,274,302,330) GOTO :E_RPT ELSE :K_RPT ;
-:K_RPT
-*If CUS_DOY is not the first day of the month then kill the jobor exit
-TYPE "This is not the day to execute the report."
-TYPE FROMDATE &FROMDATE TODATE &TODATE ;
-SET &FROM_DATE = EDIT(&FROMDATE, '$$$$99') || '/' || EDIT(&FROMDATE, '$$$$$$99') || '/' || EDIT(&FROMDATE, '9999');
-SET &TO_DATE = EDIT(&TODATE, '$$$$99') || '/' || EDIT(&TODATE, '$$$$$$99') || '/' || EDIT(&TODATE, '9999');
-TYPE FROM_DATE &FROM_DATE TO_DATE &TO_DATE ;
-SET &KILL_RPC = 'Y' ;
-EXIT
-:E_RPT
-*If CUS_DOY is first day of the month then continue to the report code
-TYPE "This is the day to execute the report."
-TYPE FROMDATE &FROMDATE TODATE &TODATE ;
-SET &FROM_DATE = EDIT(&FROMDATE, '$$$$99') || '/' || EDIT(&FROMDATE, '$$$$$$99') || '/' || EDIT(&FROMDATE, '9999');
-SET &TO_DATE = EDIT(&TODATE, '$$$$99') || '/' || EDIT(&TODATE, '$$$$$$99') || '/' || EDIT(&TODATE, '9999');
-TYPE FROM_DATE &FROM_DATE TO_DATE &TO_DATE ;
-GOTO STRT_RPT
-ESCAPE