Context change problem
Team,
I have a problem with context change in a peculiar mapping requirement.
Scenario is IDOC --> XML
There's an idoc field MRKN1 which carries all shipment unit numbers seperated by spaces.
MRKN1 : 50325 50326 50329 50321 50215
This field should be mapped to target XML as below:
<Package> <identifier>50325</identifier>
</Package>
<Package> <identifier>50326</identifier>
</Package>
<Package> <identifier>50329</identifier>
</Package>
<Package> <identifier>50321</identifier>
</Package>
<Package> <identifier>50215</identifier>
</Package>
I created a USD StringTokenizer to extract the values from MRKN1 & to populate it in the identier field:
import java.lang.*;
public void StringTokenizer(String[] input,ResultList result,Container container){
String x[] = new String[input.length];
for(int j=0; j<input.length;j++) {
x = input[j].split(" ");
for(int i=1;i<x.length;i++) {
result.addValue(x<i>);
and mapped liked below:
MRKN1 --> StringTokeniser --> identifier
But the output xml looks like this:
<Package> <identifier>50325</identifier> <identifier>50326</identifier> <identifier>50329</identifier> <identifier>50321</identifier>
<identifier>50215</identifier>
</Package>
Please help me how to create new Package tag for every new identifier tag.
I already tried adding result.addContextChange() just by returning empty value to the above code & mapped it to Package node. But it throws error.
Any immediate help is appreciated.
Thanks in advance,
Shanthi
The above logic works quite different. The complete XML looks like this
Given 3 items & 2 values in MRKN1
<GoodsItem..1>
<Packaging>
<marksNumber>503124</marksNumber>
<PackagesCollection>
<Package>
<identifier>50216</identifier>
</Package>
</PackagesCollection>
<packageType>PK</packageType>
</Packaging>
</GoodsItem..1>
<GoodsItem..2>
<Packaging>
<marksNumber>503124</marksNumber>
<PackagesCollection>
<Package>
<identifier>50215</identifier>
</Package>
</PackagesCollection>
<packageType>PK</packageType>
</Packaging>
</GoodsItem..2>
<GoodsItem..3>
<Packaging>
<marksNumber>503124</marksNumber>
<PackagesCollection/>
<packageType>PK</packageType>
</Packaging>
</GoodsItem..3>
But the customer requirement is quite different
Similar Messages
-
Context change by DOM parsing Java Mapping in XI
Hi Team,
I would like to know that how can I handle Context Change by DOM Parser Java Mapping in XI.?
Suppose the source XML structure I have like below:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:Header xmlns:ns0="urn:bp:xi:hr:edm:test:100">
<FileName>
<filesub>
<subname>a</subname>
<subname>b</subname>
<subname>c</subname>
</filesub>
</FileName>
<FileName>
<filesub>
<subname>d</subname>
<subname>e</subname>
<subname>f</subname>
</filesub>
</FileName>
</ns0:Header>
Where the field FileName can occur maximum thrice(0...3) but the subname field is (0....unbounded) but in the target source I would like to have as given below:
<?xml version="1.0" encoding="UTF-8" ?>
- <MT_Test4 xmlns="urn:bp:xi:hr:edm:test:100">
- <Header>
<FileName>a</FileName>
<FileName1>d</FileName1>
</Header>
- <Header>
<FileName>b</FileName>
<FileName1>e</FileName1>
</Header>
Header>
<FileName>c</FileName>
<FileName1>f</FileName1>
</Header>
</MT_Test4>
That means the first value from every context of the source field is forming my first and second value in my target first context.Thensecond value from every context is forming my 1st and 2nd value of my target 2nd context and finally 3rd value of every context is forming my 1st and 2nd value of my target 3rd context.Is this possible to done through DOM parsing or we have to do it by UDF only?Hi Atanu,
In my last post I gave an alogorithm to solve the mapping problem. Here is the complete program for the mapping.
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
public class DOMParser1 implements StreamTransformation{
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
try
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builderel=factory.newDocumentBuilder();
/input document in form of XML/
Document docIn=builderel.parse(in);
/document after parsing/
Document docOut=builderel.newDocument();
TransformerFactory tf=TransformerFactory.newInstance();
Transformer transform=tf.newTransformer();
Element root,child,child1=null;
Node textChild;
NodeList l;
int i,n1,j,div,k;
String s[];
root=docOut.createElement("MT_Test4");
root.setAttribute("xmlns","urn:bp:xi:hr:edm:test:100");
l=docIn.getElementsByTagName("subname");
n1=l.getLength();
s=new String[n1];
for(i=0;i<n1;++i)
s<i>=l.item(i).getFirstChild().getNodeValue();
l=docIn.getElementsByTagName("filesub");
div=l.getLength();
j=n1/div;
for(i=0,k=0;i<j;++i)
child1=docOut.createElement("Header");
root.appendChild(child1);
child=docOut.createElement("FileName");
textChild=docOut.createTextNode(s[k]);
child.appendChild(textChild);
child1.appendChild(child);
child=docOut.createElement("FileName1");
textChild=docOut.createTextNode(s [ k + j ]);
child.appendChild(textChild);
child1.appendChild(child);
++k;
docOut.appendChild(root);
transform.transform(new DOMSource(docOut), new StreamResult(out));
catch(Exception e)
e.printStackTrace();
public void setParameter(Map arg0) {
public static void main(String[] args) {
try{
DOMParser1 genFormat=new DOMParser1();
FileInputStream in=new FileInputStream("C:/Apps/my dw/sdnq/apps.xml");
FileOutputStream out=new FileOutputStream("C:/Apps/my dw/sdnq/tgt1.xml");
genFormat.execute(in,out);
catch(Exception e)
e.printStackTrace();
source -> apps.xml
<?xml version="1.0" encoding="UTF-8" ?>
- <ns0:Header xmlns:ns0="urn:bp:xi:hr:edm:test:100">
- <FileName>
- <filesub>
<subname>a</subname>
<subname>b</subname>
<subname>c</subname>
</filesub>
</FileName>
- <FileName>
- <filesub>
<subname>d</subname>
<subname>e</subname>
<subname>f</subname>
</filesub>
</FileName>
</ns0:Header>
target structure -> tgt1.xml
<?xml version="1.0" encoding="UTF-8" ?>
- <MT_Test4 xmlns="urn:bp:xi:hr:edm:test:100">
- <Header>
<FileName>a</FileName>
<FileName1>d</FileName1>
</Header>
- <Header>
<FileName>b</FileName>
<FileName1>e</FileName1>
</Header>
- <Header>
<FileName>c</FileName>
<FileName1>f</FileName1>
</Header>
</MT_Test4>
Hope this helps
one more thing in this line "textChild=docOut.createTextNode(s k + j );" somehow the the third braces one opening before k and one closing after j is missing for unknown reasons. Please correct it when you actually run this code.
regards
Anupam
Edited by: anupamsap on Mar 7, 2011 12:47 PM -
Context Mapping Problem from IDoc to EDI
Hi,
I'm trying to map an IDoc to an EDI and I get this problem.
In my IDoc, I have segment E1ADRM1 (1:N)
My mapping condition is if E1ADRM-PARTNER_Q = OSP then copy E1ADRM-REGION into x (EDI field)
So here is my problem:
In my IDoc test, the segment E1ADRM1 is repeated 6 times and the field REGION is not populated in all iterations so the wrong
REGION is being copied to my EDI field.
If I do a display queue on E1ADRM-PARTNER_Q, the value OSP is at the 5th position
AG
SP
VE
WE
OSP ***
OSO
If I do a display queue on E1ADRM-REGION, since only 5 segment E1ADRM have the field REGION populated, I get
KS
VA
KS
ON
VA
**(E1ADRM-PARTNER_Q = SP do not have the RIGION populated so not showing in the IDoc)
So now, since E1ADRM-PARTNER_Q = OSP is at the 5th position, it is copying the 5th E1ADRM-REGION from the list but it should be the 4th.
How can I do that?
Rgds,
YvesHi,
For the mapping to work as you are expecting the queue should look like this(<b>CC</b> denotes context change)..
KS
<b>CC</b>
<b>CC</b>
VA
<b>CC</b>
KS
<b>CC</b>
ON
<b>CC</b>
VA
If you are not having the context changes, check at what level is field REGION at, right click on REGION in graphical mapping and choose menu item context, the 1st entry should have the tick mark(same should be for the PARTNER_Q field also).
Thanks,
Renjith. -
Add a context change after a set of values in a context
Dear experts,
My requirement is as follows:
Scenario: Idoc to Idoc. I need to check if there are line items > 5- I need to do a split. The split is happening properly via my mapping but I have a problem at the header record level on the target- I do not get the values populated correctly. I need to add a context change after 5 values in the queue.
eg:
Say there are 2 Idocs at the source with following unique IDs: called Journal ID:
My source:
Idoc 1: Journal ID 123
Line Itme 1
Line Item 2
Idoc 2: Journal ID 124
Line item 1
Line item 2
Line item 3
Line item 4
Line item 5
Line item 6
Line item 7
So I need to get total of three Idocs in my target:
Idoc 1: Journal Entry 123
Line Item 1
Line Item 2
Idoc2: Journal Entry 124
Line item 1
Line item 2
Line item 3
Line item 4
Line item 5
Idoc3: Journal entry 124
Line item 6(new 1)
Line item 7(new 2)
The split in the target Idoc is working perfectly. But inside the header record the journal ID field(taken from Item record level) is not populating correctly. I am getting this output:
Idoc 1: Journal Entry 123
Header Record-->JournalID Field value= '123'
Line Item 1
Line Item 2
Idoc2: Journal Entry 124
Header Record-->JournalID Field value= '124'
Line item 1
Line item 2
Line item 3
Line item 4
Line item 5
Idoc3: Journal entry 124
Header Record-->JournalID Field value= Null
Line item 6(new 1)
Line item 7(new 2)
So please suggest a UDF/standard function to populate the right values inside header record--->Journal ID field.Something like the below...
public void calculate(String[] var1, ResultList result, Container container) throws StreamTransformationException{
for ( int i = 0; i < var1.length; i++ )
if( var1[i].length() > 5) //here var1 I am passing the Journal ID
result.addContextChange();
Apparently this doesnt work.The first Idoc has two line items and the second idoc has 7 line items. As the split is per 5 line item- the target has 3 Idocs.
Now the problem is that the header value in the target: REF_DOC_NO has to be created as per the number of line items and doesnt come from header record directly. -
Hi,
i am getting small problem in the context change..
i have input as
1
2
3
[3]context change
4
5
[5]conext change
6
7
8
[8]context change
i want out put as
2
3
[3]conext change
5
[5]context change
7
8
[8]context change
my requirement is the element after context change in the input sholud be deleted.
Thank you,
Madhav.Hi Madhav,
Try This
for(int i=0;i<a.length;i++)
if(a<i>.equals(ResultList.CC))
result.addValue(ResultList.CC);
i++ ;
else
result.addValue(a<i>);
"if(a.equals(ResultList.CC))" it should be a(i) but in rect bracket ,Dont know why it is not showing the same in above code
Thanks
Sunil Singh
Edited by: SUNIL SINGH on Nov 19, 2008 5:57 AM
Edited by: SUNIL SINGH on Nov 19, 2008 5:59 AM -
Context menu problem in ADF 11g
Hi All,
A context menu problem puzzle me. Following is the source,
=======================================
<af:tree id="tree" value="#{treeTest.collectionModel}" var="node"
contentDelivery="immediate"
disclosedRowKeys="#{treeTest.treeDisclosedRowKeys}"
rowDisclosureListener="#{treeTest.rowDisclosureListener}"
rowSelection="single">
<f:facet name="nodeStamp">
<af:group id="g1">
<af:image source="/image/#{node.treeLevel}.jpg" id="i1"
inlineStyle="width:16px; height:16px; vertical-align:middle;"/>
<af:outputText id="ddl" value="#{node.name}">
<af:showPopupBehavior popupId="myPopup" triggerType="contextMenu"/>
</af:outputText>
</af:group>
</f:facet>
<f:facet name="contextMenu">
<af:popup id="myPopup" popupFetchListener="#{treeTest.popupListener}"
contentDelivery="lazyUncached">
<af:switcher id="s1" facetName="#{treeTest.level}">
<f:facet name="1">
<af:menu text="menu 1" id="m1">
<af:forEach items="#{treeTest.menuItems['0']}" var="menuItemss">
<af:commandMenuItem text="#{menuItemss.name}"
actionListener="#{bindings.onNodeClicked.execute}"
disabled="#{!bindings.onNodeClicked.enabled}">
</af:commandMenuItem>
</af:forEach>
</af:menu>
</f:facet>
<f:facet name="2">
<af:menu text="menu 2" id="menu1">
<af:forEach items="#{treeTest.menuItems['1']}" var="menuItemss">
<af:commandMenuItem text="#{menuItemss.name}"
actionListener="#{bindings.onNodeClicked.execute}"
disabled="#{!bindings.onNodeClicked.enabled}">
</af:commandMenuItem>
</af:forEach>
</af:menu>
</f:facet>
</af:switcher>
</af:popup>
</f:facet>
</af:tree>
========================================================
I want to get the commandMenuItem tag's information, i use following code in onNodeClicked method try to get it,
FacesContext facesContext =FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory =facesContext.getApplication().getExpressionFactory();
ValueExpression exp =expressionFactory.createValueExpression(elContext,"#{menuItemss.name}", Object.class);
but the exp is null.
Please help me to solve this problem.
Thank you very much.
Edited by: Yitao Li on Dec 4, 2009 1:06 PMYou might need a #
ValueExpression exp =expressionFactory.createValueExpression(elContext,"#{menuItemss.name}", Object.class); -
How to apply context change explicitly?
Hi,
Refer the section context handling page No 19: Explicit Context selection.
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f59730fa-0901-0010-df97-c12f071f7d3b
/people/riyaz.sayyad/blog/2006/04/23/introduction-to-context-handling-in-message-mapping
Also u can achieve it by writing the code in UDF.Already provided by experts
Thnx
Chirag -
wat is context and how it changes?
Hi,
Assume u have message type as follows.
i.e MTO_Sample-
-Data1
- filed1
- filed2
- filed3
-Data2
- filed1
- filed2
-filed3
-Data N
- filed1
- filed2
- filed3
where Data1, Data2 and Date3 are context..
assume u have Data1 with 2 records, then start of second record nothing but context change.
please chk the following link.
http://help.sap.com/saphelp_nw04s/helpdata/en/48/444941db42f423e10000000a155106/frameset.htm
/people/yukai.shi/blog/2006/06/02/b2b-mapping-techniques-using-the-graphical-mapping-tool
/people/harrison.holland5/blog/2006/12/08/mapping-context-changes-in-xi
regards
mahesh. -
Context Changes got impact on what?
Context Changes got impact on what?.
Hi Ash,
Context changes have impact on:
�� User-Defined Functions
�� Breaking and inserting of hierarchy levels
For more see below PPT of SAP:
<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/be05e290-0201-0010-e997-b6e55f9548dd">https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/be05e290-0201-0010-e997-b6e55f9548dd</a>
Regards,
Subhasha Ranjan -
Hi,
what is context change?? where it is implemented?
thanks in advance.Hi!
Context changes take place in Message Mapping when the source structure is processed. for more details about mapping and context change see sap online help - e.g. here http://help.sap.com/saphelp_nwpi71/helpdata/en/49/1ebc6111ea2f45a9946c702b685299/content.htm
Regards,
Volker
Additionally:
More detailed information about contexts and context changes see here: http://help.sap.com/saphelp_nwpi71/helpdata/en/3d/24e15bf9d79243b45d49b13b03de8f/content.htm
Edited by: Volker Kolberg on May 25, 2009 10:10 AM -
User changes in tab strip ui element are not recorded in context change log
Hi All,
We are using a tab strip ui element in webdynpro component. But user changes inside tab strip ui element are not getting recorded to the context change log. I have an input field on the same view besides tab strip ui element. User changes to this input field are getting recorded to the context change log.
Is there any restriction on context change log usage with tab strip ui element?
Could you please suggest If there is any way to record changes inside tab strip ui element.
Thanks,
Sudheer.I think there are some limitations exists, context change logs are not complete when you do value help , i am not sure about tab strip.
[http://help.sap.com/saphelp_nw70ehp1/helpdata/en/47/a8e5d273b12fe2e10000000a42189d/content.htm|http://help.sap.com/saphelp_nw70ehp1/helpdata/en/47/a8e5d273b12fe2e10000000a42189d/content.htm] -
Message Mapping - Initialize counter every context change
Hi all,
is there any way to develop a counter customer function in a graphical message mapping so every context change of a field the counter initializes?
Imagine i have the following structure:
1 DATA
1.1 DETAIL
1.2 DETAIL
2 DATA
2.1 DETAIL
2.2 DETAIL
and i wanna count DETAIL fields but initialize the counter every DATA field. Is there any way to do it?
Thanks a lot.Hi,
If your Source structure is
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_DATA xmlns:ns0="http://yash.com.YH1309">
<DATA>
<DETAIL/>
<DETAIL/>
</DATA>
<DATA>
<DETAIL/>
<DETAIL/>
<DETAIL/>
</DATA>
</ns0:MT_DATA>
and You want the Target as
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_DATA xmlns:ns0="http://yash.com.YH1309">
<DATA>
<DETAIL>COUNTER=1</DETAIL>
<DETAIL>COUNTER=2</DETAIL>
</DATA>
<DATA>
<DETAIL>COUNTER=1</DETAIL>
<DETAIL>COUNTER=2</DETAIL>
<DETAIL>COUNTER=3</DETAIL>
</DATA>
</ns0:MT_DATA>
Create the below UDF with one argument (DETAIL) and select Execution type all values of a Context
for (int i =1;i<=DETAIL.length;i++)
result.addValue("COUNTER=" + i);
but if you want Your Target as
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_DATA xmlns:ns0="http://yash.com.YH1309">
<DATA>
<DETAIL>1</DETAIL>
<DETAIL>2</DETAIL>
</DATA>
<DATA>
<DETAIL>1</DETAIL>
<DETAIL>2</DETAIL>
<DETAIL>3</DETAIL>
</DATA>
</ns0:MT_DATA>
So please Follow abhishek salvi's reply -
Context Change & Explicit Context Change
Hi
i need some info about Context Change and Context Handling, explisit context change how can we r defineing
Thanks&Regards
rajashekarHi Raja,
Please refer these:
http://help.sap.com/bp_bpmv130/Documentation/Operation/MappingXI30.pdf
Pages 62-74
http://www.riyaz.net/blog/index.php/2007/12/08/xipi-introduction-to-context-handling-in-message-mapping/
http://help.sap.com/saphelp_nw70/helpdata/en/bd/ca1105c81c6742a0f8c8d49f8834bf/frameset.htm
Refer section: Structure Mapping by Setting the Context
Thanks ,
Shweta -
Mapping query for context change without UDF
Hi,
My requirement is as below:
Input queues are
4319, 4319,4320,4321,4321
M1,M1,M1,M2,M2,M2
Required output is
4319,4320,CC,4321
COntext change is to be inserted when there is a change in value in second queue.
regards, Anirudh.Hi,
Have you tried using the formatByExample as specified?
input1-->removeContext--> concat --> splitByValue:ValueChanged --> collapseContext --> substring (2..6) --> formatByExample (1) --> Target
input2-->removeContext--> /
input1-->removeContext--> concat --> splitByValue:ValueChanged --> collapseContext --> substring (0..2) --> splitByValue:ValueChanged -->formatByExample (2)
input2-->removeContext--> /
code explanation
input1 and input 2 when concatted outputs M12319,M12319,M12320,M22321,M22321,M22321
The upper part of the code does this: M12319,M12320,M22321, when you use the substring it outputs now 2319,2320,2321
The lower part of the code does this: M12319,M12320,M22321, when you use the substring it outputs
M1,M1,M2, then you use splitByValue. The output is now M1,M1,CC,M2.
When you input the code from the upper part and lower part into a formatByExample node, the output becomes
2319,2320,CC,2321
Hope this helps, -
How to address the IP address automatically changing problem?
My Oracle database 10g(10.2.0) is on the WinXP platform and the system IP address often changes automatically. This leads to some troubles with my Oracle database. How to deal with this problem? How to stop the IP changing problem?
frank.qian wrote:
But my database is using an ipaddress now. When I use loalhost instead, can database accept this?The database doesn't know or care. Its all in your network configuration files ... listener.ora and tnsnames.ora, and your 'hosts' file.
Edited by: EdStevens on Dec 1, 2008 8:47 PM
Maybe you are looking for
-
After an install of Lion, my secondary internal hard drive used for backup and time machine is not showing on the desktop. Cannot be located with Disk Utility either. Contains vital files! please help...
-
My 3 year-old son placed one of his toys on top of our Apple TV. The problem is, the toy contains a magnet so he basically set a magnet on top of the Apple TV! Can this magnet damage the unit, it's hard drive, etc.??
-
Hyperion Web Analysis Security
Hi, user can not able to open a report in web analysis. User have total access in shared services and workspace. user have access for the dimensions also. but user cannot able to open report. please tel me, If i missed any to give access to user. tha
-
Getting a Font Error when opening a pdf file with Adobe Reader. All the newest versions of Reader, OSX etc. The error says missing font Univers-Light Sometimes Reader crashes. It turns out this is an Adobe font that I have to pay for???
-
Once you import a video file into Encore and transcode it can you delete the original file and still build properly or will that cause a problem? I do understand that you will not be able to revert to original if you do this.