cancel
Showing results for 
Search instead for 
Did you mean: 

How can i read context's ITAB data?

former_member194142
Participant
0 Kudos

Hello

Below is standard SAP code from WDDOINIT of a standard webdynrpo, now i want to write a post-exit and want to modify the ITAB and finally rebind it to context,


   METHOD WDDOINIT.

  DATA: ls_result_line LIKE LINE OF wd_this->mr_component_ctrl->mt_search_result,
        ls_result_info LIKE wd_this->mr_component_ctrl->ms_search_result_inf,
        lt_key_field TYPE dpr_tt_api_name_value_pair.       "#EC NEEDED
*        ls_key_field TYPE dpr_ts_api_name_value_pair.

  DATA: lt_construct TYPE dpr_tt_api_name_value_pair,
        ls_construct LIKE LINE OF lt_construct,
        lv_begin     TYPE i,
        lv_end       TYPE i,
        i            TYPE i VALUE 1,

        lt_url TYPE dpr_tt_api_name_value_pair,
        ls_url TYPE dpr_ts_api_name_value_pair,
        lv_columns TYPE i.

  DATA: lr_type_desc   TYPE REF TO cl_abap_typedescr,
        lr_struc_desc  TYPE REF TO   cl_abap_structdescr,
        lt_field_desc  TYPE abap_component_tab.

  DATA: ls_dyn_wa TYPE REF TO cl_abap_structdescr,
        lt_dyn_comp_tab TYPE cl_abap_structdescr=>component_table,
        ls_dyn_comp     LIKE LINE OF lt_dyn_comp_tab.

  DATA: lt_cxt_like TYPE REF TO  data,
        ls_cxt_like TYPE REF TO  data.

  FIELD-SYMBOLS: <comp>             TYPE any,
                 <comp_url>         TYPE string,
                 <itab>             TYPE STANDARD TABLE,
                 <wa>               TYPE any,
                 <ls_dyn_comp_tab>  LIKE LINE OF lt_dyn_comp_tab.

  DATA : lv_result TYPE string.

* Get key information for links in the result list
  CALL METHOD wd_this->mr_component_ctrl->mr_ui_log_search->get_key_fields
    RECEIVING
      et_key_fields = lt_key_field.

* Construct component table
  lt_construct   = it_construct.
  ls_result_info = wd_this->mr_component_ctrl->ms_search_result_inf.

  LOOP AT lt_construct INTO ls_construct .
    ls_dyn_comp-name = ls_construct-name.
    ls_dyn_comp-type ?= cl_abap_typedescr=>describe_by_name( ls_construct-value ).
    APPEND ls_dyn_comp TO lt_dyn_comp_tab.
  ENDLOOP.

* Construct working area
  ls_dyn_wa = cl_abap_structdescr=>create( lt_dyn_comp_tab ).

* DATA creation and handling
  CREATE DATA ls_cxt_like TYPE HANDLE ls_dyn_wa .
  ASSIGN ls_cxt_like->* TO <wa>.
  wd_comp_controller->mr_select_cxt_structure = ls_cxt_like.

  CREATE DATA lt_cxt_like LIKE TABLE OF <wa>.
  ASSIGN lt_cxt_like->* TO <itab>.

  lv_begin = 1.
  lv_end   = ls_result_info-num_columns .

  CHECK lv_end IS NOT INITIAL.
  WHILE  lv_end <= ls_result_info-num_return.

    LOOP AT wd_this->mr_component_ctrl->mt_search_result
         INTO ls_result_line FROM lv_begin TO lv_end.

*     check if this column is relevant
      READ TABLE lt_dyn_comp_tab
                 WITH KEY name = ls_result_line-fieldname
                 TRANSPORTING NO FIELDS.

      IF sy-subrc = 0.
*       Yes, use outputvalue for the result table

        ASSIGN COMPONENT  sy-tabix  OF STRUCTURE <wa> TO <comp>.

        IF <comp> IS ASSIGNED AND sy-subrc EQ 0.

          <comp> = ls_result_line-fieldval .
        ENDIF.

      ENDIF.

      i = i + 1.

      UNASSIGN <comp>.

    ENDLOOP.
    IF <wa> IS NOT INITIAL.
      APPEND <wa> TO <itab>.
    ENDIF.
    lv_begin = lv_begin + ls_result_info-num_columns.
    lv_end   = lv_end   + ls_result_info-num_columns.
    i = 1.

  ENDWHILE.


  CALL METHOD wd_comp_controller->mr_ui_log_search->fill_breadcrumb
    EXPORTING
      iv_breadcrumb_sel = wd_comp_controller->mv_breadcrumb_sel
    CHANGING
      ct_result_tab     = <itab>.


