cancel
Showing results for 
Search instead for 
Did you mean: 

assigning text to text property of linktoaction created dynamically.

Former Member
0 Kudos

Hi All,

My requirement is to create a link to action dynamically based on entries in a ztable. And on click of this, the respective tcodes should open.

I have created a node link_to_action of cardinality 1..n and attribute called text of type string. Now the ztable is looped and the field transcode is set to the attribute , which is passed as bind text to the dynamically created linktoaction. In the output i am getting the linktoaction as much as the records but all have the same text as the last record. Please help. PFB the code.

   loop at it_zps_reports_port into wa_zps_reports_port.



*********Dynamically add the link to action buttons .




      lo_nd_link_to_action = wd_context->get_child_node( name = wd_this->wdctx_link_to_action ).


* get element via lead selection
      lo_el_link_to_action = lo_nd_link_to_action->get_element( ).


* @TODO handle not set lead selection
      if lo_el_link_to_action is  initial.
       endif.
* @TODO fill attribute
        lv_textt = wa_zps_reports_port-trans_code.

* set single attribute

*ASSIGN lv_textt to <fs_text>.

lo_el_link_to_action->set_static_attributes( lv_text ).
* set single attribute
     lo_el_link_to_action->set_attribute(
      name =  `TEXT`
       value = lv_textt ).

*lv_link_text = wa_zps_reports_port-TRANS_CODE.

lr_count = lr_count + 1.



concatenate lr_id lr_id_d into lr_id_d.

      call method cl_wd_link_to_action=>new_link_to_action
        exporting
*         activate_access_key         =
*         bind_control_menu_disabling =
*         bind_design                 =
*         bind_enabled                =
*         bind_image_first            =
*         bind_image_height           =
*         bind_image_source           =
*         bind_image_width            =
          bind_text                   = 'LINK_TO_ACTION.TEXT'
*         bind_text_direction         =
*         bind_tooltip                =
*         bind_type                   =
*         bind_visible                =
*         bind_wrapping               =
*         context_menu_behaviour      = E_CONTEXT_MENU_BEHAVIOUR-INHERIT
*         context_menu_id             =
*         control_menu_disabling      = 'X'
*         design                      = E_DESIGN-STANDARD
*         enabled                     = 'X'
*         hotkey                      = E_HOTKEY-NONE
        id                          = lr_id_d
*         image_first                 = 'X'
*         image_height                =
*         image_source                =
*         image_width                 =
*         on_action                   =
*         text                        = lv_link_text
*         text_direction              = E_TEXT_DIRECTION-INHERIT
*         tooltip                     =
*         type                        = E_TYPE-FUNCTION
*         view                        =
*         visible                     = E_VISIBLE-VISIBLE
*         wrapping                    =
        receiving
          control                     = lr_linktoaction.


      lr_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data(
*      cell_background_design = E_CELL_BACKGROUND_DESIGN-TRANSPARENT
*      cell_design            = E_CELL_DESIGN-R_PAD
*      col_span               = '1'
*      drag_data              = drag_data
              element                = lr_linktoaction
*      height                 = height
*      h_align                = E_H_ALIGN-BEGIN_OF_LINE
*      id                     = id
*      v_align                = E_V_ALIGN-BASELINE
*      v_gutter               = E_V_GUTTER-NONE
*      width                  = width
                 ).

      lr_linktoaction->set_layout_data( the_layout_data = lr_matrix_head_data   ).

      lr_uielement_container->add_child(
*    index     = lr_ind
          the_child = lr_linktoaction
             ).

   clear : lo_el_link_to_action , lr_linktoaction.


      endloop.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Soumya,

  i done one example my be it's help ful for you,

   ->Created two nodes in Component controller-> i.e,EMP

& LINK_TO_ACTION  with cardinality 1 to N.

EMP-EID TYPE STRING

      - ENAME TYPE STRING

      -  LINK TYPE STRING

LINK_TO_ACTION - link type STRING

IN WDDOINIT MEHOD write this logic.

    DATA LO_ND_EMP TYPE REF TO IF_WD_CONTEXT_NODE.
  DATA LS_EMP TYPE WD_THIS->ELEMENT_EMP.
  DATA LT_EMP TYPE WD_THIS->ELEMENTS_EMP.
*   navigate from <CONTEXT> to <EMP> via lead selection
  LO_ND_EMP = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_EMP ).

  LS_EMP-EID = '1'.
  LS_EMP-ENAME = 'A'.
  LS_EMP-LINK = 'Click Here'.
  APPEND LS_EMP TO LT_EMP.

  LS_EMP-EID = '2'.
  LS_EMP-ENAME = 'A'.
  LS_EMP-LINK = 'Click Here'.
  APPEND LS_EMP TO LT_EMP.

  LO_ND_EMP->BIND_TABLE( LT_EMP ).

  DATA LO_ND_LINK_TO_ACTION TYPE REF TO IF_WD_CONTEXT_NODE.
  DATA LS_LINK_TO_ACTION TYPE WD_THIS->ELEMENT_LINK_TO_ACTION.
  DATA LT_LINK_TO_ACTION TYPE WD_THIS->ELEMENTS_LINK_TO_ACTION.
