cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping issue

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

rajasekhar_reddy14
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

gagandeep_batra
Active Contributor
0 Kudos

Hi Kalyan

i think you can handle  it without UDF also just use dateTrans function  as below screen:

Remember one thing that please uncheck the "Calender is lenient" 

then it will automatic give exception

Regards

Gagan

rajasekhar_reddy14
Active Contributor
0 Kudos

Fisrt write a logic to validate date format and include below statments in UDF to throw exceltption.

if ( s=="")  {

  throw new RuntimeException("DATE FORMAT NOT CORRECT");

  }

  else {

  return s;

  }

You need to write this logic for only DATE field and remaining all fields one to one mapping.

anupam_ghosh2
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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?

anupam_ghosh2
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Anupam ,

Thanks for the reply..total code is missing can you paste it once again...

anupam_ghosh2
Active Contributor
0 Kudos

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