Skip to Content

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

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Nov 24, 2016 at 05:34 AM

    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.
    Add comment
    10|10000 characters needed characters exceeded

  • Nov 23, 2016 at 03:18 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 24, 2016 at 09:27 AM

    Hi Evgeniy,

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

    Thanks,

    Ramu.

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 05, 2016 at 07:02 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 06, 2016 at 06:48 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded