Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

issue with BAPI_PS_PRECOMMIT

shmilo666
Explorer
0 Kudos
951

Hi,

I'm calling BAPI_PS_PRECOMMIT after updating the profit center field of a project. It's done within the BADI PROJECTDEF_UPDATE (method AT_SAVE).

For some reason, when I call the PRECOMMIT BAPI it goes back to the beginning of the method and gets into an endless loop..

Any idea how it can be resolved?

Thanks in advance.

7 REPLIES 7

JoeyLi
Product and Topic Expert
Product and Topic Expert
0 Kudos
787

Hello Shmilovitz,

Without more information about your specific implementation and the code you're using, it's difficult to provide a precise solution. However, here are a few general suggestions to help you troubleshoot the issue:

1. Check the logic within the PROJECTDEF_UPDATE BAdI: Review the code within the AT_SAVE method of the BAdI implementation and ensure there are no recursive calls or loops that might be causing the endless loop.

2. Verify the parameters passed to BAPI_PS_PRECOMMIT: Double-check the parameters you are passing to the BAPI_PS_PRECOMMIT function module. Ensure that you are providing the correct input values and that the function module is being called with the appropriate parameters.

3. Debug the code: Use a debugger to step through the code and identify the point at which the endless loop occurs. This will help you pinpoint the exact cause of the issue and find a solution.

4. Review the BAPI_PS_PRECOMMIT function module: Examine the code within the BAPI_PS_PRECOMMIT function module and check if there are any potential recursive calls or loops that could lead to an endless loop.

BR,

0 Kudos
787

Thanks for your reply.

There's no other code implemented in this BADI, only my code. Also there's no parameters passed to the PRE_COMMIT BAPI but the return table.

Here is the entire code I'm using. The intention is to update profit center value within a project and its related WBS's:

method IF_EX_PROJECTDEF_UPDATE~AT_SAVE.
*--> Local data - start
DATA: lv_prctr type PRCTR,
ls_proj_def TYPE bapi_bus2001_chg,
ls_bapi_updt TYPE bapi_bus2001_upd,
lt_bapi_return TYPE bapirettab,
ls_return TYPE BAPIRET2,
lt_return like TABLE OF ls_return,
ls_bapi_return like line OF lt_bapi_return.
DATA: BEGIN OF lwa_posid,
POSID TYPE PS_POSID,
END OF lwa_posid,
lt_posid like TABLE OF lwa_POSID.
DATA: lt_wbs TYPE bapi_bus2054_chg_tab,
lwa_wbs like LINE OF lt_wbs,
lt_wbs_upd TYPE bapi_bus2054_upd_tab,
lwa_wbs_upd like LINE OF lt_wbs_upd,
lt_ret_wbs TYPE bapirettab,
ls_ret_wbs like LINE OF lt_ret_wbs.
*--> Local data - end

*--> Get profict center from PCA Substitution
select SINGLE prctr
FROM ZCOT_PCA_SUBS
into lv_prctr
WHERE vtweg = IM_PROJECTDEFINITION-vtweg AND
vkbur = IM_PROJECTDEFINITION-zz_vkbur.
if sy-subrc eq 0 AND lv_prctr IS NOT INITIAL.
*--> Update profit center in table PROJ
clear: ls_proj_def, ls_bapi_updt, lt_bapi_return[].
MOVE-CORRESPONDING IM_PROJECTDEFINITION to ls_proj_def.
ls_proj_def-PROJECT_DEFINITION = IM_PROJECTDEFINITION-pspid.
ls_proj_def-PROFIT_CTR = lv_prctr.
ls_bapi_updt-PROFIT_CTR = 'X'.
CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
CALL FUNCTION 'BAPI_BUS2001_CHANGE'
EXPORTING
I_PROJECT_DEFINITION = ls_proj_def
I_PROJECT_DEFINITION_UPD = ls_bapi_updt
TABLES
ET_RETURN = lt_bapi_return.
if sy-subrc eq 0.
READ TABLE lt_bapi_return INTO ls_bapi_return with KEY type = 'E'.
if sy-subrc ne 0.
refresh lt_bapi_return.
*--> Find all WBS relevant to project
CLEAR lt_wbs[].
SELECT posid FROM prps INTO CORRESPONDING FIELDS OF TABLE lt_posid WHERE PSPHI = IM_PROJECTDEFINITION-PSPNR.
*--> Update profit center in all WBS table PRPS
CLEAR: lt_wbs[], lt_wbs_upd[], lt_ret_wbs[].
LOOP AT lt_posid INTO lwa_posid.
lwa_wbs-WBS_ELEMENT = lwa_posid-POSID.
lwa_wbs-PROFIT_CTR = lv_prctr.
APPEND lwa_wbs to lt_wbs.
lwa_wbs_upd-WBS_ELEMENT = lwa_posid-POSID.
lwa_wbs_upd-PROFIT_CTR = 'X'.
APPEND lwa_wbs_upd to lt_wbs_upd.
ENDLOOP.
CALL FUNCTION 'BAPI_BUS2054_CHANGE_MULTI'
EXPORTING
I_PROJECT_DEFINITION = IM_PROJECTDEFINITION-PSPID
TABLES
IT_WBS_ELEMENT = lt_wbs
IT_UPDATE_WBS_ELEMENT = lt_wbs_upd
ET_RETURN = lt_ret_wbs.
if sy-subrc eq 0.
READ TABLE lt_ret_wbs INTO ls_ret_wbs with KEY type = 'E'.
if sy-subrc ne 0.
CALL FUNCTION 'BAPI_PS_PRECOMMIT'
TABLES
ET_RETURN = lt_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
endmethod.

Many thanks in advance!

JoeyLi
Product and Topic Expert
Product and Topic Expert
0 Kudos
787

Let me guess,

When you call `BAPI_PS_PRECOMMIT`, it triggers the save process again, which calls the `AT_SAVE` method of the BADI, thus creating an infinite loop.

You may set a break point and find the buffer details.

A common practice to avoid such a loop is to use a static flag to check whether the BADI has been called already. If it has been called, you can skip the BAPI_PS_PRECOMMIT call to avoid the recursive call.

method IF_EX_PROJECTDEF_UPDATE~AT_SAVE.*Local definations..........*--> Static data (to control recursion)CLASS-DATA: lv_already_called TYPE abap_bool.*--> If this is a recursive call, exitIF lv_already_called EQ abap_true. RETURN.ENDIF.".... (rest of your code) ....CALL FUNCTION 'BAPI_PS_PRECOMMIT'TABLESET_RETURN = lt_return.*--> Set the flag to true before commitlv_already_called = abap_true.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'."Reset the flag after commitlv_already_called = abap_false.endmethod.

raymond_giuseppi
Active Contributor
0 Kudos
787

Basically you are breaking the current transction logic when calling this FM (as a COMMIT WORK) during this BAdI AT-SAVE execution?

Why do you call this FM in the BAdI, did you call some BAPI before?

shmilo666
Explorer
787

Thanks all!

It seems like I can't do the submit within the BADI's implementation therefore I put the entire code in an RFC FM and called it in a background task as a separate unit and it works..

Thanks a lot.

0 Kudos
787

Please mark the best answer, I guess it should be yours.

raymond_giuseppi
Active Contributor
0 Kudos
787

Read the documentation of PROJECTDEF_UPDATE BAdI, method AT_SAVE

(...) Also note that the command 'commit work' cannot be carried out in the methods as this would lead to data inconsistencies in the database (...)