Skip to Content
Author's profile photo Luís Pérez Grau

PPF Actions: Recursive action call saving the document

Component Support Package
BBPCRM SAPKU70204
SAP_ABA SAPKA73105
SAP_BASIS SAPKB73105
WEBCUIF SAPK-73105INWEBCUIF

Hi everyone,
This time is a very short and quite simple blog but I hope is useful enough 🙂  

Scenario

I want to determine and redetermine some custom fields which are generated via AET on CRMD_CUSTOMER_I, the values for the custom fields on each item rely on all the items of the order.

PPF and Actions


From here I expect you have some basics about PPF and Actions if is not your case I would suggest the following readings:

I also recommend the Stephen Johannes book Book review: SAP CRM: Technical Principles and Programming which covers in a very easy and detailed way this topic in chapter 6.

Solution


After creating the action profile, the action and assign them to corresponding business transaction the only thing you should take “special” attention is in the action definition.
Capture1.JPG
Capture.JPG
I implemented a new PFF BADI for the method call (EXEC_METHODCALL_PPF) and inside the method, I did all my stuff and finally I called the API CRM_ORDER_MAINTAIN, what happened? since I’m modifying the document itself once I register it for saving, the action will be trigered again and again and again becoming a endless loop. and now what?

Note 1034624 – Dependencies between actions and side effects, gives you the solution/hint to overcome this issue, the secrete relays on the static methods ACTION_EXECUTED_SAVE and ACTION_WAS_EXECUTED_SAVE of the class CL_ACTION_EXECUTE.

A typical example of the implementation of those two method is:

Begining of the BADI for the method call:

METHOD if_ex_exec_methodcall_ppf~execute.

INCLUDE crm_log_states_con.
INCLUDE crm_object_kinds_con.

DATA: lo_action_execute   TYPE REF TO cl_action_execute,

DATA: lv_guid_ref          TYPE crmt_object_guid,
       lv_kind_ref          TYPE crmt_object_kind.
       lv_message           TYPE char80.

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

* not relevant iv preview is active
  IF NOT ip_preview IS INITIAL.
    MESSAGE s007(crm_action) INTO lv_dummy.
    cl_log_ppf=>add_message( ip_problemclass = ‘4’
                             ip_handle       = ip_application_log ).
    RETURN.
  ENDIF.

  CREATE OBJECT lo_action_execute.

* get parameter from reference object
  CALL METHOD lo_action_execute->get_ref_object
    EXPORTING
      io_appl_object = io_appl_object
      ip_action      = ip_action
      ii_container   = ii_container
    IMPORTING
      ev_guid_ref    = lv_guid_ref
      ev_kind_ref    = lv_kind_ref.

* Only on header level
  IF lv_kind_ref NE gc_object_kind-orderadm_h.
    MESSAGE s010(crm_action) WITH lv_kind_ref INTO lv_dummy.
    cl_log_ppf=>add_message( ip_problemclass = ‘1’
                             ip_handle       = ip_application_log ).
    RETURN.
  ENDIF.

  IF cl_action_execute=>action_was_executed_save( iv_head_guid =  lv_guid_ref
                                                  iv_action    =  ip_action ) EQ abap_true.
*   Prevent endless loop
    RETURN.
  ENDIF.

Ending of the BADI for the method call:

  cl_action_execute=>action_executed_save(  EXPORTING iv_head_guid = lv_guid_ref
                                                      iv_action    = ip_action ).

* Save the document
  CALL METHOD lo_action_execute->register_for_save
    EXPORTING
      iv_source_header_guid = lv_guid_ref
      ip_application_log    = ip_application_log
*     iv_recursive_det      =
    IMPORTING
      rp_status             = rp_status.

ENDMETHOD.

I know this is not a something very complicated or hard to figure it out, but I looked at scn and I didn’t find it, so why not? 😉

Cheers!

Luis

Assigned Tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo sakshi sawhney
      sakshi sawhney

      Hi ,

      Will the message adding to log work in both cases i.e. if we execute the action from backend and UI.

      Author's profile photo Luís Pérez Grau
      Luís Pérez Grau
      Blog Post Author

      Yes, in both cases.

      Cheers!

      Luis

      Author's profile photo sakshi sawhney
      sakshi sawhney

      Hi Luis,

      Would be grateful if u could help in a query for PPF Actions.

      The requirement is to create a follow up activity for quotation in case sold to party BP was in inactive state and then set action status to Red.

      The issue is when i run the action via batch report i.e. rsppfprocess then whenever i set action status to red , the activity creation does not occur and the changes don't commit to database.If i change status to green all changes are committed to database.

      I am using register_for_save method of cl_action_execute class after activity creation.Could you guide as to what should be done in this particular case as i cant set action status to green (As per requirement green is only done when all checks on quotation are passed and follow up contract is created successfully )?

      However during Immediate action run i.e via crmd_order while creation and save of quotation activity is created successfully , even though i am setting action status to red.