cancel
Showing results for 
Search instead for 
Did you mean: 

Values for dynamically created attributes not being displayed in ALV

Former Member
0 Kudos

Hi experts,

I have created a Web Dynpro application where the user enters a range of months, and certain cash amounts are displayed in each month in an ALV based on a set of predefined criteria. To create these months, I created a node, and to this node I added the dynamic attributes as shown below.

LOOP AT lt_dates INTO lv_date.

alv_node_info = alv_node->get_node_info( ).

"GET THE NAME OF THE COLUMN BASED ON THE BUSINESS RULES

lv_name = zcl_dpr_shared=>get_date_name( lv_date ).

attr_info-name = lv_name.

attr_info-type_name = 'NUMC15'.

alv_node_info->add_attribute( attr_info ).

ENDLOOP.

This piece of code works. I then add elements of this type to the alv_node as follows

lr_alv_data_elem = lr_node->create_element( ).

......

lr_alv_data_elem->set_attribute( name = 'lv_name'

value = lv_amount ).

.....

lr_alv_data_elem->set_attribute( name = lv_date_name

value = lv_amount ).

The node has already been bounded to the ALV, and all the static attributes are displayed, but not the dynamic attributes

Any idea why?

Thanks in advance

Johan Kriek

View Entire Topic
Former Member
0 Kudos

Hi Johan,

After setting attribute values you have to bind the newly created element to the node.

Do this and ur problem will be solved.

alv_node->bin_element(

new_item = lr_alv_data_elem

set_initial_elements = abap_false).

Regards,

Sumit Oberoi

Former Member
0 Kudos

Hi Omit, thanks for the quick response.

I have done as you have suggested, and the newly created elements are now displayed in the ALV grid.

However, the values in the Dynamic Attributes are not displayed. They default to the initial value 0.

Former Member
0 Kudos

Hi Johan,

Now i got your requirement clearly.

You want to add an attribute dynamically and want this to appear in the alv also.

See for this you have to get the reference of the node info and add the attribute their like this.

data: lv_info type ref to if_wd_context_info,
        ls_attribute type wdr_context_attribute_info.

lv_info = wd_context->get_node_info( )
ls_attribute-name = 'carrid'
ls_attribute-type_name = 's_carr_id'

call methods lv_info->add_attribute
exporting
attribute_info = ls_attribute

Then u have to set the value of this attribute in all existing elements.

I hope it helps.

Regards,

Sumit Oberoi

Former Member
0 Kudos

Hi Sumit,

Thank you for your reply.

I have performed all the actions as you have suggested.

I use "

lr_alv_data_elem = lr_node->create_element( ).

lr_alv_data_elem->set_attribute( name = 'TOTAL'

value = lv_amount ).

lr_alv_data_elem->set_attribute( name = lv_dynamic_attribute1

value = lv_value).

lr_alv_data_elem->set_attribute( name = lv_dynamic_attribute2

value = lv_value).

lr_node->bind_element( new_item = lr_alv_data_elem

set_initial_elements = abap_false ).

However, the value (lv_value) for the dynamic attribute does not get displayed in the ALV.

The value of lv_amount for the static attribute 'TOTAL' does display

Former Member
0 Kudos

Hi johan,

I am not able to understand the situation clearly.

Did u mean that the dynamic column is being displayed but its blank or not even the column is visible in the alv?

I hope you are binding the node to the alv after adding new attribute.

Regards

Sumit

Former Member
0 Kudos

Hi Sumit.

The column is displayed correctly for the dynamic attribute, but the value is not correct (it defaults to 0).

Because the node is dynamic, I bind the node to the ALV table using the SET_DATA command of the controller. I bind the node after I have set up the dynamic attributes for the node.

Former Member
0 Kudos

Hi Johan,

These steps need to be performed in total:

1)Add atrribute to the node

2)set value of the dynamic attribute in existing elements of node

It should show if your node is binded correctly to the alv node.

Please try defining an external mapping for the alv node and bind it to your context node.

I hope it helps.

Regards,

Sumit Oberoi

Former Member
0 Kudos

Hi Sumit,

I have set up a demo application to reproduce the error.

I have added the following code to the WDDOINIT method of the component controller

lr_node = wd_context->get_child_node( 'ALV_DATA' ).

