User defined function in java for message mapping

I wrote the following user defined function in java for message mapping and mapped vendor with this. The aim of this function is to write a error file at defined path when i send empty Vendor value from File to RFC-Function module BAPI_PO_CREATE. The "err.txt" error file is not written when i execute in TEST but the value "ERROR" is returned to destination Vendor Field.
public String  validation(String a, Container container) {
//write your code here
if (a.equals("")) {
try {
String source = "Vendor cannot be empty";
char buffer[] = new char[source.length()];
source.getChars(0, source.length(), buffer, 0);
for (int i = 0; i < buffer.length; i +=2)
   f0.write(buffer<i>);
f0.close();
FileWriter f1 =  new FileWriter("/10.10.0.55/sapmnt/trans/edixiin/err.txt");
f1.write(buffer);
f1.close();
catch (IOException e) {}
return "ERROR";

Hi Senthil,
Check these things :
1) Whether you have permission to create a file in that directory.
2) try giving this 
10.10.0.55
sapmnt
trans
edixiin
err.txt
3) Also check for permissions.
Hope this will help you.
Regards
Suraj

Similar Messages

  • Logic for user defined function in java language.

    Hi Guys,
    I want to use a "&" function in below code & include vafrdate.substring(130,132).equals("01").
    if ( delperiod.substring(4,6).equals("01") )
    Need your help to include & function in java code.
    In layman language , i need,
    if ( delperiod.substring(4,6).equals("01")  & (vafrdate.substring(130,132).equals("01"))
    pls help me to do it in java language.

    Santosh,
    Use this -
    if ( delperiod.substring(4,6).equals("01")  && vafrdate.substring(130,132).equals("01"))
    Regards,
    Neetesh

  • Need help with user defined function

    Hello SDN,
    I need some help with a user-defined function. My source message contains multiple
    generic records (1000 char string), and my target message is 1 header record,
    then multiple generic records.  See description of source and target messages below:
    Source:
      GenericRecordTable 1..unbounded
        Row (1000 char string)
    Target:
      Field1 (char5)
      Field2 (char5)
      Field3 (char5)
      IT_Data
        GenericRecordTable 1..unbounded
          Row (1000 char string)
    Basically, what I need to do in my user defined funtion is to map the first record
    in my source record to the 3 header fields, then map all of the rest of the records
    (starting from line 2) into the GenericRecordTable.
    Can someone please help me with the code for the user defined function(s) for this
    mapping?
    Thank you.

    hi,
    Activities
    1. To create a new user-defined function, in the data-flow editor, choose Create New Function (This
    graphic is explained in the accompanying text), which is located on the lower left-hand side of the
    screen. In the menu, choose Simple Function or Advanced Function.
    2. In the window that appears, specify the attributes of the new function:
    Name
    Technical name of the function. The name is displayed in the function chooser and on the data-flow
    object.
    Description
    Description of how the function is used.
    Cache
    Function type (see above)
    Argument Count
    In this table, you specify the number of input values the function can process, and name them. All
    functions are of type String.
    3. In the window that appears, you can create Java source code:
    a. You can import Java packages to your methods from the Imports input field, by specifying them
    separated by a comma or semi-colon:
    You do not need to import the packages java.lang., java.util., java.io., and java.lang.reflect. since
    all message mappings require these packages and therefore import them. You should be able to
    access standard JDK and J2EE packages of the SAP Web Application Server by simply specifying the
    package under Import. In other words, you do not have to import it as an archive into the Integration
    Repository. You can also access classes of the SAP XML Toolkit, the SAP Java Connector, and the
    SAP Logging Service (see also: Runtime Environment (Java-Mappings)).
    In addition to the standard packages, you can also specify Java packages that you have imported as
    archives and that are located in the same, or in an underlying software component version as the
    message mapping.
    b. Create your Java source text in the editor window or copy source text from another editor.
    4. Confirm with Save and Close.
    5. User-defined functions are limited to the message mapping in which you created the function. To
    save the new function, save the message mapping.
    6. To test the function, use the test environment.
    The new function is now visible in the User-Defined function category. When you select this category,
    a corresponding button is displayed in the function chooser pushbutton bar. To edit, delete, or add the
    function to the data-flow editor, choose the arrow next to the button and select from the list box
    displayed.
    http://help.sap.com/saphelp_nw04/helpdata/en/d9/718e40496f6f1de10000000a1550b0/content.htm
    http://java.sun.com/j2se/1.5.0/docs/api/
    /people/krishna.moorthyp/blog/2006/07/29/documentation-html-editor-in-xi
    /people/sap.user72/blog/2006/02/06/xi-mapping-tool-exports
    http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm
    UDF -
    http://help.sap.com/saphelp_nw04/helpdata/en/22/e127f28b572243b4324879c6bf05a0/content.htm
    Regards

  • InvocationTargetException in User Defined Function in Oracle CEP

    I was trying to use a UDF in my CQL query. But I got the following error:
    An InvocationTargetException was encountered while attempting to register the user defined function
    "mymod".  The message was: null
    My code snippet is bellow:
    Bean:
    package com.bea.wlevs.example.function;
    import com.bea.wlevs.oracle.ci.event.CiMessages;
    public class UpdateMessage  {
        public CiMessages addChannel(CiMessages cm, String channel){
            System.out.println("I am in function");
            cm.setChannel(channel);
            return cm;
    config.xml:
    <processor>
    <name>CiRuleEngine</name>
    <rules>
    <query id="filterRule"> <![CDATA[ select addChannel(*,"SMSData") from DCInputChannel[now] as dc ]]> </query>
    </rules>
        </processor>
    content.xml:
    <wlevs:processor id="CiRuleEngine">
    <wlevs:listener ref="IntermediateChannel" />
    <wlevs:function function-name="mymod" exec-method="addCHannel">
    <bean class="com.bea.wlevs.example.function.UpdateMessage"/>
    </wlevs:function>
        </wlevs:processor>
    Can any one help me to resolve this error?

    The asterisk * in invocation addChannel(*,"SMSData") does not mean the event object. This is the cause of the exception.
    For your case, it's much easier to implement a userbean to do the insertion of the channel.
    Thanks
    Junger

  • How to apply dll file or user defined function in B1

    Dear all,
    I have dll file and user defined function which use for converting number amount to text of my language. I plan to create UDF to keep the result of function on A/R invoice and I will use this UDF on print layout desiner but I don't know how to apply my function on B1. Please kindly suggest.
    Thanks you in advanced.
    Angnam

    Hi Angnam,
    Check this link.
    Re: amount in words
    Thanks,
    Srujal Patel

  • Java user-defined function for mapping a complex structure

    All,
    Hope one of you can help me with this. I have a structure with over 15 fields and would like to concatenate all the fields into one target field and while I do this, I need to ensure that each field is padded with blanks as defined the data type. Can one of tell me if this is possible with a java user-defined function and if so, what type of logic is needed.
    Input_MT
    Field_1  string len=10 "need"
    Field_2  string len=6 "java"
    Field_3  string len=7 "help"
    Field_4  string len=8  "asap"
    etc,
    Output_MT 
    DataOut string  "need      java  help   asap    "
    (for some reason the exact spaces in between the words disappear in my Preview message)
    I have several fields in the input mt and therefore I find graphical mapping using concatenate and my own user defined function padWithSpace too messy.
    Thank you for you help.

    Hi,
    If your final req is to write all these fields next each other in a file, you can configure this in receiver file adapter by specifying the fixed length for each field.
    If you want the padded string as your MM o/p, you can create a simple user defined funtion with 15 fields as input and 15 constants for their lengths, and find out the length of the each string and pad it with required no of spaces.
    int max_len = 10;
    int actual_len;
    actual_len = a.lengh();
    for(int i=0; i < (max_len-actual_len; i++)
    a = a.append(" ");
    return a;
    praveen

  • Need user define function for the message  mapping structure

    Hi All
    I am new to XI.I need the java code for Udf for the following structure.
    i have two input and one out put as error.
    order_nos----
    user define function-------error message
    order_details----
    num of orders---- i.e. 10
    order_details------ i.e. whole order records details
    1.i have to compare the 1st  input with 2nd one means if the ist input contain 10 means there are 10 orders in 2nd input.if not then i have to give error message .
    2.then i have to check the fields in 2nd input has no null values.if no values the output will be error message.
    Edited by: Rohit Kumar on Dec 18, 2008 4:43 PM

    Hi Sudhir
    thanks for your continues help.i need some help so that i can fulfill my requirmrnt
    this is my message mapping xml.
    <?xml version="1.0" encoding="UTF-8" ?>
    - <ns0:methodCall_MT xmlns:ns0="http://www.dfdsf">
      <num_orders>10</num_orders>
      <test_mode />
    - <order_x>                        ( which is order details)
      <order_id>t78tyu8t</order_id>
      <order_date />
      <mfg_id />
      <catalog_id />
      <first_name />
      <last_name />
      <recipient />
      <message />
      <address1 />
      <address2 />
      <address3 />
      <city />
      <state />
      <zip />
      <country />
      <country_code />
      <phone />
      <subtotal />
      <tax />
      <shipping />
      <total />
      <shopatron_total />
      <fulfiller_total />
      <shipment_id />
    - <additional_info>
      <in_store_pickup />
    - <express_shipping>
      <express_shipping_flag />
      <express_shipping_text />
      <express_shipping_arrival />
      </express_shipping>
      </additional_info>
    - <discount>
      <discount_description />
      <discount_percentage />
      <discount_total />
      </discount>
      <lang_id />
      <currency_id />
      <packing_list />
      <num_items />
    - <items>
      <item_id />
      <quantity />
      <price />
      <part_number />
      <fulfiller_total />
      <shopatron_total />
    - <options>
      <option_x />
      </options>
      </items>
      </order_x>
      </ns0:methodCall_MT>
    this my mapping where under one element number elements are there.when i am excuting the code to check the null value its always giving the there is null val but i have filled evrything.its due to first its checking the order_x and which will be always null.uder this all data will be filled.please suggest what to change in the udf.the code  given by u is working fine but its failing in this scenario because it getting the parent filed is null.

  • Message Mapping (user-defined function)

    Hi all,
    Is there anyway to determine the XML message ID using an user-defined function in Message Mapping? When I go to SXI_MONITOR I see that all messages have an unique ID, but I'm having some difficulties to understand if there is any way to get that ID in a message mapping and pass it to a target structure? I see that it is possible to use constants like "Sender" and "Receiver", but I haven't found anything for the message ID.
    Can you please help me?
    Thanks in advance.
    Regards,
    Ricardo Inácio

    Try this code..
    Create an UDF and do not pass any arguments to it..
    java.util.Map map;
    // get runtime constant map
    map = container.getTransformationParameters();
    // get value of header field by using variable key
    String msgid = (String) map.get(StreamTransformationConstants.MESSAGE_ID);
    return msgid;
    Now map this udf to your target field. Now test it....
    P.s. Since message id is run time property therefore in mapping test tab it will not work. Try it at runtime.
    Regards,
    Sarvesh

  • Making a User Defined Function for Mapping in XI

    Hi folks..
    I knw how to make User defined Function in XI,
    i was wondering about can we have any room for making a function for Initializing Purpose, which intializes few fields in source Message to some Global variables, and later we can use these Global Variables to set the the Target field
    My Doubt is this...
    i have Source & target Structure like this Structure like this....
    SOURCE  TEST DATA IS... 
    Parentsrc                   
        child1src a              
        child2src b              
        child3src c                     
        child4src hi
        child4src hello
        child4src hey            
    (On the basis of instances of child4src the istance of the Parentdst will be generated)                                        
    TARGET DATA SHUD BE LIKE THIS....
    Parentdst                    
        child1dst a              
        child2dst b              
        child3dst c                     
        child4dst hi
    Parentdst                     
        child1dst a              
        child2dst b              
        child3dst c                     
        child4dst hello
    Parentdst                     
        child1dst a              
        child2dst b              
        child3dst c                     
        child4dst hey

    Hi
    You have to modify  your target structure:
    <b>Source</b>
    Parentsrc
    child1src a
    child2src b
    child3src c
    child4src hi
    child4src hello
    child4src hey
    <b>Target</b>
    <b>root</b>
    Parentdst
    child1dst a
    child2dst b
    child3dst c
    child4dst hi
    Parentdst
    child1dst a
    child2dst b
    child3dst c
    child4dst hello
    Parentdst
    child1dst a
    child2dst b
    child3dst c
    child4dst hey
    <b></root></b>
    Now map like this:
    child4src -
    Parentdst
    child1src--|
    child4src--| UseOneAsMany -- Splitbyvalue --- child1dst
    child4src--|
    child2src--|
    child4src--|UseOneAsMany --Splitbyvalue --- child2dst
    child4src--|
    child3src--|
    child4src--| UseOneAsMany -- Splitbyvalue --- child3dst
    child4src--|
    child4src -- SplitbyValue -- child4src.
    Regards
    Suraj

  • User Defined Function is not recognizing java class in IR.

    Hi All,
    i have written one normal java class, and i imported that java class into IR using imported Archive as a .jar file,
    it will add just two values .
    now in message mapping i created one user defined function in that
    iam trying to call this java class. while testing it is showing error as cannot resolve symbol java class name
    so experts please help me in this or it would be appreciate if any one will provide
    step by step process of one java class and one USD just to add two numbers.
    thanks in advance,
    jasmine .

    Hi,
    The steps are as follows:
    1) Create a java file with .java extension.
    2)Compile it to create a .class file.
    3) Create a zip file for this .class file using any compressed archive program(ex-winrar)
    4) Upload this zip file as an imported archive ,save and activate.
    When you go to this archive,below , you can see your .class file with the older path,for below ex:
    ObjRecord.class     jxl/biff/drawing/
    you have to give following entry in imports section:
    jxl.biff.drawing.ObjRecord;
    Please try this and let us know if this works.
    Thanks.
    Regards,
    Shweta

  • Error in User defined function for dynamic file naming

    Hi,
    While creating User Defined function with this following code for dynamic fieldname
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    String ourSourceFileName = conf.get(key);
    return ourSourceFileName;
    which options should i select for cache Value, Context, Queue
    for Augument , what name shd i mention.
    Regards,
    Varun

    Hi Varun,
    I guess I have answered a similar question just a few minutes before on very similar post from you. Just pasting the same here .................
    Are you trying to access the ASMA values from the SOAP header of the XI message for the source file name?
    First of all you need to Set the Sender File Adapter for Set ASMA and then file name. So it will work fine when you actually run the scenario end to end.
    But in the mapping tool when you test the mapping - there is not message header updated with the actual source filename - and whenever you try to read the FileName attribute in the message header from the UDF - it cannot find the object and returns a NullPointerException.
    I would suuggest for your mapping tool testing to be successful, have a check in the java code for null values,
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    String ourSourceFileName = conf.get(key);
    If (ourSourceFileName != null)
       Return ourSourceFileName;
    Return "NoFileName.txt";
    Let us know if this works.
    Regards,
    Suddha

  • Error in conditional map using User Defined Function

    All,
    In my mapping I basically have a user defined function that returns the filename of my inbound file from the adapter-specific message attributes (file adapter).  I know this is coded properly because if I simply assign this function to my destination field I can see the filename in the payload XML.
    However if I conditionally check that returned value using if,then,else I get an error message stating:
    "During the application mapping com/sap/xi/tf/_MaterialData2ZcustProdMastMulti_ a com.sap.aii.utilxi.misc.api.BaseRuntimeException was thrown: RuntimeException in Message-Mapping transformation"
    Essentially in my if I'm checking if the value returned by my user defined function is equal to the constant "SOMECONSTANT" then I'm setting my destination field to some other constant value.  Otherwise it's equal to a different constant value.
    Any thoughts?

    Claus,
    Thanks for the help.  I actually had figured the problem out on my own.  Sorry for not updating the thread sooner.  What happened was this (as I suspected it wasn't related to my user defined function).  For the newbies out there (of which I'm one) the problem was I was comparing strings in the graphical mapping tool using the Boolean "EQUALS" rather than the Text "EQUALSS".
    Can you give yourself points for solving

  • User defined function during Mapping.

    Hi,
    I am trying to retrieve filename using user defined function.
    The payload is simple.
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:FTPTOFTP_MT_OB xmlns:ns0="urn://ftptoftp.com">
       <RECORD>
          <ROW>
             <EMPNO>723</EMPNO>
             <NAME>Jack</NAME>
          </ROW>
       </RECORD>
    </ns0:FTPTOFTP_MT_OB>
    the code for user defined function is
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    String ourSourceFileName = conf.get(key);
    return  ourSourceFileName; 
    now during message mapping ...
    do I have to have extra xml tag in the destination
    message which is now having
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:FTPTOFTP_MT_IB xmlns:ns0="urn://ftptoftp.com">
       <RECORD>
          <ROW>
             <EMPNO>723</EMPNO>
             <NAME>Jack</NAME>
          </ROW>
       </RECORD>
    </ns0:FTPTOFTP_MT_IB>.
    If yes ...
    Then how to graphically map this extra xml tag.

    Hi Deepak,
    If u want to display the source file name in ur output, then ur output XML structure there should be an extra tag for displaying the file name.
    In message mapping, select the user defined function which u have already created and map it to the tag for storing the file name in the target message XML format.
    There is a editor present to write the user defined function on the bottom left corner of the message mapping screen.
    For this function u need to select the Simple Function Tab.
    Regards
    Neetu

  • User-defined function in message mappings

    Hi experts,
    I'm a senior c++ programmer, but I never write program by abap/java.
    I want to create a user-defined function for mapping. Who can give me some instruction?
    Many thanks.

    SDN can. A simple search on SDN could provide you the steps and code as well. Try a search and come up with more specific doubts. I am sure most of the doubts would be gone.
    Regards,
    Prateek

  • User-defined function(java)

    hi expects,
    how to write user defined finction in javain meesage mapping.please help me.

    Hi Rohit,
    In order to create UDFs, you need to have a basic idea about using Core Java. Also, based on the kind of functonality of the code, you will need to know if you require any extra jar files.
    To create a UDF, all you need to do is click on LHS icon in the graphical mapping editor. Also, keep in min that the input and otput of a udf is always in strings.
    To test your functions, you can either use the test tab present in the mapping editor or you can even use the following editor(blog by Sravya):-
    /people/sravya.talanki2/blog/2006/07/24/integrating-java-editor-in-xi-integration-stack
    I think info will be enough for you to start off with creating and using UDFs:)
    This link for User Defined Functions,
    http://help.sap.com/saphelp_nw04/helpdata/en/d9/718e40496f6f1de10000000a1550b0/content.htm
    Writing use defrined functions in XI is quite simple. Create a simple UDF, give the import parameters and then just go ahead with the logic coding and then return the output from the UDF.
    Just remember that all inputs and outputs to an UDF are always Strings.
    Cheers...
    Vasu
    <b>** REward Points if found useful **</b>

