SAP Webdynpro Dynamic Changing Layout

How to change SAP Webdynpro Layout dynamically in method WDDOMODIFYVIEW.

Webdynpro enhancement offer variety of options and it is very flexible. However, sometimes you are left with no option but layout of view dynamically. Below is Application Wizard webdynpro (E-Recruitment) in SAP which lets candidate apply for Job posting. Requirement was to display Job Posting advert next to the form in highlighted green box in below screen shot.

01

Looking at the underlying webdynpro HRRCF_C_COVERLETTER_UI view VW_COVERLETTER it became apparent that layout of view need to be changed to allow two columns. With left column to host existing controls and right column to host new control required to display job advert.

All existing controls in view are grouped together in two transparent container APPLICATION_SOURCE and COVER_LETTER which needs to be moved in new transparent container. Below is what I want to achieve after Enhancement of view.

plan

Trouble is you only get limited number of options when enhancing Webdynpro view, reassigning the existing control to new layout isn’t one of them. And this reassignment need to be carried out at runtime.

Do as much as possible at design time. I have added transparent container U0 with colCount = 2, then added two child transparent container both with colSpan = 1 this make a 1 row with two column. I have already added IFRAME under U2 container where job advert will be shown. All that is required not is to move APPLICATION_SOURCE and COVER_LETTER under U1.

This is what we will do at runtime.

plant

Add method SHUFFLE_LAYOUT in view where all code will be kept. You can add code in post-exit of WDDOMODIFYVIEW method if you like instead of creating a separate method and calling it.

02

In this method, logic finds the reference of root element using

METHOD shuffle_layout .

  DATA lo_root_element TYPE REF TO cl_wd_uielement_container.
  DATA lo_u1 TYPE REF TO cl_wd_uielement_container .
  DATA lo_original TYPE REF TO  cl_wd_uielement_container .

  IF first_time NE abap_true .
    RETURN .
  ENDIF.

  lo_root_element ?= iv_view->get_root_element( ).
  lo_u1 ?= iv_view->get_element( id = 'U1' ).

  lo_original ?= lo_root_element->remove_child( id = 'APPLICATION_SOURCE' ) .
  lo_u1->add_child( the_child = lo_original ) .

  lo_original ?= lo_root_element->remove_child( id = 'COVER_LETTER' ) .
  lo_u1->add_child( the_child = lo_original ) .

ENDMETHOD.

post exit on WDDOMODIFYVIEW

  wd_this->shuffle_layout(
    first_time =   first_time
    iv_view =        view  ).

03

Leave a Reply