Focal Point
Working with Quarters in Dialog Manager variables

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

November 14, 2005, 12:07 PM
Francis Mariani
Working with Quarters in Dialog Manager variables
In the past, I've shown how to use some date functions in Dialog Manager by first converting the DM variable to a smart date.

I cannot figure out a simple, clean way to manipulate Quarters in DM variables.

I would like to take a DM variable with a value like '2004 Q2' and add or subtract a number of quarters from it without using IF-THEN-ELSE.

Any ideas?


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 16, 2005, 07:19 PM
Mikel
We can define our own QADD function...
(and use it with DM, DEFINE or COMPUTE)

-* Add or subtract quarters. - 2005.11.16 - Mikel Gómez
DEFINE FUNCTION QADD(YYQ/A7, DIF/I2)
YEAR1/I4 = EDIT(EDIT(YYQ, '9999')) ;
QUARTER1/I1 = EDIT(EDIT(YYQ, '$$$$$$9')) ;
OPER/I9 = YEAR1 * 4 + QUARTER + DIF - 1 ;
YEAR2/I4 = INT(OPER / 4) ;
MONTH2/I1 = IMOD(OPER, 4, 'I1') + 1;
QADD/A7 = EDIT(YEAR2) | ' Q' | EDIT(MONTH2) ;
END
-RUN

-* Example:
-SET &Q = '2005 Q3' ;
-TYPE QADD examples:

-SET &Q1 = QADD(&Q, 1) ;
-TYPE &Q + 1 = &Q1

-SET &Q2 = QADD(&Q, 2) ;
-TYPE &Q + 2 = &Q2

-SET &Q2 = QADD(&Q, -4) ;
-TYPE &Q - 4 = &Q2

-SET &Q3 = QADD(&Q, -20) ;
-TYPE &Q - 20 = &Q3


WebFOCUS 8.1.05, 8.2.01
November 17, 2005, 11:10 AM
reFOCUSing
Don't if this will help but it could give you an idea:

-* Set the Start and End date for QUARTER.
-* Default date is yesterday.
-SET &DT = AYMD(&YYMD,-1,'I8');
-* Change value to work with date manipulation.
-SET &TIME_BACK = &TIME_BACK * 3;
-SET &TIME_DURA = (&TIME_DURA - 1) * 3;
-* Produce the end date and start date.
-SET &END_YYMD = DATECVT((DATEMOV(DATEADD((DATECVT
-  (&DT,'I8YYMD','YYMD')),'M',-&TIME_BACK),'EOQ')),'YYMD','I8YYMD');
-SET &START_YYMD = DATECVT((DATEMOV(DATEADD((DATECVT
-  (&END_YYMD,'I8YYMD','YYMD')),'M',-&TIME_DURA),'BOQ')),'YYMD','I8YYMD');
-RUN

November 17, 2005, 12:55 PM
Francis Mariani
Thanks!

I didn't realize that a DEFINEd function could be used in Dialog Manager - wonders never cease!


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 17, 2005, 02:03 PM
Prarie
The Documentation States it doesn't. hmmm

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


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
Thanks. The Documentation will be corrected. The following will be removed from the Creating Reports With WebFOCUS Language manual:
"You cannot call DEFINE functions from Dialogue Manager commands."
And here I never used it, because I only saw a use for it in DM!


(Prod: WebFOCUS 7.7.03: Win 2008 & AIX hub/Servlet Mode; sub: AS/400 JDE; mostly Self Serve; DBs: Oracle, JDE, SQLServer; various output formats)