Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

In this blog I will exchange my experience in the Web Dynpro for ABAP technology. The blog content will be extanded gradually...

Web Dynpro View

Dynamic Modification of View Elements Properties

Issue

The view elements are designed as ready for input (editable). There is a request to make view elements non-editable all at once.

A solution for this problem can be achieved in the view method WDDOMODIFYVIEW.

Solution

The method WDDOMODIFYVIEW receives two parameters: FIRST_TIME and VIEW. The view instance VIEW provides the access to all view elements. As the view elements are different of the type (Input Fields, Drop Down, Buttons etc.) we need to create right references to each of them.

Code

METHOD wddomodifyview.

  DATA:
    lo_view            TYPE REF TO cl_wdr_view,
    lo_input_field     TYPE REF TO cl_wd_abstract_input_field,
    lo_drop_down       TYPE REF TO cl_wd_abstract_dropdown,
    lo_button          TYPE REF TO cl_wd_abstract_button,
    ltbl_view_elements TYPE wdr_element_tab.

  FIELD-SYMBOLS <lfs_view_element> LIKE LINE OF ltbl_view_elements.

  IF ( first_time = abap_true ).

* The own method WD_THIS->GET_VIEW_STATE( ) delivers the state of view (CREATE, CHANGE, SHOW)
* The state values (CREATE, CHANGE, SHOW) are defined in the assistant class

    IF ( wd_this->get_view_state( ) = wd_assist->con_view_state-show ).

      lo_view ?= view.

* Get all view elements
      ltbl_view_elements = lo_view->get_elements( ).  " this method is available within SAP system depending on its version and release level
     
* Loop the view elements and set theirs properties (here read only and enabled)

      LOOP AT ltbl_view_elements ASSIGNING <lfs_view_element>.

* Abstract Input Field
        TRY.
            lo_input_field ?= <lfs_view_element>-view_element.
            lo_input_field->set_read_only( abap_true ).
            CONTINUE.
          CATCH cx_sy_move_cast_error .

        ENDTRY.

* Abstract Drop Down List
        TRY.
            lo_drop_down ?= <lfs_view_element>-view_element.
            lo_drop_down->set_read_only( abap_true ).
            CONTINUE.
          CATCH cx_sy_move_cast_error .
        ENDTRY.


* Abstract Button
        TRY.
            lo_button ?= <lfs_view_element>-view_element.
            lo_button->set_enabled( abap_false ).
            CONTINUE.
          CATCH cx_sy_move_cast_error .
        ENDTRY.

      ENDLOOP.

    ENDIF.

  ENDIF.


ENDMETHOD.

6 Comments