on 01-14-2014 5:11 AM
How to split value in the below format:
Split Profit Center/GL #1 (Serengeti File) at '='. GL_ACCOUNT is the value after '='.
Prefix zeroes to make the length 10
Example:
2687=41013 ---> value of GL_ACCOUNT = 0000041013
Hi Mahi,
You can try this UDF too
public String validate(String Serengeti,Container container) throws StreamTransformationException
{
String s="";
String delimiter="=";
int i=Serengeti.indexOf(delimiter);
if(i>=0)
{
s=Serengeti.substring(i+1);
int l=s.length();
for(i=0;i<10-l;++i)
{
s="0"+s;
}
}
return s;
}
below are corresponding input and output
input => output
2687=41013 => 0000041013
268=1013 => 0000001013
2=3 => 0000000003
267=413 => 0000000413
8=41013 => 0000041013
2687=4 => 0000000004
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gavaksh,
Thank you for your kind response to this thread.
Only one thing I would like to point out in your code is that you are fixing the number of zeroes to four.
The number of zero might vary depending on the length of GL_ACCOUNT value after '=' symbol.
Thus you need to make the number of zeroes variable. Hope you understood my point.
Regards
Anupam
Hi Anupam,
Thanks for clarification. I didnt see this specific requirement. However, this can easily be handled inside the UDF. we have the second string(after =). we can easily calculate its length, and append equal number of zeros.
I don't see any problem in implementing this. Looks like a simple requirement.
Regards,
Gavaksh Saxena
Hi Gavaksh,
We need to be careful in posting solution in a public forum. Our solutions is going to be used in projects directly. I understand that in this case a few additional lines is enough to meet the requirement and you could have easily written those. Thus anything that remains in forum uncorrected might be followed by future members. My intention was not to point out your mistake or make you show that you are not a good programmer. I regard this forum as my family as whatever little I know about PI till date , I gathered from forum itself. Hope you do not misunderstand me.
Regards
Anupam
Hello,
U can use below UDF:
String[] split = var1[0].split("=");
result.addValue(split[1]);
And then to format ur output u can use below mapping:
Input - UDF - Format Number(0000000000) - output
Thanks
Amit Srivastava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Amit
I tried the above one but is giving flowwing error
Function Split, Line 1:
array required, but java.lang.String found String[] split = var1[0].split("="); ^
Function Split, Line 2:
cannot find symbol symbol : variable result location: class com.sap.xi.tf._InvoiceReceiptandValidation_AccountsPayable_ result.addValue(split[1]); ^ Note: /usr/sap/GEJ/J00/j2ee/cluster/server1/./temp/classpath_resolver/Map72b994387cde11e3c9ed000000669cf3/source/com/sap/xi/tf/_InvoiceReceiptandValidation_AccountsPayable_.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 2 errors
Runtime exception when processing target-field mapping /ACC_INVOICE_RECEIPT03/IDOC/E1BPACAP03/GL_ACCOUNT; root message: Exception:[java.lang.ArrayIndexOutOfBoundsException: 1] in class com.sap.xi.tf._InvoiceReceiptandValidation_AccountsPayable_ method Split[[Ljava.lang.String;@4cfdd9bc, com.sap.aii.mappingtool.tf7.rt.ResultListImpl@2de1ed21, com.sap.aii.mappingtool.tf7.rt.Context@4b97290f] See error logs for details
Hello,
Amazing..we have exchanged 12 posts for such a simple thread
Anyway, how many instances of "profit_center" are present in ur sample input xml?
Open ur mapping for gl_account target field -> right click on source field profit_center -> then select display queue option.
Repeat same steps for UDF step and paste ur screenshots here.
Thanks
Amit Srivastava
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.