cancel
Showing results for 
Search instead for 
Did you mean: 

Get values of dynamic attributes in node

0 Kudos

Hello,

I have a UI table in my view which displays static columns. Then I had to add some columns dynamically with a checkbox as cell editor and obviously I added same number of attributes to the context node dynamically. It works fine. The problem is that I do not know how to retrieve the values in the checkboxes when user presses Save. When I read the context node I get only the static fields in the node but not those created dynamically for every record in the table.

How can I read the information ??

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello jorge,

Unfortunately this is limitation of ALV. It do not support dynamic attributes.

Instead of using dynamic attributes, consider instead dynmically generating the entire context node.  Using the RTTS you can build a dynamic type that is a combination of all the fields you need.  You can then use this dynamic data type as the source of the context and all the attributes will be consider static.

For example you can build the dynamic node using

DATA:

   rootnode_info TYPE REF TO if_wd_context_node_info,

   dyn_node      TYPE REF TO if_wd_context_node,

   tabname_node  TYPE REF TO if_wd_context_node,

   struct_type   TYPE REF TO cl_abap_structdescr,

   comp_tab      TYPE cl_abap_structdescr=>component_table,

   comp          LIKE LINE OF comp_tab.

   comp-name = 'FLD1'.

   comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).

   APPEND comp TO comp_tab.

   comp-name = 'FLD2'.

 

   comp-type ?= cl_abap_datadescr=>describe_by_name( 'STRING' ).

   APPEND comp TO comp_tab.

 

*Code for getting node info of root node

   rootnode_info = wd_context->get_node_info( ).

*Code for creating a new node with structure defined in comp_tab

   struct_type = cl_abap_structdescr=>create( comp_tab ).

   rootnode_info = rootnode_info->add_new_child_node(

   name = 'NEW_NODE'

   is_mandatory = abap_true

   is_multiple = abap_true

   static_element_rtti = struct_type

   is_static = abap_false

   ).

   dyn_node = wd_context->get_child_node( name = 'NEW_NODE' ).

And you can set this data to the ALV using

DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.

 

    lo_cmp_usage = wd_this->wd_cpuse_alv( ).

   IF lo_cmp_usage->has_active_component( ) IS INITIAL.

     lo_cmp_usage->create_component( ).

   ENDIF.

   DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .

   lo_interfacecontroller = wd_this->wd_cpifc_alv( ).

   lo_interfacecontroller->set_data(

* only_if_new_descr = " wdy_boolean

   "r_node_data =

   dyn_node " ref to if_wd_context_node

   ).

I hope this helps you....


Answers (6)

Answers (6)

0 Kudos

Hello all,

thanks but in some answers there´s a misunderstanding. As I mentioned, I created a node with some static attributes and in runtime I have to add some attributes dynamically. I cannot create a structure in the DDIC because I cannot know the number of new attributes and I cannot use lo_el_test_node->get_attribute because the system triggers an error because the element is not available (it reads only static attributes).

The other problem is that I should not generate the whole node and UI table because the work was for nothing; I should then start from zero. Now I know for the next time. I tried the topic RTTI and it works !!

former_member191728
Active Participant
0 Kudos

HI Jorge

I think u are using Table UI element

so u can use cell variant feature in table

In table UI element u can insert cell variant to collumn

By this u can make collumns visible and invisible dynamically

and bind the collumns properties to the attributes of the node

use code wizard to read the node

it will solve your problem

if you dont konw how to use cell variant google it u will lot of tutorials on that

regards

Pawan Akella

former_member215632
Discoverer
0 Kudos

Hi Jorge,

You can do it simple by looping through context node elements and reading it attributes:

  DATA:

       dyn_node     TYPE REF TO if_wd_context_node

     , lt_rows  TYPE wdr_context_element_set

     , lr_elem         TYPE REF TO if_wd_context_element

     , lv_checkbox TYPE wdy_boolean

   .

   dyn_node = wd_context->get_child_node( name = 'NODE_NAME' ).

   lt_rows = dyn_node->get_elements( ).

   LOOP AT lt_rows INTO lr_elem.

      lr_elem->get_attribute( EXPORTING name = 'ATTRIBUTE_NAME'  IMPORTING value = lv_checkbox ).

*    Here your processing of lv_checkbox value

    ENDLOOP.

Another way to achive your needs is usage of RTTI:

DATA:

       dyn_node     TYPE REF TO if_wd_context_node

     , node_info    TYPE REF TO if_wd_context_node_info

     , struct_type  TYPE REF TO cl_abap_structdescr

     , table_type   TYPE REF TO cl_abap_tabledescr

     , t_newtable   TYPE REF TO data

     , t_newline    TYPE REF TO data

   .

   FIELD-SYMBOLS:

       <t_data> TYPE STANDARD TABLE

     , <fs_data> TYPE any

     , <fs_checkbox> TYPE wdy_boolean

   .

   dyn_node = wd_context->get_child_node( name = 'NODE_DATA' ).

   node_info = dyn_node->get_node_info( ).

   struct_type = node_info->get_static_attributes_type( ).

   table_type = cl_abap_tabledescr=>create( p_line_type = struct_type ).

   CREATE DATA t_newtable TYPE HANDLE table_type.

   ASSIGN t_newtable->* TO <t_data>.

   CREATE DATA t_newline TYPE HANDLE struct_type.

   ASSIGN t_newline->* TO <fs_data>.

   ASSIGN COMPONENT 'ATTRIBUTE_NAME' OF STRUCTURE <fs_data> TO <fs_checkbox>.

   dyn_node->get_static_attributes_table( IMPORTING table = <t_data> ).

   LOOP AT <t_data> INTO <fs_data>.

*    Here your processing of <fs_checkbox> value

   ENDLOOP.

Take a look at the example component DEMODYNAMIC in the SWDP_DEMO package, which was delivered together with your system.



Former Member
0 Kudos

Hello,

Give an empty action on the checkbox field so that the wdmodifyview is run everytime you give an entry.

And on save :

data: lrcl_node type ref to if_wd_context_node,

        lt_data     type table of <your_table>.

        lrcl_node = wd_context->get_child_node('<node_name>').

        lrcl_node->get_static_attributes_table( importing table = lt_data ).

You will have the data.

Cheers!!!

guillaume-hrc
Active Contributor
0 Kudos

Hi,

Do you use the wizard to access the context node?

Have you checked this?

http://www.sdn.sap.com/irj/scn/elearn?rid=/library/uuid/201ddd3b-b4ce-2b10-8883-880ae8147f89&overrid...

Does your context node refer to a DDIC structure for your internal table (method GET_STATIC_ATTRIBUTES) ?

Try using the node info to find out the components of your node, build a dedicated internal table dynamically and retrieve the data from the context node.

Best regards,

Guillaume

0 Kudos

Hi Jorge,

when we use get_static_attributes( )method, it will read only static attibues only. we can see dynamic attributes in debug mode.

if you want to read dynamic attributes then call method via element ref as

lo_el_test_node->get_attribute(

     exporting

          name = 'DYN_ATTR_NAME'

     importing

           value = lw_value

Regards,

Venkat