*     navigate from <CONTEXT> to <LINK_TO_ACTION> via lead selection
  LO_ND_LINK_TO_ACTION = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_LINK_TO_ACTION ).

  LS_LINK_TO_ACTION-LINK = 'http://www.google.co.in/'.
  APPEND LS_LINK_TO_ACTION TO LT_LINK_TO_ACTION.

  LS_LINK_TO_ACTION-LINK = 'http://www.sdn.sap.com/irj/scn'.
  APPEND LS_LINK_TO_ACTION TO LT_LINK_TO_ACTION.

  LO_ND_LINK_TO_ACTION->BIND_TABLE( LT_LINK_TO_ACTION ).

in View level

----------------------------

created table with 3 columns & third column cell editor taken as LINK_TO_ACTION.

In that action write this logic:

   DATA:LV_INDEX TYPE SY-INDEX.

  DATA LO_ND_EMP TYPE REF TO IF_WD_CONTEXT_NODE.
  DATA LO_EL_EMP TYPE REF TO IF_WD_CONTEXT_ELEMENT.
  DATA LS_EMP TYPE WD_THIS->ELEMENT_EMP.
  DATA LT_EMP TYPE WD_THIS->ELEMENTS_EMP.
  FIELD-SYMBOLS:<LS_EMP> TYPE WD_THIS->ELEMENT_EMP.
*   navigate from <CONTEXT> to <EMP> via lead selection
  LO_ND_EMP = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_EMP ).
  LO_ND_EMP->GET_STATIC_ATTRIBUTES_TABLE( IMPORTING TABLE = LT_EMP ).

  DATA LO_ND_LINK_TO_ACTION TYPE REF TO IF_WD_CONTEXT_NODE.
  DATA LS_LINK_TO_ACTION TYPE WD_THIS->ELEMENT_LINK_TO_ACTION.
  DATA LT_LINK_TO_ACTION TYPE WD_THIS->ELEMENTS_LINK_TO_ACTION.
* navigate from <CONTEXT> to <LINK_TO_ACTION> via lead selection
  LO_ND_LINK_TO_ACTION = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_LINK_TO_ACTION ).
  LO_ND_LINK_TO_ACTION->GET_STATIC_ATTRIBUTES_TABLE( IMPORTING TABLE = LT_LINK_TO_ACTION ).
**  get element via lead selection
   LO_EL_EMP = LO_ND_EMP->GET_ELEMENT( ).

   LV_INDEX = LO_EL_EMP->GET_INDEX( ).

*  LV_INDEX = LO_ND_EMP->GET_LEAD_SELECTION_INDEX( ).



  READ TABLE LT_EMP ASSIGNING <LS_EMP> INDEX LV_INDEX.
  IF SY-SUBRC EQ 0.
    READ TABLE LT_LINK_TO_ACTION INTO LS_LINK_TO_ACTION INDEX LV_INDEX.
    IF SY-SUBRC EQ 0.
      <LS_EMP>-LINK = LS_LINK_TO_ACTION-LINK.
    ENDIF.
  ENDIF.

  READ TABLE LT_EMP INTO LS_EMP INDEX LV_INDEX.
  IF SY-SUBRC EQ 0.

    DATA LO_WINDOW_MANAGER TYPE REF TO IF_WD_WINDOW_MANAGER.
    DATA LO_API_COMPONENT  TYPE REF TO IF_WD_COMPONENT.
    DATA LO_WINDOW         TYPE REF TO IF_WD_WINDOW.

    LO_API_COMPONENT  = WD_COMP_CONTROLLER->WD_GET_API( ).
    LO_WINDOW_MANAGER = LO_API_COMPONENT->GET_WINDOW_MANAGER( ).
    LO_WINDOW         = LO_WINDOW_MANAGER->CREATE_EXTERNAL_WINDOW(
             URL      = LS_EMP-LINK
                       ).

    LO_WINDOW->OPEN( ).


  ENDIF.

but here the problem is you need to select that patticular record then it works.

Answers (4)

Answers (4)

Former Member
0 Kudos

Thanks to all who took time to reply. for others benefit, what i did for the above is.. for the link to action text i have assigned the workarea element as required. And in the on_click method , i used parameters to get the ID of the linktoaction clicked and mapped the ID to te values in the table. Hence eleminated the usage of attributes for my requirement.

Former Member
0 Kudos

Hi All,

The problem with those suggested like usage of rowrepeater is that, a tabstrip is to be created dynamically, and as per the records is a ztable tabs are to be created, and based on the tab index marked in the ztable link to action must be created in that particular tab. so thats y it has to be dynamically created. If someone could help with code it would be very useful.!

Former Member
0 Kudos

Hi Soumya,

I think you are not binding the context node with proper table data.

You are setting the context node attribute TEXT every time.

Instead get the text data in an internal table by looping into ztable and then bind the context node with the internal table data.

I think this will work.

Regards,

Sayan

chengalarayulu
Active Contributor
0 Kudos

Soumya,

you can make use of RowRepeater instead of dynamic creation. just fetch data from Z table and bind to node.

and you can write your code on LinkToAction UI action.

Former Member
0 Kudos

Hi Chengalarayulu,

The thing is there is a condition as well.. not all records shud be created with linktoaction at the same place. THe whole requirement is to create tabs for different type of reports dynamically and then fetch records pertaining to that type of reports and then for each transaction create a linktoaction along with textedits for description of  the reports.

chengalarayulu
Active Contributor
0 Kudos

soumya,

can you check the below document it may helpful. its regarding ViewSwitch which is one of the way to display Tabular as well as LinkToAction UI element performs.

http://scn.sap.com/docs/DOC-25062