cancel
Showing results for 
Search instead for 
Did you mean: 

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

ramu_g4
Participant
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

former_member190293
Active Contributor

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.
ramu_g4
Participant
0 Kudos

Hi Evgeniy,

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

-Ramu.

Answers (4)

Answers (4)

ramu_g4
Participant
0 Kudos

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.

ramu_g4
Participant
0 Kudos

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.

former_member190293
Active Contributor
0 Kudos

Hi Ramu!

And what is the line separator in second case?

Regards, Evgeniy.

ramu_g4
Participant
0 Kudos

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.

former_member190293
Active Contributor
0 Kudos

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.

ramu_g4
Participant
0 Kudos

Thank you Evgeniy!!

ramu_g4
Participant
0 Kudos

Hi Evgeniy,

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

Thanks,

Ramu.

former_member190293
Active Contributor

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.

ramu_g4
Participant
0 Kudos

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.

former_member190293
Active Contributor
0 Kudos

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

Regards, Evgeniy.

ramu_g4
Participant

Hi Evgeniy,

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

Thank you!

Ramu.

former_member190293
Active Contributor

I'm glad that it helped 🙂

Regards, Evgeniy.

apu_das2
Active Contributor
0 Kudos

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