Graphical mapping or UDF
Hi,
In my mapping i have a requirement where the input can be any of three values or not existing. (lets just call them V0, V1, V2 and V3, where V0 is the not existing tag)
If the input is V0, or V1 or V2 i need output an Empty Constant, If the input is V3 i need to pass the value.
I've worked this out with a graphical mapping, but it involves a lot of boxes. It works though.
I'm still wondering if i can do it with a UDF though. Only problem is that my JAVA knowledge is not nearly as good as it should be, so maybe one of you out there can give me some ideas/code.
The thing that give the most headache is the fact that the tag might not exist at all in the source message. How do I deal with that in JAVA code?
Any ideas are welcome.
Kind regards
Robert
Hi Robert,
below is the Jave code, below code is w.r.t exection type as CONTEXT/QUEUE
public void calculate(String[] var1, String[] var2, String[] var3, String[] var4, ResultList result, Container container) throws StreamTransformationException{
if(var1.length != 0 || var2.length != 0 || var3.length != 0)
result.addvalue(" ");
else if(var4.length != 0)
result.addValue(<passthe value>);
Similar Messages
-
Create Attachment within Graphical Mapping using UDF
Hi!
We want to create an attachment witihn a graphical mapping using an UDF function.
I use that function:
public String addAttachment(String filename, String mimeType, String content, Container container) throws StreamTransformationException{
BASE64Decoder decoder=new BASE64Decoder();
try {
GlobalContainer globalContainer = container.getGlobalContainer();
OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
Attachment attachments = outputAttachments.create(filename, mimeType,decoder.decodeBuffer(content));
outputAttachments.setAttachment(attachments);
return "Adde1: "+filename;
} catch (Exception e) {
return e.toString();
(SDN helped me much in creating that
This function has no compiling errors, anything workes fine:
It takes 3 input-parameters, see also: http://help.sap.com/javadocs/pi/SP3/xpi/com/sap/aii/mapping/api/OutputAttachments.html
filename (ok, more or less contentID)
mimeType (more or less contentType)
content: Base64-encoded String which should be set as content
In my sample I use the following constants for that function:
filename = "fn1.txt"
mimeType="application/xml"
content = "UG9seWZvbiB6d2l0c2NoZXJuZCBhw59lbiBNw6R4Y2hlbnMgVsO2Z2VsIFLDvGJlbiwgSm9naHVydCB1bmQgUXVhcms=" --> cames directly from http://de.wikipedia.org/wiki/Base64
When using the message, I got this error within SXMB_MONI:
<SAP:AdditionalText>com.sap.engine.interfaces.messaging.api.exception.MessagingException: Could not queue receive for
message 0022642d-b106-02df-8e8c-f41c243bd112(INBOUND). Reason: java.lang.NullPointerException: while trying to
invoke the method com.sap.aii.af.sdk.xi.lang.Binary.getBytes() of an object returned from
com.sap.aii.af.sdk.xi.mo.xmb.XMBPayload.getContent()</SAP:AdditionalText>
This looks pretty much the same as Add Attachment from ABAP Mapping but this tread is also not answered.
Adding attachment from PI level looks also in that direction, again, no answer.
So, I was wondering if someone has solved such problem?Hi Divyesh!
We did it that way:
1. Choosing the XML-Mailstructure as Destination as described in Configuring the Receiver Mail Adapter - Advanced Adapter Engine - SAP Library - Example (XI payload with mail package)
2. now we have created a UDF for creating the "content"
public void getContent(String[] text, String[] attFname, String[] attType, String[] attContent, ResultList result, Container container) throws StreamTransformationException{
// vergleich ob alle att-Arrays selbe anzahl haben
if (attFname.length!=attType.length || attFname.length!=attContent.length) {
result.addValue(Integer.parseInt("Fehler: alle Attachment-Eingänge müssen die selbe Anzahl an Elementen haben!"));
String CRLF = "\r\n";
String output="This is a multi-part message in MIME format."+CRLF+CRLF+
"--"+getBoundary(container)+CRLF+
"Content-Type: text/plain; charset=UTF-8"+CRLF+
"Content-Disposition: inline" + CRLF + CRLF +
text[0]+CRLF;
for (int i=0;i<attFname.length;i++) {
output+="--"+getBoundary(container)+CRLF+
"Content-Type: "+attType[i]+"; name="+((char)34)+attFname[i]+((char)34)+CRLF+
"Content-Disposition: attachment; filename="+((char)34)+attFname[i]+((char)34)+CRLF+
"Content-Transfer-Encoding: Base64"+CRLF+CRLF+attContent[i]+CRLF;
output+="--"+getBoundary(container)+CRLF;
result.addValue(output);
This UDF is configured as "QUEUE"
We have configured this input-structure
The Content itself is allready base64.
So we can call this mapping and it creates a Multipart-Mail for us. -
Copy of source message to an element with graphical mapping
Hi all,
Is there a way to copy the complete source message of a mapping to an element of the destination message (with CDATA) with the graphical mapping (or UDF, but I want to avoid XSL) ?
For example, from this message:
<source>
<element>test</element>
<element2>test2</element2>
</source>
I expect the following result:
<dest>
<data><![CDATA[<source><element>test</element><element2>test2</element2></source>]]>
</data>
</dest>
Thanks for your help.
GregHi,
Use this Simple Concept
XML node into a string with graphical mapping
/people/michal.krawczyk2/blog/2005/11/01/xi-xml-node-into-a-string-with-graphical-mapping
Regards
Seshagiri -
How to debug global values in UDF in a graphical mapping
Hi Every one,
I got a situation in PI where i have to use global values in graphical mapping UDF.
I can't able to get the values in "Display Queue " option.
Can you please tell me what is the best way of debugging global variable in graphical mapping UDF.
1. I declare one array list in the global values
2. store some values using another UDF to the arraylist.
3. I am traversing the values in the arraylist, but the values are not showing in "Display Queue".
What is the solution to this.Did you try with trace.addInfo?
https://help.sap.com/javadocs/NW04/current/pi/com/sap/aii/mapping/api/AbstractTrace.html
Sample code for the setMail UDF (Carrier B2B) - Business Process Expert - SCN Wiki -
Performance of an UDF v/s standard graphical mapping functions
Hello Experts,
I would like to get your opinion/comments on the performance issues with respect to speed of execution when using graphical functions for doing the date conversion requirement given below:
Requirement is to convert input date u20182008-12-03u2019 from the source side to u201820081203u2019 on the target side.
We have used the standard graphical mapping functions 'substring' & 'replacestring' for doing this conversion as explained here: The u2018substringu2018 function is used to capture the part of the string from the source. A u2018constantu2019 with value u2018u2013u2018 is replaced by u2018constantu2019 (empty value) by using the standard text function u2018replaceStringu2019 in the target side.
We did the same using the following UDF too:
public String convertDate(String dateStringInOriginalFormat) {
SimpleDateFormat originalFormatter = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat newFormatter = new SimpleDateFormat("yyyyMMdd");
ParsePosition pos = new ParsePosition(0);
Date dateFromString = originalFormatter.parse(
dateStringInOriginalFormat, pos);
String dateStringInNewFormat = newFormatter.format(dateFromString);
return dateStringInNewFormat;
From a critical performance point of view, which approach will fare better?
Thanks in Advance,
Earnest A Thomas
Edited by: Earnest Thomas on Dec 4, 2008 6:54 AMHi,
Not only in this case but in general it is always better to use the functions available in MM and only if your requirement is not satisfied with the standard mapping functions then go for UDF.
Also for your requirement no need of going for substring....you can directly use the DateTransform function available.
Source --> DateTransform --> Target
Regards,
Abhishek.
Edited by: abhishek salvi on Dec 4, 2008 11:25 AM -
Hello All
I have a requirement like below:
Source fields
TXT
AddTXT
Target Field
Node
I want to create Node as many times as AddTXT comes with value Concatinate(TXT+AddTXT). This I have achieved not a issue.
Now I want concatinate should happen only for 1st Node other nodes should contain only value of AddTXT.
e.g.
TXT = 001
AddTXT = James
AddTXT = Dheeraj
AddTXT = Rajesh
Result should be
Node = 001-James
Node = Dheeraj
Node = Rajesh
I believe using Graphical mapping this is not possible so how can I achieve this using UDF.
Thanks
Dheeraj KumarHi Dheeraj
Please use the below code.
In the UDF
TXT = var1
AddTXT = var2
Regards
Osman -
Do we any tool to test the UDF other than Graphical Mapping
Hi Experts,
in graphical mapping we come across UDF i just want to is there any seperate tool in market to test the UDF
Thanks
MethaHi,
Here you have the Effective Tool to Test Our Mappings
The specified item was not found.
Regards
Seshagiri -
Bug in exists() function of XI Graphical Mapping Tool?
Hi!
If I connect a source field with the exists() function in XI Graphical Mapping Tool and the tag exists it returns TRUE, otherwise it returns FALSE, so everything works as expected.
But I have to connect a user-defined function with exists(). The user-defined function will either calculate a value or set Resultset.SUPPRESS.
If there is a value the exits() function returns TRUE, however if Resultset.SUPPRESS is set it does also return TRUE! This looks to me like a bug in exists() function. Shouldn't it always return FALSE if the input is Resultset.SUPPRESS?
Regards, TanjaHi Stefan!
> The exists() function checks, if a queue is empty.
> An empty queue is <b>not</b> represented by the
> SUPPRESS value.
> If inside a queue there is a SUPPRESS value, the
> queue is <b>not</b> empty.
Ok, so it's not a bug and the exists() function is working as expected.
> If you want the exist() function after a UDF, provide
> an empty queue, or easier: return the values "true"
> or "false" directly from the UDF.
Yes, that's how I actually solved the problem. The UDF was used at several places where the ResultList.SUPPRESS output was needed. So I copied the UDF and changed it so that the output was TRUE or FALSE instead.
Regards, Tanja -
Graphic Mapping:IDOC to File-Avoid Error in Adapter Engine
Hi all,
I'm using Graphic Mapping in my IDOC to File scenario in which each segment in source IDOC will generate a ROW in target File with the condition: DATBI >= currentdate (and some other conditions)
I have a UDF and use the mapping function CREATEIF for this purpose:
DATBI -> UDF -> CREATEIF -> ROW
Problem scenario: In the source IDOC if all the segments have DATBI < currentdate then there is no ROW created, and I get the error in Adapter Engine
Exception in XML Parser (format problem?):'java.lang.Exception: Message processing failed in XML parser: 'Conversion configuration error: Unknown structure ...
How can I avoid this?
I've tried to put this condition using XPATH in Interface Determination and got the error.
There is a way to use function current-date() in XPATH condition?
Thanks for your help,
ElaineHi all,
How can I "suppress the row node if condition fails"? I'm new in PI, so please give more details.
My FCC as follows:
Record Structure: Record, Row
Row.addHeaderLine 0
Row.fieldSeparator ,
Record.fieldSeparator 'nl'
Row.endSeparator ; 'nl'
It works fine if the condition satisfied.
In Message Mapping, I've use Test to double check my mapping, and in the scenario that conditions fails, there is no Row in the target message.
Please advise.
Thanks,
Elaine -
How to delete target field in graphical mapping
Hi all,
i have a field called failedsubject in my target my requirement is if their is no value in this field then it has to be deleted means it should not be shown iam using graphical mapping. please help me
thanks in advanceHi,
Please try with the below logic.
public String failedSubject(String sub1, String sub2, String sub3, Container container) throws StreamTransformationException{
if (Integer.parseInt(sub1) >= 40) //assuming 40 as passmark
if (Integer.parseInt(sub2) >= 40)
if (Integer.parseInt(sub3) >= 40)
return false;
else
return true;
else
return true;
else
return true;
failedSubject---->ifWithoutElse-->failedSubject
pass all subjects as input to the UDF.
Regards
Priyanka
Edited by: priyanka.anagani on Sep 16, 2011 3:26 PM -
Hi all,
i have a Graphical mapping logic here
Source Structure:
GS
GP[1]
F1- QI
SDQ
F2- 2
GP[2]
F1- QD
SDQ
F2- 3
GP[3]
F1- PC
CTP
F2- 5.3
GP[4]
F1- AI
SDQ
F2- 4
GS
Target structure:
MT
Material[1]
Qty
Material[2]
Qty
Material[3]
Qty
Material[4]
Price
MT
Here the Material node occurences is 0 to Unb.
For values QI,QD and AI should be a seperate mapping ie) three nodes will be created.
For values 'PC' seperate mapping ie. last node will be created only if F1 receives 'PC' beacause i need to implement the separate mapping logic for a value 'PC'.
If i send the data sequence QI,QD,AI and PC my mapping is working correctly.
MT
Material[1]
Qty 2
Material[2]
Qty 3
Material[3]
Qty 4
Material[4]
Price 5.3
MT
But if i send the the data sequence QI,QD,PC and AI my mapping is not working properly for 'AI'. But for QI,QD and PC mapped correctly.
Output:
MT
Material[1]
Qty 2
Material[2]
Qty 3
Material[4]
Price 5.3
MT
Note: For Value 'AI' , target node Material[3] is completly ignored/not coming.
We used createif function to create the target node in the target structure based on the value 'PC'.
we think that once if mapping executed the value for 'PC', mapping for 'AI' is not executed i.e. it doesn't go back and execute the mapping for 'AI'.
Can you please help me to solve this problem,
Thanks and Regards
KamalHi Kamal,
I understand that your src is
GS
GP
F1
SDQ/CTP
F2
and depending on the value of F1 the target nodes has to be created.
here, by using the createif, u can generate the nodes properly, but the problem arises when u have to get the corressponding values in the feild QTY of your target.
in such a situation, writing a UDF would be better a better option.
Thanks
Hari. -
Mapping Help/UDF needed.
Hi my source looks something like this
Recordset. 0-Unbounded.
Record 0-Unbounded
Value1
Value2
DOCNO
MatNo
target
=====
MT_Target
Recordset 0-Unb
Header
Val1
Val2
DOCNO
Material 0-Unb
Matno
Example Mapping
=============
Recordset. .
Record
XXX
YYY
100
01
Record
XXX
YYY
100
02
Record
AAA
ZZZ
200
22
Record
AAA
ZZZ
200
33
Then My Target would be like
MT_Target
Recordset
Header
XXX
YYY
100
Material
01
02
Recordset
Header
AAA
ZZZ
200
Material
22
33
Please notice the Grouping of DOCNo and Corresponding material numbers
So I am trying to group the Materials in the Target structure based on the DOCNO field. So all the materials falling under the same DocNo are listed under that DOCNo,Like if Matno 01,02 fall under Docno 100 so they are listed Under DOCNO :100
So if there are 3 DOCNos then we will have 3 Recordset in the target and each Recordset will have the corresponding MATNO for that DocNo. Hope u understand.
Could anybody please help me out with this, I have tried using SplitByValue Changing and Collapse Conetxt, it works for the Header but not for the "Material" Node. Help needed, Points Guaranteed.John,
DO you know the DOCNO value before runtime? Will it have only values 100 and 200? If so, then it is easy to do this using graphical mapping.
You need to evaluate the condition at recordset level in target.
Have a look at this thread for evaluating the condition at root level
Re: How to get access to sub-node elements with a UDF?
If the value of DOCNO is unknown at design time, then it is better to handle the mapping using JAVA mapping.
Regards,
Jai Shankar -
XSLT using Java function from graphical mapping (RFClookup)
Hi,
I was wondering if it is possible to use the standard Java functions of the graphical mapping (RFCLookup, Datetrans, ...) or from my own UDF inside an xslt mapping. Does anyone have every tried this or is an example available ?
Regards BerndHi Bernd,
here you can find an example how to use RFC lookup from an XSLT Mapping:
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/05a3d62e-0a01-0010-14bc-adc8efd4ee14?quicklink=index&overridelayout=true
Is this what you're looking for?
Regards,
Gábor -
Hi All,
I have a requirement in graphical mapping that i have a two nodes in source side both are identical. Each node has corresponding sub elements. Target side i have node with subelements. Based on certain conditions like if one condition satisfies i need to map first node and its corresponding sub elements in source side to target side node and its subelemts. If second condition satisfies then i need to map second node in source and its subelements to the target node and its sub elements. If both conditions not satisfy then target node should not be populated.
Please let me know how to acheive this in graphical mapping.
Thanks in advance.
Regards,
Rajeshotherwise go for udf which takes the input as your values and checks the condition in the udf and based on that value map the result to target node
string empty=;
if ( NODEAelement.equals("A"))
return A;
else if (NODEBelement.equals("B"))
return B
else
return empty;
I just provided the logic, you can procced with this...
HTH
Rajesh -
Access Message ID in graphical mapping
Hi,
I could not find a solution: How do I access the Message ID in the graphical mapping?
During Runtime, I need to get the Message ID in graphical mapping and map it to a field in the target rfc.
Can I do this either direct in mapping or is there a parameter in UDF?
thx
holgersearch in sdn before posting...
http://wiki.sdn.sap.com/wiki/display/Snippets/UDFtoReadMessageIDofaPIMessage
Regards,
Raj
Maybe you are looking for
-
Oracle North American Payroll Customers - US Q2 Statutory Updates Released
Dear Oracle North American Payroll Customer, The United States (US) Second Quarter Statutory Update (Q2), 2006 has been released! The following patches are available: R11i: 4938760 R11: 4938760 Please be sure to carefully read ALL the readmes before
-
hi there my iphone 3gs is an openline but im using 02 sim card..when i am trying to update it on itunes it restore all the system..but when im trying to activate it..it dosent want to activate and my sim is no longer detecting on my phone..any ideas
-
One large message or multipels small ones?
Hi: I'm working in an application using weblogic 8.1. We receive in a JMS queue a large message containing thouthands of transactions to be processed. What should be more eficient? processing the whole transactions in the message (with one MDB) or sp
-
Why my Quick Time 7.5 doesn't work at all?
I just installed Quick Time Player 7.5 and I tried to play several movies (.avi) but there are no audio and video at all. Can somebody give me the solution for my problem? Thanks.
-
Captivate 7 is only recordin the top left hand of my screen (almost like im zooming in) no matter if im panning or not, what mode im in (simutlation demonstration etc) and it doesnt matter how big or small i make the screen either. It doesnt matter