cancel
Showing results for 
Search instead for 
Did you mean: 

Cardinality Error

Former Member
0 Kudos

Hi Experts,

I have just started learning Web dynpro ABAP. Recently, I have created a simple webdynrpo ABAP Application in which I have 3 input fields and a button. When I enter certain value in 1st input field and press the button the corresponding values are filled up in the respective 2 input fields. Everything works fine when the cardinality in 1.1. But the moment I change the cardinality to 0.1 it goes for cardinality error.

I did some research regrading cardinality but still unable to understand.In every document it is stating that if you need one element or a structure then you can set the cardinality as 0.1 or 1.1.

Do suggest as to how to select the cardinality accordingly.

With Thanks & Regards,

Varun Kumar Sahu

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Varun,

As far as my understanding is: when you set Cardinality as 0:1, WD runtime does not find any element where the value of the input field can be set/captured. In this case, you'll have to manually initialize your context node. You can do so by binding empty structure to your node in WDDOINIT method of your view.

In case of Cardinality 1:1, this initialization is taken care by WD Runtime.

Please cross check.

Regards,

Rohit

Former Member
0 Kudos

Hello Rohit,

Thanks for responsing so quick.

Got the theory part in my head. Binding empty structure means shall I have to take a node which is not binded to any UI elements or any other and how do I manually initialize my context node. Please do elaborate as I'm having still certain clouds of confusion.

Thanks & Regads,

Varun Kumar Sahu    

Former Member
0 Kudos

Hi Varun,

The code below is one of the ways you can do it. I kept the Cardinality of the node TEST1 as 0:1.

I wrote this code in WDDOINIT of my view.

   data lo_nd_test1 type ref to if_wd_context_node.
   data ls_test1 type wd_this->element_test1.

    lo_nd_test1 = wd_context->get_child_node( name = wd_this->wdctx_test1 ).
    lo_nd_test1->bind_structure( new_item = ls_test1 set_initial_elements = abap_true ).

You can go through this document to know more about context in WDA.

http://scn.sap.com/docs/DOC-2213

Regards,

Rohit

Former Member
0 Kudos

Hello Rohit,

Again many thanks for such a quick response.

Just like to clear out as to what I have understood. In your above demo application you have not created any attribute inside the node. Only an node is declared and that is being called in the hook method.

For using the cardinality 0.1 shall I have create a node in which I can have exactly 1 UI element or nothing. If so how this 0.1 property be used exactly?

Thanks & Regards,

Varun Kumar Sahu    

Former Member
0 Kudos

Hi Varun,

My TEST1 node has multiple attributes in it.

Cardinality of a node has nothing to do with the no. of attributes it has. It is about No. of Elements a node can have at runtime.

A table UI element which displays multiple rows (elements) at a time, should be bind to a node which have Cardinality as 0:N or 1:N. This implies that this Node can have 0 to n number of elements at Runtime.

For a normal User Input form or Selection Screen like functionality, the cardinality of the Node should be 0:1 or 1:1.

This document will really help you understand all this.

http://scn.sap.com/docs/DOC-2213

Regards,

Rohit

Former Member
0 Kudos

Hello Rohit,

Understood the concept. I implemented the concept, getting the error.

Declared a node, set to 0..1 cardinality. In view layout inserted a input field UI element and the code being written in WDOINIT.

Please find the attached screenshots.

Thanks & Regards,

Varun Kumar Sahu

Former Member
0 Kudos

Hi Varun,

The earlier code was working perfectly for me.

You can try the code below.

data lo_nd_test1 type ref to if_wd_context_node.
   data ls_test1 type wd_this->element_test1.

    lo_nd_test1 = wd_context->get_child_node( name = wd_this->wdctx_test1 ).
   lo_nd_test1->create_element( exporting static_attribute_values = ls_test1 ).

Regards,

Rohit

Former Member
0 Kudos

Hello Rohit,

Thanks once again.

Did try out your code. Still having the same error as sent you in the screenshot. Maybe I think its because of the IDES system ! I don't know but will keep looking in other servers. Willpost accordingly.

Thanks & Regards,

Varun Kumar Sahu    

amy_king
Active Contributor
0 Kudos

Hi Varun,

You can initialize your context node by writing a supply function for the node. The supply function is called automatically by the web dynpro framework when the context node is initialized by the runtime.

method supply_mynode.

data ls_mynode type wd_this->element_mynode.

* Bind a single element
   node->bind_structure(
     new_item             = ls_mynode
     set_initial_elements = abap_true ).

endmethod.

If your plan is always to initialize the node with a blank element though, you may as well define your node as 1..1 and let the framework create the blank element automatically.

Cheers,

Amy

Former Member
0 Kudos

Hello Amy,

Many Thanks to you. My problem has been solved.

Thanks & Regards,

Varun Kumar Sahu

Answers (1)

Answers (1)

sudarmanikandan
Explorer
0 Kudos

Hi Varun,

Please do mark the Initialization Lead Selection property of the node "TEST", so the WDA framework automatically set the lead selection during runtime.

I hope this will solve your problem when you use cardinality as 0 to 1.

Thanks,

Sudar

Former Member
0 Kudos

Hello Sudar,

Many Thanks to you. My problem has been solved.

Would also like to tell that along with checking the Initialization Lead Selection property, we also have to write a supply function whereby we have initialize the node.

You may see the comment given by Amy King.

Thanks & Regards,

Varun Kumar Sahu