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
Similar Messages
-
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ácioTry 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 -
Dear experts,
the following funktion has 3 inputs an one output. It shall forward input 3 if input 2 is found in input 1.
public void take3IfFound2In1(String[] a, String[] b, String[] c, ResultList result, Container container) throws StreamTransformationException{
for ( int i = 0; i < a.length; i++ )
if(a<i>.equals(b[0])) {
result.addValue(c<i>);
else {
result.addSuppress();
So far it is working, but I am not able to put a CopyValue behind. Why not? I need the output undefined times. Please help.Hello,
The boolean function ifWithoutElse function would almost do the same thing as the UDF you've written since you are comparing the contents of array a to a constant b[0] and then outputting the contents of c[]. Since it is not possible to use copyValue for suppressed values, you can try this approach:
1. Use spaces first
2. Do your copy value
3. Suppress the spaces using another UDF
Hope this helps, -
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 -
How to deploy jar file for use within mapping user-defined fcn
Hi all,
I have a java class I'd like to called from a mapping user-defined function.
Here's what I've done (but hasn't worked)
1. Added 'package com.<mycompany>.xi.util.base64 to the source class file and compiled it.
2. Created a sda with a plain provider.xml file, i.e. no references were made to any other library files.
3. Deployed the sda to the xi 3.0 j2ee server successfully using SDM.
4. Under the Visual Admin tool, I see that the library was deployed successfully.
5. In the import text box in the user-defined function (design time), I enter com.<mycompany>.xi.util.base64.*.
A syntax check returns an error indicating the package could not be found.
Can anyone give me pointers as to how I can get this working?
Thanks,
--jtbHey James,
No! That's not the right way!
What you have done is for accessing external JMS & JDBC drivers in their corresponding adapters. For the access inside a mapping user defined function, it's enough if you import the jar files.
Look at this blog and you will be very clear!
/people/divya.vidyanandanprabhu/blog/2005/06/28/converting-xml-to-pdf-using-xi
regards,
Felix -
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 -
XSLT Mapping - user defined Extension function
Hi to all,
can somebody helps me, please?
I need an own function, that can be used by the XSL Mapper. First I have only tried the sample given in Path <BPELPM>\integration\orabpel\samples\demos\XSLMapper\ExtensionFunctions
There is a java file with the defined functions and a xml file with the definition of this function for the mapper and last but not least a jar-file with the java class.
I have copied the jar to <JDEV_HOME>\jdev\lib\ext directory and in JDeveloper I have added SampleExtensionFunctions.xml to Tools->Preferences->XSL Map -> "User Defined Extension Functions Config File" field. After a restart of JDeveloper I find 2 new functions in the "User Defined Extension Functions" component palette page when a XSL Map is open. That's fine.
But if I test the mapping I get an error: "Failed to transform source XML.
java.lang.NoSuchMethodException: For extension function, could not find method org.apache.xpath.objects.XNodeSet.replaceChar([ExpressionCotext,]#STRING, #STRING)."
What is wrong?
Thanks in advance of your answer
best regard,
unoOracle XML support Extension function.
For example:
If we would like to import FAQDBUri.class with user-defined java functions, like TranslateDBUri(), we can write XSL file like this:
<xsl:template match="/" xmlns:dburig="http://www.oracle.com/XSL/Transform/java/FAQDBuri">
<xsl:variable name="urladd" select="dburig:TranslateDBUri($url)"/> -
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 PMHi 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. -
Idoc to cXMLmapping..user defined function help
hello Everybody,
I am new to XI and I am working on a new mapping. In a nutshell, the requirement is to concat the TDLine of segment E1EDPT2 and map the data to comments of the cXML. The segment E1EDPT2 is segment in E1EDP01( Purchase Order line item segment) This the data that is coming from the vendor text of the SRM system. This needs to repeat for each line item in the Purchase Order. I have created a user defined function which concats the TD lines but I am not able to differenciate the tD line for other line items. Please help. I would appreciate it if anyone could share the User Defined function which suits my needs.
Thanks!
<E1EDP01> (PO lIne Item 1)
<E1EDPT1 SEGMENT="1">
<TDID>F01</TDID>
<TSSPRAS>E</TSSPRAS>
<TSSPRAS_ISO>EN</TSSPRAS_ISO>
<E1EDPT2 SEGMENT="1">
<TDLINE>XI mapping test - Newline1</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDPT2>
<E1EDPT2 SEGMENT="1">
<TDLINE>Line1- text2 end</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDPT2>
<E1EDPT2 SEGMENT="1">
<TDLINE>Line1 - text3</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDPT2>
</E1EDPT1>
</E1EDP01>
<E1EDP01> ( PO lien item 2)
<E1EDPT1 SEGMENT="1">
<TDID>F01</TDID>
<TSSPRAS>E</TSSPRAS>
<TSSPRAS_ISO>EN</TSSPRAS_ISO>
<E1EDPT2 SEGMENT="1">
<TDLINE>XI mapping test - line2</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDPT2>
</E1EDPT1>
</E1EDP01>Hi,
Please create context UDF which will concatenate all TDLine. Afterwards pass to this function TDLine with changed context to E1EDPT1.
In this function you need to concat full input array.
Regards,
Wojciech -
User Defined Function (UDF) help required. Pls advice urgent.
Hi ,
CRM -- XI (UDF) -- Socket Connection
Now in User Defined Function (UDF) of Message Mapping I will open Socket Connection.
Send CRM XML request to socket and get XML response from Socket and then map to some system.
Can I write Java Class code in User Defined Function (UDF) of Message Mapping instead of Java Mapping in blog below?
/people/saravanakumar.kuppusamy2/blog/2005/12/15/socket-integration-with-xi
RegardsHenry,
Do you have a structure for your response...if you do then you can do extended reciever det with sync/async..shouldent matter, i just tried it and i dont get any error.
in your reciever determination..Check the box for standard rec det then add your first condition..of the value of a field to true..then send to A..
then you select add condition..and add for second reciever..that should be it, you shouldent need a bpm for such a simple scenario..it definetly is an overkill.
Regards
Ravi Raman -
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 -
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 ?
madAll - 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 -
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 heyHi
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
Maybe you are looking for
-
I use this code below to record sound, but it failed. The output is : Press ENTER to start the recording. Recording... Press ENTER to stop the recording. Recording stopped. After I pressed ENTER, it stoped recording immediately. The code is: * Si
-
Podcasts and syncing with iTunes 6.0
So I just hooked up my iPod with iTunes 6.0 for the first time. After changing the drive letter (don't know why I needed to do that), it seemed to sync fine. Except that it started uploading 188 old podcasts that I've played (Parts of audiobooks). Th
-
How can I set an expiration date on a pdf in adobe acrobat 9?
I am trying to set an expiration date for some documents, I have tried to use several javascript methods with no success. My adobe skills are very minimal so the easiest way possible would be appreciated.
-
I posted this in the iMac forum, but it was pointed out to me that you guys are probably better qualified to help... A friend sent me some Quicktime movie files to look at and my iMac won't open them. I get audio only, no visuals. They were created i
-
Premier pro crashes on startup every time
Premier Pro CC 2014 crashes on startup every time. Operating system is OSX Yosemite 10.10. However, the problem begane with previous OS versions and the update did not fix the issue. CC is up to date as version 8.1.0. I've verified and repaired my st