cancel
Showing results for 
Search instead for 
Did you mean: 

Copy Nodes

Former Member
0 Kudos
165

Hi,

I am trying to copy nested nodes from a model node into a value node, but my subnodes are not copied anyway.

The structure that should be copied looks like

o context

|-- masternode (0..n)

|------ subnode (0..n)

|------ subnode2 (0..n)

|----


subsubnode (0..n)

they should be copied into nodes having the same structure

o

|-- newnode (0..n)

|------newsubnode (0..n)

|------newsubnode2 (0..n)

|----


subsubnode (0..n)

which means every node can contains several subnodes.

I used WDCopyService.copyElements(masternode, newnode) with the effect that all attributes were copied correctly, but all subnodes were empty.

A way I found was to copy all subnodes manually.

WDCopyService.copyElements(masternode, newnode)

WDCopyService.copyElements(masternode.subnode, newnode.newsubnode)

WDCopyService.copyElements(masternode.subnode2, newnode.newsubnode2)

But this won't copy subsubnode and I have no idea how this should work.

I tried WDCopyService.copySubtree(masternode.subnode2, newnode.newsubnode2) but the subsubnode isn't filled anyway.

Hopefully you unterstand my question and can help me out with some answers.

Thanks in advance

Fabian

Accepted Solutions (1)

Accepted Solutions (1)

monalisa_biswal
Contributor
0 Kudos

When you are using copysubtree, you should check names of the subnodes.Even though the sturcture of subnodes are matching, it wont copy elemnets if the names do not match.

So your target node should have subnodes with same name as parent node.To achieve this your target node should be under different controller's context.Because you cant have two nodes with same name under same context.

Another alternative is to do it manually. Before that you need to check the singleton property of subnodes. If singleton is false, you have to iterate over elements of parent node, access subnodes from those elements and use copyelements to copy elements from parent subnode to child.

int size=wdContext.nodemasternode().size();

for(int i=0;i<size;i++)

{

IPublic<Controllername>.IMasterNodeElement element_source=

wdContext.nodemasternode().getMasterNodeElementAt(i);

IPublic<Controllername>.INewNodeElement element_target=wdContext.newNode().createNewNodeElement();

wdContext.newNode().addElement(element_target);

wdCopyService.copyCorresponding(element_source, element_target);

wdCopyService.copyElements(element_source.nodeSubNode(),

element_target.nodeNewSubNode());

wdCopyService.copyElements(element_source.nodeSubNode2(),

element_target.nodeNewSubNode2());

}

If singleton is set to true you can directly access child node and do copy elemnts.

wdCopyService.copyElements(wdContext.nodeSubNode(),

wdContext.nodeNewSubNode());

wdCopyService.copyElements(wdContext.nodeSubNode2(),

wdContext.nodeNewSubNode2());

Hope it helps.

Former Member
0 Kudos

Hi all,

many thanks to Monalisa and apurva. They got the solution for my problem.

Her idea with "singleton = true" did not work for me, so I decided to change the property singleton to false for the relevant business AND model nodes and copied them manually.

Here is the code that works fine for me: (It will be optimized for productive use)

for (int i = 0; i < wdContext.nodeWirtsch_Einheit().size(); i++) {
    IWirtsch_EinheitElement sourceElement = wdContext.nodeWirtsch_Einheit().getWirtsch_EinheitElementAt(i);
    IBPFS_WirtschaftlicheEinheitElement targetElement = wdContext.nodeBPFS_WirtschaftlicheEinheit().createBPFS_WirtschaftlicheEinheitElement();
    wdContext.nodeBPFS_WirtschaftlicheEinheit().addElement(targetElement);
    WDCopyService.copyCorresponding(sourceElement, targetElement);
    WDCopyService.copyElements(sourceElement.nodeWe_Partner(),  targetElement.nodeBPFS_WirtschaftlicheEinheitPartner());
}

Edited by: Fabian Häusler on Jul 14, 2008 2:52 PM

Former Member
0 Kudos

Hi,

It was wonderful to know the solution for copying the node having the singleton property as false. Could you please let me know if the same approach is mentioned anywhere in the SAP document. And WDCopyService.copySubtree() method cannot be applied directly in this scenario.

Thanks to you and to Fabian as well for bringing this solution.

