User define Function at Mapping Time

Hello Everyone,
My requirement is I input the one value to the user define function (at mapping time). That function calls the RFC to R/3 system and return the 3 output values. Now my question is how can I return 3-output value from the user define function.
What is the other possibility to solve this type of problem?
Where we have one input parameter and more than one output parameter.
If any one did this kind of job. Please give me the idea how can I solve this.
Regards,
Gaurav Jain

Hello Richard,
Are you talking about <b>copy head to line</b> example given in MappingFunctionality.pdf.
In my scenario:
Input - NULL
Output - OP1, OP2, RESULT
And I write my Advance user define function as
import com.sap.mw.jco.*;
public void Lookupfunction(ResultList result, Container container){
JCO.Repository mRepository;
// Change the logon information to your own system/user
JCO.Client mConnection = JCO.createClient(
    "100", // SAP client
    "user", // userid
    "pass", // password
    "EN", // language
    "hostid", // host name
    "00" ); // system number
// connect to SAP
mConnection.connect();
// create repository
mRepository = new JCO.Repository( "SAPLookup", mConnection );
// Create function
JCO.Function function = null;
IFunctionTemplate ft = mRepository.getFunctionTemplate("ZTEST2");
function = ft.getFunction();
mConnection.execute( function );
result.addValue( function.getExportParameterList().getString( "OP1" ) );
result.addValue(function.getExportParameterList().getString( "OP2" ) );
result.addValue(function.getExportParameterList().getString( "RESULT" ) );
mConnection.disconnect();
But it shows me only one field as output in mapping icon.
so as per the mapping document i attach splitbyvalue over that but in the example only one field at the output side where i have three field.
How can i solve the problem?
Even i check in XI 2.0 System it doesn't show output at all.
Thanks & Regards,
Gaurav Jain
Message was edited by: Gaurav Jain

Similar Messages

  • 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

  • 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

  • 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

  • User define functions in Mapping - Need help...

    I have the following Source structure
    <root> (1...Unbounded)
      <field1>
      <field2>
      <field3>
    </root>
    and need to map this in
      <target>
          <fields1>
          <struct1>
             <field2>
           </struct1>
          <struct1>
             <field3>
          </struct1>
        </target>
    i.e i need to create twice the struct1 one for each field (field2, field3) no matter how many rows I have...
    Example:
    <row>
       <f1>1.1
       <f2>1.2
       <f3>1.3
    </row>
    <row>
       <f1>2.1
       <f2>2.2
       <f3>2.3>
    </row>
    should result:
      <target>
           <f1>1.1
           <struct1>
               <f>1.2
           </struct1>
           <struct1>
              <f>1.3</f>
           </struct1>
      </target>
    Please advide

    Thanks for the answer. But the problem is that the target structure is a standard IDOC and can not be change to be more exact:
    The target message has two fields
    <row>
       GIDate
       DocDate
    </row>
    and need to create two segments of the idoc  SHP_IBDLV_CONFIRM_DECENTRAL.SHP_IBDLV_CONFIRM_DECENTRAL02
    for segment E1BPDLVDEADLN where TIMETYPE and TIMESTAMP_UTC changes based on the two flat fields of the row structure:
    e.g.
    if I have
    <row>
      <deliveryNo>1111111111
      <GIdate>20070909</gidate>
      <DocDate>20071010</DocDate>
    </row>
    in the Idoc I neew to have
    <E1BPDLVDEADLN>
    <DELIV_NUM>1111111111
    <TIMETYPE>WSHDRWADTI
       <TIMESTAMP_UTC>20070909
    </E1BPDLVDEADLN>
    <E1BPDLVDEADLN>
      <DELIV_NUM>1111111111
      <TIMETYPE>WSHDRLFDAT
       <TIMESTAMP_UTC>20071010
    </E1BPDLVDEADLN>
    I hope this is more clear...

  • How to migrate User Define Function to another mapping in other namespace

    Hi Everybody
    I have define many User Define Functions in mapping
    How can i use them in other mapping
    Thank you in advance

    Hi,
    I tried to explain the steps.
    1. Take the JAVA code of your User-Defined Functions
    2. Go to a JAVA editor (e.g NWDS, Eclipse, etc...)
    2.1. create a Java project
    2.2. create a Java class
    2.3. inside your Java class, put each JAVA code of your User-Defined Function inside a Method
    2.4. Export your Java class to a JAR file (e.g my_tools.jar)
    3. Go to IR
    3.1 create an Imported Archive (IA) and upload your JAR file.
    3.2 in this IA, you see your Java class which contains all your methods.
    4. inside your mapping,
    4.1 create a User-Defined Function <u>and import</u> your class
    4.2 use your method.
    So, you define in only one place your code (thanks to a IA) and you will be able to use it inside several mappings.
    I hope I don't forget steps...
    Advantage: if tomorrow, you want to create a new function, just add a new method to your Java class and re-import your JAR file
    Oh, I missed: your IA must be created inside a specific Software Component (SC__TOOLS) and this one must be linked with the others by a "Usage dependency", else your IA will be recognise only in one Software Component (and maybe only in one namespace)
    Mickael

  • User-defined function in FILTER clause

    hi,
    can i create the user-defined functions and use them in the FILTER clause in the sem_match function? there are some built-in functions for the FILTER clasue. however, only one function (DATATYPE(literal)) support for date/time in the built-in functions. i want to implement some user-defined funcitons in the FILTER clause which can check time intervals in ontology. there are some functions about valid time in the WorkSpace Manager such as WM_OVERLAPS, WM_CONTAINS,WM_MEETS, etc. so, can i write some functions using the these valid time functions in WM and use them in the FILTER clause? thanks a lot in advance.
    hong

    Hi Hong,
    You don't need user-defined functions to do time interval comparisons. You can directly compare xsd:dateTime values with the built-in comparison operators: <, >, =, !=, <=, >=
    For example, the query pattern below could find events that happened during event1 if we have data such as:
    :event1 :startTime "2013-01-01T03:15:00Z"^^xsd:dateTime .
    :event1 :endTime "2013-02-01T02:15:00Z"^^xsd:dateTime .
    :event2 :startTime "2013-01-11T14:15:00Z"^^xsd:dateTime .
    :event2 :startTime "2013-01-14T12:15:00Z"^^xsd:dateTime .
    SELECT ?e2
    WHERE
    { :event1 :startTime ?e1_st; :endTime ?e1_et .
    ?e2 :startTime ?e2_st; endTime ?e2_et .
    FILTER (?e1_st < ?e2_st && ?e2_et < ?e1_et) }
    In general, it is trivial to convert interval relations such as meets and overlaps to conditions on start and end times.
    Hope this helps.
    - Matt

  • 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

  • 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

  • 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 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

  • Multi mapping question using user defined function

    Hi,
    I have a message with multiple occuring nodes (i.e. one message with multiple orders (header + detail)) that I need to map to a idoc. I need to filter out of the source based on order type (in header) from creating an idoc.. How do I do it using user defined function + message mappping ?
    mad

    All - Thanks much.. Here is my requirement that is no solved by regular mapping
    <Root>
    <Recordset>
      <Ordheader>
        <ord>
        <ord_type>
      </Ordheader>
       <Ord_line>
         <ord>
         <Linnum>
       </Ord_line>
      </Recordset>
    <Recordset>
      <Ordheader>
        <ord>
        <ord_type>
      </Ordheader>
       <Ord_line>
         <ord>
         <Linnum>
       </Ord_line>
    </Recordset>
    <Root>
    As you see above, each recordset has order transaction. One Root message can contain multiple of these. So, when I map to the IDOC, I want to filter out any ord_type <> XX.
    If I use regular graphical map, it only looks at first recordset and accepts all or rejects all.
    I need to use UDF. In the UDF, what comes in as input ? Resultset is output -correct ? Now how do I usse graphical mapping with UDF to generate the correct target info

  • Help in Mapping: User defined function

    Hi All, I need your help in doing the following mapping:
    The source contains the below fields:
    Source_MT -- Under this          1...1
       LineItem                                 1...Unbounded
         CompanyCode          1..1
         Amount               1..1
       SubTotal                               1...Unbounded
         CompanyCode          1...1
         Amount               1...1
    And the Target strunture should be:
    Target_MT -- Under this
       Target                               1...unbounded
         CompanyCode          1...1
         AmountMatched          1...1
    There will be multiple line items in the source for each compony code which I need to loop through and add the amounts. For a company code, The sum of the amounts in the line items should match with the amount in the Subtotal/Amount.
    For each company code, a target should be created with the result whther the amounts were matched or not.
    Below is the data example:
    Source:
    Line Item :
         CompanyCode          Amount
         ABC               5
         ABC               5
         XYZ               10
         ABC               7     
         XYZ               6
    Sub Total :
         CompanyCode          Amount
         ABC               17
         XYZ               5
    Target should be:
    CompanyCOde          Amount
    ABC               Matched
    XYZ               Not Matched
    Hope I am clear with my requirement. Please let me know if you need more clarity.
    I was able to create mapping, if the line items contains single company code. Need help with multiple company codes.
    Any help would be appreciated.
    Edited by: GP on Jan 29, 2008 5:55 PM
    Edited by: GP on Jan 29, 2008 5:57 PM

    I am still working on the same map (please refer above) for which you gave th3e solution. The solution almost worked.
    I need to validate the line items with the subtotals. If the validation fails, I should throw an custom exception. If the validation is successful, then do nothing (do not create the target element).
    Hope I am clear. Please let me know if I am not clear.
    LineItem1: 10
    LineItem2: 20
    SubTotal1: 30
    LineItem3: 5
    LineItem4: 5
    SubTotal2: 15
    In the above example, eventhough LineItem1 and LineItem2 sum up to Subtotal1,  LineItem3 and LineItem4 doesn't sum up to SubTotal2. So it should throw an exception because second validation failed.
    Also, it should not create target element because first validation was successful.
    I used the logic int he below link :
    [http://www.flickr.com/photo_zoom.gne?id=2229287904&size=o]
    In the "else" part of "If else" statement, I have a user defined function which throws exception.
    If the output is "true", I am avoiding creating the target element using "Createif" statement.
    But strangely, when the vaildation of first set fails (LineItem1, LineItem2 and Subtotal1), then it is throwing the exception.
    But when the validation of second set fails, then it is not throwing the exception.
    My current map looks like below:
    [http://www.flickr.com/photos/23389577@N02/2234471441/sizes/l/]
    Edited by: GP on Feb 1, 2008 6:46 PM
    Edited by: GP on Feb 1, 2008 6:50 PM
    Edited by: GP on Feb 1, 2008 7:01 PM

  • 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.

  • User-Defined Function and Context Manipulation

    Hi Mapping Gurus, I need your help.
    I have a user-defined function and one of my input parameter (c) is in a loop (EDI segment).  So one, if I execute my function I get:
    Exception:[java.lang.ArrayIndexOutOfBoundsException: 0]
    If I change the context or use the remove context node function it’s working but it’s always taking the first row in consideration since I'm using c[0] .  Here is the logic:
    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[0]"'";
    So since c is an array [], I have tried different logic to get to the right row.
    1- I tried using another parameter (e) to pass a counter or an index to my function.  So each time it's looping, it's passing a new value to the function but I’m still getting the first row and I’m not to sure why?
    int G = Integer.parseInt(e[0]);  // e[] = My counter field
    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";
    2- I tried using a parameter stored in the container:
    String Num;
    Num = (String)getParameter(“counter”);
    if (Num == null)  G = 0;
    else
    G = Integer.parseInt(Num);
    G = G + 1;
    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";
    Num = "" + G;
    setParameter(e[0], Num);
    and I’m still getting the first one, look like it’s using a different container each time it’s looping so the Value is always the same?
    4- I created a new user-defined function with the container logic, then it’s working but I’m back to the same problem in my main function, it’s only looking at e[0] for my counter all the time.
    5- I tried using the Seeburger Java Variables and guess what in the main fonction, as new UDF,... and guess what, same result!
    So anybody out there that was able to get UDF's working into a multiple context scenario?
    Am I missing something?
    I will reward points and beer for any help!

    This is one of the text with passing a counter to the function to try to go to the right row in the array since I'm doing a remove context and I'm getting all the d_234's:
    public void ReadTable(String[] a,String[] b,String[] c,String[] d,String[] e,ResultList result,Container container){
    int G = Integer.parseInt(e[0]); // My counter
    String var;
    String DBTABLE = a[0];
    String lookUpField = d[0];
    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";
    Now this one was with the internal container logic:
    int G;
    String DBTABLE = a[0];
    String lookUpField = d[0];
    String Num;
    Num = (String)getParameter(e[0]);
    if (Num == null)  G = 0;
    else
    G = Integer.parseInt(Num);
    G = G + 1;
    Num = "" + G;
    setParameter(e[0], Num);
    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";
    And now with the Seeburger Variables:
    int G;
    try {
    VariableBean be=VariableFactory.getVariableInstance("");
    G = Integer.parseInt(String.valueOf(be.getStringVariable("yves")));
    } catch (Exception f) {
    throw new RuntimeException(f);
    String DBTABLE = a[0];
    String lookUpField = d[0];
    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";
    try {
    G = G + 1;
    Num = "" + G;
    VariableBean be=VariableFactory.getVariableInstance("");
    be.setStringVariable("yves",Num);
    catch (Exception f) {
    throw new RuntimeException(f);
    All 3 logics were returning always the first row or a counter of 1 if the logic is in the main ReadTable function.

Maybe you are looking for