Skip to Content
0

Spliting source string

Mar 21, 2017 at 12:05 PM

72

avatar image

Message mapping my source string having 150 Char but I want to break up 20 Char 20 char put in the target mgs .

We need write UDF or we can do any other way

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

6 Answers

Best Answer
chandrasekhar reddy Mar 22, 2017 at 11:28 AM
0

Thanks for given answers

Share
10 |10000 characters needed characters left characters exceeded
mayank gupta Mar 21, 2017 at 12:35 PM
0

Can you please give example of source and target message.

Share
10 |10000 characters needed characters left characters exceeded
chandrasekhar reddy Mar 21, 2017 at 01:34 PM
0

Source field

AAABBBCCCDDD…….YYYZZZ

Target filed

I want break up 3 , 3 ,3 char like

Field1AAA

Field2BBB

Field3CCC

Field4DDD

.

.

FieldNZZZ

I think Countable Char means we can use substring,, If we get more char What we have to do?

Share
10 |10000 characters needed characters left characters exceeded
Iñaki Vila Mar 21, 2017 at 01:48 PM
0

Hi,

Have you checked his link

https://wiki.scn.sap.com/wiki/display/XI/Split+Mapping+using+UDF

?

Regards.

Share
10 |10000 characters needed characters left characters exceeded
Baskaran Elumalai Mar 21, 2017 at 01:50 PM
0

Hi Chandra,

You mean to say target is one field with occurrence, 0..unbounded ?

Regards

Baski

Share
10 |10000 characters needed characters left characters exceeded
Baskaran Elumalai Mar 21, 2017 at 09:17 PM
0

Hi Chandra,

Please find the logic below.


Mapping screen


UDF Elements


Count Parameter

In the code, Count is used as constant which specifies the length of each string that should be split from the Input String. This can be passed as normal constant or parameter. In your case, it should be 3.

The parameter can be varied based on the requirement.

Length Condition Handled

If the input string can't be split up into equal sub strings, [For e.g AAABBBC(length7) is to be split into strings of length 3] we are padding tilde symbol at last of source string for initial splitting and finally removing the same while posting to the target.


UDF Code

int len = Inp[0].length();

int Mod = len % Count[0];

if( Mod != 0)

{

Inp[0] = String.format("%0$-" +(len+Count[0]-Mod)+ "s", Inp[0]).replace(' ','~');

}

String out;

for(int i=0;i<len;i=i+Count[0])

{

out = Inp[0].substring(i,Count[0]+i);

if( i == len-Mod)

{

out = out.replace("~","");

}

Res.addValue(out);

}


Mapping Test 1 [Count -3]


Mapping Test 2 [Count -3]


Mapping Test 3 [Count -4]

Could you please let us know if this is helpful.

Regards

Baski


mapping.png (21.2 kB)
udf-elements.png (7.7 kB)
testing1.png (14.1 kB)
testing2.png (14.0 kB)
testing3.png (14.3 kB)
Share
10 |10000 characters needed characters left characters exceeded