Skip to Content

Java Mapping to add new line charactor in a string

Hallo Gurus,

my problem is, i got a very long string from customer, which contains thousands lines, but without new line charactor. Therefore the file content conversion does not work.

My idea is to add new line charater after fix length.

Here is an example:

The length of a string has 1000 characters. A line should be 50 characters. There would be 20 lines. By using this java mapping the new line character "\n" would be added every 50 characters.

Anyone could help me out?

thanks a lot!

Regards

Sara

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    Jun 20, 2017 at 03:07 PM

    I can only emphasize what other have already said here: don't send files this large to the messaging system!

    Try to talk to the person supporting the source application and convince them of splitting the single large files into multiple smaller files. PI generally shows the best performance on files that do not exceed 5 MB. If a change at the source is not possible, consider using a pre-process to handle the splitting.

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 20, 2017 at 01:30 PM

    Hi Sara!

    You can use simple java mapping to get source string, split it into pieces of required length and even parse each substring to fill desired output XML structure.

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Sara!

      You had to mention in your original question that your source file could have the size about 50 MB. In such case you should split your source file by any way before sending it to messaging system.

      The best way of doing that is to request the sender party to split the source file before upload.

      Regards, Evgeniy.

  • Jun 20, 2017 at 12:33 PM

    If the length is fixed, Why cant you repeat the target and use substring like below.

    Source---->Substring(0,50)--->Target1(0--Unbounded)

    Source---->Substring(50,100)--->Target1(0--Unbounded)

    and so on.

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 20, 2017 at 01:14 PM

    Sara ,

    Is this what you are expecting.

    test.png

    UDF : Execution Type All value of context

    if(!var1[0].equals(""))  
    {  
    int len = var1[0].length();  
    int divide = len/3;  
    String out = "";  
    int temp = 0;  
    if(len%3 == 0)  
    {  
    for(int i=0;i<divide;i++)  
    {  
    temp = 3*i;  
    out = var1[0].substring (0+temp,3+temp);  
    result.addValue(out);  
    }  
    }  
    else  
    {  
    for(int j=0;j<divide;j++)  
    {  
    temp = 3*j;  
    out = var1[0].substring (0+temp,3+temp);  
    result.addValue(out);  
    }  
    result.addValue (var1[0].substring (divide*3, len));  
    }  
    }  
    else  
    result.addSuppress();  
    
    

    Br,

    Manoj

    Add comment
    10|10000 characters needed characters exceeded

    • Sara,

      Irrespective of what you use graphical/java/xslt/abap the file size with 50 MB would always cause issue . As Eve has already mentioned the best approach is to split in into multiple files bu your source application.

      Br,

      Manoj