Menu

How to Change the User Status Profile of an Object

2014-05-14       

In this little article, I explain how it is possible to change the user status profile of an existing business object in SAP ERP. This is not possible normally if the object already has a user status profile assigned to it, however there is a simple way to do this.

Recommended Now

Fire TV Stick Lite Essentials Bundle

This bundle contains Amazon Fire TV Stick Lite and Mission USB Power Cable. The USB power cable eliminates the need to find an AC outlet near your TV by powering Amazon Fire TV directly from your TV's USB port. Includes special power management circuitry that enhances the peak power capability of the USB port by storing excess energy and then releasing it as needed.

Check it out on amazon.com →

Warning: You can seriously screw up your business objects with the following instructions if you don’t know what you’re doing. Only use this method if you know that what you do will keep the objects in a consistent state.

How to do it

The key to change a user status profile lies in the usage of a specific function module from the function group BSVA, STATUS_PROFILE_CHANGE. It allows you to change the user status profile of an object programmatically.

As parameters, this function module will take an object number and a status profile. Any SAP ERP business objects that use status management have an object number. It is assembled from a two-letter abbreviation that indicates the object type (e.g. “OR” for orders) and the internal key from the object table. It can usually be found in the master data tables themselves, for orders e.g. it’s in the field AUFK-OBJNR.

In addition to filling these fields, the function module also takes another parameter, NO_CHECK. This must be set to “X”, otherwise this method will not work. Once you filled these input parameters, execute the function module. It needs a COMMIT WORK afterwards to save the changes, so you need a little program.

Example program

I’ve written a little example program that you can copy to change the user status profile of objects. Enjoy (but use carefully)!

 REPORT zchangestatus NO STANDARD PAGE HEADING.
 
 PARAMETERS pa_objnr TYPE j_objnr OBLIGATORY.
 PARAMETERS pa_stsma TYPE j_stsma OBLIGATORY.
 PARAMETERS pa_nochk TYPE xfeld AS CHECKBOX DEFAULT 'X'.
 
 CALL FUNCTION 'STATUS_PROFILE_CHANGE'
   EXPORTING
     objnr                    = pa_objnr
     stsma                    = pa_stsma
     no_check                 = pa_nochk
   EXCEPTIONS
     object_not_found         = 1
     no_stsma_change_possible = 2
     stsma_not_found          = 3
     OTHERS                   = 4.
 IF sy-subrc <> 0.
   MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   EXIT.
 ENDIF.
 
 WRITE 'Status Profile was changed for object.'.
 
 COMMIT WORK.

Is it documented?

Of course. Since SAP ERP logs (almost) everything, there is a table specifially to log the changes of status profiles to objects. This table is JCDO (Change Documents for Status Object). It will hold an entry for each object of which the status profile was changed, and also the names of the old and new profile.

However, most other things are lost. All user statuses that the object might have had (table JEST) will be lost, even if statuses with the same name exist on the new status profile. Also, the status change logs (table JCDS) of the old statuses will be removed. The object will have the initial status (if one exists) of the new status profile.

Bonus tip – status change docs!

Here’s another useful thing: change documents for system and user statuses are enabled and disabled at object level, in table JSTO. If they are inactive and you decide to activate them later, status change logs will only be written for newly created objects.

This issue can be solved in a very similar manner to the one above. There’s the function module STATUS_CDOCS_ACTIVATE, that allows to activate change documents on a per-object basis. Read all relevant objects from their table, call this function module, and status change docs will be active for them too.