thanks & regards,

Manoj

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

Use for loop .

Suppose copyinf from mainnode-subnode to mainnode1-subnode1:

WDCopyService.copyElements(wdContext.nodemainnode(),wdContext.nodemainnode1());

//seize=size of main node

for (int index = 0; index < size;index++)

{

mainElement = wdContext.nodemainnode().getmainnodeElementAt(index);

mainElement1= wdContext.nodemainnode1().getmainnode1ElementAt(index);

WDCopyService.copyElements(mainElement .nodesubnode(), mainElement1.nodesubnode1());

}

Regards,

Apurva

Former Member
0 Kudos

Hi

Make sure that the attribute names must be same in both nodes to use WDCopyService(). Also name is case sensitive.

WDCopyService().copyCorresponding(arg1, arg2) ;

Mandeep Virk

former_member201361
Active Contributor
0 Kudos

Hi ,

please check whether the cardinality is same for both the nodes and attribute type is also same .

WDCopyService.copyElements(wdContext.nodesubnode2, wdContext.nodenewsubnode2);

thanks and regards

Former Member
0 Kudos

both nodes having exactly the same cardinality

Former Member
0 Kudos

Hi,

Well i dont have the solution to your problem but I also have faced the similar problem. Here is the link:

Still searching for the reason and the solution. I cant say that your scenario is exactly the same.

Hope you get a solution which can help me as well.

thanks & regards,

Manoj

Former Member
0 Kudos

Hi,

Is the masternode and newnode of same structure??? Was newnode created with the same attributes??

Regards

Ishita

Former Member
0 Kudos

masternode and newnode were both generated by binding it to the same structure which was deleted afterwards. So all subnodes and all attributes having the same structure / type in masternode and in newnode.

Former Member
0 Kudos

Hi

So does that mean the structure was changed later on? If so did you re-import the model?

Regards

Ishita

Former Member
0 Kudos

>

> Hi

> So does that mean the structure was changed later on? If so did you re-import the model?

>

>

> Regards

> Ishita

No. The model was imported once, afterwards the value node structure was generated by using a structure binding which was deleted manually to allow some modifications in teh structure later on. But so far it exactly the same structure.

Former Member
0 Kudos

Hi,

One approach which i can say is that if everything is correct and proper then just debug your application. The same thing i did and found that it was not copying the values to the sub nodes properly.

Just give it a try.

thanks & regards,

Manoj

Former Member
0 Kudos

Hi

Paste the code i.e the loop where you have written the WDCopyService method.

Regards

Ishita

Former Member
0 Kudos

sorry for letting you wait for about an hour, but my boss decided to catch me for a meeting

here is the code fragement

jcoManager.execute(wdContext.currentZ_Bapfw_Bp_Factsheet_Data_InputElement().modelObject(), wdContext.nodeOutputFactsheet(), transId);
logManager.logFSCAA_RFC_CALL(method, transId, wdContext.nodePe_T_Bpdata());
jcoManager.reportRFCMessages(wdContext.nodePe_T_MessagesFactsheet(), transId, method, pathPrefix);
IPe_T_BpdataNode masterNode = wdContext.nodePe_T_Bpdata();
IBusinessPartnerFactsheetNode slaveNode = wdContext.nodeBusinessPartnerFactsheet();
WDCopyService.copyElements(masterNode, slaveNode);
WDCopyService.copySubtree(masterNode.nodeWirtsch_Einheit(), slaveNode.nodeBPFS_WirtschaftlicheEinheit());

here is the part of the logoutput

Masternode (log begins in the last row)
 
