Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
amy_king
Active Contributor
The series Web Dynpro Selection Screen Variants continues from Part 3 with creation of the views and windows.

Part 4: Views and Windows


Views


In Web Dynpro component ZWDR_SELECT_OPTIONS_VARI, create one view for selection of variants options Get, Delete and Save as Variant and a second view for a save dialog.

V_VARI


Create view V_VARI. In this view, the user will select among variants options Get, Delete and Save as Variant.

Context


Map Component Controller nodes VARIANT and CONFIRM to V_VARI's context.

Methods


Create three new event handler methods.

ON_CONFIRM_DELETE


METHOD on_confirm_delete .

DATA lt_confirm TYPE wd_this->elements_confirm.

CASE wdevent->name.
WHEN if_wd_popup_to_confirm_n=>co_popup_button_event-on_ok.

DATA(lo_nd_confirm) = wd_context->get_child_node( name = wd_this->wdctx_confirm ).
lo_nd_confirm->get_static_attributes_table( IMPORTING table = lt_confirm ).

wd_comp_controller->variant_delete( lt_confirm ).
lo_nd_confirm->invalidate( ).

ENDCASE. " wdevent->name

ENDMETHOD.

ON_VARIANT_DELETE


METHOD on_variant_delete .

DATA lt_confirm TYPE wd_this->elements_confirm.

FIELD-SYMBOLS <result_tab> TYPE STANDARD TABLE.

* Identify the selected variants
ASSIGN wdevent->parameters[ name = 'RESULT_TAB' ] TO FIELD-SYMBOL(<ref_tab>).
ASSIGN <ref_tab>-value->* TO <result_tab>.

CHECK <result_tab> IS NOT INITIAL.

* Hold onto selected variants until user confirms their deletion
LOOP AT <result_tab> ASSIGNING FIELD-SYMBOL(<result>).
ASSIGN COMPONENT 'VARIANT' OF STRUCTURE <result> TO FIELD-SYMBOL(<variant>).
APPEND VALUE zwdvari( variant = <variant> ) TO lt_confirm.
ENDLOOP. " <result>

DATA(lo_nd_confirm) = wd_context->get_child_node( name = wd_this->wdctx_confirm ).
lo_nd_confirm->bind_table( new_items = lt_confirm ).

* Confirm deletion
DATA(lv_confirmation_text) =
COND string(
WHEN lines( <result_tab> ) = 1 THEN
|Delete variant?|
ELSE
|Delete { lines( <result_tab> ) } variants?|
).

DATA(lo_confirm_dialog) = wd_this->wd_get_api( )->get_component( )->get_window_manager( )->create_popup_to_confirm(
text = VALUE string_table( ( lv_confirmation_text ) )
button_kind = if_wd_window=>co_buttons_okcancel
message_type = if_wd_window=>co_msg_type_information
window_title = |Delete variants|
).

TRY.
lo_confirm_dialog->popup_to_confirm->subscribe_to_button_event(
controller = wd_this->wd_get_api( )
handler_name = 'ON_CONFIRM_DELETE'
button = if_wd_window=>co_button_ok
).
CATCH cx_wdr_rt_exception.
ENDTRY.

lo_confirm_dialog->open( ).

ENDMETHOD.

ON_VARIANT_GET


METHOD on_variant_get .

FIELD-SYMBOLS <result_tab> TYPE STANDARD TABLE.

* Identify the selected variant
ASSIGN wdevent->parameters[ name = 'RESULT_TAB' ] TO FIELD-SYMBOL(<ref_tab>).
ASSIGN <ref_tab>-value->* TO <result_tab>.

CHECK <result_tab> IS NOT INITIAL.

* Set selected variant in context
READ TABLE <result_tab> ASSIGNING FIELD-SYMBOL(<result>) INDEX 1.

ASSIGN COMPONENT 'VARIANT' OF STRUCTURE <result> TO FIELD-SYMBOL(<variant>).
ASSIGN COMPONENT 'VTEXT' OF STRUCTURE <result> TO FIELD-SYMBOL(<vtext>).

