Skip to Content

File Content Conversion (FCC) in SFTP Receiver Adapter

Hello All,

My requirement is

Sender Receiver (SFTP)

(txt file with Tab separated) -> PI/PO ->(csv file with pipe separated)

Sender channel i don't have to touch, it's already sending the data to some ERP system

I have to implement FCC in receiver side with SFTP adapter.

I don't know how to implement it.

Could you please help me with your idea to resolve it. I have attached sample txt file for sender side.

Regards,

Binod Kumar

sample.txt (290 B)
Add a comment
10|10000 characters needed characters exceeded

Related questions

7 Answers

  • Best Answer
    Posted on Dec 21, 2018 at 11:55 AM

    Hi Evgeniy/Binod,

    Sorry for the confusion.

    Actually I meant that adding java mapping would help in replacing the tab with pipeline and it will always work irrespective of structure change.

    If we want to replace the char using custom module then blog https://blogs.sap.com/2014/04/11/adapter-module-replacestring/ can be useful (but again this is for XML file). But as you mentioned, yes agree, this is not quick and easy solution. I was just trying to mention different approach.

    I tried to check my suggestion on Java mapping to replace the tab with pipeline. Good thing is that this mapping will always work irrespective of structure change and I am expecting it to be faster in performance compared to changing the payload from Tab ->XML and then again XML to Pipeline file.

    Below is the sample code:


    import java.io.*;

    import com.sap.aii.mapping.api.*;

    public class ReplaceCommaToPipeline extends AbstractTransformation {

    public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {

    try {

    InputStream inputstream = transformationInput.getInputPayload().getInputStream();

    OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();

    // Copy Input content to Output content

    byte[] b = new byte[inputstream.available()];

    inputstream.read(b);

    //replace tab with pipeline

    outputstream.write(new String(b).replaceAll("\t", "|").getBytes());

    } catch (Exception exception) {

    getTrace().addDebugMessage(exception.getMessage());

    throw new StreamTransformationException(exception.toString());

    }

    }

    }

    Below is the test result.

    Hope this helps!

    Thanks& Regards,

    Binod


    s81eo.png (20.8 kB)
    Add a comment
    10|10000 characters needed characters exceeded

    • Hello Binod,

      Thanks your code is working fine, it replaced tab with pipe delimiter for complete payload.

      But, I was checking in Quality, some special characters got converted in different format

      I modified your java code, now it's working fine when i test it in OM in ESR

      now character is not getting changed, and tab is also getting replaced by pipe delimiter

      Here is the code.

      package com.test.com;
      
      
      import java.io.BufferedReader;
      import java.io.IOException;
      import java.io.InputStream;
      import java.io.InputStreamReader;
      import java.io.Reader;
      import com.sap.aii.mapping.api.AbstractTransformation;
      import com.sap.aii.mapping.api.StreamTransformationException;
      import com.sap.aii.mapping.api.TransformationInput;
      import com.sap.aii.mapping.api.TransformationOutput;
      
      
      public class ReplaceTabWithPipeDelimiter extends AbstractTransformation {
      	String strData = null;
      
      
      	public void transform(TransformationInput arg0, TransformationOutput arg1)throws StreamTransformationException {
      		getTrace().addInfo("File Reading started ");
      		String strData = convertStreamToString(arg0.getInputPayload().getInputStream());
      		getTrace().addInfo("File Reading successfully completed ");
      		try {
      			getTrace().addInfo("Generating XML started");
      			// Specify the Encoding type you would like to have in Below line(un
      			// comment one you like)
      			// arg1.getOutputPayload().getOutputStream().write(strData.getBytes("ISO-8859-1”));
      
      
      			arg1.getOutputPayload().getOutputStream().write(strData.replaceAll("\t", "|").getBytes("ISO-8859-1"));
      			getTrace().addInfo("Generating XML started");
      		} catch (IOException e) {
      			e.printStackTrace();
      		}
      
      
      	}
      
      
      	public String convertStreamToString(InputStream in) {
      		StringBuffer sb = new StringBuffer();
      		try {
      			InputStreamReader isr = new InputStreamReader(in);
      			Reader reader = new BufferedReader(isr);
      			int ch;
      			while ((ch = in.read()) > -1) {
      				sb.append((char) ch);
      			}
      			reader.close();
      		} catch (Exception exception) {
      		}
      		return sb.toString();
      	}
      
      
      }
      
      
      
      
      
      Modified line: 
      arg1.getOutputPayload().getOutputStream().write(strData.replaceAll("\t", "|").getBytes("ISO-8859-1"));
      

      As, I mentioned it's working as expected when i test in ESR, but in 2e2 character is getting changed.

      Could you please guide me on this.

      Thanks,

      Binod

      capture1.png (13.7 kB)
      capture.png (24.7 kB)
  • Posted on Dec 20, 2018 at 07:18 AM

    Hi,

    What I understand is you want the tab to be replaced with comma. Use xslt/java mapping to replace the tab with comma. No change would be needed in SFTP adapter.

    In case you want to do it using receiver sftp adapter then you have many blogs already on scn.

    Thanks,

    Binod

    Add a comment
    10|10000 characters needed characters exceeded

    • Thanks Binod,

      For your quick response.

      This is pass-through scenario and PI 7.40 I'm using. When i select message protocol as FCC attached tab is coming.

      But mostly blogs suggesting to use message transform bean. Already we have option for FCC in PI 7.40.

      And, My requirement is replace tab by pipe delimiter.

      Regards,

      Binod

      1.png (15.1 kB)
  • Posted on Dec 20, 2018 at 07:47 AM

    Hi Binod,

    You may go ahead with message transformation bean. I remember we were getting some issues while using FCC.

    Thanks,

    Binod

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 20, 2018 at 08:33 AM

    Hi Binod!

    I guess you could use MessageTransformBean twice in your SFTP receiver channel: first - to transform your flat .txt file to XML structure, second - to transform it back to .csv structure using pipe separator.

    https://blogs.sap.com/2014/09/24/fcc-parameter-reference-for-messagetransformbean-module/

    Regards, Evgeniy.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Evgeniy,

      I didn't get "You could try to use this type (with the only structure) to remove header row". Can you please tell me exactly what i have to mention to remove the header filed for Plain2XML conversion?

      As you suggested to convert, flat .txt file to XML structure, second - to transform it back to .csv structure using pipe separator.

      Do i have to implement both conversion in SFTP reciver channel only,,,OR .txt file to XML in Sender and 2nd conversion in receiver?

      Since, existing sender channel i don't have to touch, it is transferring flat .txt with tab separation file to some other ERP

      i want to just configure everything in new created receiver SFTP channel.

      Regards,

      Binod Kumar

  • Posted on Dec 20, 2018 at 01:34 PM

    One more point, now after thinking more on this. I guess introducing mapping to replace tab with pipeline or introducing custom bean to repwould be more quicker and manageable solution.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 24, 2018 at 10:33 AM

    Hello Binod & Evgeniy,

    Both of your suggestion works fine. Thank you very much.

    Binod Mondal with java mapping it's working fine, tested. (as expected, but

    don't want to include ESR, it's pass through)

    Evgeniy Kolmakov with message transformation bean it's also works fine now, but little bit of output mismatch.

    I have attached the complete module configuration details with sample .txt file and output .csv file, that m getting.

    After every field pipe should be there, but here project name character is getting reduced.

    Please check it and provide me the suggestion.

    I guess it due to xml.fieldFixedLengths value, since "ProjectName" in sender side is not constant in character wise, some project name is of 20 characters, some of even 80 characters, don't know what to mentioned here.




    Thanks a lot,

    Binod


    6.png (291.8 kB)
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 22, 2019 at 09:39 AM

    Hi All,

    Thanks for all your support.

    I am closing this thread, used java mapping. It's working as expected.

    Add a comment
    10|10000 characters needed characters exceeded