cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Link to action UI element dynamically

Former Member
0 Kudos

   Hello,

       I have to create UI elemet link to action dynamically...

   when the user enters the data in input field and clicks enter, then ui element link to action shoud create dynamicaally with the value of the input field and

then link to action action event sholud trigger..

i have created ui element in modify view method but as per my requirement it will not work properly..

can you please let me know how to create.

Thanks ,

Nagalakshmi.

Accepted Solutions (0)

Answers (5)

Answers (5)

former_member210804
Active Participant
0 Kudos

Hi Nagalakshmi,

I have done one example for the same scenario recently .. Please go through the steps.

It displays the personal details of employee(info type 0002) based on pernr selected.

1. Created 2 nodes PERNR and PERSONAL with cardinality 1..1 and 0..n respectively.

2.  Map the 2 nodes to the MAIN view and created a lable and inputfield.

    

3. Created an Action 'ENTER' for the inputfield. and write the below code.

METHOD onactionenter.

   DATA: lr_link_to_action      TYPE REF TO cl_wd_link_to_action.
   DATA lr_container  TYPE REF TO cl_wd_uielement_container.
   DATA lr_matrix    TYPE REF TO cl_wd_matrix_head_data.
   DATA: view TYPE REF TO cl_wdr_view.
   DATA: lv_str TYPE string.

   DATA lo_nd_pernr TYPE REF TO if_wd_context_node.
   DATA lo_el_pernr TYPE REF TO if_wd_context_element.
   DATA ls_pernr TYPE wd_this->element_pernr.
   DATA: lv_pernr TYPE wdy_md_translatable_text.

   DATA lo_el_context TYPE REF TO if_wd_context_element.
   DATA ls_context TYPE wd_this->element_context.
   DATA lv_count TYPE wd_this->element_context-count.
   DATA lv_visible TYPE wd_this->element_context-lv_visible.

*   get element via lead selection
   lo_el_context = wd_context->get_element( ).
*   navigate from <CONTEXT> to <PERNR> via lead selection
   lo_nd_pernr = wd_context->get_child_node( name = wd_this->wdctx_pernr ).
*   get element via lead selection
   lo_el_pernr = lo_nd_pernr->get_element( ).

   CLEAR: ls_pernr,lv_pernr.
*   get all declared attributes
   lo_el_pernr->get_static_attributes(
     IMPORTING
       static_attributes = ls_pernr ).

*************************************************************************
   DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .
   lo_componentcontroller wd_this->get_componentcontroller_ctr( ).


   lv_pernr = ls_pernr-pernr.

* Create a method in component controller to get the personal details(infotype 0002) for the selected employee.

   lo_componentcontroller->get_it0002( EXPORTING pernr = lv_pernr ).                          " p0002-pernr
*************************************************************************

   view ?= wd_this->wd_get_api( ).
*  lv_str = view->if_wd_controller~name.
   lr_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).

*   get single attribute
   lo_el_context->get_attribute(
     EXPORTING
       name `COUNT`
     IMPORTING
       value = lv_count ).

   DATA: view_info TYPE REF TO if_wd_rr_view.
   DATA: lv_id1 TYPE string.
   DATA: lv_idx TYPE char2 VALUE 1.

   IF lv_count IS NOT INITIAL.
     DATA: id TYPE string.
     id = wdevent->get_string( lv_count ).

******************************************************************

* To remove the existing LinkToAction UI element

******************************************************************

   CALL METHOD lr_container->remove_child
       EXPORTING
         id        = id
         index    = 3
*      RECEIVING
*        the_child =
         .
*********************************************
* TO change the ID of UI element dynamically
*********************************************

*    lv_visible = 01.
     CALL METHOD lo_el_context->set_attribute
       EXPORTING
         value = lv_visible
         name  = 'LV_VISIBLE'.


     lv_idx = lv_idx + 1.
     CONCATENATE 'ID' lv_idx INTO lv_count.

     CALL METHOD lo_el_context->set_attribute
       EXPORTING
         value = lv_count
         name  = 'COUNT'.
   ELSE.
*    lv_visible = 02.
     lv_count = 'ID'.
     CALL METHOD lo_el_context->set_attribute
       EXPORTING
         value = lv_count
         name  = 'COUNT'.
   ENDIF.

   CALL METHOD cl_wd_link_to_action=>new_link_to_action
     EXPORTING
        id                          = lv_count
        on_action                   = 'DISPLAY_DETAIL'
       text                        = lv_pernr
        view                        = view
       visible                     = 02
      RECEIVING
       control                    = lr_link_to_action.


   lr_matrix = cl_wd_matrix_head_data=>new_matrix_head_data( lr_link_to_action ).
   CALL METHOD lr_container->add_child
     EXPORTING
       index    = 3
       the_child = lr_link_to_action.

ENDMETHOD.

4.  Create an Action name 'DISPLAY_DETAIL'  and write the code.

   
   DATA lo_nd_personal TYPE REF TO if_wd_context_node.
   DATA lo_el_personal TYPE REF TO if_wd_context_element.
   DATA ls_personal TYPE wd_this->element_personal.
   DATA lt_personal TYPE wd_this->elements_personal.


   DATA lo_el_context TYPE REF TO if_wd_context_element.
   DATA ls_context TYPE wd_this->element_context.
   DATA lv_lv_visible TYPE wd_this->element_context-lv_visible.

 
CALL METHOD lo_nd_personal->get_static_attributes_table
     IMPORTING
       table = lt_personal.


  lv_lv_visible = 02.

   CALL METHOD lo_el_context->set_attribute
     EXPORTING
       value = lv_lv_visible
       name  = 'LV_VISIBLE'.

   lo_nd_personal->bind_table( lt_personal ).

5.  Check the output.

            

Once we enter pernr and click on ENTER button,the below screen appears.

 

click on LinkToAction UI, We can get personal information as below.

Try to change the pernr and click on ENTER again

Once we click on Enter ..

Hope it will be useful.

Best regards,

RAO.

       

Harsh_Bansal
Contributor
0 Kudos

Hi,

Follow the steps as mentioned in -

http://wiki.sdn.sap.com/wiki/display/WDABAP/Creating+UI+Elements+Dynamically+in+Abap+Webdynpro+Appli...

In method 'NEW_LINK_TO_ACTION' prut the Input field value in 'TEXT' parameter and give a method name in 'ON_ACTION' parameter.

Now create an event handler method in your view with the same name as provided above and write your functionality there.

In the event handler for press of enter in input field, after you write the code to create the Link to Action, manually call the event handler method created for it.

Regards,

Harsh Bansal

Former Member
0 Kudos

Hello,

you can make LTA dynamically using the Input field value but the action which will be triggered after enter/click can't be dynamic. you have to make method statically.

guillaume-hrc
Active Contributor
0 Kudos

Hi,

Check this thread, you have the code to dynamically create LTA.

http://scn.sap.com/thread/3390780

Best regards,

Guillaume

Former Member
0 Kudos