cancel
Showing results for 
Search instead for 
Did you mean: 

Split

former_member350687
Participant
0 Kudos

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

Accepted Solutions (0)

Answers (3)

Answers (3)

anupam_ghosh2
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Mahi,

this is a very simple situation. you just have to use tokenizer functionality of java.

String delim="=";

String[]  value = Input.split(delim);

return "0000"+value[1];

PFA images for more details

I hope this will work.

anupam_ghosh2
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

anupam_ghosh2
Active Contributor
0 Kudos

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            

Former Member
0 Kudos

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

former_member350687
Participant
0 Kudos

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

Former Member
0 Kudos

Hello,

Define a variable "var1" and select execution type as " All values of a context"

Thanks

Amit Srivastava

former_member350687
Participant
0 Kudos

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

former_member350687
Participant
0 Kudos

Hi Amit

above is the error when i tried with result list

can you help ne on this

Former Member
0 Kudos

Hello,

It's quite evident that u are not passing values in proper format. According to ur post, input value should be like: 1234=45678??

Or there can be a possibility that sometime input values can come without any "=" separator??

Thanks

Amit Srivastava

former_member350687
Participant
0 Kudos


input value will be like: 1234=45678 so how can i use this split

Former Member
0 Kudos

Hello,

Check below screenshots:

Split UDF:

Thanks

Amit  Srivastava

former_member350687
Participant
0 Kudos

Hi Amit

can you reply with any other way i am not able to do it

former_member350687
Participant
0 Kudos

Hi Amit i tried with the same example given by yiu but i am not able to get the result. please see the above screen shorts

Thanks

Mahi

Former Member
0 Kudos

Hello,

U have to use string array instead of just string. u have to paste code properly

String []  split = var1[0].split("=");

result.addValue(split[1]);

Thanks

Amit Srivastava

former_member350687
Participant
0 Kudos

I am used the smae code see the bwloe screen shorts. but it is showing ArrayIndex out of bound error

Former Member
0 Kudos

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

former_member350687
Participant
0 Kudos

First is the input value and send one is the UDF.

Former Member
0 Kudos

Hello,

Weird...ur input queue and UDF looks OK to me but still u are getting array out of bound exception.

Check below workaround:

Substring UDF:

Execution type : single value

Input: var1 of type int

and var2 of type string

return (var2.substring(var1+1,var2.length()));

Thanks

Amit Srivastava