Jump to content
The ibi Community has moved to a new platform: Please Sign In and choose Forgot Password to continue

Sharing is Caring - From one of my co-workers from a long ti...


Matt Chapin

Recommended Posts

Have you ever tried using DEFINE FUNCTIONS to replicate DATEADD, DATEMOV AND DATEDIF These are as least 10 years old from the old FOCAL POINT board. Stick these in baseapp and -INCLUDE them in edasprof. Then use them in Dialogue Manager just like you would in TABLE, DEFINE, etc.

DEFINE FUNCTION UDATEADD(INDATE/A8YYMD, INUNIT/A2, INNBR/I4)

INDATE1/YYMD = INDATE;

UDATEADD1/YYMD = DATEADD(INDATE1, INUNIT, INNBR);

UDATEADD/A8YYMD = UDATEADD1;

END

-RUN

DEFINE FUNCTION UDATEDIF(FROM_DATE/A8YYMD, TO_DATE/A8YYMD, DIF_UNIT/A2)

FRDT/YYMD = FROM_DATE;

TODT/YYMD = TO_DATE;

UDATEDIF/I8 = DATEDIF(FRDT, TODT, DIF_UNIT);

END

-RUN

DEFINE FUNCTION UDATEMOV(INDATE/A8YYMD, INMVTO/A3)

INDATE1/YYMD = INDATE;

UDATEMOV1/YYMD = DATEMOV(INDATE1, INMVTO);

UDATEMOV/A8YYMD = UDATEMOV1;

END

-RUN

For example:

-SET &LSTYR=UDATEADD(&YYMD,Y,-1);

-SET &CURBOQ=UDATEMOV(&YYMD,BOQ);

-SET &DAYS_BETWEEN=UDATEDIF(&LSTYR,&CURBOQ,D);

As a coder for over 35 years, IMHO, DEFINE FUNCTION is one of the top 10 language enhancements in the history of the FOCUS/WebFOCUS. We probably have 40+ DEFINE FUNCTIONS that are used on a regular basis.

Heres one more. We have to report on State and Federal Fiscal Year. State begins in July, Federal begins in October. This function returns the appropriate year for any date in A8YYMD format. This is primary for Dialogue Manage but will use any date once converted to A8YYMD.

DEFINE FUNCTION GETFY(INDATE/A8YYMD,YRTYP/A1)

-*

-* For YRTYP S, get State Fiscal Year for INDATE (Default)

-* For YRTYP F, get Federal Fiscal Year for INDATE

-*

INDATE1/YYMD=INDATE;

INMTH/M=INDATE1;

INYEAR/YY=INDATE1;

YRTYP=IF NOT YRTYP IN (F,S) THEN S;

GETFY/I4=IF YRTYP EQ F AND INMTH LT 10 OR YRTYP EQ S AND INMTH LT 7

THEN INYEAR ELSE INYEAR+1;

END

-RUN

Link to comment
Share on other sites

Sharing is Caring - From one of my co-workers from a long time ago shared this with me. This is a great way to have a bunch of dates ready to go. Throw this in a fex on the server and use as a MFD Profile in your Master.

-* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

-* THIS SETS THE GLOBAL DATE VARIABLES USED IN THE METADATA

-* &YYMD is the system date.

-* This sets what Yesterday is:

-SET &&YESTERDAY=AYMD(&YYMD,-1,I8YYMD);

-* This sets Current Year based upon Yesterday

-SET &&CYEAR=EDIT(&&YESTERDAY,9999);

-* This sets Prior Year based upon Yesterday

-SET &&PYEAR=&&CYEAR-1;

-* This sets Prior Year based upon Yesterday

-SET &&P2YEAR=&&CYEAR-2;

-* This sets prior year yesterday

-SET &&PYYESTERDAY=&&PYEAR.EVAL || EDIT(&&YESTERDAY,$$$$9999);

-SET &&PYYESTERDAY_MDYY=EDIT(&&YESTERDAY,$$$$9999) || &&PYEAR.EVAL;

-* This sets 7 days prior based upon &YESTERDAY

-SET &&P7DAY=AYMD(&&YESTERDAY,-7,I8YYMD);

-SET &&P7DAY_MDYY=EDIT(&&P7DAY,$$$$9999) || EDIT(&&P7DAY,9999$$$$);

-* This sets 14 days prior based upon &YESTERDAY

-SET &&P14DAY=AYMD(&&YESTERDAY,-14,I8YYMD);

-SET &&P14DAY_MDYY=EDIT(&&P14DAY,$$$$9999) || EDIT(&&P14DAY,9999$$$$);

