cancel
Showing results for 
Search instead for 
Did you mean: 

Modify Status based on User Action

Former Member
0 Kudos

Hi Gurus

For a Change Request we have added a custom button, which if clicked will result in the immediate change to the Status of the Transaction.

However the code we've implemented does not appear to be working, the status is not getting saved.

I suspect we need to update the "In Memory" values of the current transaction and then perform a save which will then update the "In Memory" and "Database Values"

Currently we're using CRM_ORDER_MAINTAIN and then CRM_ORDER_SAVE

Would anyone have a sample piece of code with the function modules I should be using.

Many Thanks in advance

Panduranga

Accepted Solutions (1)

Accepted Solutions (1)

suchita_phulkar
Active Contributor

Hi Pandurang,

If you are coding in WEB UI Component, i.e in the event hadnler of your button on click on which you want to change the status then

1) Do not use CRM_ORDER_MAINTAIN and related FM. Because they deal directly on Database layer whereas you need to work on Database Buffer layer.

2) Your solution is simple. You can change the status within your entitty using BOL programming. That is a lengthy process but not difficult. You can find a HOW TO guide on BOL programming in WiKi area and learn to do it. The other simple solution i am gonna give is use following code in you button click event handler :

          DATA : lr_current       TYPE REF TO if_bol_bo_property_access.

CONSTANTS : lc_my_new_status TYPE CRM_J_STATUS VALUE 'E0013' ,

*  Get the Header instance

       lr_current = me->typed_context->BTAdminH->collection_wrapper->get_current( ). " assuming you are working in oneorder framework and wanna change                                                                                                                                   " header status

     

       CHECK lr_current IS BOUND.

*  Trigger the Status change Process by changing status


       lr_current->get_property_as_value( EXPORTING IV_ATTR_NAME = 'GUID' IMPORTING EV_RESULT = lv_guid ) .

       CALL FUNCTION 'CRM_STATUS_CHANGE_EXTERN_OW'

         EXPORTING

           objnr               = lv_guid

           user_status     = lc_my_new_status

           iv_no_1o_maintain   = 'X'

         EXCEPTIONS

           OBJECT_NOT_FOUND    = 1

           STATUS_INCONSISTENT = 2

           STATUS_NOT_ALLOWED  = 3

           OTHERS              = 4.

       IF sy-subrc <> 0.

*           Implement suitable error handling here

       ENDIF.

It is safe to use the above function module as it is OW so it acts in buffer layer.

Hope this helps you.

Thanks & Regards

Suchita

Answers (4)

Answers (4)

former_member212653
Active Contributor
0 Kudos

You have to use BOL programming, simple back-end API's  won't change the status in CRM UI level.

0 Kudos

Hi,

Try using this FM "CRM_STATUS_SET_INTERN".

If you are doing the development in the genil class level, then you can use the CRM _ORDER_MAINTAIN FM, but you need not call the CRM_ORDER_SAVE FM.

IF you coding in the event method on the UI, then use the BOL programming to set the attribute.

Thanks,

Bhargava.

samantak_chatterjee
Active Contributor
0 Kudos

Hi Kumar,

A couple of things from you issue is that you don't want to commit the changes in the database but you want the 'In Memory' or Buffer to be in sync with the database. I guess you are executing the changes from the SAP CRM Web UI in the real time.

Also, ideally you should avoid making application layer calls in the UI Layer ( Web UI Framework - Presentation Layer). But if that is unavoidable then you need to call only the sub object API (in this case - Status Change API) only instead of full ORDER Maintain. You can also use the ORDER_SAVE BadI provided by SAP to handle your scenario.

In the current issue, the full flow of ORDER Maintain includes a call to BAPI_TRANSACTION_COMMIT or some kind of commit as this will persist the data from the Buffer to the database.

Let me know if you still have some doubts with the technical objects and then I can provide the Status change API for your requirement.

Hope this helps.

Thanks,

Samantak.

0 Kudos

Panduranga,

  you will have to use BAPI_TRANSACTION_COMMIT to make the changes persistent.

Reward points if this helps

Former Member
0 Kudos

Hi Ashok

I do not want to add a commit within the existing processing as this could cause undesirable results. If it was not an Online process then it would be fine.

0 Kudos

Hi Panduranga,

  In fact it it is WEB UI..I would strongly advise you to avoid these APIs...As a matter of fact, you should try to use the BOL layer extensively...When don't you try changing the status in the BOL layer instead? Let me know the component and view details

Thanks,
Deepa