Static and Dynamic Context Menu in ABAP Web Dynpro

...Previous

7.     Bind context node to UI Elements as specified above.

8.     Assign “actions” to “button” and “Menu action items” as specified above.

9.     Click on method tab and create method “LOAD_TABLE”

10.  Double click on method “LOAD_TABLE” paste following code

METHOD load_table .
  
DATAlo_nd_table TYPE REF TO if_wd_context_node,
        ls_table 
TYPE wd_this->element_table,
        lt_table 
TYPE wd_this->elements_table.

* navigate from <CONTEXT> to <TABLE> via lead selection
  lo_nd_table 
wd_context->get_child_nodename wd_this->wdctx_table ).

* Loading sample data for Demo: Use query instead of this
  
DO TIMES.
    
WRITE sy-index TO ls_table-id.
    
CONCATENATE 'Name ' ls_table-id INTO ls_table-name.
    
APPEND ls_table TO lt_table.
  
ENDDO.

  lo_nd_table
->bind_tablenew_items lt_table set_initial_elements abap_true ).
ENDMETHOD.

11.  Double click on method “ONACTIONCLEART” paste following code

METHOD onactioncleart .

  
DATAlo_nd_table TYPE REF TO if_wd_context_node,
        lt_table 
TYPE wd_this->elements_table,
* get message manager
        lo_api_controller     
TYPE REF TO if_wd_controller,
        lo_message_manager    
TYPE REF TO if_wd_message_manager.

* navigate from <CONTEXT> to <TABLE> via lead selection
  lo_nd_table 
wd_context->get_child_nodename wd_this->wdctx_table ).
  lo_nd_table
->get_static_attributes_tableIMPORTING table lt_table ).

  
IF lt_table IS INITIAL.
    lo_api_controller ?= wd_this
->wd_get_api( ).
    
CALL METHOD lo_api_controller->get_message_manager
      RECEIVING
        message_manager 
lo_message_manager.
* report message
    
CALL METHOD lo_message_manager->report_message
      
EXPORTING
        message_text 
'Table is already empty'.
  
ELSE.
    
CLEAR lt_table" Clearing Data of Table
    lo_nd_table
->bind_tablenew_items lt_table set_initial_elements abap_true ).

  
ENDIF.

ENDMETHOD.

12.  Double click on method “ONACTIONRELOADT” paste following code

METHOD onactionreloadt .
*  Reload old data into table
  wd_this
->load_table(
  
).
ENDMETHOD.

13.  Double click on method “ONACTIONRESET” paste following code

METHOD onactionreset .

  
DATAlo_nd_input TYPE REF TO if_wd_context_node,
        lo_el_input 
TYPE REF TO if_wd_context_element,
        ls_input 
TYPE wd_this->element_input.

*   navigate from <CONTEXT> to <INPUT> via lead selection
  lo_nd_input 
wd_context->get_child_nodename wd_this->wdctx_input ).

*   get element via lead selection
  lo_el_input 
lo_nd_input->get_element( ).

  
CLEAR ls_input" Clearing Input Field

*   set all declared attributes
  lo_el_input
->set_static_attributes(
     static_attributes 
ls_input ).

ENDMETHOD.

14.  Double click on method “ONACTIONSAVE” paste following code

METHOD onactionsave .
  
DATAlo_nd_input TYPE REF TO if_wd_context_node,
        lo_el_input 
TYPE REF TO if_wd_context_element,
        ls_input 
TYPE wd_this->element_input,
        lo_nd_table 
TYPE REF TO if_wd_context_node,
        lt_table 
TYPE wd_this->elements_table,
* get message manager
        lo_api_controller     
TYPE REF TO if_wd_controller,
        lo_message_manager    
TYPE REF TO if_wd_message_manager.


*   navigate from <CONTEXT> to <INPUT> via lead selection
  lo_nd_input 
wd_context->get_child_nodename wd_this->wdctx_input ).

*   get element via lead selection
  lo_el_input 
lo_nd_input->get_element( ).

*   get all declared attributes
  lo_el_input
->get_static_attributes(
    
IMPORTING
      static_attributes 
ls_input ).

  
IF ls_input-id IS INITIAL OR ls_input-name IS INITIAL.
    lo_api_controller ?= wd_this
->wd_get_api( ).
    
CALL METHOD lo_api_controller->get_message_manager
      RECEIVING
        message_manager 
lo_message_manager.

* report message
    
CALL METHOD lo_message_manager->report_error_message
      
EXPORTING
        message_text 
'Enter data then click save'.

  
ELSE.
* navigate from <CONTEXT> to <TABLE> via lead selection
    lo_nd_table 
wd_context->get_child_nodename wd_this->wdctx_table ).
    lo_nd_table
->get_static_attributes_tableIMPORTING table lt_table ).

    
APPEND ls_input TO lt_table" Adding a record to table

    lo_nd_table
->bind_tablenew_items lt_table set_initial_elements abap_true ).
    
CLEAR ls_input.

*   set all declared attributes
    lo_el_input
->set_static_attributes(
       static_attributes 
ls_input ).

  
ENDIF.

ENDMETHOD.

15.  Double click on method “WDDOONCONTEXTMENU” paste following code.

METHOD wddooncontextmenu .
*  context_menu_event->originator->id contains the name of UIElement
*  if context menu called on a row of table control and it contains some value, then
*  condition ( CONTEXT_MENU_EVENT->CONTEXT_ELEMENT IS BOUND ) will be true.
*  Use this condition to bind context menu for existing records in the table control.

  
IF strlencontext_menu_event->originator->id 4
    
AND context_menu_event->originator->id(5) = 'TABLE'.
    
" Condition for all UIElement having 1st 5 character = 'TABLE'
    
" This condition covers all Table UIElement
    menu 
context_menu_manager->get_context_menu'DYN_MENU' ).
  
ENDIF.

ENDMETHOD.

16.  Double click on method “WDDOINIT” paste following code

METHOD wddoinit .
* Load table to show
  wd_this
->load_table(
  
).

ENDMETHOD.

17.  Create web dynpro application “zwa_context_menu”. Save and test it

18.  Initial view

Click here to continue...
 

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image