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

Similar Messages

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

  • User defined function for getting last string in the line

    Hi Experts,
    I am not java expert, can anyone give me user defined function for getting last string in the line.
    for example if the source field is "NEW ARBOUR SQUARE"  i want to pass to target field only last string that is "SQUARE"
    please help me out of this.
    Kind Regards.
    Praveen.

    You don't even need a UDF for this. In the graphical editor look for the standard functions and once you do a scroll over on 'text functions; you will find what you are looking for.
    Just a piece of advice, try keeping UDF's to minimum unless really required or it is complicated without it.
    regards

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

  • 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

  • UDF(user defined function) for standard date transformate function,

    Hi All,
    Hope you are doing good !!!
    I have a requirement where i need to write an UDF(user defined function). Please help me in writing the code for below logic-
    I am getting my Input as 111213 where 11 denotes HH 12 denotes mm 13 denotes ss. I need ti insert : between hh:mm:ss
    Please help me achieving a code for below logic
    I have used standard date transformate function, there i am getting spaces as separator in my input resulting an errors i am sending without spaces.
    Regards,
    Vijay Kumar.

    Hello,
    I am getting my Input as 111213 where 11 denotes HH 12 denotes mm 13 denotes ss. I need ti insert : between hh:mm:ss
    Please help me achieving a code for below logic
    I have used standard date transformate function, there i am getting spaces as separator in my input resulting an errors i am sending without spaces.
    What do you mean by spaces? Can you try the mapping below?
    inputDate -> replaceString -> dateTrans(inputDateFormat: HHmmss outputDateFormat: HH:mm:ss) -> target
    Constant: -> /
    Constant:-> /
    Hope this helps,
    Mark

  • User - defined functions for calculating the taxes of state and country

    hi expects,
        how can write user-defined function in message mapping in which i want to calculate the states taxes (2500) and country taxes (5000) and give the result as grand total in output.please help me?

    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.
    Regards
    Seshagiri

  • SQL User Defined Functions for performing statistical calculations

    Hi!
       I hope you can help.  I just wasn’t sure where to go with this question, so I’m hoping you can at least point me in the right direction.
       I’m writing a SQL Server stored procedure that returns information for a facility-wide scorecard-type report.  The row and columns are going to be displayed in a SQL Server Reporting Services report. 
       Each row of information contains “Current Month” and “Previous Month” numbers and a variance column.  Some rows may compare percentages, others whole numbers, others ratios, depending on the metric they’re measuring.  For each row/metric the company has specified whether they want to see a t-test or a chi-squared statistical test to determine whether or not there was a statistically significant difference between the current month and the previous month. 
       My question is this:  Do you know where I can find a set of already-written user defined functions to perform statistical calculations beyond the basic ones provided in SQL Server 2005?  I’m not using Analysis Services, so what I’m looking for are real SQL User Defined Functions where I can just pass my data to the function and have it return the result within a stored procedure. 
       I’m aware that there may be some third-party statistical packages out there we could purchase, but that’s not what I’m looking for.   And I’m not able to do anything like call Excel’s analysis pack functions from within my stored procedure.   I’ve asked.   They won’t let me do that.   I just need to perform the calculation within the stored procedure and return the result.
       Any suggestions?  Is there a site where people are posting their SQL Server UDF’s to perform statistical functions?  Or are you perhaps aware of something like a free add-in for SQL that will add statistical functions to those available in SQL?   I just don’t want to have to write my own t-test function or my own chi-squared function if someone has already done it.
     Thanks for your help in advance!  Oh, and please let me know if this should have been posted in the TSQL forum instead.  I wasn't entirely sure.
    Karen Grube

    STATS_T_TEST_
    docs.oracle.com/cd/B19306_01/server.102/b14200/functions157.htm 
    STATS_T_TEST_ONE: A one-sample t-test
    STATS_T_TEST_PAIRED: A two-sample, paired t-test (also known as a crossed t-test)
    STATS_T_TEST_INDEP: A t-test of two independent groups with the same variance (pooled variances)
    STATS_T_TEST_INDEPU: A t-test of two independent groups with unequal variance (unpooled variances)

  • User defined function for removing wrong data ... !!!

    Hi  Experts,
    I'm having a source data like this
    1001     545     6895895     1584     654     5478
    1002     525     6895895     5084     654     5472
    1003     535     6895895     0584     654     5478
    1004     545     6895895     5184     654     5478     4XXX     &^%%     1004     545
    1005     555     6895895     5824     654     5478     8547     0000     522#     ##00
    1006     565     6895895     5844     654     5478
    1007     575     6895895     5845     654     5478
    1008     585     6895895     5846     654     5478
    Some times I get a wrong data in my source file (above 4 and 5 th rows) .
    My requirement is to remove these kind of wrong lines(entire lines to be removed) whenever XI reads the data. For this what is the standard function i can use in mapping. I thought I can create my own function to remove such kind of false data lines. It would be helpful for me if some body provide me the java code.
    Thanks very much.

    Hi Swarna,
    1001 545 6895895 1584 654 5478
    1002 525 6895895 5084 654 5472
    1003 535 6895895 0584 654 5478
    1004 545 6895895 5184 654 5478 4XXX &^%% 1004 545
    1005 555 6895895 5824 654 5478 8547 0000 522# ##00
    1006 565 6895895 5844 654 5478
    1007 575 6895895 5845 654 5478
    1008 585 6895895 5846 654 5478
    is it the .txt file you are keeping.  Or the input in your mapping.
    You just Tell your requirement properly.
    If it is input in Mapping. Map like this
    input ----->subtring( starting position 0 andNumber of characters 30) ---->Output
    substring is a standard Text function.
    Thanks.

  • Error in User defined function for jdbc lookup

    I am getting th error as follows "Method TestJDBCAPI$ with 2 arguments not found in class com.sap.xi.tf._JLU_MM_" when i a m testing in message mapping

    //write your code here
    String Query = " ";
    Channel channel = null;
    DataBaseAccessor accessor = null;
    DataBaseResult resultSet = null;
    //Build the Query String
    Query = "Select role from login where username = " + username[0] + " and password = " + password[0] ;
    try{
    //Determine a channel as created in the configuration
    channel = LookupService.getChannel("JLU_BUSS","JLU_chan");
    //  Get a system accessor for a channel.As the call is being made to the database an database accessor is obtained.
    accessor = LookupService.getDataBaseAccessor(channel);
    // Execute the Query and get the values in the resultSet.
    resultSet = accessor.execute(Query);
    for(Iterator rows = resultSet.getRows();rows.hasNext();)
    Map rowMap = (Map)rows.next();
    result.addValue((String)rowMap.get("role"));
    catch(Exception ex){
    result.addValue(ex.getMessage());
    Above is my udf.My logic is that for the given username and password it should select the corresponding role from the database.

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

  • User define function for SQL Server

    Hi all,
    it's possible to write an UDF for SQL Server in Java?
    I know that it is possible with DB2 and Oracle.
    My main goal is to write an UDF that works well with all of these DB.
    Thank's

    Hi all,
    it's possible to write an UDF for SQL Server in
    Java?Okay, JDBC can talk to any database (given you have a driver implementation). Also, JDBC is like a conduit. So the real question is likely, will your database let you do this?
    I know that it is possible with DB2 and Oracle.
    My main goal is to write an UDF that works well with
    all of these DB.I also don't know what a UDF is, but if you ARE talking about stored procedures, then no, it's not possible. All databases are different. On that note, I typically recommend NEVER using stored procedures unless absolutely necessary.
    But it also sounds like you want to do this at runtime. I've seen systems that do this (bind stored procs at runtime dynamically) and it's a freakin nightmare! So be careful.

  • 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

Maybe you are looking for