Skip to Content
Author's profile photo Philip Johnston

ABAP WebDynpro – Scrolling and Setting Focus

This is a very short and sweet explanation of scrolling your view to an element and also setting the focus to an element.  I was asked several times how to do this, so I thought I’d put a short document together.  I have found that you often want to scroll into view and set the focus of elements especially when doing dynamic programming.  For example, if you are building elements on a screen dynamically, you may always want to make sure that the last dynamic element created is visible on the screen.  Note: if you have a scrolling screen (you might have configured scrolling on the rootuielementcontainer), and you are adding dynamic elements to your view, you won’t want to scroll to the next dynamic control created. Rather, create an invisible static control at the end of the view.  I do this because depending on the type of dynamic control being created, you might only get the very top of it displayed if you scroll to it.  I prefer to create the invisible control (statically) and place it at the bottom of the screen and scroll to it.  This always makes sure that my last dynamically created element is in view.



I created a view with a scrollable rootuielementcontainer:


I then added a transparentcontainer (TC_QUESTIONS) where I will build dynamic controls:


I then add an invisible horizontalgutter control for scrolling to:



“Insert code here for building dynamic controls (not shown)

“Code below is for scrolling and setting focus

data lr_elem type ref to if_wd_view_element.
data lr_bottom_elem type ref to if_wd_view_element.

“Scroll to Invisible Control

= view->get_element( ‘HG_BOTTOM’  ).
if lr_bottom_elem is bound.
->scroll_into_view( lr_bottom_elem ).
catch cx_root into wd_this->g_cxroot.

“Set Focus on Control

          lr_elem = view->get_element( ‘ID_OF_CONTROL’ ).
if lr_elem is bound.
->request_focus_on_view_elem( lr_elem ).


In the WDDOMODIFYVIEW, you can set a pointer to your view so it is globally available:

define the view attribute: G_VIEW RefTo IF_WD_VIEW

  if first_time = abap_true.
        wd_this->g_view ?= view.
      catch cx_root into wd_comp_controller->g_cxroot.


then in any of you view methods, you can use the scroll and focus like:

    wd_this->g_view->scroll_into_view( lr_scroll_to_elem ).
    wd_this->g_view->request_focus_on_view_elem( lr_scroll_to_elem ).

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Yurii Sychov
      Yurii Sychov

      Thanks a lot!

      Author's profile photo Christopher Solomon
      Christopher Solomon

      VERY clever! Using an invisible element to "jump" to. I knew you were a WDA wizard!