* Sort result tab according to first& second visible column
  SORT <itab> BY (wd_this->mv_sortfield1) (wd_this->mv_sortfield2).

* Bind table
  CALL METHOD ir_child_node->bind_elements  " ==> Pls. let me know the counter part method for this method so that i                                                                                            "will read the <itab> data into my local <my_local_itab> 
    EXPORTING
      new_items            = <itab>
      set_initial_elements = abap_true.


ENDMETHOD.

In my post-exit of the above method, i want to modify the <itab> data and want to rebind it again, hence, pls. let me know

1) How can get / read the <itab> data into my local <my_itab> or my_itab? i tried with STATIC_ATTRIBUTE / STATIC_ATTRIBUTES / GET_ELEMENTS method of IF*NODE* but no use!, pls. let me know how can read <itab>?

2) To bind the modified <my_itab> i guess,, just i will copy the abpve code and use for my post-exit

Thank you

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi there,

First to get data do this:

Data: lv_node type ref to if_wd_context_node,

          lt_tab type standard table of if_view=>element_tableofdata,

          lv_wa like line of lt_tab.

lv_node = wd_context->get_child_node( name = 'TABLEOFDATA' ).

lv_node->get_static_attributes_table( importing table = lt_tab ).


Now do your processing

To bind back to the context do the following:

lv_node->bind_table( lt_tab).

hope it helps..

former_member194142
Participant
0 Kudos

Thank you, but here my case is ALV stuff, hence your code is not working for my case, the <iatb> is a dynamic itab, pls. see how they built it

I tried couple of ways, but not getting of reading the <itab> data into my_itab


ramakrishnappa
Active Contributor
0 Kudos

Hi,

I would suggest that to use OVERWRITE exit of the method WDDOINIT( ) as it skips the execution of standard code.

Copy all the existing code in WDDOINIT and put it in overwrite exit. Now you can modify the data of <itab> as you like and bind it.

Hope this helps you.

Regards,

Rama

former_member194142
Participant
0 Kudos

Than you. Instead of OVERWRITE i will go with POST-EXIT wherein i will put all standard code as pasted above in my OP, so that i will get again <itab> then i will modify finally i will bind.

Bcz overwrite is not suggestable right?

Just curious, so there is no way to read <itab> data into <my_itab>?

ramakrishnappa
Active Contributor
0 Kudos

Hi,

If you go for POSTEXIT, the standard code still executes and the same is again executed in POSTEXIT as well. To avoid the execution of same again, we can overwrite it by using OVERWRITE exit.

Also, you can check if data is stored in either component controller attributes / class attributes. In your case it can be accessed from wd_this->mr_component_ctrl->mt_search_result

Regards,

Rama

former_member194142
Participant
0 Kudos

Thank you, yes, it will be executed again, but still i feel post-exit is better option over overwrite.

Yes, in my case, MT_SEARCH_RESULT is holding data, but the data is not in tabular / easily accesable (not matrix) format, its like in XML format, hence i want to play around with <itab> bcz its a tabular format data

So, there is not way to read the <itab> data,

ramakrishnappa
Active Contributor
0 Kudos

Hi,

I think, node reference ir_child_node is an importing parameter. You have already tried GET_ELEMENTS( ) method.

I have few questions:

Did you get elements collection by using method get_elements( ) ?

Is the node exist statically in the context with all attributes ?

Regards.

Rama

former_member194142
Participant
0 Kudos

Thank you, yes, you are correct that the IR_CHILD_NODE is a import param.

1) yes, am getting elements collection

2) no, its not statically defined node on context, its dynamic ALV from standard WDC

As a last resort i will copy & paste all standard code into my post-exit,m then i will modify then rebinds again

Than you

ramakrishnappa
Active Contributor
0 Kudos

Okay, you can achieve your requirement by using POSTEXIT and placing all the required code in it.

All the best

FYI:

As you have elements collection, you can also get data by using context element reference

  • Loop over the elements and use context element reference
      • Get the attribute value by using GET_ATTRIBUTE
      • Set the attribute value by using SET_ATTRIBUTE to modify data

Regards,

Rama

Answers (0)