-* This sets 21 days prior based upon &YESTERDAY

-SET &&P21DAY=AYMD(&&YESTERDAY,-21,I8YYMD);

-SET &&P21DAY_MDYY=EDIT(&&P21DAY,$$$$9999) || EDIT(&&P21DAY,9999$$$$);

-* This sets 28 days prior based upon &YESTERDAY

-SET &&P28DAY=AYMD(&&YESTERDAY,-28,I8YYMD);

-SET &&P28DAY_MDYY=EDIT(&&P28DAY,$$$$9999) || EDIT(&&P28DAY,9999$$$$);

-* This sets what the current month is based upon todayss date

-SET &&CMONTH_E=DATECVT(DATEMOV(DATECVT(&&YESTERDAY,I8YYMD, YYMD),EOM),YYMD,I8YYMD);

-SET &&CMONTH_E_MDYY=EDIT(&&CMONTH_E,$$$$9999) || EDIT(&&CMONTH_E,9999$$$$);

-SET &&CMONTH_S=EDIT(&&CMONTH_E,999999) || 01;

-SET &&CMONTH_S_MDYY=EDIT(&&CMONTH_S,$$$$9999) || EDIT(&&CMONTH_S,9999$$$$);

-SET &&CMONTHYYM=EDIT(&&CMONTH_E,999999);

-* This sets what the prior year current month is based upon todayss date

-SET &&PYCMONTH_E=DATECVT(DATEMOV(DATECVT(&&PYYESTERDAY,I8YYMD, YYMD),EOM),YYMD,I8YYMD);

-SET &&PYCMONTH_E_MDYY=EDIT(&&PYCMONTH_E,$$$$9999) || EDIT(&&PYCMONTH_E,9999$$$$);

-SET &&PYCMONTH_S=EDIT(&&PYCMONTH_E,999999) || 01;

-SET &&PYCMONTH_S_MDYY=EDIT(&&PYCMONTH_S,$$$$9999) || EDIT(&&PYCMONTH_S,9999$$$$);

-SET &&PYCMONTHYYM=EDIT(&&PYCMONTH_E,999999);

-* This sets what last month is based upon todays date

-SET &&PMONTHYYM=EDIT(AYM(&&CMONTHYYM, -1,I6YYM));

-SET &&PMONTH_S=EDIT(&&PMONTHYYM,999999) || 01;

-SET &&PMONTH_S_MDYY=EDIT(&&PMONTH_S,$$$$9999) || EDIT(&&PMONTH_S,9999$$$$);

-SET &&PMONTH_E=DATECVT(DATEMOV(DATECVT(EDIT(&&PMONTH_S),I8YYMD, YYMD),EOM),YYMD,I8YYMD);

-SET &&PMONTH_E_MDYY=EDIT(&&PMONTH_E,$$$$9999) || EDIT(&&PMONTH_E,9999$$$$);

-* This sets prior 6 months based upon last month - it will generate complete data

-SET &&P6MONTHYYM=EDIT(AYM(&&CMONTHYYM, -6,I6YYM));

-SET &&P6MONTH_S=EDIT(&&P6MONTHYYM,999999) || 01;

-SET &&P6MONTH_S_MDYY=EDIT(&&P6MONTH_S,$$$$9999) || EDIT(&&P6MONTH_S,9999$$$$);

-SET &&P6MONTH_E=DATECVT(DATEMOV(DATECVT(EDIT(&&P6MONTH_S),I8YYMD, YYMD),EOM),YYMD,I8YYMD);

-SET &&P6MONTH_E_MDYY=EDIT(&&P6MONTH_E,$$$$9999) || EDIT(&&P6MONTH_E,9999$$$$);

-* This sets prior 12 months based upon last month - it will generate complete data

-SET &&P12MONTHYYM=EDIT(AYM(&&CMONTHYYM, -12,I6YYM));

-SET &&P12MONTH_S=EDIT(&&P12MONTHYYM,999999) || 01;

-SET &&P12MONTH_S_MDYY=EDIT(&&P12MONTH_S,$$$$9999) || EDIT(&&P12MONTH_S,9999$$$$);

-SET &&P12MONTH_E=DATECVT(DATEMOV(DATECVT(EDIT(&&P12MONTH_S),I8YYMD, YYMD),EOM),YYMD,I8YYMD);

-SET &&P12MONTH_E_MDYY=EDIT(&&P12MONTH_E,$$$$9999) || EDIT(&&P12MONTH_E,9999$$$$);

-* This sets prior 24 months based upon last month - it will generate complete data

