Focal Point
[CODE] Simplifying the use of Date functions in Dialogue Manager

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

November 27, 2008, 04:04 PM
Francis Mariani
[CODE] Simplifying the use of Date functions in Dialogue Manager
In the past, when I've explained how to use a Date function in Dialogue Manager, I've usually provided an example:
-SET &REQUEST_TIME1 =
- DATECVT( DATEADD(DATECVT(&REQUEST_TIME,'I8YYMD','YYMD'),'D', 7),'YYMD','I8YYMD');
and an explanation:
quote:
The code above looks crazy, but what's happening is you have to convert the alpha string to a Date format using DATECVT, then use DATEADD to add 7 days, then use DATECVT to convert from Date format back to alpha string - read the line of code form inside going outwards.

Recently I wrote a few DEFINE FUNCTIONs to determine Fiscal periods for a given date. The DEFINE FUNCTIONs can be used in WebFOCUS reporting and Dialogue Manager. I had to create these because there aren't any IBI supplied functions to do this as the Fiscal period is company dependent.

This led me to think about creating DEFINE FUNCTIONs that would simplify calling existing Date functions in Dialogue Manager. In the example above, you have to first convert the DM variable to a Date format (DATECVT), then call the Date function (DATEADD), then convert the Date format back to a DM variable (DATECVT).

Using the DEFINE FUNCTION below, you simply have to call the function passing the required parameters, no conversion necessary - the DEFINE FUNCTION takes care of that. You can create a DEFINE FUNCTION for each of the Date functions commonly used, put them in an INCLUDEd fex, then simply call the DEFINED FUNCTION.

The DEFINE FUNCTION for DATEADD:
DEFINE FUNCTION UDATEADD(INDATE/A8YYMD, INUNIT/A2, INNBR/I4)
INDATE1/YYMD    = INDATE;
UDATEADD1/YYMD  = DATEADD(INDATE1, INUNIT, INNBR);
UDATEADD/A8YYMD = UDATEADD1;
END
-RUN

Calling it in Dialogue Manager:
-SET &DATE1 = UDATEADD(&YYMD, 'M', -3);

-TYPE &YYMD - &DATE1

NOTE: The DATEADD function allows multiple Date formats as input ("any day-based non-legacy date, for example, YYMD, MDY, or JUL"), my example uses only YYMD because that format is what I always use in my programs, the DEFINE FUNCTION could probably be modified to work with multiple formats.

I think this would simplify things quite a bit if this kind of manipulation is used a lot. I hope you find this useful.

Those Fiscal period functions:
-*-- Beginning of Fiscal Quarter
DEFINE FUNCTION BOFQ(INDATE/A8)
INDTYYA/A4 = EDIT(INDATE,'9999$$$$');
INDTYY/I4  = EDIT(INDTYYA);
OUTDTYY/I4 = INDTYY - 1;
INDTMD/A4  = EDIT(INDATE,'$$$$9999');
BOFQ/A8    =
  IF INDTMD FROM '1101' TO '1231' THEN INDTYYA || '1101' ELSE
  IF INDTMD FROM '0101' TO '0131' THEN EDIT(OUTDTYY) || '1101' ELSE
  IF INDTMD FROM '0201' TO '0430' THEN INDTYYA || '0201' ELSE
  IF INDTMD FROM '0501' TO '0731' THEN INDTYYA || '0501' ELSE
  IF INDTMD FROM '0801' TO '1031' THEN INDTYYA || '0801' ELSE INDATE;
END
-RUN

-*-- End of Fiscal Quarter
DEFINE FUNCTION EOFQ(INDATE/A8)
INDTYYA/A4 = EDIT(INDATE,'9999$$$$');
INDTYY/I4  = EDIT(INDTYYA);
INDTMD/A4  = EDIT(INDATE,'$$$$9999');
OUTDTYY/I4 = INDTYY + 1;
EOFQ/A8    =
  IF INDTMD FROM '1101' TO '1231' THEN EDIT(OUTDTYY) || '0131' ELSE
  IF INDTMD FROM '0101' TO '0131' THEN INDTYYA || '0131' ELSE
  IF INDTMD FROM '0201' TO '0430' THEN INDTYYA || '0430' ELSE
  IF INDTMD FROM '0501' TO '0731' THEN INDTYYA || '0731' ELSE
  IF INDTMD FROM '0801' TO '1031' THEN INDTYYA || '1031' ELSE INDATE;
END
-RUN

-*-- Beginning of Fiscal Year
DEFINE FUNCTION BOFY(INDATE/A8)
INDTYYA/A4 = EDIT(INDATE,'9999$$$$');
INDTYY/I4  = EDIT(INDTYYA);
INDTMM/A2  = EDIT(INDATE,'$$$$99$$');
OUTDTYY/I4 = IF INDTMM LT '11' THEN INDTYY - 1 ELSE INDTYY;
BOFY/A8    = EDIT(OUTDTYY) || '1101';
END
-RUN

-*-- End of Fiscal Year
DEFINE FUNCTION EOFY(INDATE/A8)
INDTYYA/A4 = EDIT(INDATE,'9999$$$$');
INDTYY/I4  = EDIT(INDTYYA);
INDTMM/A2  = EDIT(INDATE,'$$$$99$$');
OUTDTYY/I4 = IF INDTMM LT '11' THEN INDTYY ELSE INDTYY + 1;
EOFY/A8    = EDIT(OUTDTYY) || '1031';
END
-RUN

Calling them:
-SET &DT_BOFQ = BOFQ(&YYMD);
-SET &DT_EOFQ = EOFQ(&YYMD);
-SET &DT_BOFY = BOFY(&YYMD);
-SET &DT_EOFY = EOFY(&YYMD);


For documentation on creating DEFINE FUNCTIONs, look for "Creating Temporary Fields Unrelated to Master Files" in the "Creating Reports With WebFOCUS Language" manual. For documentation on Date functions, look for "Date and Time Functions" in the "WebFOCUS Using Functions" manual.

This message has been edited. Last edited by: Francis Mariani,


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
November 28, 2008, 03:14 PM
FrankDutch
Merci beaucoup Francis!




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7