Focal Point
[SOLVED] compare my trans date to current date

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

October 05, 2011, 10:11 AM
Brenda Wilkerson
[SOLVED] compare my trans date to current date
I set up define:
DEFINE FILE WKFLOW_SUM_FACT
TransactionDate/MDYY=HDATE( WKFLOW_SUM_FACT.WKFLOW_SUM_FACT.DT_KEY ,'YYMD' );
TRAN_YEAR/YY=TransactionDate;
TRAN_MONTH/Mtr=TransactionDate;
TRAN_QTR/YYQ=TransactionDate;
CURDATE/HMDYY=HGETC(10,'HMDYY');
END

Then I set up where/if:
WHERE ( WKFLOW_SUM_FACT.WKFLOW_SUM_FACT.TransactionDate EQ CURDATE )

and get this error:
0 ERROR AT OR NEAR LINE 67 IN PROCEDURE myprocedure
(FOC280) COMPARISON BETWEEN COMPUTATIONAL AND ALPHA VALUES IS NOT ALLOWED
(FOC009) INCOMPLETE REQUEST STATEMENT
BYPASSING TO END OF COMMAND

If I look at both I see them coming in as m/d/yy.

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



WebFOCUS 7.7.03
Windows 7
October 05, 2011, 10:26 AM
ERINP
Brenda,
either use a Smart Date to a Smart Date comparison or use Alpha to Alpha comparisons. Within any report you have amper variables available to you for this type of comparison:
 
 &DATE         = 10/05/11
 &DMY          = 051011
 &DMYY         = 05102011
 &MDY          = 100511
 &MDYY         = 10052011
 &YMD          = 111005
 &YYMD         = 20111005
 

any of these can be used for a smart date to smart date comparison or you could convert them to Alpha and compare. Hope this helps.

ERINP

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


WebFOCUS 7.6.9

Reporting client Windows 2003 Service pack 2 using IIS and TomCat 5.5
Reporting Server OS/400 V5R4M0
Outputs: HTML, Excel, PDF, CSV, and Flat Files
October 05, 2011, 10:43 AM
njsden
Assuming tha TransactionDate is a date-time field (e.g. HYYMDs), why not:
...
WHERE WKFLOW_SUM_FACT.WKFLOW_SUM_FACT.TransactionDate EQ DT(&YYMD 00:00:00)
...

You can then get rid of all those DEFINE'd fields



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
October 05, 2011, 10:46 AM
njsden
Of course, it would be easier to help if you told us what ACTUAL and USAGE values are there for TransactionDate in your master file.



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
October 05, 2011, 11:01 AM
Brenda Wilkerson
for report I only want to select records where the transactions date in my master file is = to the current date.
The format in my master file is: HYYMDS (2011/02/14 00:00:00.000)

Is that what you were asking?



WebFOCUS 7.7.03
Windows 7
October 05, 2011, 11:13 AM
njsden
Exactly! Didn't this work for you?

WHERE WKFLOW_SUM_FACT.WKFLOW_SUM_FACT.TransactionDate EQ DT(&YYMD 00:00:00)


That should retrieve the records with TransactionDate equals to the current date, which in WebFOCUS can be obtained by reading &YYMD.

The DT() function is there to convert current date (which would give you 20111005 for instance) to a date-time value that can be compared to your database field.



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
October 05, 2011, 11:30 AM
Brenda Wilkerson
this is what i get:
0 ERROR AT OR NEAR LINE 45 IN PROCEDURE dexflow_ca_rater_w
(FOC006) THE FORMAT OF THE TEST VALUE IS INCONSISTENT WITH FIELD FORMAT:
20111005 00:00:00
BYPASSING TO END OF COMMAND
(FOC009) INCOMPLETE REQUEST STATEMENT