-SET &&P24MONTHYYM=EDIT(AYM(&&CMONTHYYM, -24,I6YYM));

-SET &&P24MONTH_S=EDIT(&&P24MONTHYYM,999999) || 01;

-SET &&P24MONTH_S_MDYY=EDIT(&&P24MONTH_S,$$$$9999) || EDIT(&&P24MONTH_S,9999$$$$);

-SET &&P24MONTH_E=DATECVT(DATEMOV(DATECVT(EDIT(&&P24MONTH_S),I8YYMD, YYMD),EOM),YYMD,I8YYMD);

-SET &&P24MONTH_E_MDYY=EDIT(&&P24MONTH_E,$$$$9999) || EDIT(&&P24MONTH_E,9999$$$$);

-* This sets what the prior year current month is based upon todayss date

-SET &&PYCMONTH_E=DATECVT(DATEMOV(DATECVT(&&PYYESTERDAY,I8YYMD, YYMD),EOM),YYMD,I8YYMD);

-SET &&PYCMONTH_E_MDYY=EDIT(&&PYCMONTH_E,$$$$9999) || EDIT(&&PYCMONTH_E,9999$$$$);

-SET &&PYCMONTH_S=EDIT(&&PYCMONTH_E,999999) || 01;

-SET &&PYCMONTH_S_MDYY=EDIT(&&PYCMONTH_S,$$$$9999) || EDIT(&&PYCMONTH_S,9999$$$$);

-SET &&PYCMONTHYYM=EDIT(&&PYCMONTH_E,999999);

-* This sets what next month is based upon todays date

-SET &&NMONTHYYM=EDIT(AYM(&&CMONTHYYM, 1,I6YYM));

-SET &&NMONTH_S=EDIT(&&NMONTHYYM,999999) || 01;

-SET &&NMONTH_S_MDYY=EDIT(&&NMONTH_S,$$$$9999) || EDIT(&&NMONTH_S,9999$$$$);

-SET &&NMONTH_E=DATECVT(DATEMOV(DATECVT(EDIT(&&NMONTH_S),I8YYMD, YYMD),EOM),YYMD,I8YYMD);

-SET &&NMONTH_E_MDYY=EDIT(&&NMONTH_E,$$$$9999) || EDIT(&&NMONTH_E,9999$$$$);

-* This sets next 6 months based upon last month - it will generate complete data

-SET &&N6MONTHYYM=EDIT(AYM(&&CMONTHYYM, 6,I6YYM));

-SET &&N6MONTH_S=EDIT(&&N6MONTHYYM,999999) || 01;

-SET &&N6MONTH_S_MDYY=EDIT(&&N6MONTH_S,$$$$9999) || EDIT(&&N6MONTH_S,9999$$$$);

-SET &&N6MONTH_E=DATECVT(DATEMOV(DATECVT(EDIT(&&N6MONTH_S),I8YYMD, YYMD),EOM),YYMD,I8YYMD);

-SET &&N6MONTH_E_MDYY=EDIT(&&N6MONTH_E,$$$$9999) || EDIT(&&N6MONTH_E,9999$$$$);

-* This sets next 12 months based upon last month - it will generate complete data

-SET &&N12MONTHYYM=EDIT(AYM(&&CMONTHYYM, 12,I6YYM));

-SET &&N12MONTH_S=EDIT(&&N6MONTHYYM,999999) || 01;

-SET &&N12MONTH_S_MDYY=EDIT(&&N12MONTH_S,$$$$9999) || EDIT(&&N12MONTH_S,9999$$$$);

-SET &&N12MONTH_E=DATECVT(DATEMOV(DATECVT(EDIT(&&N12MONTH_S),I8YYMD, YYMD),EOM),YYMD,I8YYMD);

-SET &&N12MONTH_E_MDYY=EDIT(&&N12MONTH_E,$$$$9999) || EDIT(&&N12MONTH_E,9999$$$$);

-* This sets next 24 months based upon last month - it will generate complete data

-SET &&N24MONTHYYM=EDIT(AYM(&&CMONTHYYM, 6,I6YYM));

-SET &&N24MONTH_S=EDIT(&&N24MONTHYYM,999999) || 01;

-SET &&N24MONTH_S_MDYY=EDIT(&&N24MONTH_S,$$$$9999) || EDIT(&&N24MONTH_S,9999$$$$);

-SET &&N24MONTH_E=DATECVT(DATEMOV(DATECVT(EDIT(&&N24MONTH_S),I8YYMD, YYMD),EOM),YYMD,I8YYMD);

