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.
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.
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.
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.
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.