cancel
Showing results for 
Search instead for 
Did you mean: 

wd_context modification in order to trigger the CHANGE badi

matteo_montalto
Contributor
0 Kudos

Hi all gurus,

I'm working on an SRM 7 system and basically I'd like to understand how any modification on a field can trigger a BBP_DOC_CHANGE_BADI execution.

This is my scenario: on the item overview dynpro, the user can click on a custom toolbar button which set a ZZATTRIBUTE (abap_bool) to 'X'; my desiderata is that, after that button click, also the BBP_DOC_CHANGE_BADI is executed.

So, that's basically how I'd like it to work: when the user clicks on that button, the associated action - method is executed.

That's a sketch in pseudocode of the method:

CALL METHOD wd_context->get_child_node
    EXPORTING
      name       = 'CTR_ITEM'
    RECEIVING
      child_node = lon_ctr_item.

* Get the selected elements of the item table
  lt_elem_set  = lon_ctr_item->get_selected_elements( abap_true ).

* for each selected element, set  ZZATTRIBUTE value
  LOOP AT lt_elem_set INTO ls_element.
      CALL METHOD ls_element->set_attribute
        EXPORTING
          value  = abap_true
          name   = 'ZZATTRIBUTE'.        
...

This sequence works but does NOT trigger the BBP_DOC_CHANGE_BADI (which is usually executed when an input field is filled or modified, or more in general, when a modification occoured on the document).

I found out that setting the changed attribute by client in this way:

CALL METHOD ls_element->set_changed_by_client
      EXPORTING
        flag   = ABAP_TRUE.

makes the CHANGE BADI trigger but not immediately; after the screen refresh, any other following operation implies the BADI to be executed. That's not what we would like to get as we'd like to understand how to trigger immediately the CHANGE BADI implementation for contracts changing some context element.

Any suggestion/help is welcome, thanks again.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI ,

I am not sure if I understand your question properly ,

But still try to have a look at the following link and check if this could help you somehow.

[link|http://help.sap.com/saphelp_nw70ehp1/helpdata/en/47/a8e5d273b12fe2e10000000a42189d/frameset.htm]

Thanks,

Aditya.

matteo_montalto
Contributor
0 Kudos

Thanks Aitya,

the issue seems not to be a matter of change log; as I stated in my above message, now the question is why triggering an update with a selection of more than one position does not execute the BBP_DOC_CHANGE_BADI.... while if selection has cardinality equal to 1, then the update triggers it.

Answers (2)

Answers (2)

matteo_montalto
Contributor
0 Kudos

Solved... partially. I'm gonna open another message to describe a new issue related to this one.

Former Member
0 Kudos

Hello I am trying to trigger the change badi when a user clicks a button or the change event when the user clicks a button. Can you help explain how did you do it?

So when the user clicks the button, it will kick off the change badi hitting my breakpoint? Thank you.

matteo_montalto
Contributor
0 Kudos

SAPpuff, I used the SET_CHANGED_BY_CLIENT method, as shown in the above sketch of code. This method sets an attribute on the context that implies that something's changed and, as a consequence, any other action/ move triggered by the used after that method will trigger the CHANGE badi.

Hope it's a bit more clear; if not, please open a new thread for your question.

Kind regards,

M.

Former Member
0 Kudos

hey thanks man.. Yeah i posted a thread about it but i didnt get a reply. I appreciate it that! I see that your post you said that any action after setting the elements will trigger the change badi.. My question would be the only action the user will do on the view is click the button. Would your method work for that scenario if the user decides to click the button or not? Thank you!

matteo_montalto
Contributor
0 Kudos

Hello,

yes, it would probably work, if you associate a pre exit to the the method triggered by your button. In that you could for example set that flag on the attribute IS_CHANGED_BY_CLIENT, then execute your code. I'd suggest to try it in your code and see if that meets your desiderata.

Happy Easter!

matteo_montalto
Contributor
0 Kudos

I've seen your thread has been marked as closed but unaswered, SAPpuff. I guess you found your solution. Anyway; if no CHANGE badi has been triggered with that sketch of code, that probably means you have not set a changed_by_client flag on the proper context element. As far as I've seen you should check that flag on a context node which represents the underlying document in order to trigger the badi.

matteo_montalto
Contributor
0 Kudos

Hello, it's me again Strange things happen here....

I found the way to trigger the CHANGE BADI after any modification and it works if and only if a single position is selected.

That's the code in my method:

CALL METHOD wd_context->get_child_node
    EXPORTING
      name       = 'CTR_ITEM'
    RECEIVING
      child_node = lon_ctr_item.

* Get the selected elements of the item table
  lt_elem_set  = lon_ctr_item->get_selected_elements( abap_true ).

* for each selected element, set respectively ZZATTRIBUTE value
* Get the static attributes of all SELECTED elements into an internal table
  LOOP AT lt_elem_set INTO ls_element.
    CALL METHOD ls_element->get_attribute
      EXPORTING
        name   = 'ZZATTRIBUTE'
      IMPORTING
        value  = already_set
        .
    CASE already_set.
      WHEN abap_false.
        CALL METHOD ls_element->set_attribute
          EXPORTING
            value  = abap_true
            name   = 'ZZATTRIBUTE'
            .
      WHEN abap_true.
        CALL METHOD ls_element->set_attribute
          EXPORTING
            value  = abap_false
            name   = 'ZZATTRIBUTE''
            .
    ENDCASE.

    CALL METHOD ls_element->set_changed_by_client
      EXPORTING
        flag   = ABAP_TRUE.
  ENDLOOP.

  CALL METHOD wd_comp_controller->mo_bom_ctr->/sapsrm/if_cll_bo_mapper~fire_event_refresh( ).

Can anyone explain why the above method does trigger the BBP_DOC_CHANGE_BADI only when a single position is selected?

Thanks in advance.