on 05-23-2012 2:01 AM
Hi,
I am new to PI and exploring the graphical editor for message mapping. Can someone please guide me how I can split the full name in my source message into first name and last name in my target message?
For example.. source: Full Name=John Smith -----------> Target: First Name= John
Last Name= Smith
Thank you.
Alex, Greg,
I was able to get both the codes to work and do my mapping as wanted. Thank you very much for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
2 Greg - you function has execution type "All values of queue" so you must handle context changes then. And what if name has no space? It leads to ArrayIndexOutofBounds exception
2 Batul - Here is working function code. BTW, I checked and debugged this code with Testview.
public void splitFullName(String[] fullName, ResultList firstName,
ResultList lastName, Container container)
throws StreamTransformationException {
for (int i = 0; i < fullName.length; i++){
if (fullName[i].equals(ResultList.CC)){
firstName.addContextChange();
lastName.addContextChange();
}else{
String name = fullName[i].trim();
int start = name.indexOf(' ');
int end = name.lastIndexOf(' ');
String firstNameStr = "";
String middleNameStr = "";
String lastNameStr = "";
if (start > 0) {
firstNameStr = name.substring(0, start);
if (end > start) {
middleNameStr = name.substring(start + 1, end);
}
lastNameStr = name.substring(end + 1, name.length());
} else {
lastNameStr = name;
}
firstName.addValue(firstNameStr);
lastName.addValue(lastNameStr);
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you all for your inputs. Substring won't work as I do not want to limit my number of characters.
Greg, I cannot get your code to compile either. Throws an ArrayIndexOutofBounds exception. Please advise.
Thank you!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Batul,
A few cents,
The name split problem is for me a no solution problem if the source with all the name has a special char, like ',', to delimit the name and the last name can be an aproximation. In Spain, i guess in almost countries too, we have two last names that can have several words and the people can have a first and middle-name or more like "José María Sanchez de la Morena".
Good Luck
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
In my opinion, you wouldn't be satisfied with any of the solutions already mentioned. The graphical mapping provided by Raja will only work if the length of the first name is 4 characters, I think you can't take it as a rule. In general, you can't make it any better with graphical mapping, so a UDF is required. Still, the UDF by Baskar isn't even a correct Java code and doesn't compile.
So instead here is a complete solution: the UDF to be defined
UDF's code:
for (int i = 0; i < fullName.length; i++)
{
String tokens[] = fullName[i].split(" ");
firstName.addValue(tokens[0]);
lastName.addValue(tokens[1]);
}
And how to use it in graphical mapping, with an example of Display Queue:
By the way, use this SAP Help document for a jumpstart in graphical mapping functions learning:
http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm
Regards,
Greg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you dont have fixed size length for full name, it is not easier to do using graphical mapping. In this case doing UDF is better way.
Say your fullname has first name followed by space as delimiter and then last name,
Create UDF using parameter fullName as String type. Insert below one line code.
result.addValue(fullName.split(" ");
Map the fullName field to UDF input and UDF two outputs to two different target fields.
refer this site for understanding the logic
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Batul,
Option1:
Use substring function to in grapgical edition
FullName---->Substring(0,3)---->FirstName
FulName----->Substring(4,0)------>LastName
but the problem here is if you are expecting first string with specific length then substring works.
Option2:
You have to write a small UDF to split the string based on space between first name and last name.
If you want t familarize with Graphical functions then search in scn":standard function in PI".
You will fine many links with exapmles.
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.