alv_node_info = lr_node->get_node_info( ).

attr_info-name = 'DYNAMIC1'.

attr_info-default_value = '0'.

attr_info-type_name = 'CHAR40'.

alv_node_info->add_attribute( attr_info ).

alv_node_info = lr_node->get_node_info( ).

attr_info-name = 'DYNAMIC2'.

attr_info-default_value = '0'.

attr_info-type_name = 'CHAR40'.

alv_node_info->add_attribute( attr_info ).

lr_alv_data_elem = lr_node->create_element( ).

lr_alv_data_elem->set_attribute( name = 'GROUPING'

value = 'Cost Element').

lr_alv_data_elem->set_attribute( name = 'ELEMENT_DESCRIPTION'

value = 'DESCR1' ).

lr_alv_data_elem->set_attribute( name = 'CURRENCY'

value = 'EUR' ).

lr_alv_data_elem->set_attribute( name = 'TOTAL'

value = '5555' ).

lr_alv_data_elem->set_attribute( name = 'DYNAMIC1'

value = 'l234' ).

lr_alv_data_elem->set_attribute( name = 'DYNAMIC2'

value = '4567' ).

lr_node->bind_element( new_item = lr_alv_data_elem

set_initial_elements = abap_false ).

lr_alv_data_elem = lr_node->create_element( ).

lr_alv_data_elem->set_attribute( name = 'GROUPING'

value = 'Cost Element').

lr_alv_data_elem->set_attribute( name = 'ELEMENT_DESCRIPTION'

value = 'DESCR2').

lr_alv_data_elem->set_attribute( name = 'CURRENCY'

value = 'EUR' ).

lr_alv_data_elem->set_attribute( name = 'TOTAL'

value = '4567' ).

lr_alv_data_elem->set_attribute( name = 'DYNAMIC1'

value = '9999' ).

lr_alv_data_elem->set_attribute( name = 'DYNAMIC2'

value = '9999' ).

lr_node->bind_element( new_item = lr_alv_data_elem

set_initial_elements = abap_false ).

I have set up an external mapping between the DATA node in the SALV_WD_TABLE component, and set up the component usage.

After running the application in test mode, I get the following result in the ALV

GROUPING ELEM CURRENCY TOTAL DYN1 DYN2

Cost Element DESCR1 EUR 5555 0 0

Cost Element DESCR2 EUR 4567' 0 0

As you can see, the static attributes are updated, but not the dynamic attributes?

Is there something I am missing, or should I log a note?

Thanks in advance,

Johan Kriek

Former Member
0 Kudos

Hi Johan,

Please check in the debug mode that whether the values for dynamic attribute are available in the context node before u are binding it to the ALV node.

Regards,

Sumit Oberoi

Former Member
0 Kudos

Hi Sumit,

After adding the elements to the node, I used method lr_node->get_elements( ) to interrogate the elements in the node.

Both elements contain the correct entries in the DYNAMIC_ATTRIBUTES variable of each element

Regards,

Johan Kriek.

Former Member
0 Kudos

Hi Johan,

I think I have got the problem.

See the reason for the dynamic attribute showing the default value is.

When u add an attribute to the node dynamically you expect to

see the updated value.

That is only possible if u update the mapping after creation of the new attribute.

Please try updating the mapping also after u add the dynamic attribute.

Regards,

Sumit Oberoi

Former Member
0 Kudos

Hi Sumit,

Thank you once again for your quick reply.

How should I update the mapping after adding the dynamic attribute?

Regards,

Johan

Former Member
0 Kudos

Hi Johan,

I am not able to find any functions.

While rethinking on the problem I came up with this thought:

The ALV show the New Attribute that means it is getting the updated node.

Reason for not getting the right value might be something else.

Please revisit the place in the application flow where you are changing the value of the dynamic attribute.

I think we find something there.

Regards,

Sumit Oberoi

SebastianK
Explorer
0 Kudos

Hi there,

for everyone who is still struggling with this issue the SAP Help gives a hint:

http://help.sap.com/saphelp_nwpi711/helpdata/en/49/3e09af347d3ef0e10000000a421937/frameset.htm (see context node, 3rd requirement)

Dynamical Attributes are not supported! That's it