-SET &&N24MONTH_E_MDYY=EDIT(&&N24MONTH_E,$$$$9999) || EDIT(&&N24MONTH_E,9999$$$$);

-* This sets the first day of the fiscal year

-* Customer per users fiscal year

-SET &FMONSTART=01;

-SET &&FYTDSTART=IF EDIT(&&PMONTH_E,$$$$99$$) GE &FMONSTART THEN (&&CYEAR || &FMONSTART.EVAL || 01) ELSE (&&PYEAR || &FMONSTART.EVAL || 01);

-SET &&FYTDSTART_MDYY=EDIT(&&FYTDSTART,$$$$9999) || EDIT(&&FYTDSTART,9999$$$$);

-SET &&PYFYTDSTART=IF EDIT(&&PMONTH_E,$$$$99$$) GE &FMONSTART THEN (&&PYEAR || &FMONSTART.EVAL || 01) ELSE (&&P2YEAR || &FMONSTART.EVAL || 01);

-SET &&PYFYTDSTART_MDYY=EDIT(&&PYFYTDSTART,$$$$9999) || EDIT(&&PYFYTDSTART,9999$$$$);

-* This sets the first day of the calendar year

-SET &&YTDSTART=EDIT(&&YESTERDAY,9999) || 0101;

-SET &&YTDSTART_MDYY=EDIT(&&YTDSTART,$$$$9999) || EDIT(&&YTDSTART,9999$$$$);

-SET &&COMPANY_NAME=Company Name Here;

-*This will type out what the date variables are:

-TYPE CURRENT DATE: &YYMD

-TYPE YESTERDAY: &&YESTERDAY

-TYPE PYYESTERDAY: &&PYYESTERDAY

-TYPE CURRENT YEAR: &&CYEAR

-TYPE PRIOR YEAR: &&PYEAR

-TYPE PRIOR 2 YEAR: &&P2YEAR

-TYPE CURRENT MONTH START DATE: &&CMONTH_S

-TYPE CURRENT MONTH END DATE: &&CMONTH_E

-TYPE CURRENT MONTH PY START DATE: &&PYCMONTH_S

-TYPE CURRENT MONTH PY END DATE: &&PYCMONTH_E

-TYPE CURRENT MONTH PY START DATE (MDYY): &&PYCMONTH_S_MDYY

-TYPE CURRENT MONTH PY END DATE (MDYY): &&PYCMONTH_E_MDYY

-TYPE LAST MONTH START DATE: &&PMONTH_S

-TYPE LAST MONTH END DATE: &&PMONTH_E

-TYPE LAST MONTH START DATE (MDYY): &&PMONTH_S_MDYY

-TYPE LAST MONTH END DATE (MDYY): &&PMONTH_E_MDYY

-TYPE LAST 6 MONTH START DATE: &&P6MONTH_S

-TYPE LAST 6 MONTH END DATE: &&P6MONTH_E

-TYPE LAST 6 MONTH START DATE (MDYY): &&P6MONTH_S_MDYY

-TYPE LAST 6 MONTH END DATE (MDYY): &&P6MONTH_E_MDYY

-TYPE LAST 12 MONTH START DATE: &&P12MONTH_S

-TYPE LAST 12 MONTH EN

Link to comment
Share on other sites

and more

DEFINE FILE CAR

-* System Date

-DATEX/YYMD = 2012/10/01;

DATEX/YYMD = &DATEYYMD;

DATE1/I8YYMD = DATEX;

DATE2/A4 = DOWK(DATE1,DATE2);

DATE3/YYMD = IF DATE2 EQ SAT THEN DATEX + 2 ELSE

IF DATE2 EQ SUN THEN DATEX + 1 ELSE DATEX;

WCD/DMYY = DATE3;

WMY/MtY = DATE3;

- Day Current

DAY/DMYY = &DATEDMYY;

DCA/Wtr = DATEX;

-* Work Day - Prior/Next

WPD/DMYY = DATEMOV(WCD,PWD);

WND/DMYY = DATEMOV(WCD,NWD);

-* Business Day - Prior/Next

BPD/DMYY = DATEMOV(WCD,PBD);

BND/DMYY = DATEMOV(WCD,NBD);

-* Work Week - Current/Prior/Next

WCS/DMYY = DATEMOV(WCD,BOW);

WCE/DMYY = DATEMOV(WCD,EOW);

WPS/DMYY = WCS-7;

WPE/DMYY = WCE-7;

WNS/DMYY = WCS+7;

WNE/DMYY = WCE+7;

-* Month - Current/Prior/Next