Maybe you are looking for

  • HT204364 How do I purchase more than one card at a time?

    I can't figure out how to buy several cards at once without paying for shipping multiple times? Thanks

  • Flash drive for Macbook?

    Really want to install one these in my Macbook once I can soucre one, does anyone know if it would fit ok.? http://www.tomshardware.co.uk/2007/03/13/sandisk25_32gbssd/ MacBook White 2GHz   Mac OS X (10.4.8)  

  • Decimal Notation IDR Currency on SAP Fiori

    Dear Expert, I had trouble with decimal notation on SAP Fiori. While I look My Spend on SAP Fiori, amount is different in ECC SAP with decimal notation. In SAP Fiori : 98.130 IDR In ECC SAP : 9.813.000 IDR That's different on SAP Fiori and ECC SAP. I

  • Iphone will not sync with my laptop

    Hi I have an Iphone 3g and macbook laptop. Recently my iphone has no longer been able to connect to my computer. This problem is specific to my laptop and specific to my phone in regards to the USB ports as they are in working order and when connecte

  • Manage Access to Named Credentials via EMCLI

    Hi Colleagues, does anyone know how to manage access to Named Credentials via EMCLI or does anyone know if this function exist in EMCLI. We want to configure the access via scripts, so that we can for example grant access for all database administrat