Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CODE] Simplifying the use of Date functions in Dialogue Manager

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[CODE] Simplifying the use of Date functions in Dialogue Manager
 Login/Join
 
Expert
posted
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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Virtuoso
posted Hide Post
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

 
Posts: 2387 | Location: Amsterdam, the Netherlands | Registered: December 03, 2006Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CODE] Simplifying the use of Date functions in Dialogue Manager

Copyright © 1996-2020 Information Builders