cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic context, ALV, no data - but everything seems to be in place!

matt
Active Contributor
0 Kudos

I've created a component for displaying data in an ALV, with the intention of using it in other components.

The component controller has two methods:

SET_DATA_STRUCTURE (parameter I_attributes IMPORTING type WDR_CONTEXT_ATTR_INFO_MAP).

SET_CONTENTS (parameter i_reference_contents IMPORTING type ref to data).

The both trigger similarly named events which are reacted to by the view controller.

The handler for the data structure is this:

   data root_info type ref to if_wd_context_node_info.

   root_info = wd_context->get_node_info( ).

   data data_node type ref to if_wd_context_node_info.

   data_node = root_info->add_new_child_node( name = 'DATA'

                                  is_initialize_lead_selection = abap_false

                                  is_static = abap_false

                                  is_multiple = abap_true

                                  attributes = i_structure ).

The handler for set_contents sets the view attribute reference_to_contents.

The WDDOMODIFYVIEW method handles the contents (only when there is new data).

     data lo_nd_table_contents type ref to if_wd_context_node.

     lo_nd_table_contents = wd_context->get_child_node( name = 'DATA' ).

     field-symbols <table_contents> type any table.

     assign wd_this->reference_to_contents->* to <table_contents>.

     if <table_contents> is assigned.

       lo_nd_table_contents->bind_table( new_items = <table_contents> set_initial_elements = abap_true ).

     endif.

     data lo_interfacecontroller type ref to iwci_salv_wd_table .

     lo_interfacecontroller =   wd_this->wd_cpifc_alv( ).

     lo_interfacecontroller->set_data( r_node_data = lo_nd_table_contents ).

     wd_this->new_contents = abap_false.

When I test my application, I can see inthe debugger that the context is correctly created and populated. The data is bound correctly to the context. But no data is displayed in the grid.


I've looked through the various tutorials, and can't see what I've missed.


I've instantiated the usage in WDOINIT of the view. I've embedded the control in the window. Every step checks out - but still no data is seen. I've tried the refresh method on the interface controller of the usage - nothing.


I've just checked, and the field order and field names of the data being sent in reference_to_contents are identical to that in i_attributes.


Accepted Solutions (1)

Accepted Solutions (1)

ramakrishnappa
Active Contributor
0 Kudos

Hi Matthew,

If we create a dynamic node by using ATTRIBUTES parameter, we cannot get the data in alv table. But,

To get data inside alv, we need to create a node by using parameter "static_element_rtti"

Sample Code:


  DATA lo_str_descr TYPE REF TO cl_abap_structdescr.
  DATA lt_comp      TYPE cl_abap_structdescr=>component_table.
  DATA ls_comp LIKE LINE OF lt_comp.
  DATA LV_NAME TYPE STRING.

  CLEAR lt_comp.


  LOOP AT lt_fields ASSIGNING <ls_fields> WHERE check EQ abap_true.

    CLEAR ls_comp.
    ls_comp-name = <ls_fields>-fieldname.

    CONCATENATE ls_demo_input-tabname ls_comp-name INTO lv_name SEPARATED BY '-'.

      LS_COMP-TYPE ?= cl_abap_typedescr=>describe_by_name( p_name = LV_NAME  ).

    APPEND ls_comp TO lt_comp.
  ENDLOOP.

  cl_abap_structdescr=>create(
    EXPORTING
      p_components =   lt_comp
    RECEIVING
      p_result     = lo_str_descr
  ).
*    CATCH cx_sy_struct_creation.    " Exception when creating a structure description

  lo_nd_info = wd_context->get_node_info( ).

  lo_nd_info->add_new_child_node(
    EXPORTING
      name                         =    'DATA'
      is_initialize_lead_selection = abap_false  
      static_element_rtti          =  lo_str_descr
      is_static                    = abap_false

     attributes       = i_structure
    RECEIVING
      child_node_info              = lo_nd_info
  ).


Hope this helps you.

Regards,

Rama

matt
Active Contributor
0 Kudos

Do you know this for a fact, or are you suggesting another way of building the attribute list that might work? I say this, because I know the SET DATA method goes through the context and if it doesn't have the RTTI data, it seems to generate it.

But I will try it.

ramakrishnappa
Active Contributor
0 Kudos

I was also having the same issue. I could able to get data in alv by using STATIC_ELEMENT_RTTI.

matt
Active Contributor
0 Kudos

Well, I tried it, and a few other things based on it, and it appears you have the solution.

My code is:

   DATA root_info TYPE REF TO if_wd_context_node_info.

   root_info = wd_context->get_node_info( ).

   " Convert attributes to RTTI entries

   DATA attribute TYPE wdr_context_attribute_info.

   LOOP AT i_structure INTO attribute.

     DATA components TYPE cl_abap_structdescr=>component_table.

     DATA component  TYPE abap_componentdescr.

     DATA type       TYPE REF TO cl_abap_datadescr.

     CLEAR component.

     component-name = attribute-name.

     component-type ?= cl_abap_typedescr=>describe_by_name( attribute-type_name ).

     INSERT component INTO TABLE components.

   ENDLOOP.

  " Create the new context, starting at TABLE DATA with attributes as in "components"

   root_info->add_new_child_node(

                                  name = 'DATA'

                                  is_initialize_lead_selection = abap_false

                                  is_static = abap_false

                                  static_element_rtti = cl_abap_structdescr=>create( components ) ).


(I'm in a 7.3 system, so I get to use chaining of methods!)

ramakrishnappa
Active Contributor
0 Kudos

Yes, the chaining of methods is really a wonderful option in NW 7.3+ , as it minimizes the data declarations

Answers (2)

Answers (2)

former_member184578
Active Contributor
0 Kudos

Hi,

Yes, Looks like the initialization of ALV component usage was missed!


DATA: lr_alv_cmp_usage TYPE REF TO if_wd_component_usage.

  lr_alv_cmp_usage = wd_this->wd_cpuse_<usage_name>( ).

  IF lr_alv_cmp_usage->has_active_component( ) IS INITIAL.

    lr_alv_cmp_usage->create_component( ).

  ENDIF.

Regards,

Kiran

matt
Active Contributor
0 Kudos

No. I already said " I've instantiated the usage in WDOINIT of the view"

Florian
Active Contributor
0 Kudos

Hi MAtthew,

just a thought, might be you perhaps missed something at the ALV-Binding. I worked through this document a few days ago and it worked fine.

Do you know that tutorial?

What I missed first, is located at page 8 below. I missed to instantiate the ALV itself.

Regards

Florian

matt
Active Contributor
0 Kudos

I did say "I've instantiated the usage in WDOINIT of the view" - so it isn't that.