Skip to Content
0

Java Mapping to add new line charactor in a string

Jun 20, 2017 at 11:41 AM

96

avatar image

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

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

4 Answers

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

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.

Share
10 |10000 characters needed characters left characters exceeded
Evgeniy Kolmakov Jun 20, 2017 at 01:30 PM
0

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.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Evgeniy,

this is also my idea.

But I am not good at java-mapping. ;-)

I'm trying to program it, but with errors. ;-(

Could you help me with some codes?

Thanks and regards

Sara

0

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.

2
Raghuraman S Jun 20, 2017 at 12:33 PM
0

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.

Show 4 Share
10 |10000 characters needed characters left characters exceeded

Hi Raghuraman,

thank you for your input!

But I cannot get your idea.

Is this a UDF, Java-Mapping or FCC?

Regards

Sara

0

Hello Sara,

If I am not wrong your scenario is file->file where in the output you need to split 50 characters in every line?

My idea is instead of java mapping create a simple structure of one field with occurrence 0-unbouded.

You can do a graphical mapping to split every 50 characters using sub string function then do a normal FCC

0

Hi Raghuraman,

aha, you mean a graphical mapping?!

I think it will not work, since the length of the source file is variable.

Today there is over 3000 lines inside. Tomorrow there would be 5000 lines in it. But the every line has fixed length.

It is impossible to create thousands of output fields in graphical mapping .

Regards

Sara

0

That's why I asked whether its Fixed length Sara,

Try Manoj suggestion it that's not satisfying the requirement ,please post one sample input and output required.

0
Manoj K Jun 20, 2017 at 01:14 PM
0

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


test.png (21.7 kB)
test.png (21.7 kB)
mm.png (27.3 kB)
Show 3 Share
10 |10000 characters needed characters left characters exceeded

Hi Manoj,

this looks interesting!

I will try.

But i still find java-mapping chic. ;-)

Could u code it?

Thanks and regards

Sara

0

Hi Manoj,

regarding UDF I'm worry about the proformance, because the source files are fast 50 MB big.

After converting to XML it would bigger. With your UDF it could make "Java heap space" problem?

Actually this is just the first step.

After adding line break in the source file i will read it via FCC and send it to proxy.

Regards

Sara

0

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

0