Skip to Content
avatar image
Former Member

Copy Nodes

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    Jul 12, 2008 at 02:48 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • avatar image
    Former Member
    Jul 10, 2008 at 11:47 AM

    Hi,

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

    Regards

    Ishita

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • avatar image
    Former Member
    Jul 10, 2008 at 11:49 AM

    Hi,

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

    Regarding the functionality of WDCopyService.copySubtree

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 10, 2008 at 11:52 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 11, 2008 at 04:58 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 11, 2008 at 07:22 AM

    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

    Add comment
    10|10000 characters needed characters exceeded