DATA(ls_variant) = VALUE zwdvari( variant = <variant> vtext = <vtext> ).
DATA(lo_nd_variant) = wd_context->get_child_node( name = wd_this->wdctx_variant ).
DATA(lo_el_variant) = lo_nd_variant->get_element( ).
lo_el_variant->set_static_attributes( ls_variant ).

* Load the variant into select-options
wd_comp_controller->variant_get( ls_variant ).

ENDMETHOD.

Actions


Create two new actions, validation-independent action MENU_ACTION and standard action CONFIRM_SAVE, and implement their event handlers.
ONACTIONMENU_ACTION


METHOD onactionmenu_action .

CASE id+7. " ACTION_*
WHEN 'GET'.
wd_this->wd_get_api( )->get_component( )->get_window_manager( )->open_value_help(
search_term = |Get variant|
view = wd_this->wd_get_api( )
event_handler = 'ON_VARIANT_GET'
structure = NEW zwdvari( component = wd_comp_controller->mv_component
application = wd_comp_controller->mv_application ) " SHLP importing parameters
fieldname = 'VARIANT'
).

WHEN 'DELETE'.
wd_this->wd_get_api( )->get_component( )->get_window_manager( )->open_value_help(
search_term = |Delete variants|
view = wd_this->wd_get_api( )
event_handler = 'ON_VARIANT_DELETE'
structure = NEW zwdvari( component = wd_comp_controller->mv_component
application = wd_comp_controller->mv_application ) " SHLP importing parameters
fieldname = 'VARIANT'
multi_select = abap_true
).

WHEN 'SAVE'.
wd_comp_controller->mo_save_dialog = wd_this->wd_get_api( )->get_component( )->get_window_manager( )->create_and_open_popup(
window_name = 'W_SAVE'
title = |Save variant|
is_resizable = abap_false
buttons = wd_this->wd_get_api( )->get_component( )->get_window_manager( )->get_buttons_okcancel( )
).

TRY.
wd_comp_controller->mo_save_dialog->subscribe_to_button_event(
button = if_wd_window=>co_button_ok
action_name = 'CONFIRM_SAVE'
action_view = wd_this->wd_get_api( )
).
CATCH cx_wdr_rt_exception.
ENDTRY.

ENDCASE. " id

ENDMETHOD.

ONACTIONCONFIRM_SAVE


METHOD onactionconfirm_save .

DATA ls_variant TYPE wd_this->element_variant.

DATA(lo_nd_variant) = wd_context->get_child_node( name = wd_this->wdctx_variant ).
DATA(lo_el_variant) = lo_nd_variant->get_element( ).
lo_el_variant->get_static_attributes( IMPORTING static_attributes = ls_variant ).

* Save the variant and close the dialog window
wd_comp_controller->variant_save( ls_variant ).
wd_comp_controller->mo_save_dialog->close( ).

ENDMETHOD.

Layout


View V_VARI contains a ButtonChoice with options for Get, Delete and Save as Variant. In the view's ROOTUIELEMENTCONTAINER, insert a ButtonChoice and assign it the following properties.




























ID
BTNC_VARIANT
ContextMenuBehavior
inherit
enabled checked
ImageSource ~Icon/FunctionVariant
text Variants
visible visible


 

Insert into the ButtonChoice three options.














































ID
enabled hotkey needsMoreInfo text textDirection visible onAction
ACTION_GET
checked none checked Get inherit checked MENU_ACTION
ACTION_DELETE checked none checked Delete inherit checked MENU_ACTION
ACTION_SAVE checked none checked Save as Variant
inherit checked MENU_ACTION


 

V_SAVE


Create view V_SAVE. In this dialog for saving new variants, the user will enter a name and description for the new variant.

Context


Map Component Controller node VARIANT to V_SAVE's context.

Layout


View V_SAVE contains two InputFIelds for assigning a name and description to a new variant. Use the Code Wizard to insert into the view's ROOTUIELEMENTCONTAINER attributes VARIANT and VTEXT from context node VARIANT.





Windows


Create two windows to embed the two views.

W_VARI


Create window W_VARI and embed as its default view the view V_VARI.

W_SAVE


Create window W_SAVE and embed as its default view the view V_SAVE.

Up Next


In Part 5, the series concludes with a demonstration of using component ZWDR_SELECT_OPTIONS_VARI within a Web Dynpro report selection-screen.
Labels in this area