Focal Point
SOLVED - MASKING ALPHA TO NUMERIC

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

July 21, 2009, 02:36 PM
<Mary3001>
SOLVED - MASKING ALPHA TO NUMERIC
I'm creating a branch hours report based on alpha fields that are formated as follows: MON_OPEN 0900 MON_CLOSE 0530. My goal is to subtract The day's open hours from the day's close hours to get the total number of hours a branch is open each day. My formula (shown below) has been working, when the branch open hours are before noon. However, I've run into a situation where one branch is opened at 1 and closed at 5. The formula below doesn't capture that scenario. Any ideas on how to code for that and where it should go in the formula?

Sample of report with error:
SUN_HOURS SUN_OPEN SUN_CLOSE
4.00 1100 0300 - OKAY
5.00 1200 0500 - OKAY
4.00 1100 0300 - OKAY
16.00 0100 0500 - ERROR



CODE:
IF EDIT(SUN_CLOSE) LE 0 THEN 0

ELSE IF (EDIT(SUN_CLOSE) GT 0 AND
EDIT (SUN_CLOSE) LT 1200) THEN
12 + (EDIT(EDIT(SUN_CLOSE, '99$$')) +
EDIT(EDIT(SUN_CLOSE, '$$99'))/60) -
(EDIT(EDIT(SUN_OPEN, '99$$')) +
EDIT(EDIT(SUN_OPEN, '$$99'))/60)

ELSE (EDIT(EDIT(SUN_CLOSE, '99$$')) +
EDIT(EDIT(SUN_CLOSE, '$$99'))/60) -
(EDIT(EDIT(SUN_OPEN, '99$$')) +
EDIT(EDIT(SUN_OPEN, '$$99'))/60)

This message has been edited. Last edited by: <Mary3001>,
July 21, 2009, 03:40 PM
Francis Mariani
Mary,

Here's what looks like a clumsy way to do it, using Date/Time functions and columns. This is a working example using the CAR file. SUN_OPEN and SUN_CLOSE contain the example data you provided. I convert the times to date/time fields with the HINPUT function, using Jan 1 2000 as the date (it could be any date). You have to decide what the normal earliest open hour would be - I decided on 8am: if the time is less than 0800 then it must be after noon, so I add 12 hours to the date/time field using the HADD function. Then I use the HDIFF function to determine the hours open. Then I use the FTOA function to convert back to alpha.

DEFINE FILE CAR
SUN_OPEN/A4         = DECODE COUNTRY ('ENGLAND' '1100', 'FRANCE' '1200', 'ITALY' '1100', 'JAPAN' '0100' ELSE '0000');
SUN_CLOSE/A4        = DECODE COUNTRY ('ENGLAND' '0300', 'FRANCE' '0500', 'ITALY' '0300', 'JAPAN' '0500' ELSE '0000');

SUN_OPENDT/A14      = '20000101' || SUN_OPEN;
SUN_CLOSEDT/A14     = '20000101' || SUN_CLOSE;
SUN_OPEN24/HHI      = HINPUT(14, SUN_OPENDT, 8, 'HYYMDS');
SUN_OPEN24          = IF SUN_OPEN LT '0800' THEN HADD(SUN_OPEN24, 'HOUR', 12, 8, 'HYYMDS') ELSE SUN_OPEN24;
SUN_CLOSE24/HHI     = HINPUT(14, SUN_CLOSEDT, 8, 'HYYMDS');
SUN_CLOSE24         = IF SUN_CLOSE LT '0800' THEN HADD(SUN_CLOSE24, 'HOUR', 12, 8, 'HYYMDS') ELSE SUN_CLOSE24;
SUN_HOURSNUM/D5.2   = HDIFF(SUN_CLOSE24, SUN_OPEN24, 'HOUR', 'D12.2');
SUN_HOURS/A5        = FTOA(SUN_HOURSNUM, '(D5.2L)', 'A5');
END

TABLE FILE CAR
PRINT
SUN_HOURS
SUN_OPEN
SUN_CLOSE

SUN_HOURSNUM
SUN_OPEN24
SUN_CLOSE24
BY COUNTRY
END



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
July 21, 2009, 04:42 PM
Darin Lee
There's also a TIMETOTS function that easily converts a time to a date time. I think it uses current date for the day. Caveat is that the time must be in acceptable time format - 11:22:33 - but that's easy enough to do with EDIT.

The biggest problem is that your times do not include any sort of 24-hour indicator (either on 24hr time or AM/PM so you have a bunch of extra steps to get them to that point.

Once you've got it in date-time format the rest is easy with HDIFF. This is the best way.

Your approach seems to be more just straight math. The logic would look like

IF (OPEN - CLOSE) GE 0 THEN ABS(OPEN - CLOSE - 1200) ELSE ABS(OPEN - CLOSE)

Always comes up with he correct answer. You would have to add some additional similar logic to calculate minutes to add/subtract from hours.

Still think the conversion to date-time values works best.


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
July 22, 2009, 11:14 AM
<Mary3001>
Thank you Darin and Francis. I will give both ways a try. I'm a beginner and don't use SQL, just the GUI. Can both ways be written using the GUI?

My work around has been to add a couple more IF Else statements, one which uses OPEN GT 800 and OPEN NE 1 and another that uses OPEN EQ 1. I'm doing my audits by day to see if anything else pops up. My guess is there are some branches (in retirement centers) that have odd hours, like 2 to 4, so I may see more issues.



The final step after getting the hours correct is to do a weekly average hours by branch.

I don't have the am/pm or the information in 24 segments. That may be something to request for future downloads.

Thanks so much for your help.

Mary