CRM and CX Blogs by Members
Find insights on SAP customer relationship management and customer experience products in blog posts from community members. Post your own perspective today!
cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
In this blog we will talk about the requirement to check the exiting user status selected  before saving a document. In my case, this was needed to capture the current status of a ChaRM document and save the status in a custom table for further processing. 

We know that we can use FM  CRM_ORDER_READ_OW to get the status from the buffer, however this does not always give the most recent status. I first tried using this in BADI ORDER_SAVE, but the current value was never found, the FM would pull the status from the database.

After looking at few other BADIs, I found BADI CRM_STATUS_CHECK to be useful, this has two methods, BEFORE_SAVE and AFTER_SAVE. The code inside BEFORE_SAVE gets called multiple times, and using FM ‘CRM_ORDER_READ_OW’ does not bring the most recent status initially, but it does right before SAVE.

Sample code –

DATA: lt_obj      TYPE crmt_object_name_tab,
ls_obj      TYPE crmt_object_name,
lt_status   TYPE crmt_status_wrkt,
ls_status   TYPE crmt_status_wrk,


DATA: lt_guidh      TYPE crmt_object_guid_tab.
DATA: ls_guidh      LIKE LINE OF lt_guidh,
lt_log_handle TYPE balloghndl.


 CONSTANTS:  lc_object_status   TYPE crmt_object_name VALUE 'STATUS'.

* Update Staging table for Status changes.
MOVE is_status_wrk-guid TO ls_guidh.
INSERT ls_guidh INTO TABLE lt_guidh.
APPEND lc_object_status TO lt_obj.
CLEAR lv_upd.


CALL FUNCTION 'CRM_ORDER_READ_OW'
EXPORTING
it_header_guid       = lt_guidh
it_requested_objects = lt_obj
IMPORTING
et_status            = lt_status
CHANGING
cv_log_handle        = lt_log_handle
EXCEPTIONS
document_not_found   = 1
error_occurred       = 2
document_locked      = 3
no_change_authority  = 4
no_display_authority = 5
no_change_allowed    = 6
OTHERS               = 7.
IF sy-subrc <> 0.
* Implement suitable error handling here

ELSE.

*Lock custom table.

* Update Custom table with new status user is saving.

   ENDIF.

Now the new status saved by the user will be available, you can use this status to make any further checks/updates.For example, in my case, I needed to update a custom table with the new status during SAVE.  

You can use method AFTER_SAVE for additional checks or changes after save. For example, unlocking custom table updated.
1 Comment