on 02-01-2016 5:30 AM
Hello,
I am new to SAP PI.
I am creating a scenario where -
source message format is as below :
<Record>
<text>
emp id, joining_date [dd.mm.yy],name,address,reporting_date [dd.mm.yy]
</text>
</Record>
destination message format is as below :
<Record>
<emp id>
<joining_date [yyyymmdd]>
<name>
<address>
<reporting_date [yyyymmdd] ---- if reporting date is less than 2 days from current date, 00000000 will get populated in this field.
</Record>
I am facing problem in UDF creation in java message mapping.
Can anyone please guide me regarding this ?
Regards,
Murari
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Murari,
I think 7.0 does not support multiple result list.
Use below mapping for emp_id(CopyValue with 0), joing_date(CopyValue with 1), name(CopyValue with 2), address(CopyValue with 3).
Use below UDF for splitString.
Use below mapping for reporting_date (CopyValue with 4)
reportingDate UDF:
You need to mention the below imports, PI 7.0 is different you need import these.
Regards,
Praveen.
Hello Praveen,
I have created UDF and also done mapping.
But while Activating changes for mapping object MM_EmpData I am getting following error :
Activation of the change list canceled Check result for Message Mapping MM_EmpData | urn:wbsedcl.test.tcskolempreceiverlist: Starting compilation Source code has syntax error: /usr/sap/WDX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapeb3f82c0c8d711e5a503001517f85c58/source/com/sap/xi/tf/_MM_EmpData_.java:99: ';' expected for(String field : fields) ^ /usr/sap/WDX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapeb3f82c0c8d711e5a503001517f85c58/source/com/sap/xi/tf/_MM_EmpData_.java:103: illegal start of expression } ^ 2 errors
Please suggest.
Regards,
Murari
Hi Murari,
Ok enhanced for loop came from java 5, your PI version uses java 1.4 that is why enhanced for loop is not recognizing. Change the code like below.
public void splitString(String[] text, ResultList result, Container container) {
String[] fields = text[0].split(",");
for (int i = 0; i < fields.length; i++) {
result.addValue(fields[i]);
}
}
Regards,
Praveen.
Hello Praveen,
For report date function I am facing error with import statement, please find below processing logs and advise:
Activation of the change list canceled
Check result for Message Mapping MM_EmpData | urn:wbsedcl.test.tcskolempreceiverlist:
Source code has syntax error:
/usr/sap/WDX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapd2ac03f0c8e611e5964b001517f85c58/source/com/sap/xi/tf/_MM_EmpData_.java:3: ';' expected
import com.sap.aii.mappingtool.tf3.*;import com.sap.aii.mappingtool.tf3.rt.*;import java.util.*;import java.io.*; import java.lang.reflect.*;import com.sap.aii.mappingtool.tf7.rt.*;import com.sap.aii.mapping.lookup.*;import java.text.ParseException;import java.util.*java.text.SimpleDateFormat;import com.sap.aii.mapping.api.*;import java.lang.reflect.*;import import;import java.io.*;
^
/usr/sap/WDX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapd2ac03f0c8e611e5964b001517f85c58/source/com/sap/xi/tf/_MM_EmpData_.java:3: <identifier> expected
import com.sap.aii.mappingtool.tf3.*;import com.sap.aii.mappingtool.tf3.rt.*;import java.util.*;import java.io.*; import java.lang.reflect.*;import com.sap.aii.mappingtool.tf7.rt.*;import com.sap.aii.mapping.lookup.*;import java.text.ParseException;import java.util.*java.text.SimpleDateFormat;import com.sap.aii.mapping.api.*;import java.lang.reflect.*;import import;import java.io.*;
^
/usr/sap/WDX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapd2ac03f0c8e611e5964b001517f85c58/source/com/sap/xi/tf/_MM_EmpData_.java:3: '.' expected
import com.sap.aii.mappingtool.tf3.*;import com.sap.aii.mappingtool.tf3.rt.*;import java.util.*;import java.io.*; import java.lang.reflect.*;import com.sap.aii.mappingtool.tf7.rt.*;import com.sap.aii.mapping.lookup.*;import java.text.ParseException;import java.util.*java.text.SimpleDateFormat;import com.sap.aii.mapping.api.*;import java.lang.reflect.*;import import;import java.io.*;
^
3 errors
Regards
Murari
Hello Praveen,
The import issue resolved after adding only two imports java.text.*;java.util.*;
But facing compilation issue due to return statement.
Below is my reportdate UDF :
public String reportingDate(String Reporting_Date,Container container){
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
try {
Calendar c=Calendar.getInstance();
c.setTime(sdf.parse(Reporting_Date));
Calendar c1=Calendar.getInstance();
c1.setTime(new Date());
c1.add(Calendar.DATE,-2);
if (c.before(c1))
return "00000000";
else
return Reporting_Date;
}
catch (ParseException pe)
{
pe.getMessage();
}
}
Below is the compilation error got while activating message mapping :
Activation of the change list canceled
Check result for Message Mapping MM_EmpData | urn:wbsedcl.test.tcskolempreceiverlist:
Source code has syntax error:
/usr/sap/WDX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map88d5cf40c96d11e58fde001517f85c58/source/com/sap/xi/tf/_MM_EmpData_.java:134: missing return statement
}
^
1 error
Please advise.
Regards,
Murari
The below code should help
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
String out;
try {
Calendar c=Calendar.getInstance();
c.setTime(sdf.parse(Reporting_Date));
Calendar c1=Calendar.getInstance();
c1.setTime(new Date());
c1.add(Calendar.DATE,-2);
if (c.before(c1))
out = "00000000";
else
out = Reporting_Date;
}
catch (ParseException pe)
{
pe.getMessage();
}
return out;
}
Hi Murari,
You can create the UDF like below, use execution type Context in your case.
UDF Code:
public void splitString(String[] text, ResultList empId, ResultList joining_date, ResultList name, ResultList address,
ResultList reporting_date, Container container) throws StreamTransformationException {
String[] fields = text[0].split(",");
empId.addValue(fields[0]);
joining_date.addValue(fields[1]);
name.addValue(fields[2]);
address.addValue(fields[3]);
reporting_date.addValue(fields[4]);
}
You can do the mapping like below.
Mapping result:
Regards,
Praveen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Praveen/Raghuraman,
Thanks for reply. I am facing one problem while creating UDF.
I have selected Context as cache and I have got one Argument field and one Result field.
When I click on Add, only Arguments are adding, Results are not adding. Refer Screen shot above.
As I require one argument type and multiple result type.
Please revert.
Regards,
Murari
Hello Murari,
Try the below UDF
public static String compareDates(String JoiningDate,String CurrentDate)
{
String difference="";
try
{
String pattern = "dd.mm.yy";
long diff;
final long MilliSecondsInADay=1000 * 60 * 60 * 24 ;
java.text.SimpleDateFormat Dateformat = new java.text.SimpleDateFormat(pattern);
java.util.Date JoiningDate= Dateformat.parse(EndDate);
java.util.Date CurrentDate= Dateformat.parse(startDate);
diff=(JoiningDate.getTime()-StartDate.getTime())/MilliSecondsInADay;
if(diff==-2)
{
difference = "00000000"
}
else
{
}
catch(java.text.ParseException e)
{
e.printStackTrace();
}
return difference;
}
In case if the difference is not equal to 2 what you want to return?.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Raghuraman,
Thanks for reply.
But I require creating UDF for splitting a string into parts present in source message <text> tag and how to map splitted parts into destination message format. Please guide.
Also regarding that date difference, if the difference is not equal to 2 I want to return the date as yyyymmdd format.
Regards,
Murari
Hello Raghuraman,
Basically that logic part related to split of a string by a delimiter (,) and store it into a String Array and adding the string array indexes into result (ResultList object) I have written in java code.
But I have stuck below :
1. I have created a source data type DT_Employee with record as a subelement and text as a subelement of it with type string.
2. I have created a destination data type DT_Employee_Receiver with Record as subelement and following as a attributes : Emp_No (integer), Joining_date(date), name(String),address (string),reporting_date(date).
3.Now I have tried to do message mapping with Source and Destination with a UDF creation. I know about the java logic of splitting of string and store into some array and result list.
But I am stuck in doing the actual mapping between source and destination. Please guide.
Also while creating UDF the return type of the method is coming as default void and I am not able to change it. below is the method :
public void empname(String[] Text,ResultList result,Container container){
String[] arg = Text[0].split(",");
for(int j=0; j<arg.length; j++)
{
result.addValue(arg[j]);
}
}
How I will return the result list and map with destination.
Please help.
Regards
Murari
User | Count |
---|---|
78 | |
9 | |
9 | |
7 | |
7 | |
6 | |
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.