13:25:54:191 , 1 |     END-----> Node: Wirtsch_Einheit Element(2) 
13:25:54:191 , 2 |     |     END-----> Node: We_Partner Element(1) 
13:25:54:191 , 2 |     |     |     END -----> Attributes: 
13:25:54:191 , 2 |     |     |     |     Partner = 57002239 
13:25:54:191 , 2 |     |     |     |     Db2 = 2'000 , Debug 
13:25:54:191 , 2 |     |     |     |     Zzkurzbez = Gerber Heidi 
13:25:54:191 , 2 |     |     |     |     Zzrating =  
13:25:54:191 , 2 |     |     |     BEGIN -----> Attributes:
13:25:54:191 , 2 |     |     BEGIN---> Node: We_Partner Element(1) 
13:25:54:191 , 1 |     |     END -----> Attributes: 
13:25:54:191 , 1 |     |     |     Db2 = 2'000 
13:25:54:191 , 1 |     |     |     Partner = 57002239  
13:25:54:191 , 1 |     |     |     Identbez = Test E20 Kreditgr. 2 
13:25:54:191 , 1 |     |     |     Ident = 0000099998
13:25:54:191 , 1 |     |     BEGIN -----> Attributes:  
13:25:54:191 , 1 |     BEGIN---> Node: Wirtsch_Einheit Element(2)  
13:25:54:175 , 1 |     END-----> Node: Wirtsch_Einheit Element(1) 
13:25:54:175 , 2 |     |     END-----> Node: We_Partner Element(1)  
13:25:54:175 , 2 |     |     |     END -----> Attributes: 
13:25:54:175 , 2 |     |     |     |     Partner = 57002239 
13:25:54:175 , 2 |     |     |     |     Db2 = 2'000 
13:25:54:175 , 2 |     |     |     |     Zzkurzbez = Gerber Heidi 
13:25:54:175 , 2 |     |     |     |     Zzrating =  
13:25:54:175 , 2 |     |     |     BEGIN -----> Attributes: 
13:25:54:175 , 2 |     |     BEGIN---> Node: We_Partner Element(1) 
13:25:54:175 , 1 |     |     END -----> Attributes: 
13:25:54:175 , 1 |     |     |     Db2 = 2'000 
13:25:54:175 , 1 |     |     |     Partner = 57002239  
13:25:54:175 , 1 |     |     |     Identbez = Test E20 Kreditgr. 2 
13:25:54:175 , 1 |     |     |     Ident = 0000099998
13:25:54:175 , 1 |     |     BEGIN -----> Attributes:  
13:25:54:175 , 1 |     BEGIN---> Node: Wirtsch_Einheit Element(1)  
13:25:54:144 , 0 |     END -----> Attributes: 
13:25:54:144 , 0 |     BEGIN -----> Attributes: 
13:25:54:144 , 0 BEGIN---> Node: Pe_T_Bpdata Element(1) 
 
 
Copied Node
 
13:25:54:238 , 1 |     END-----> Node: BPFS_WirtschaftlicheEinheit Element(2) 
13:25:54:238 , 2 |     |     Node: BPFS_WirtschaftlicheEinheitPartner      ---> Structure is empty
13:25:54:238 , 1 |     |     END -----> Attributes: 
13:25:54:238 , 1 |     |     |     Db2 = 2'000  
13:25:54:238 , 1 |     |     |     Identbez = Test E20 Kreditgr. 2  
13:25:54:238 , 1 |     |     |     Ident = 0000099998 
13:25:54:238 , 1 |     |     |     Partner = 57002239 
13:25:54:238 , 1 |     |     BEGIN -----> Attributes: 
13:25:54:238 , 1 |     BEGIN---> Node: BPFS_WirtschaftlicheEinheit Element(2)
13:25:54:238 , 1 |     END-----> Node: BPFS_WirtschaftlicheEinheit Element(1) 
13:25:54:238 , 2 |     |     Node: BPFS_WirtschaftlicheEinheitPartner      ---> Structure is empty 
13:25:54:238 , 1 |     |     END -----> Attributes: 
13:25:54:238 , 1 |     |     |     Db2 = 2'000 
13:25:54:238 , 1 |     |     |     Identbez = Test E20 Kreditgr. 3 
13:25:54:238 , 1 |     |     |     Ident = 0000099997
13:25:54:238 , 1 |     |     |     Partner = 57002239 
13:25:54:238 , 1 |     |     BEGIN -----> Attributes:
13:25:54:238 , 1 |     BEGIN---> Node: BPFS_WirtschaftlicheEinheit Element(1)
13:25:54:206 , 0 |     END -----> Attributes:
13:25:54:206 , 0 |     BEGIN -----> Attributes: 
13:25:54:206 , 0 BEGIN---> Node: BusinessPartnerFactsheet Element(1)

hope this helps ...

thx

Fabian

Edited by: Fabian Häusler on Jul 10, 2008 2:58 PM