Skip to Content
avatar image
Former Member

Dynamic action to the button

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

6 Answers

  • Best Answer
    Jan 08, 2009 at 05:29 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 08, 2009 at 05:23 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 08, 2009 at 05:26 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 08, 2009 at 05:54 AM

    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|Dynamically insert fields in the Screen; 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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 08, 2009 at 12:39 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 09, 2009 at 11:43 AM

    Hi Uday,

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

    Add comment
    10|10000 characters needed characters exceeded