WebFOCUS 7.7.03
Windows 7
October 05, 2011, 11:30 AM
ERINP
Brenda,
I assume you are only concerned with the date portion of the time stamp?? Otherwise are you ever going to have a transaction that exactly matches the current date and time to the millisecond?
I would HCNVRT the timestamp to get the date portion as an Alpha field and convert it to a smart date:

 
-* In the DEFINE
-* timestamp to alpha
ALPHA_DATE_TIME1/A20 = HCNVRT(Transactiondate, '(H17)', 17, 'A20');
-*strip out the date portion
ALPHA_DT/A8 = EDIT(ALPHA_DATE_TIME1, '99999999$$$$$$$$$$$$'); 
-*convert to a date field
TRANS_DT/YYMD = DATECVT(ALPHA_DT, 'A8YYMD', 'MDYY'); 
-*make todays date EQ to &YYMD
TODAYS_DATE/YYMD = '&YYMD'; 
-*Then compare TRANS_DT to TODAYS_DATE for your WHERE statement
 



WebFOCUS 7.6.9

Reporting client Windows 2003 Service pack 2 using IIS and TomCat 5.5
Reporting Server OS/400 V5R4M0
Outputs: HTML, Excel, PDF, CSV, and Flat Files
October 05, 2011, 11:33 AM
njsden
Okay ... what happens if you simply say:

WHERE WKFLOW_SUM_FACT.WKFLOW_SUM_FACT.TransactionDate EQ DT(&YYMD)




Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
October 05, 2011, 11:37 AM
njsden
ERINP, though your approach may work it might cause WebFOCUS to retrieve all of the data to then be filtered internally, as opposed to having the database apply the filters directly (and therefore taking advantage of any available table partitions, indices, etc).

Of course, if the volume of data is not significant this may not be an issue at all but I always try to make the database work harder Wink



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
October 05, 2011, 11:39 AM
Brenda Wilkerson
Bingo Good One



WebFOCUS 7.7.03
Windows 7
October 05, 2011, 11:45 AM
ERINP
Brenda,
was njsden solution functional? if it is I will start using that for ALL of my timestamp comparisons. A lot shorter and more direct approach.


ERINP


WebFOCUS 7.6.9

Reporting client Windows 2003 Service pack 2 using IIS and TomCat 5.5
Reporting Server OS/400 V5R4M0
Outputs: HTML, Excel, PDF, CSV, and Flat Files
October 05, 2011, 11:50 AM
njsden
And more efficient too.

You can enable traces to see what SQL statement WebFOCUS generates to query the data.

In most cases, you will find that filters on date fields based on DEFINES are *not* sent to SQL so there will be a performance hit.

Using DT( <constant> ) on the other hand, allows iWay to translate this into a proper WHERE statement in SQL and now the database (and WebFOCUS) are going to query and fetch only the intended records.



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
October 05, 2011, 11:50 AM
Brenda Wilkerson
ERINP, yes, it is a very simple approach and functional.



WebFOCUS 7.7.03
Windows 7
October 05, 2011, 01:15 PM
ERINP
I learn something new just about every day on this site. I will have to give this a try to see if I notice any performance differences in some of my reports. I am surprised that the comparison between a timestamp and a date field does not throw any errors.

Thanks,
ERINP


WebFOCUS 7.6.9

Reporting client Windows 2003 Service pack 2 using IIS and TomCat 5.5
Reporting Server OS/400 V5R4M0
Outputs: HTML, Excel, PDF, CSV, and Flat Files
October 05, 2011, 01:27 PM
njsden
quote:
I am surprised that the comparison between a timestamp and a date field does not throw any errors

Such a comparison would always fail but this is not the case as Brenda is comparing a date-time field [ TransactionDate/HYYMDS ] to a date-time constant [ DT(&YYMD) ].

That's the magic of DT(). Smiler



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
October 05, 2011, 01:52 PM
ERINP
njsden,
thanks for the insight. dually noted and book marked for future use Nice Thread


WebFOCUS 7.6.9

Reporting client Windows 2003 Service pack 2 using IIS and TomCat 5.5
Reporting Server OS/400 V5R4M0
Outputs: HTML, Excel, PDF, CSV, and Flat Files
October 05, 2011, 02:13 PM
njsden
You're welcome! I just found some interesting stuff related to this matter here.



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
October 05, 2011, 02:48 PM
Francis Mariani
I'm getting the D.T.'s just thinking about this!




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
October 05, 2011, 03:17 PM
njsden
I had not heard of "delirium tremens" in such a loooong time

Boy, that was refreshing!



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.