Skip to Content
In recent days, when I went through the XI forum, I noticed the real need of a scenario which has to transfer some binary data from one location to another with the same filename. Hence, I decided to take this as a challenge and do it. This blog is about how I achieved file copy scenario using XI 3.0 SP 9 (without SP12). The easiest way to achieve this is using modules.    h3. Overall process in a brief diagram    image     Brief Description on the above diagram       As a first step, the binary file is read by the module ‘ReadFileBean’ and converts the binary data into Base64. This module reads the filename directly form the Sender Channel. Both these are put into the tags and passed into the AFW. There mapping is made using the same data type and message type, and finally the XML is passed to the ‘WriteFileBean’ module. Here, this module converts the Base64 back to binary data, and writes into the directory found on Receiver Channel using the filename found on the tag. We will not use the CallSapAdapter module on Receiver Channel    h3. Integration Repository Designs      Data type design      image     Message Mappings       image   h3. Integration Directory Configurations      Sender Channel      image     You can notice the binary file (dll file) is read.      Sender Module      image     In the above figure, you can see that the ReadFileBean module is read before the CallSapAdapter. This helps the module to load first and transform the binary file to an XML file and send it to adapter engine.      Receiver Channel      image     In the above figure, only the target directory is read by the module and the filename is read from the tag.      Receiver Module      image
To report this post you need to login first.


You must be Logged on to comment or reply to a post.

      1. Anonymous
              I have a couple of questions on your blog .

        1)Why are you converting the binary to base64 and back again to binary – please let me know if I am missing something basic here – I have a requirement in which I want to ‘pass through’ i.e avoid converting a text file taken in into XML and back into text file again. I wanted to pass through the text file – through XI so that XI could route it to an appropriate receiver destination – file/ftp
        2) If I want to use XI as a pure ftp service – conversion to xml and back would be time-consuming for huge text files, right ?

        Thank you for your time in advance

        1. Anonymous
          Yes you can! You can even bypass the mapping. Don’t give any mapping in Interface mapping and you can achieve the same 🙂
        2. Jason Scott
          Anyone able to answer why its necessary to encode the data with Base64 before placing in the message payload? Why bot just leave it as the binary data?


          1. Stefan Grube
            The module creates an XML structure which contains the original file name and the content of the file as separate elements inside the XML. To create this structure, it is necessary to encrypt the content of the file to avoid illegal characters (like & or<or >)

            Starting with SP14 you can use the ASMA for storing the file name, so this blog is obsolete; but it still remains a good example for learning adapter modules.


  1. Anonymous
    Hi Felix,
    Can you tell me the package name for channel used inside your code.
    From Receiver Module is there any way to get to the sender channel id and hence the source file name through API.


    1. Anonymous
      The channel package is,
      Also, from the UML diagram provided by SAP for module, I can get the channel ID only from the module context using getChannelID() which will only return the current channel ID (ie, receiver if your module is in receiver or similarly for sender). Here in this blog, I am using completely a different technique by creating a new channel object using the channel id from the module context which seems a little odd and the best part is, it works!!
      Best regards,
  2. Prasad Ulagappan

    Hi Felix,++FHR</Data></Record><br/><Record><Data>+FQ1FILENAME_20050627_0001.dat</Data></Record><br/><Record><Data>+FQ2</Data></Record><br/><Record><Data>+DQ4FINANCE</Data></Record><br/><Record><Data>0010|etc</Data></Record><br/><Record><Data>0030|etc</Data></Record><br/><Record><Data>0570|etc</Data></Record><br/><Record><Data>0575|etc</Data></Record><br/><Record><Data>0575|etc</Data></Record><br/><Record><Data>+DTL</Data></Record><br/><Record><Data>+DQ4FINANCE</Data></Record><br/><Record><Data>0010|etc</Data></Record><br/><Record><Data>0030|etc</Data></Record><br/><Record><Data>0580|etc</Data></Record><br/><Record><Data>+DTL</Data></Record><br/><Record><Data>+FTL000002</Data><br/></Record></p2:MT_ChequeprintingOut><br/>[/b]<br/>In this if you look at the fourth line, “<Record><Data>+FQ1FILENAME_20050627_0001.dat</Data></Record>”[/b], it will contain the filename as “FILENAME_20050627_001.dat”. This filename should be the output file name. I have written the code to get this filename from the payload. The code will be look like …<br/><br/>               try {<br/>                    Channel ch = new Channel(moduleContext.getChannelID());<br/>                    obj = inputModuleData.getPrincipalData();<br/>                    msg = (Message) obj;<br/>                    //ch.<br/>               } catch (Exception e) {<br/><br/>               }<br/><br/>               try {<br/>                    XMLPayload xmlpayload = msg.getDocument();<br/>                    String myPayload = xmlpayload.getText();<br/>                    String fileName;<br/>                    fileName = getFileName(myPayload);<br/>……<br/>…..<br/>……                    xmlpayload.setText(myPayload);<br/>                    msg.setDocument(xmlpayload);<br/>                    inputModuleData.setPrincipalData(msg);<br/>….<br/>…..<br/>…..<br/>…..<br/>     public String getFileName(String filestr){<br/>          String substr = filestr.substring(filestr.indexOf(“<Data>+FQ1″)12);<br/>          String filename = substr.substring(0,substr.indexOf(“</Data>”));<br/>          System.out.println(“FileName :” + filename );<br/>          return filename;<br/>     }<br/><br/><br/>Now I would like to know, after getting the filename in the variable “fileName”,(refer code) how to set it in the receiver file adaptor file name. Please help me out in this…. <br/><br/>Thanks in advance,<br/>Regards,<br/>Prasad U

  3. Atis Purins
    Your blog provides helpful code for implementing the custom XI module for Base64 conversion. I am surprised that SAP does not have standard one, as it seems to be a common scenario.
    Also, is it necessary to develope the EJB in Studio Developer or is there an easier way to create the EJB module.

    Thanks, Marc

    1. Anonymous
      Thanks Marc.

      It is not really necessary but it is easier in NetWeaver Developer Studio with all plugins pre-loaded.
      Honestly, I haven’t tried deploying using other Java IDEs. May be we can give a try!

      Best regards,

  4. Dieter Aelker

    your blog is very helpful. In the end you bypass the file adapter when you write the PDF file. Is there anyway to use the FTP-Adapter to FTP the decoded PDF file to a target location? I tried it, but it does not seem to work. Maybe I have to change the payload type, I don’t know.

    Thanks in advance!

    Thanks in advance,

  5. Viktor Varga
    Thanks a lot, it’s a great weblog!
    I succesfully deployed the code you published but I am getting an error in my file adapter.
    “Error: java.lang.ClassCastException”
    Any idea what this could be or how to figure
    out what the problem is?
    Your help would be much appreciated.
    Thanks a lot,

Leave a Reply