on 09-25-2012 4:44 PM
Hi Folks,
I am working File to Proxy..where pi picks file with records and process to sap.
IS00~TP~~08152012~DM435~CNY~User~1.0~50~9523.17~9523.17~~IS0126~303011000~0~0~CN002~0~0~0~~
IS00~TP~~08152012~DM435~CNY~User~1.0~40~9523.17~9523.17~~IS0126~984000000~0~V~CN002~0~0~0~~
IS00~TP~~08152012~DM435~CNY~User~1.0~50~32758.67~32758.67~~IS0126~303011000~0~0~CN001~0~0~0~~
IS00~TP~~15082012~DM435~CNY~User~1.0~40~32758.67~32758.67~~IS0126~984000000~0~V~CN001~0~0~0~~
In above file the date format should be MMDDYYYY,if i pass the date format like in 4th record it should through error.
But i have done 1:1 map as of now..it is picking files successfully,but my req is if i send wrong date format then it should through error in PI itself..
Can anyone suggest me what to do in this case..
Thanks
Kalyan
write a user defined fucntion in mapping level to validate the date format , if format is wrong then throw manual exception (mapping failure) with some custome message.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can you send me the UDF ..i am having 0% knowledge in java...it will be helpfull
below is the source structure
ControllingArea,Source_id,Tran_type,Tran_date,Journal_id,Currency_code,Currency_conversion_type,Currency_conversion_rate,Credit_debit,Entered_amount,Accounted_amount,Translate,Segment1,Segment2,Segment3,Segment4,Segment5,Segment6,Segment7,Segment8,Segment9,Segment10
Hi Kalyan,
Please try this code
public static String checkDateFormat(String strDate,String reqDateFormat)
{
Date tempDate = null;
SimpleDateFormat sdf = new SimpleDateFormat(reqDateFormat);
sdf.setLenient(false);
try
{
tempDate = sdf.parse(strDate);
}
catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException("Error: The given date format is wrong, Required date format is: "+reqDateFormat);
}
return strDate;
}
regards
Anupam
Hi
Thanks for the reply..its working now..
but only thing is below is the source file in which PI going to pick the file and process to sap(proxy).
IS00~TP~~15082012~DM435~CNY~User~1.0~50~9523.17~9523.17~~IS0126~303011000~0~0~CN002~0~0~0~~
IS00~TP~~08152012~DM435~CNY~User~1.0~40~9523.17~9523.17~~IS0126~984000000~0~V~CN002~0~0~0~~
IS00~TP~~08152012~DM435~CNY~User~1.0~50~32758.67~32758.67~~IS0126~303011000~0~0~CN001~0~0~0~~
IS00~TP~~08152012~DM435~CNY~User~1.0~40~32758.67~32758.67~~IS0126~984000000~0~V~CN001~0~0~0~~
In first record the date i mentioned in wrong format and now it showing error in moni.but nt able to process next 3 sucess records....:-(
but my req if 1st record through error ,remaing 3 successfull records shd process.
for this any logic has to be written?need help on this?
Hi Kalyan,
try this code,use UDF of type context
public void chkdate(String[] strDate,String reqDateFormat,ResultList result,Container container){
MappingTrace importanttrace;
importanttrace = container.getTrace();
java.util.Date tempDate = null;
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(reqDateFormat);
sdf.setLenient(false);
try
{
for(int i=0;i<strDate.length;++i)
{
try
{
tempDate = sdf.parse(strDate[i]);
result.addValue(strDate[i]);
}
catch(Exception e)
{
// resultresult.addValue(e.getMessage()+ " : Error: The given date format is wrong,Required date format is: " + reqDateFormat) ;
importanttrace.addInfo(e.getMessage());
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
you can choose to send the error to target or put it in trace object as shown above. I have commented some lines since you might not need to send them to target.
Regards
Anupam
Hi Kalyan,
Here it is once again
public void chkdate(String[] strDate,String[] reqDateFormat,ResultList result,Container container){
MappingTrace importanttrace;
importanttrace = container.getTrace();
java.util.Date tempDate = null;
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(reqDateFormat);
sdf.setLenient(false);
try
{
for(int i=0;i<strDate.length;++i)
{
try
{
tempDate = sdf.parse(strDate[i]);
result.addValue(strDate[i]);
}
catch(Exception e)
{
//result.addValue(e.getMessage()+ " : Error: The given date format is wrong, Required date format is: " + reqDateFormat) ;
importanttrace.addInfo(e.getMessage());
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
Regards
Anupam
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.