cancel
Showing results for 
Search instead for 
Did you mean: 

mass values of context structures copying

Former Member
0 Kudos

Hi,

a view has a context with 2 structures like as:

Node1

|_ Attribute1

|_ Attribute2

|_ Attribute3

...

|_ AttributeN

Node2

|_ Attribute1

|_ Attribute2

|_ Attribute3

...

|_ AttributeN

Structures Node1 and Node2 have the same set of attributes(by name and size).

I did a primitive code:

wdContext.Node2.setAttribute1(wdContext.Node1.getAttribute1());

wdContext.Node2.setAttribute2(wdContext.Node1.getAttribute2());

...

wdContext.Node2.setAttributeN(wdContext.Node1.getAttributeN())

and so on for all of fields. But it's too long code!

Is it possible to do copying of attributes' values from structure Node1 into Node2? something like ABAP:

Node 2 = Node 1

or

move-corresponding Node1 to Node2

Regards,

Alex

Accepted Solutions (1)

Accepted Solutions (1)

pravesh_verma
Active Contributor
0 Kudos

Hi Alex,

Just use thios code.. This is a small and simple code to do what exactly you want:


IWDNode node1 = wdContext.nodeNode1();
IWDNode node2 = wdContext.nodeNode2();
	  
WDCopyService.copyElements(node1, node2);

Read this documentation for copyElements:


/**
   * Copies all elements from source to target. The method is the same as
   * {@link #copyElements(IWDNode, IWDNode, boolean)} with full=false.
   * @param source The source node
   * @param target The target node
   * @throws RuntimeException if target is a model node and 
   *    source is nota model node holding the same class.
   */

Also read about WDCopyService.copyCorresponding(source, target). this is exactly same as above, however the only difference is it accepts the object as the parameter. The API copyElements accepts the node as the parameter. Read the documentation of copyCorresponding:


/**
   * The Web Dynpro equivalent for the well know abap feature
   * "MOVE_CORRESPONDING". It intentionally has been renamed because the term
   * "move", although always being used in Cobol and ABAP, is not quite correct
   * and unusual in Java.
   * 
   * The method inspects all attributes of source, searches a
   * compatible attribute in target and copies the value if it 
   * finds one. Values are considered compatible if their Java class matches:
   * 
   *  - All numeric classes (Byte, Short, Integer, Long, Float, Double,
   *        BigInteger and BigDecimal) and primitives (byte, short, int, long,
   *        float, double) are compatible.
   *  - Boolean class and primitive are compatible.
   *  - Character (class) and char (primitive) are compatible.
   *  - Otherwise source and target attribute must be based on the same class.
   * 
   * 
   * Currently, both source and target may be either
   * an {@link IWDNodeElement} or an {@link com.sap.tc.cmi.model.ICMIGenericModelClass}.
   * If any object is of another class, it is simply ignored. These both classes
   * have been chosen, because they can tell about their structure at run time
   * without the need of Java reflection.
   * 
   * @param source The source object
   * @param target The target object

I hope this solves your issue. Please revert back in case you need any further information on this.

Thanks and Regards,

Pravesh

Former Member
0 Kudos

Hi Pravesh,

WDCopyService.copyCorresponding(source, target) goes fine! Thank you!

Alex

Answers (0)