cancel
Showing results for 
Search instead for 
Did you mean: 

Binding a structure to a node element vs binding a structure to a node

Former Member
0 Kudos

In Section 5 of the NET310 course, SAP gives examples of getting reference to a context node, creating an element of the node, and binding a structure to the element,

In Section 8, on the other hand, SAP gives an example of binding a structure directly to a context node.

The difference seems to be that when you bind the structure to a context node in Section 8, the data is not going to be displayed ... it's just going to be passed to a consumer component.

The other difference is that in the Section 8 case, there is only one possible element of the node, so binding to the node is the same as binding to a singleton element of the node.

But I'm not sure if either of these is the right explanation.

So my questions are::

a) when can you bind to a node instead of an element of the node?

b) when should you bind to a node instead of an element of a node.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi David,

This is a very interesting point that you have raised. I will try to respond to it as best as possible based on my knowledge of ABAP and the documentation.

First of all, the two methods BIND_ELEMENT & BIND_STRUCTURE (and their respective counterparts in the plural form BIND_ELEMENTS & BIND_TABLE) behave in a similar manner, which can be inferred from the following statements taken from the [online WDP ABAP documentation.|http://help.sap.com/saphelp_nw04s/helpdata/en/77/3545415ea6f523e10000000a155106/frameset.htm]

- The importing parameter NEW_ITEM of the method BIND_ELEMENT, can be a reference to a context element or a reference to a data structure or a data structure itself. If it is a data structure, for performance reasons you should use BIND_STRUCTURE.

- With the BIND_STRUCTURE method a structure can be created as a new element in a node. The structure should preferably be the same as the declared structure of the node, but it does not have to be. If the structures are not the same, a move-corresponding is executed. In other respects this method behaves the same as BIND_ELEMENT.

So, coming back to your questions,

Although you can always first create a new element data using CREATE_ELEMENT and then append the element to the context node using BIND_ELEMENT, this involves two method calls and should ideally not be done if you already have an entire structure filled with data. In such a case you should directly use BIND_STRUCTURE or BIND_ELEMENT.

Therefore, from my experience I can say that it is always better to fill your structure with data and then bind directly to the node, instead of binding to an element and then again to a node. The same holds good for a table - First create an internal table with all your data, and then execute a BIND_TABLE or BIND_ELEMENTS, instead of creating elements independently and binding them to the node.

I'm not too sure about the part where it is mentioned that the data will not be displayed when binding a structure to a node, since I have used both the methods, and I am able to see data on the UI. I think internally, the methods create an element from the structure and bind it to a node.

You can also refer to the documentation whose link I have provided above.

Navigate to the section

Reference -> Programming Interfaces -> Context APIs.

I do hope I have been able to clarify your questions.

Regards,

Wenonah

former_member181923
Active Participant
0 Kudos

Hi again W -

You seem a little unsure, so I'm keeping the question open a little longer.

But I think you have the actual correct answer when you wrote:

I think internally, the methods create an element from the structure and bind it to a node.

This makes perfectly good sense for a node with cardinality 0..1. Why require the explicit creation of an element rather than implicit creation of an element behind the scenes.

Hopefully, we'll get some additional expert opinion/knowledge here.

Best

djh

Former Member
0 Kudos

Hi David,

Well, I did a little more research on this.

Yes, they both internally create elements and assign them to nodes. The difference is:

In case of BIND_STRUCTURE, the only input that can be supplied is a structure (no elements. Whereas, in case of BIND_ELEMENT, the input can be either a structure, or a reference to an element.

Therefore, if you have a structure, (eg. when you are trying to initialize a new node), you should use BIND_STRUCTURE.

If you have an element already existing (eg. you have read a context element, and changed an attribute of the element), you should use BIND_ELEMENT.

Hope this makes things more clear.

Regards,

Wenonah

former_member181923
Active Participant
0 Kudos

Thanks again, WJ.

That was vet helpful and is much appreciated.r

Answers (0)