Making Buttons Visible/Invisible in views (Web Dynpro for ABAP)

...Previous  

  1. Write the Code on WDDOINIT method:

METHOD wddoinit .

  
DATA lo_nd_button TYPE REF TO if_wd_context_node.
  
DATA lo_el_button TYPE REF TO if_wd_context_element.
  
DATA ls_button TYPE wd_this->element_button.
  
DATA: lv_button1 LIKE ls_button-button1,
        lv_button2 
LIKE ls_button-button2.

*   navigate from <CONTEXT> to <BUTTON> via lead selection
  lo_nd_button = wd_context->get_child_node( name = wd_this-   >wdctx_button ).

*   get element via lead selection
  lo_el_button = lo_nd_button->get_element(  ).

  lv_button1 = 
2.
  lv_button2 = 
2.

  lo_el_button->set_attribute(
    
EXPORTING
        name = 
'BUTTON1'
        
value =   lv_button1 ).

  lo_el_button->set_attribute(
    
EXPORTING
        name = 
'BUTTON2'
        
value =   lv_button2 ).

ENDMETHOD.  

  1. Write the Code on ONBUTTON1 method:  

METHOD onactiononbutton1 .

  
DATA lo_nd_button TYPE REF TO if_wd_context_node.
  
DATA lo_el_button TYPE REF TO if_wd_context_element.
  
DATA ls_button TYPE wd_this->element_button.
  
DATA: lv_button1 LIKE ls_button-button1,
        lv_button2 
LIKE ls_button-button2.

*   navigate from <CONTEXT> to <BUTTON> via lead selection
  lo_nd_button = wd_context->get_child_node( name = wd_this->wdctx_button ).

*   get element via lead selection
  lo_el_button = lo_nd_button->get_element(  ).

*   get single attribute
  lo_el_button->get_attribute(
    
EXPORTING
      name =  
`BUTTON1`
    
IMPORTING
      
value = lv_button1 ).

  lo_el_button->get_attribute(
    
EXPORTING
      name =  
`BUTTON2`
    
IMPORTING
      
value = lv_button2 ).

  
IF lv_button1 = 2.
    lv_button1 = 
1.
    lv_button2 = 
2.
  
ENDIF.

  lo_el_button->set_attribute(
    
EXPORTING
      name =  
`BUTTON1`
      
value = lv_button1 ).

  lo_el_button->set_attribute(
  
EXPORTING
    name =  
`BUTTON2`
    
value = lv_button2 ).

ENDMETHOD.  

  1. Write the Code on ONBUTTON2 method:

 method ONACTIONONBUTTON2 .

  
DATA lo_nd_button TYPE REF TO if_wd_context_node.
  
DATA lo_el_button TYPE REF TO if_wd_context_element.
  
DATA ls_button TYPE wd_this->element_button.
  
DATA: lv_button1 LIKE ls_button-button1,
        lv_button2 
LIKE ls_button-button2.

*   navigate from <CONTEXT> to <BUTTON> via lead selection
  lo_nd_button = wd_context->get_child_node( name = wd_this->wdctx_button ).

*   get element via lead selection
  lo_el_button = lo_nd_button->get_element(  ).

*   get single attribute
  lo_el_button->get_attribute(
    
EXPORTING
      name =  
`BUTTON1`
    
IMPORTING
      
value = lv_button1 ).

  lo_el_button->get_attribute(
    
EXPORTING
      name =  
`BUTTON2`
    
IMPORTING
      
value = lv_button2 ).

  
IF lv_button2 = 2.
    lv_button2 = 
1.
    lv_button1 = 
2.
  
ENDIF.

  lo_el_button->set_attribute(
    
EXPORTING
      name =  
`BUTTON1`
      
value = lv_button1 ).

  lo_el_button->set_attribute(
  
EXPORTING
    name =  
`BUTTON2`
    
value = lv_button2 ).

endmethod.  

  1. Create the Web Dynpro application.
  2. Save and activate it.
  3. Test the application.
  4. You will get the output like this:  

     Both the button appears.  

Click the Button1. Button2 appears.

Now click the Button2. Button1 appears.

 

 

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