Create Attachment within Graphical Mapping using UDF

Hi!
We want to create an attachment witihn a graphical mapping using an UDF function.
I use that function:
public String addAttachment(String filename, String mimeType, String content, Container container) throws StreamTransformationException{
     BASE64Decoder decoder=new BASE64Decoder();
     try {
          GlobalContainer globalContainer = container.getGlobalContainer();
          OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
          Attachment attachments = outputAttachments.create(filename, mimeType,decoder.decodeBuffer(content));
          outputAttachments.setAttachment(attachments);
          return "Adde1: "+filename;
     } catch (Exception e) {
          return e.toString();
(SDN helped me much in creating that
This function has no compiling errors, anything workes fine:
It takes 3 input-parameters, see also: http://help.sap.com/javadocs/pi/SP3/xpi/com/sap/aii/mapping/api/OutputAttachments.html
filename (ok, more or less contentID)
mimeType (more or less contentType)
content: Base64-encoded String which should be set as content
In my sample I use the following constants for that function:
filename = "fn1.txt"
mimeType="application/xml"
content = "UG9seWZvbiB6d2l0c2NoZXJuZCBhw59lbiBNw6R4Y2hlbnMgVsO2Z2VsIFLDvGJlbiwgSm9naHVydCB1bmQgUXVhcms=" --> cames directly from http://de.wikipedia.org/wiki/Base64
When using the message, I got this error within SXMB_MONI:
<SAP:AdditionalText>com.sap.engine.interfaces.messaging.api.exception.MessagingException: Could not queue receive for
message 0022642d-b106-02df-8e8c-f41c243bd112(INBOUND). Reason: java.lang.NullPointerException: while trying to
invoke the method com.sap.aii.af.sdk.xi.lang.Binary.getBytes() of an object returned from
com.sap.aii.af.sdk.xi.mo.xmb.XMBPayload.getContent()</SAP:AdditionalText>
This looks pretty much the same as Add Attachment from ABAP Mapping but this tread is also not answered.
Adding attachment from PI level looks also in that direction, again, no answer.
So, I was wondering if someone has solved such problem?

Hi Divyesh!
We did it that way:
1. Choosing the XML-Mailstructure as Destination as described in Configuring the Receiver Mail Adapter - Advanced Adapter Engine - SAP Library -  Example (XI payload with mail package)
2. now we have created a UDF for creating the "content"
public void getContent(String[] text, String[] attFname, String[] attType, String[] attContent, ResultList result, Container container) throws StreamTransformationException{
// vergleich ob alle att-Arrays selbe anzahl haben
if (attFname.length!=attType.length || attFname.length!=attContent.length) {
    result.addValue(Integer.parseInt("Fehler: alle Attachment-Eingänge müssen die selbe Anzahl an Elementen haben!"));
    String CRLF = "\r\n";
    String output="This is a multi-part message in MIME format."+CRLF+CRLF+
    "--"+getBoundary(container)+CRLF+
    "Content-Type: text/plain; charset=UTF-8"+CRLF+
    "Content-Disposition: inline" + CRLF + CRLF +
    text[0]+CRLF;
for (int i=0;i<attFname.length;i++) {
    output+="--"+getBoundary(container)+CRLF+
    "Content-Type: "+attType[i]+"; name="+((char)34)+attFname[i]+((char)34)+CRLF+
    "Content-Disposition: attachment; filename="+((char)34)+attFname[i]+((char)34)+CRLF+
    "Content-Transfer-Encoding: Base64"+CRLF+CRLF+attContent[i]+CRLF;
output+="--"+getBoundary(container)+CRLF;
result.addValue(output);
This UDF is configured as "QUEUE"
We have configured this input-structure
The Content itself is allready base64.
So we can call this mapping and it creates a Multipart-Mail for us.

Similar Messages

  • Graphical mapping or UDF

    Hi,
    In my mapping i have a requirement where the input can be any of three values or not existing. (lets just call them V0, V1, V2 and V3, where V0 is the not existing tag)
    If the input is V0, or V1 or V2 i need output an Empty Constant, If the input is V3 i need to pass the value.
    I've worked this out with a graphical mapping, but it involves a lot of boxes. It works though.
    I'm still wondering if i can do it with a UDF though. Only problem is that my JAVA knowledge is not nearly as good as it should be, so maybe one of you out there can give me some ideas/code.
    The thing that give the most headache is the fact that the tag might not exist at all in the source message. How do I deal with that in JAVA code?
    Any ideas are welcome.
    Kind regards
    Robert

    Hi Robert,
    below is the Jave code, below code is w.r.t exection type as CONTEXT/QUEUE
    public void calculate(String[] var1, String[] var2, String[] var3, String[] var4, ResultList result, Container container) throws StreamTransformationException{
    if(var1.length != 0 || var2.length != 0 || var3.length != 0)
             result.addvalue(" ");
    else if(var4.length != 0)
         result.addValue(<passthe value>);

  • IDOC to FILE(xml) graphical mapping using node function createIf

    Greetings All,
                My Scenario is Idoc to File(XML)
    Target Structure is 
                           MO_MAT_LAN....................(0: unbound)
                                LAN_KEY.......................(0 :1)
                                DESCRIPTION.................(0 : 1)
    Source MATMAS Idoc
                           E1MAKTM.........................(0 : 99)
                                SPRAS_ISO..................(0 :1) 
                                MAKTX..........................(0 :1)
    initially i had mapped E1MAKTM----->MO_MAT_LAN but i dont want target node MO_MAT_LAN to be created when the SPRAS_ISO is equal to EN
    I have tried using node function createIf but the node is geting created only once although the input stucture is having occurance more than 5.
    Can anyone please help me to achive this.
    Many thanks,
    Rohit

    U have to use:-
    SPRAS_ISO mak the context to E1MAKTM compare (Use equals) it with Constant function EN out put to be given to If without else and in then Give E1MAKTM and map out put of If node to MO_MAT_LAN.
    chirag

  • How to read attachment data in mapping

    Hi,
    In my scenario I receive an XML file with another file as attachment. I need to map both the content of the XML file and the attachment to the target which will be sent as an attachment in a mail.
    I have used JavaMapping and I'm now able to send the mail with the attachment. But i'm not sure how to  read the contents of the attachment in the mapping.
    Any help would be appreciated.
    Thanks,
    Bhargav
    Edited by: Bhargav Srinadh Gundabolu on Feb 12, 2009 10:03 PM

    Hello Bhargav,
    It depends on the version of SAP PI you have,
    Prior to Version 7.1 there was no support to access attachments in a Mapping Programm, so in that
    case the only way to handle it is e.g. to access it in an adapter module (dependent on your scenario).
    In SAP PI 7.1 you can easily access an attachment within a mapping.
    Within a Java mapping program this can be done with the TransformationInput Class, calling the method getInputAttachments() which will give you all available attachments.
    Also see the SAP PI 7.1 javadocs (com.sap.aii.mapping.api):
    https://help.sap.com/javadocs/pi/SP3/xpi/index.html
    In a graphical mapping you can access attachments within a UDF through the GlobalContainer parameter:
    GlobalContainer globalContainer = container.getGlobalContainer();
    InputAttachments inputAttachments = globalContainer.getInputAttachments();
    With best regards
                Sebastian

  • Java Mapping  and Graphical Mapping

    Hi All,
    Could any one clarifies the situation where we need to write in a same interface ,
    Both Java mapping and Graphical mapping.
    Regards,
    venu.

    Hi,
       Here is a scenario where you might need to use both graphical and user defined functions.
    source: <fname> <lname> <filename>
    target: <name> <filetype>
    Suppose, you need to concatenate fname and lname into the target <name> tag, you could use the normal graphical mapping using the concat function.
    <fname>\
    concat <name>
    <lname>/
    next, if we need to extract only the filetype from the filename, for example, if we have filename.txt... and we want only the value .txt, we need to write a user defined function which would achieve this for u, since there are no inbuilt function which can solve this for you in graphical mapping.
    Further XSLT mapping comes into picture when we need to create the entire target xml structure. Again, graphical mapping would not be useful here.
    Regards,
    Smitha.

  • File to file transfer using UDF

    Hi
      i am doing one scenario,file tofile transfer using UDF.
    I will write one UDF which will read the whole content from text file and write to the target path.Ok.so i am mentioning both sender and reciver URL in UDF.is this the correct way.
    then if am writing URL in UDF then is it again need to create  communication channel for both.
    and how i will do mapping  using UDF..plz let me know  weather my concept is correct or not

    Hi,
    You can do this with out UDF and through File--File Simple Scenario
    What is your Typical requirement to use the UDF here.
    If there is no Specific UDF Requirement means , we can follow Normal Scenario to pick the file from One place and to place it at another folder
    File to File scenario:
    Introduction to simple(File-XI-File)scenario and complete walk through for starters(Part1) - File to File Part 1
    Introduction to simple (File-XI-File)scenario and complete walk through for starters(Part2) - File to File Part 2
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/xi/flatFILETOFLATFILE&
    REgards
    Seshagiri

  • Read attachment content in Mapping

    Hi,
    In PI 7.1 there is one option to read attachment content inside mapping using the api: "com.sap.aii.mapping.api".
    To do that in operation mapping we have to check the option "ReadAttachments", to get the attachments in addition to the payload. If I check the Readattachments check box, message goes into the queue and the queue status is running.
    Please help me to read the attachment content in mapping.
    Thanks & Regards,
    Yuga

    Hi,
    That issue has been solved,the problem is with the syntax.
    Now I was able to get the attachment details,but i was not able to read the content of the attachment.
    Here is my code:
    String Content = "";
    String AttachmentID ="";
    GlobalContainer globalContainer = container.getGlobalContainer();
    InputAttachments inputAttachments = globalContainer.getInputAttachments();
    if(inputAttachments.areAttachmentsAvailable())
         Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true);
         Object[] arrayObj = CollectionIDs.toArray();
         int attachmentCount = arrayObj.length;
         for(int i =0;i<attachmentCount;i++)
                AttachmentID =(String) arrayObj<i>;
                  Attachment attachments =inputAttachments.getAttachment(AttachmentID);
              Content = Content + attachments.getContent().toString();
    return Content;
    My requirement is to read all the attachment's.Attachment has XML content, so after reading I need to parse the xml content inside graphical mapping itself is there is any option to do like this.
    Thanks & Regards,
    Yuga

  • Copy of source message to an element with graphical mapping

    Hi all,
    Is there a way to copy the complete source message of a mapping to an element of the destination message (with CDATA) with the graphical mapping (or UDF, but I want to avoid XSL) ?
    For example, from this message:
    <source>
      <element>test</element>
      <element2>test2</element2>
    </source>
    I expect the following result:
    <dest>
      <data><![CDATA[<source><element>test</element><element2>test2</element2></source>]]>
      </data>
    </dest>
    Thanks for your help.
    Greg

    Hi,
    Use this Simple Concept
    XML node into a string with graphical mapping
    /people/michal.krawczyk2/blog/2005/11/01/xi-xml-node-into-a-string-with-graphical-mapping
    Regards
    Seshagiri

  • Can't create correct routes in Maps

    Why is it that when I'm creating a route in Maps, the outcome varies dependent on how I created the route, thus using the same route parameters?
    I've created the same route using different ways of creating the route, and the created route is different every time.
    If I create the route in Maps using the search facility, the route is different if I use an address via the people and contacts interface. And again it is different when using Drive.
    I made the discovery when a suggested route made a 16.2 km de-tour on a 11 km stretch. More than a 100%. I'm now wondering if I dare to use NOKIA maps for my summer trip to Italy from Denmark.
    NOKIA -
    Please make a navigation app where I can define my own waypoints. This is essential in every navigation system.
    Please optimize the app, so I can choose an alternative route - this is basic in most modern navigation systems.
    Honest differences are often a healthy sign of progress. - M. Gandhi

    -Rich
    Thanks for your reply. Sorry for not writing phone model and software release.
    It is a Lumia 920 and I'm using Drive +Beta 2.1.0.1451
    I'm also setting the trip options like fastest / shortest, toll roads etc. In this particular case I'm referring to with, a D-tour of more than 16 km on a stretch of 12 km, it doesn't matter how I set my planning options - I'm getting the same result.
    Being well aware that the program makes some mistakes like this one, it would be nice to be able to plane the route in details by using waypoints. That is not possible at the moment with the present software by NOKIA.
    Honest differences are often a healthy sign of progress. - M. Gandhi
    Attachments:
    wp_ss_20130106_0001.png ‏168 KB

  • UDF or Graphical Mapping

    Hello All
    I have a requirement like below:
    Source fields              
    TXT                                 
    AddTXT
    Target Field
    Node
    I want to create Node as many times as AddTXT comes with value Concatinate(TXT+AddTXT). This I have achieved not a issue.
    Now I want concatinate should happen only for 1st Node other nodes should contain only value of AddTXT.
    e.g.
    TXT = 001
    AddTXT = James
    AddTXT = Dheeraj
    AddTXT = Rajesh
    Result should be
    Node = 001-James
    Node = Dheeraj
    Node = Rajesh
    I believe using Graphical mapping this is not possible so how can I achieve this using UDF.
    Thanks
    Dheeraj Kumar

    Hi Dheeraj
    Please use the below code.
    In the UDF
    TXT = var1
    AddTXT = var2
    Regards
    Osman

  • How to debug global values in UDF in a graphical mapping

    Hi Every one,
    I  got a situation in PI where i have to use global values in graphical mapping UDF.
    I can't able to get the values in "Display Queue " option.
    Can you please tell me what is the best way of debugging global variable in graphical mapping UDF.
    1. I declare one array list in the global values
    2. store some values using another UDF to the arraylist.
    3. I am traversing the values in the arraylist, but the values are not showing in "Display Queue".
    What is the solution to this.

    Did you try with trace.addInfo?
    https://help.sap.com/javadocs/NW04/current/pi/com/sap/aii/mapping/api/AbstractTrace.html
    Sample code for the setMail UDF (Carrier B2B) - Business Process Expert - SCN Wiki

  • Performance problem in Mapping Designer using UDF with external imports

    Hello,
    we do have a big performance problem in developing (not in execution) graphical Mappings as far as we use "user defined functions" (UDF) with include-entries referencing to jar files which are imported as "imported archives".
    For example the execution of invice mapping with a little bit bigger test file in the Mapping designer:
    - after opening, not in change mod: 6 seconds
    - after switching to change mod: 37 seconds (that's clear, now everything is compiled first)
    - after adding "com.seeburger.functions.permstore.CounterFactory;" into the "import" field of one UDF, no other change: 227 seconds
    - after saving and submiting the changlist (no longer in change mode): 6 seconds
    - after switching to change mode: 227 seconds
    So execution speed of testing (and also when watching queues) only increases in changemod more then three minutes when using UDF with imports, referencing to external JAR files. It doesn't depend on Seeburger functions (we are using XI also for EDIFACT, so we also use some Seeburger functions), I can reproduce it with any other JAR file which is used from a UDF.
    Using java included functions like "java.text.NumberFormat;" in "Import" doesn't slow down the testing.
    Can anybody reproduce this? We are using XI 3.0 SP19 on a AIX machine, so we also have to use the Java version from IBM.
    cu
    Manfred

    Problem was fixed by a upgrad of the JDK.

  • Performance of an UDF v/s standard graphical mapping functions

    Hello Experts,
    I would like to get your opinion/comments on the performance issues with respect to speed of execution when using graphical functions for doing the date conversion requirement given below:
    Requirement is to convert input date u20182008-12-03u2019 from the source side to u201820081203u2019 on the target side.
    We have used the standard graphical mapping functions 'substring' & 'replacestring' for doing this conversion as explained here: The u2018substringu2018 function is used to capture the part of the string from the source. A u2018constantu2019 with value u2018u2013u2018 is replaced by u2018constantu2019 (empty value) by using the standard text function u2018replaceStringu2019 in the target side.
    We did the same using the following UDF too:
    public String convertDate(String dateStringInOriginalFormat) {
                SimpleDateFormat originalFormatter = new SimpleDateFormat("yyyy-MM-dd");
                SimpleDateFormat newFormatter = new SimpleDateFormat("yyyyMMdd");
                ParsePosition pos = new ParsePosition(0);
                Date dateFromString = originalFormatter.parse(
                            dateStringInOriginalFormat, pos);
                String dateStringInNewFormat = newFormatter.format(dateFromString);
                return dateStringInNewFormat;
    From a critical performance point of view, which approach will fare better?
    Thanks in Advance,
    Earnest A Thomas
    Edited by: Earnest Thomas on Dec 4, 2008 6:54 AM

    Hi,
    Not only in this case but in general it is always better to use the functions available in MM and only if your requirement is not satisfied with the standard mapping functions then go for UDF.
    Also for your requirement no need of going for substring....you can directly use the DateTransform function available.
    Source --> DateTransform --> Target
    Regards,
    Abhishek.
    Edited by: abhishek salvi on Dec 4, 2008 11:25 AM

  • XSLT using Java function from graphical mapping (RFClookup)

    Hi,
    I was wondering if it is possible to use the standard Java functions of the graphical mapping (RFCLookup, Datetrans, ...) or from my own UDF inside an xslt mapping. Does anyone have every tried this or is an example available ?
    Regards Bernd

    Hi Bernd,
    here you can find an example how to use RFC lookup from an XSLT Mapping:
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/05a3d62e-0a01-0010-14bc-adc8efd4ee14?quicklink=index&overridelayout=true
    Is this what you're looking for?
    Regards,
    Gábor

  • Avoid explicit closing tag in XML using graphical mapping

    Hi,
    I created a data type with an element called TAG1 which has an attribute called attr.
    I mapped an empty constant to the element and the value XXX to the attribute.  I`m using graphical mapping and the XML I get is the following:
    <TAG1 attr = u201CXXXu201D></TAG1>
    But for reasons of volume I need to generate the XML without the explicit closing tag, such as:
    <TAG1 value = u201CXXXu201D/>
    Is there any possibility to achieve this with graphical mapping?
    Thanks & Best Regards,
    Viviana

    > But for reasons of volume I need to generate the XML without the explicit closing tag, such as:
    >
    >  <TAG1 value = u201CXXXu201D/>
    >
    > Is there any possibility to achieve this with graphical mapping?
    This is not posible. The graphical mapping always creates start and end tag, even for empty elements.
    You need a seperate mapping step with XSLT or Java mapping.
    Regards
    Stefan

Maybe you are looking for

  • Sales Order (Returns)  for Approval / Reject

    Hi, I have a Sales Order of Credit Only Order type. Existing Custom Workflow When the Customer Service creates Sales Order of Order Type Credit Only, it will got to AR dept for Approval/Reject. If the AR dept rejects, then a Notification will flow to

  • MacBook Pro will not boot, only in safe mode. Tried Everything!

    My MacBook Pro was working fine yesterday. Went to boot it up today, and it freezes on the Apple grey boot screen, will not progress further. It does however start in safe mode, but will not start normally. I've tried everything I can find, reset the

  • How can I choose a font besides Myriad Pro as default when opening existing PDFs in Illustrator?

    I already know how to do this for new documents. But I work with PDFs generated in AutoCAD. When opening these files in Illustrator, the default font is always set to Myriad Pro. How can I substitute my desired font for Myriad when opening EXISTING f

  • Application Deloyment issue...

    hi, i am getting this Deployment error... we got two servers one for developers at offshore and one at the onsite... the strange thing is that it is deploying n running fine on the offshore server. but not getting deployed on the onsite server!!! i h

  • Net inventory on hand after some transports.

    Hi! Suppose I have a sales order such as S0001 that has an item - number 10 - for product MAT1 for 10 items. All of them are produced and placed in warehouse but some of them are delivered , say 3 of them in 2 batches ie. 1 in the first transport , 2