Page 1 of 1

Date check for business validation

Posted: Fri Feb 17, 2006 3:43 am
by parag.s.27
Hello, i am migrating data from SUN ERP to SAP for Purchase Orders. The condition is delivery date should be, Current system date + 1 month. But the problem is after adding 1 month, the resulting date should not have a day falling on Saturday or Sunday.

Is there any function or routine for this

Posted: Fri Feb 17, 2006 4:04 am
by ArndW
There are many ways of doing this and the optimal one depends upon the type and format of your source and where you are doing this comparison.

How do you want to add a month? Add 30 days or take the current date and change the month part. If it does fall on a weekend, do you want to take the Friday before or the Monday after or fail?

Date Validation

Posted: Fri Feb 17, 2006 4:29 am
by parag.s.27
ArndW wrote:There are many ways of doing this and the optimal one depends upon the type and format of your source and where you are doing this comparison.

How do you want to add a month? Add 30 days or take the current date and change the month part. If it does fall on a weekend, do you want to take the Friday before or the Monday after or fail?
Thanks ArndW,

Actually i am adding 1 month to the current system date as DATE.TAG(Date()+30). Now i want to check that if the resulting date falls on saturday or sunday then i should take monday.
Can you please help

Posted: Fri Feb 17, 2006 4:33 am
by ArndW
You would use the OCONV function and the 'DW' conversion to get the DOW with 1 being Monday.

Code: Select all

IF OCONV(DATE()+30,'DW') >5 THEN "Weekend" ELSE "Weekday"

Date Check

Posted: Fri Feb 17, 2006 4:44 am
by parag.s.27
ArndW wrote:You would use the OCONV function and the 'DW' conversion to get the DOW with 1 being Monday.

Code: Select all

IF OCONV(DATE()+30,'DW') >5 THEN "Weekend" ELSE "Weekday"
Hey thanx Arndw,

Just one more trouble i wanted to give you.

1st is what value should be for "Weekend" and "Weekday" that u mentioned in then and else clause respectively

and 2nd is, Can you also tell me the scenario for taking friday

Posted: Fri Feb 17, 2006 5:07 am
by ArndW
Parag,

were you looking for advice on how to do this or were you looking for a solution?

You now have the information you need - you can get the numeric day of week with the OCONV(juliandate,'DW', so if you want to handle Friday in addition to Sat and Sun you would change your condition to read ">4" instead of ">5" so days 5,6 and 7 go into one branch of the IF while other days go to the other.

So now you have "Weekend" and "Weekday"; the "Weekday" portion is easy since the date returned is valid, you would want to use your DATE.TAG conversion as you've stated. The "Weekend" branch needs to modify the date - but you haven't said what your rule is supposed to be.

Posted: Fri Feb 17, 2006 5:08 am
by kcshankar
Hi parag.s.27,
welcome aboard.One more solution

You can find the day of Delivery_Date by using Oconv(Delivery_Date , "DWA")
Declare Stage variables
Delivery Date ---S1
Delivery Date+1 ---S2
Delivery Date+2 ---S3
In your column Derivation,
If Oconv(Delivery_Date , "DWA") ="Saturday"
then Oconv(S3, "DWA") elseif
Oconv(Delivery_Date , "DWA") = "Sunday"
then Oconv(S2, "DWA") else
Oconv(Delivery_Date , "DWA")



regards
kcs

Posted: Fri Feb 17, 2006 5:23 am
by ArndW
kcs,

I like your suggestion, but if you stick with DW conversion and an integer you can make your logic simpler, this assumes you will make your order go to the Friday before a weekend, see:

Code: Select all

StageVar "DW"                = OCONV(Date()+30,'DW')
StageVar "DWCorrection"      = IF DW >5 THEN DW-5 ELSE 0
StageVar "NextMonthValidDay" = DATE.TAG(date()+30-DWCorrection))

Posted: Fri Feb 17, 2006 6:41 am
by WoMaWil
And now the add-on for the specialists:

What about holidays?

How to integrate the gauss Easter rule and all holidays like "Mardi gras" which are derivated from that, and all other holiday falling on non-Weekend-Days.

Posted: Fri Feb 17, 2006 6:56 am
by ArndW
Wolfgang - we shouldn't be so Euro-centric and should add in all those South American, Middle-eastern as well as Asian holidays as well :)

Date Check

Posted: Fri Feb 17, 2006 9:16 am
by parag.s.27
ArndW wrote:kcs,

I like your suggestion, but if you stick with DW conversion and an integer you can make your logic simpler, this assumes you will make your order go to the Friday before a weekend, see:

Code: Select all

StageVar "DW"                = OCONV(Date()+30,'DW')
StageVar "DWCorrection"      = IF DW >5 THEN DW-5 ELSE 0
StageVar "NextMonthValidDay" = DATE.TAG(date()+30-DWCorrection))
Hi All,

Thanks for suggestions. i tried method of 'DW', but dont knw why data stage is still returning the same date i.e System Date + 30 days without any modifications. don't know why but validations are not working, even if the OCONV(Date()+30,'DW') returns proper value of day of week

Any way thanks for suggestions

Re: Date Check

Posted: Fri Feb 17, 2006 10:06 am
by parag.s.27
[quote="parag.s.27"][quote="ArndW"]kcs,

Hey Thanks to all of you. It finally worked. I just made a Routine for it.

Thanks

Re: Date Check

Posted: Fri Feb 17, 2006 12:26 pm
by dsnovice
parag.s.27 wrote:
ArndW wrote:kcs,

I like your suggestion, but if you stick with DW conversion and an integer you can make your logic simpler, this assumes you will make your order go to the Friday before a weekend, see:

Code: Select all

StageVar "DW"                = OCONV(Date()+30,'DW')
StageVar "DWCorrection"      = IF DW >5 THEN DW-5 ELSE 0
StageVar "NextMonthValidDay" = DATE.TAG(date()+30-DWCorrection))
Hi All,

Thanks for suggestions. i tried method of 'DW', but dont knw why data stage is still returning the same date i.e System Date + 30 days without any modifications. don't know why but validations are not working, even if the OCONV(Date()+30,'DW') returns proper value of day of week

Any way thanks for suggestions
Your calculation's will not be right if an Holiday falls on a date during the week. if it falls on the week day that you get at the end of your calcuation then you will be having a wrong date.

Any way if your date tag does not work try the basic Oconv.It worked for me.
You can try Oconv((@DATE+30-DWCorrection),"D-YMD")

my two cents

Posted: Fri Feb 17, 2006 5:50 pm
by ray.wurlod
Holidays - of necessity - must be table (or hashed file) driven. Some holidays change year to year, such as Ramadan or Easter.

Left(Oconv(TheDate, "DWB"),1) = "S" is a convenient test for a weekend day in English.

Date check

Posted: Mon Feb 20, 2006 6:34 am
by parag.s.27
ray.wurlod wrote:Holidays - of necessity - must be table (or hashed file) driven. Some holidays change year to year, such as Ramadan or Easter.

Left(Oconv(TheDate, "DWB"),1) = "S" is a convenient test for a weekend day in English.
Hi,

Actually i have to take care of weekends only. For rest all holidays, our SAP team has some validation checks while loading data into it. I am generating target files as per SAP input format.