Easy way to overcome standard hierarchy lock of the Cost Center during mass creation
I had a situation where there is a need to create multiple cost centers from a flat file. For that, I have come across 1 BAPI named BAPI_COSTCENTER_CREATEMULTIPLE. But there were several issues while creating the Cost Centers.
Firstly, there was a limitation of records in the RFC.
Secondly, there are several locks that take time to get unlock. Which makes the whole process very time-consuming.
There are also SAP notes for the same namely 1628315, 970300 & 111752.
The SAP notes are complex to implement & time taking. So, did a small change & passed one cost center at a time to the above-mentioned BAPIs & it worked.
Based on the variable the program: SAPLKMA1(called by the BAPI) understands whether the Standard Hierarchy of the Cost Centers needs to be locked or not. I have just changed it to always test mode when called through my program at the beginning and at the end reinstated the value to its original one.
N.B: In the test mode no lock occurs.
Please check below the sample code snippet of the enhancement for further reference(Code differs from the original one due to company policy).
DATA lt_stacktable TYPE ABAP_CALLSTACK. CALL FUNCTION 'SYSTEM_CALLSTACK' IMPORTING CALLSTACK = lt_stacktable. IF line_exists( lt_stacktable[ mainprogram = 'ZREPORT_NAME' ] ). DATA(lv_testrun) = gd_bapi_testrun. gd_bapi_testrun = COND #( WHEN gd_bapi_testrun IS INITIAL THEN 'X' ELSE gd_bapi_testrun ). ENDIF. REFRESH lt_stacktable.
CALL FUNCTION 'SYSTEM_CALLSTACK' IMPORTING CALLSTACK = lt_callstack. IF line_exists( lt_callstack[ mainprogram = 'ZIHR_TM_013_GDHFISTTOSAP_CSKS' ] ). lv_testrun = gd_bapi_testrun. ENDIF. CLEAR lv_testrun. REFRESH lt_callstack.
That’s it. 🙂
If you like this blog post, please like, share & comment.
Also, please don’t forget to endorse me on LinkedIn. 🙂