Skip to Content

How to send a PDF file with File name over proxy to the SAP system

Dear Experts,

I have a requirement to pick a pdf file using SFTP channel and then to send it to the SAP system over proxy with pdf file name.

I have created a data type for proxy with two fields, one with the File name another with the file content. It is similar as described below.

Name Type Occurence DEMO FileContent xsd: base64Binary 1 FileName xsd: String 1

I have used a UDF to get the file name of the pdf and mapped this UDF to FileName field under datatype and used the dynamic file setting in the channel.

Sender channel has successfully picked up the file and sent it to adapter engine but it failed in the request message mapping stage under Pipeline with following error :

 

Runtime exception occured during application mapping

com/SAP/XI/tf/_MM_Test~

com.sap.aii.utilxi.misc.api.BaseRuntimeException : Content is not allowed in the prolog.

Although when I have sent the PDF with only one field as Filecontent, it is getting processed successfully.

Appreciate if any one can suggest any alternative/resolution. We have restriction to not use Integrated configuration in this case.

Regards,

Sudhir Kumar

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

6 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 28, 2012 at 07:30 AM

    Hi Sudhir,

    Please use java mapping to parse the PDF file into binary format and then send the binary content in file content field to ABAP proxy. But in ABAP proxym, you should do the reverse to get the PDF file. In this way, you can have both the file name + the PDF file in your ABAP proxy.

    I have done exactly the same for one of my integration with third party vendor and I was able to transfer 500-600 PDF files/Day through SAP PI 7.0.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Sudhir Kumar

      Sudhir Kumar wrote:

      Hi Jenny,

      Thanks for your reply !

      But this code is throwing compilation error in following line :

      String outputString = Base64.encode(byteArrayOut.toByteArray());

      Regards,

      Sudhir Kumar

      I had the same situation/problem and I've just used Jennilyns solution. But I got the same error like you. So I've changed Jennilync code a little bit.

      import javax.xml.bind.DatatypeConverter;
      

      ... Jennilyns code ...

      private String encodeBase64(InputStream in) throws IOException { 
           ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
           int i;
      
           while ((i = in.read()) != -1) {             
                byteArrayOut.write(i);        
           }                
           String outputString = DatatypeConverter.printBase64Binary(byteArrayOut.toByteArray());
           return outputString;    
      } 
      

      Now all works as expected.

  • Sep 27, 2012 at 03:10 PM

    Correction :*

    Sender channel has successfully picked up the file and sent it to Integration engine *

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Jenny,

      The Graphical mapping is getting the input message as:

      Input message :

      <?xml version="1.0" encoding="UTF-8"?>

      <ns0:MT_Note xmlns:ns0="urn:*">

      <File>

      <FileContent/>

      </File>

      </ns0:MT_Note>

      Output Message :

      <?xml version="1.0" encoding="UTF-8"?>

      <ns0:MT_NoteProxy xmlns:ns0="urn*"><File><FileContent>123</FileContent></File><FileName>tets</FileName></ns0:MT_NoteProxy>

      This is working fine in Message mapping but failing in SXMB_MONI at Runtime. Please suggest if any UDF/FL can be used to convert the PDF in to XML.

      Regards,

      Sudhir Kumar

  • Sep 28, 2012 at 07:27 AM

    Hi Sudhir,

    if you pick a pdf and send it to integration engine, it is not wellformed xml in the view pi. A parser of Message Mapping or XSL would have to reject it and you get this error.

    So you would need a NOT parsing mapping, for example an ABAP mapping. Just transfer the incoming XSTRING to STRING, encode it to base64 and put it into a simple xml container. Then convert back to XSTRING.

    In addition you can add a second mapping to put the file name.

    Regards,

    Udo

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Sudhir,

      It is PI standard that you can use a much mapping programs as you like within an operation mapping. The are executed in a row. The target xml of the first mapping is the source of the second and so on.

      In your case it can be most easy to put first an ABAP mapping and secondly a Message Mapping with an udf reading the ASMA header for the file name. You need only 2 interfaces, one for the pdf (Message will be ignored) and one for the message to SAP. You can take the target message type as output of the ABAP mapping (fill the filename field with a space or mark it as optional) and as input of the Message Mapping.

      What you need is in any case a NON parsing mapping. You have the choice between Java and ABAP. ABAP is from my point of view easier (very short source code, no deploy, use of standard function modules), Java would be more modern (in terms that an ABAP mapping is may be not supported in future releases).

      Of course you have the alternative to handle all inside one mapping program (then you need to read the ASMA header inside ABAP or Java what would be some development work).

      Regards,

      Udo

  • Oct 08, 2012 at 03:53 PM

    Hi,

    Why don't use proxy with attachment concept? For payload put some dummy hardcoded one line string content for string type and create an attachment with actual PDF content using a java mapping.

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 14, 2016 at 12:41 PM

    Hello All,

    I have same issues with author. I need to send the attachment pdf from third system(OA system) to ECC. How to choose the adapter(including: Sender and Receiver).

    My PI version: 7.11

    In addition, what size is the pdf every time? It is said that the size is less than 10MB every day, isn't it?

    Thank you all for your reply.

    Hubery

    Many thanks & best regards,

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 06, 2016 at 10:10 AM

    Could you please show me the abap code in abap proxy side?

    I try to get rawstring and convert it in SCMS_XSTRING_TO_BINARY and store to file system. It's not work. I cannot open that file and when I try to download to client, It's broken.

    I don't know what's the correct way to get it in abap side.

    Thanks.

    Add comment
    10|10000 characters needed characters exceeded