MCS/DMYY = DATEMOV(WCD,BOM);

MCE/DMYY = DATEMOV(WCD,EOM);

MPS/DMYY = DATEADD(MCS,M,-1);

MPE/DMYY = DATEMOV(MPS,EOM);

MNS/DMYY = DATEADD(MCS,M,+1);

MNE/DMYY = DATEMOV(MNS,EOM);

-* Month Numeric - Current/Prior/Next

MCN/M = WCD;

MPN/M = MCN-1;

MNN/M = MCN+1;

-* Period - Current/Prior/Next

PCN/M = DATEADD(WCD,M,+6);

PPN/M = PCN-1;

PNN/M = PCN+1;

-* Quarter - Current/Prior/Next

QCS/DMYY = DATEMOV(WCD,BOQ);

QCE/DMYY = DATEMOV(WCD,EOQ);

QPS/DMYY = DATEMOV(DATEADD(WCD,M,-3),BOQ);

QPE/DMYY = DATEMOV(DATEADD(WCD,M,-3),EOQ);

QNS/DMYY = DATEMOV(DATEADD(WCD,M,+3),BOQ);

QNE/DMYY = DATEMOV(DATEADD(WCD,M,+3),EOQ);

-* Quarter - Period (Adjusted for Fiscal Year)

QCN/Q = DATEADD(WCD,M,+6);

QPN/Q = QCN+3;

QNN/Q = QCN+9;

-* Fiscal Year - Current/Prior/Next

FCN/YY = IF DATEADD(WCD,M,0) LT 7 THEN WCD ELSE DATEADD(WCD,M,+6);

FPN/YY = FCN-1;

FNN/YY = FCN+1;

FC2/Y = FCN;

FP2/Y = FCN-1;

FN2/Y = FCN+1;

-* Fiscal Year - Current/Prior/Next

FCS/DMYY = DATEADD(DATEMOV(WCD,BOY),M,-6);

FCE/DMYY = DATEADD(DATEMOV(WCD,BOY),M,+6)-1;

FPS/DMYY = DATEADD(FCS,M,-12);

FPE/DMYY = DATEADD(FCE,M,-12);

FNS/DMYY = DATEADD(FCS,M,+12);

FNE/DMYY = DATEADD(FCE,M,+12);

END

-*******************************************************************************

TABLE FILE CAR

PRINT

DCA AS Day,Current,Alpha

WMY AS Month,Year

WCD AS WorkDay,Today,Numeric

WPD AS WorkDay,Prior,Numeric

WND AS WorkDay,Next,Numeric

BPD AS BusinessDay,Prior,Numeric

BND AS BusinessDay,Next,Numeric

WPS AS Week,Prior,Monday

WPE AS Week,Prior,Friday

WCS AS Week,Current,Monday

WCE AS Week,Current,Friday

WNS AS Week,Next,Monday

WNE AS Week,Next,Friday

MPS AS Month,Prior,1stDay

MPE AS Month,Prior,LastDay

MCS AS Month,Current,1stDay

MCE AS Month,Current,LastDay

MNS AS Month,Next,1stDay

MNE AS Month,Next,LastDay

MPN AS Month,Prior,Integer

MCN AS Month,Current,Integer

MNN AS Month,Next,Integer

PPN AS Period,Prior,Numeric

PCN AS Period,Current,Numeric

PNN AS Period,Next,Numeric

QPS AS Quarter,Prior,1stDay

QPE AS Quarter,Prior,LastDay

QCS AS Quarter,Current,1stDay

QCE AS Quarter,Current,LastDay

QNS AS Quarter,Next,1stDay

QNE AS Quarter,Next,LastDay

QPN AS Quarter,Prior,Numeric

QCN AS Quarter,Current,Numeric

QNN AS Quarter,Next,Numeric

FPN AS FiscalYear,Prior,Year

FCN AS FiscalYear,Current,Year

FNN AS FiscalYear,Next,Year

FP2 AS FiscalYear,Prior,Year2

FC2 AS FiscalYear,Current,Year2

FN2 AS FiscalYear,Next,Year2

FPS AS FiscalYear,Prior,1stDay

FPE AS FiscalYear,Prior,LastDay

FCS AS FiscalYear,Current,1stDay

FCE AS FiscalYear,Current,LastDay

FNS AS FiscalYear,Next,1stDay

FNE AS FiscalYear,Next,LastDay

BY COUNTRY NOPRINT

IF RECORDLIMIT EQ 1

-*ON TABLE HOLD FORMAT ALPHA

END

-RUN

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...