cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic action to the button

Former Member
0 Kudos

Hi All,

I tried the dynamic programming in webdynpro abap.But when a click on the dynamically created button it is giving the error as accessing via null object refernce is not possible. I have given On_action parameter in new_button method and i written the code but it is not working.

Plz give me solution for this......

Thanks in advance

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Srilalitha,

Try paste the below coding into your WDDOMODIFYVIEW and it would dynamically create a button with id "BUTTON", text as "My Button" & an associated action "ACTION".

METHOD wddomodifyview .
  DATA: lr_container TYPE REF TO cl_wd_uielement_container,
        lr_button TYPE REF TO cl_wd_button.

  CHECK first_time = abap_true.
  lr_container ?= view->get_element( id = 'ROOTUIELEMENTCONTAINER' ).
  cl_wd_matrix_layout=>new_matrix_layout( container = lr_container ).


  lr_button = cl_wd_button=>new_button( id         = 'BUTTON'
                                        text       = 'My Button!'
                                        on_action  = 'ACTION' ).


  cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_button ).

  lr_container->add_child( the_child = lr_button ).
ENDMETHOD.

Create an action by name ACTION under the "Actions" tab of your component. You would then get the corresponding eventhandler ONACTIONACTION. Write your desired coding in there and it should be fine.

Regards,

Uday

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Uday,

Thanks for ur reply.I got the solution with the help of your code...

Former Member
0 Kudos

Hi Uday,

Thanks for ur reply.I tried the same but in action method i wrote the code for navigation to the next,but it is not working.Is there any parameter in new_buton method to pass outbound plug.......or is there any other process to write the action.

uday_gubbala2
Active Contributor
0 Kudos

Hi Srilalitha,

You can get started with dynamic programming by going through this excellent series of blogs by Thomas Szuecs.

[Understanding UI Elements|/people/thomas.szcs/blog/2005/12/28/dynamic-programming-in-web-dynpro-abap--introduction-and-part-i-understanding-ui-elements]

[Handling ViewElements|/people/thomas.szcs/blog/2006/01/03/dynamic-programming-in-web-dynpro-abap--part-ii-handling-viewelements]

[ Aggregations and DDIC-Binding of ViewElements|/people/thomas.szcs/blog/2006/02/22/dynamic-programming-in-web-dynpro-abap--part-iii-aggregations-and-ddic-binding-of-viewelements]

You can also go [here|; where I have posted many code snippets for dynamic programming. Just copy & paste them into your WDDOMODIFYVIEW & try to analyze as to whats going on.

Regards,

Uday

former_member226203
Active Contributor
0 Kudos

if u r gettin this error, plz chk in the code of the method that you have witten which will get triggered on pressing the button. in this code check if the declaration that you made are the same as the declaration (types) of the attributes.Think this error mostly comes becuase of the type mismatch.

Edited by: Kalyan Chakravarthi on Jan 8, 2009 6:26 AM

uday_gubbala2
Active Contributor
0 Kudos

Hi Srilalitha,

Can you try go to ST22 and find out the exact line from where the error is getting triggered? Also you can paste your coding from WDDOMODIFYVIEW in here so that we can have a look at it.

Regards,

Uday