Quantcast
Channel: SCN : Blog List - Web Dynpro ABAP
Viewing all articles
Browse latest Browse all 107

How to read the data from a filtered table in SAP Web Dynpro ABAP

$
0
0

Hi welcome !!!

 

I would like to share the code/logic of method GET_TABLE_DATA of interface IF_WD_TABLE_METHOD_HNDL which helps to read the data from a filtered Table in Web Dynpro ABAP.

 

I have come across few SCN threads where in the requirement for reading filtered table data is left unanswered, as the method GET_TABLE_DATA( ) is not available in interface IF_WD_TABLE_METHOD_HNDL in their systems. I think the method GET_TABLE_DATA is available from SAP_ABA 731.

 

So, it might be useful if the logic to read the data from a filtered table is available for all.


Pre-requisite:

Basic knowledge of Webdynpro ABAP,& OO ABAP

 

 

Create below method.

 

 

GET_TABLE_DATA( )

Parameters:

IO_TBL Importing type ref to CL_WD_TABLE
RT_DATA Returning WDR_TABLE_ROW_DATA_TAB



METHOD get_table_data.

 

DATA elements         TYPE wdr_context_element_set.  DATA element          TYPE REF TO if_wd_context_element.  DATA row_data         TYPE wdr_table_row_data.  DATA last_row_index   TYPE i.  DATA first_row_index  TYPE i.  DATA wd_row_arrangement_type_id TYPE guid.  DATA wd_row_arrangement         TYPE REF TO cl_wd_view_element.  DATA first_actual_row TYPE i.  DATA fixed_row_count  TYPE i.  DATA data_source      TYPE REF TO if_wd_context_node.  DATA row_count        TYPE i.  DATA selected_elements TYPE wdr_context_element_set.  DATA first_row        TYPE i.  DATA last_row        TYPE i value -1.  CONSTANTS c_none TYPE guid VALUE ''.  CLEAR rt_data.  CLEAR selected_elements.  row_count = 0.  IF data_source IS NOT BOUND.    data_source = io_tbl->get_data_source( ).  ENDIF.  wd_row_arrangement ?= io_tbl->get_row_arrangement( ).  IF wd_row_arrangement IS NOT BOUND.    wd_row_arrangement = io_tbl->get_master_column( ).  ENDIF.  IF wd_row_arrangement IS BOUND.    wd_row_arrangement_type_id = wd_row_arrangement->_cid.  ENDIF.  fixed_row_count = io_tbl->get_row_count( ).  first_actual_row = io_tbl->get_first_actual_row( ).  CASE wd_row_arrangement_type_id.    WHEN c_none.      selected_elements = data_source->get_selected_elements( ).      IF fixed_row_count = -1.        row_count = data_source->get_element_count( ) +
first_actual_row.      ELSE.        row_count = fixed_row_count.      ENDIF.      first_row_index = first_row - first_actual_row.      IF last_row = -1 OR         last_row > row_count.        last_row_index = row_count - first_actual_row.      ELSE.        last_row_index = last_row - first_actual_row.      ENDIF.      IF last_row_index >= first_row_index.        elements = data_source->get_elements( from = first_row_index
to = last_row_index ).      ENDIF.      LOOP AT elements INTO element.        row_data-context_element = element.        row_data-level           = 0.        INSERT row_data INTO TABLE rt_data.      ENDLOOP.  ENDCASE.

ENDMETHOD.

 

Let us say, we have created the above method GET_TABLE_DATA in component controller of WD component.

 

Please refer to the below steps to read data from a filtered table

 

Steps:

  • Go to attributes tab of view and create an view attribute GO_TBL of type ref to CL_WD_TABLE
  • Go to method WDDOMODIFYVIEW( ) and write the below logic to get the reference of table ui element "MY_TABLE"
METHOD wddomodifyview .           IF first_time = abap_true.               "Note: my_table is the ui name of table in view layout               wd_this->go_tbl = view->get_element( 'MY_TABLE' )           ENDIF.
ENDMETHOD.
  • Now, to read data from filtered table, use the below code
   data lt_data type WDR_TABLE_ROW_DATA_TAB.                  wd_comp_controller->get_table_data(                    exporting                         io_tbl = wd_this->go_tbl                    receiving                         rt_data = lt_data ).

 

Thank you for your time and hope content of this blog was helpful.

 

Your comments / Feedback / suggestions are highly appreciable & always welcome


Viewing all articles
Browse latest Browse all 107

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>