Skip to Content
0

Java mapping to replace string '#$' in input text file with character 'nl' output text file

Nov 23, 2016 at 02:59 PM

255

avatar image

Hi Experts,

We are working on PI 7.3 dual stack, where the requirement is File to File where the input will be text file containing string '#$' and expected/output file is also text file with same content but the string '#$' in the input file should be replaced by 'nl' or '/n' [next line] in the output file. I mean number of lines formed in output file is dependent on number of '#$' strings present in the input file. I already tried FCC as posted in the link Handling Flat file in SAP PI 7.3 dual stack but I could not achieve this using the same/none helped me. Can you please help me with java mapping code or custom adapter module code to achieve this requirement. I have attached both input[actual-input.txt] & output[expected-output.txt] files here. Kindly help.

Thanks,

Ramu.

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

5 Answers

Best Answer
Evgeniy Kolmakov Nov 24, 2016 at 05:34 AM
1

Hi Ramu!

You can do it without java coding. Just use MessageTransformBean (instead of FCC) twice: first one - to remove "#$" from your file, second one - to convert your temporary XML back to flat file:

Regards, Evgeniy.

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

Hi Evgeniy,

Thanks for your response, let me try and get back to you!

-Ramu.

0
Apu Das Nov 23, 2016 at 03:18 PM
0

Hi,

What was your FCC in sender CC. It should work without any issue.

Put Record.fieldSeparator and Record.endSeparator both '#$' along with Record.FieldNames = Line

Thanks,

Apu

Share
10 |10000 characters needed characters left characters exceeded
Ramu G Nov 24, 2016 at 09:27 AM
0

Hi Evgeniy,

Where should I use MessageTransformBean whether in sender or receiver channel or both as suggested by you? Kindly suggest.

Thanks,

Ramu.

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

Hi Ramu!

You use MessageTransformBean modules in sender adapter before adapter's standard module. Further you can use simple pass-through scenario to transfer your result plain text file to end point.

Regards, Evgeniy.

1
Evgeniy Kolmakov

Hi Evgeniy,

Thank you for your response,so you mean no ESR objects required here? Can I use File channel on receiver side here with filename scheme as .txt ? Any extra configurations required in receiver channel to achieve this requirement?

Rgds,

Ramu.

0

Yes, Ramu, you don't need any ESR objects and your file can be saved at target side as .txt

Regards, Evgeniy.

0
Evgeniy Kolmakov

Hi Evgeniy,

You are champ ! It works like charm. Thanks a ton for your help.

Thank you!

Ramu.

1

I'm glad that it helped :-)

Regards, Evgeniy.

1
Ramu G Dec 05, 2016 at 07:02 AM
0

Hi Evgeniy,

The client changed requirement like sometimes the file comes without special character string "#$" also and remaining times with special characters "#$". Like as shown in below snippets:

CASE1: File with special characters "#$':

CASE2: File without special characters "#$" :

The splitting of file in CASE1 is possible as suggested by you both how to split the file in CASE2. In both cases file content should be separated as lines and the resulting file should look like below i.e., each line will either start with SIV8001 or IL18001.

Kindly help.

Thanks,

Ramu.


capture1.jpg (47.4 kB)
capture.jpg (44.0 kB)
capture-result.jpg (76.3 kB)
Show 4 Share
10 |10000 characters needed characters left characters exceeded

Hi Ramu!

And what is the line separator in second case?

Regards, Evgeniy.

0
Evgeniy Kolmakov

Hi Evgeniy,

Only case2 is required now, no case1 .So splitting the new lines should be generated at the starting point of either IL1 or SIV. Is it possible?

Input file:

Output file:

Thanks,

Ramu.

ip.jpg (43.8 kB)
ip.jpg (43.8 kB)
op.jpg (56.2 kB)
0

Hi Ramu!

I don't think that it's possible using FCC. The only case to make a try could be if you had fixed fields count for each row with fixed field lengths.

Regards, Evgeniy.

0
Evgeniy Kolmakov

Thank you Evgeniy!!

0
Ramu G Dec 06, 2016 at 06:48 AM
0

Hi Evgeniy,

When I click on properties of the file present in input NFS folder present locally in PI the type of file is "File" but not "TXT" as shown in below snippet.

When open with notepad the file would look like as shown below without "#$",

Can you please guide me on how to handle the file with type of file as "File" in PI? Also file opened with notepad do not contain "#$".

Thanks,

Ramu.


file.jpg (31.3 kB)
file-note.jpg (37.2 kB)
Share
10 |10000 characters needed characters left characters exceeded