cancel
Showing results for 
Search instead for 
Did you mean: 

Date Validation inside Mapping

Former Member
0 Kudos

Hello all,

I would like to perform the following date validation checks inside Mapping.

Date will come in 3 fields, Day, Month and Year.

Ii have to validate Day, Month and year whether those are proper according to the calender or not, means date should be with in the 31, Month should be with in 12 and Year can be between 1900 to 2099

Also should check months having 30 days or 31 days then allow accordingly.

Also should check if that year is leap year or not and allow that FEB date accordingly.

Please let me know how to achieve this

Regards

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

You will need to write the UDF to achieve this.

First You can use GregorianCalendar class of Java to set the date from the input values and then again retrieve the day, month and year from the Calendar object.

Compare the returned values with the input values for valid date.

Former Member
0 Kudos

Hello Yogesh,

Can you please give me the UDF for this?

Regards

Former Member
0 Kudos

Instead of following Yogesh's compare method, I'd use the strict parsing mode of the [java.util.GregorianCalendar|http://download.oracle.com/javase/1.5.0/docs/api/java/util/GregorianCalendar.html] class. E.g. you can use something similar like the following test code:


import java.util.GregorianCalendar;

final int year = 2010;
final int month = 2;
final int day = 30;

boolean dateIsValid = true;

GregorianCalendar cal = new GregorianCalendar();
cal.clear();
// Apply strict rules to validate the given date as-is
cal.setLenient(false);
// Initialize the calendar with the given date
// Note: The month is zero-based, so if January is 1, we need to pass month-1
cal.set(year, month - 1, day);
// To validate the time we have to try to retrieve it
try {
	cal.getTime();
} catch (IllegalArgumentException e) {
	dateIsValid = false;
}

System.out.println("Date is valid: " + dateIsValid);

Next time I'd recommend a quick web search for such trivial tasks...

Former Member
0 Kudos

Thnx Harald,

I am trying to call function module inside mapping to validate the date.

Function module:ISHMED_CHECK_DATE_TIME

I found UDF for that but not sure whether we need to call FM through any RFC channel or how. Working on that.

Regards

Vamsi