Skip to Content
avatar image
Former Member

Spliting source string

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    avatar image
    Former Member
    Mar 22, 2017 at 11:28 AM

    Thanks for given answers

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 21, 2017 at 12:35 PM

    Can you please give example of source and target message.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 21, 2017 at 01:34 PM

    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?

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 21, 2017 at 01:48 PM

    Hi,

    Have you checked his link

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

    ?

    Regards.

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 21, 2017 at 01:50 PM

    Hi Chandra,

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

    Regards

    Baski

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 21, 2017 at 09:17 PM

    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

    Add comment
    10|10000 characters needed characters exceeded