Hi,

Welcome, I will not take much time of yours 🙂

————————————-

I have come across the scenario, where we need to check mandatory attributes of alv in Web dynpro abap.

In complex applications we may have many views with alv table data and we need to check mandatory attributes of alv tables accordingly.

We all know that,….. we can not perform the mandatory checks as we do for normal view fields by using methd CHECK_MANDATORY_ATTR_ON_VIEW of class CL_WD_DYNAMIC_TOOL,

instead, we need to use method CHECK_MANDATORY_ATTRIBUTES.

Problem:

The method CHECK_MANDATORY_ATTRIBUTES requires the attributes list, for which the mandatory check has to happen 🙁 .

Oh, then

how to get the mandatory attributes from alv table by using VIEW reference?.

Then, isn’t it a good idea,

          if we have a method which does the trick 🙂 i.e. getting alv table mandatory attribute list by using VIEW reference.

Every alv table is embedded into an internal view called VIEW_TABLE and it contains all the columns details of alv during runtime.

Now, how to reach/get reference of  VIEW_TABLE element  from view ?

         We do get the reference of VIEW_TABLE by using recursive call of our method.

Okay, we got some idea of how we are going to get the columns of alv table using VIEW reference.

Now, its time to get into some coding part 🙂

Create a method GET_ALV_MANDATORY_ATTR as below

Parameters

params.PNG

GET_ALV_MANDATORY_ATTR

METHOD get_alv_mandatory_attr .

  “Define Data
  DATA:
    lt_view_elements  TYPE wdr_element_tab,
    lt_children       TYPE wdr_view_for_area_tab,
    ls_children       TYPE wdr_view_for_area_line,
    lo_wdr_view       TYPE REF TO cl_wdr_view,
    lo_wd_view        TYPE REF TO if_wd_view,
    lo_wdr_component  TYPE REF TO cl_wdr_component,
    lo_wd_column      TYPE REF TO cl_wd_table_column,
    lv_column_name    TYPE string,
    lv_node_path      TYPE string,
    lv_str            TYPE string,                          “#EC NEEDED
    lo_input_field    TYPE REF TO cl_wd_input_field,
    lt_ext_mapping    TYPE wdr_reverse_mapped_node_infos,
    ls_ext_mapping    TYPE wdr_reverse_mapped_node_info,
    ls_attr           LIKE LINE OF ct_attr_list.

  FIELD-SYMBOLS:
             <fs_view_element> TYPE wdr_element_line.

  “Get the delegating view reference and view elements
  lo_wdr_view ?= io_wd_view.

  lt_children = lo_wdr_view->children.

  “loop over to the view elements till the actual ALV table
  LOOP AT lt_children INTO ls_children.

    “Get the view object with table entries

    IF ls_children-view_object->get_id( ) EQ ‘VIEW_TABLE’.

      lt_view_elements = lo_wdr_view->get_elements( ).

      “Loop over the view elements, set the properties

      LOOP AT lt_view_elements ASSIGNING <fs_view_element>.

        “if the element is an UI element proceed further to property
        “settings

        IF ( <fs_view_element>-view_element->_definition_name
                                            EQ ‘INPUT_FIELD’ ).

          lo_input_field ?= <fs_view_element>-view_element.

          IF lo_input_field->get_state( ) EQ 1.

            lo_wd_column ?= <fs_view_element>-view_element->_parent.

            lv_column_name = lo_wd_column->get_id( ).

            lo_wdr_component ?=
                      <fs_view_element>-view_element->_component.

            “Get external mapping details of interface controller

            lt_ext_mapping = lo_wdr_component->get_external_mappings( ).
            READ TABLE lt_ext_mapping INTO ls_ext_mapping INDEX 1.
            ” Get node path
            SPLIT ls_ext_mapping-path AT ‘.’
                  INTO: lv_str lv_node_path.

            CLEAR ls_attr.
            ls_attr-node_path = lv_node_path.
            ls_attr-element_index = 0.
            ls_attr-attribute_name = lv_column_name.

            APPEND ls_attr TO ct_attr_list.

          ENDIF.
        ENDIF.

      ENDLOOP.

    ELSE.
      ” Pass the next view object for recursive call
      lo_wd_view ?= ls_children-view_object.

     get_alv_mandatory_attr(
        EXPORTING
            io_wd_view = lo_wd_view
        CHANGING
          ct_attr_list = ct_attr_list
    ).

    ENDIF.

  ENDLOOP.
ENDMETHOD.

Note:  The below statement

<fs_view_element>-view_element->_definition_name

                                            EQ ‘INPUT_FIELD’

I have given an example of check for a column editor of type input field.

You can also check for CHECKBOX, TEXT_EDIT,DROPDOWN_BY_KEY, DROPDOWN_BY_IDX, etc

Hope this blog is helpful for those looking for getting mandatory columns of ALV table in Webdynpro ABAP using VIEW reference.

I appreciate your comments/suggestions/feedback. 🙂

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply