03-16-2010 12:29 PM
Hi gurus,
I want to update multiple WBS elements with profit center (PRCTR) field. I created an ABAP program for this requirement which makes use of the following:
BAPI_PS_INITIALIZATION
BAPI_BUS2054_CHANGE_MULTI
BAPI_PS_PRECOMMIT
BAPI_TRANSACTION_COMMIT
The BAPIs are called inside the loop. The program works for the 1st record but it will cause a dump for the succeeding records because of an error 'Error in individual BAPIs or precommit: posting not possible' after calling BAPI_PS_PRECOMMIT the second time.
How can BAPI_BUS2054_CHANGE_MULTI be used to update multiple WBS elements? I would appreciate it if you could show me sample code.
Your feedback is very much appreciated.
Thanks.
03-16-2010 12:40 PM
Hi,
Keep only BAPI_BUS2054_CHANGE_MULTI inside the loop.
I hope in this way you may solve the issue.
Regards,
Sarbajit.
03-16-2010 12:51 PM
See FM BAPI_BUS2054_CHANGE_MULTI have IT_WBS_ELEMENT and IT_UPDATE_WBS_ELEMENT parameter in the tables statement.The WBS Elements that you want to update under a Project Definition for that first of all you have to create 2 internal table of structure BAPI_BUS2054_CHG and BAPI_BUS2054_UPD. Now in the 1st internal table you have to fill up the necessary data and in the 2nd internal Table you have to put an 'X' for the corresponding fields.
Like in 1st Internal table you have filled up data like the following one:
A B C D E
11 13 15
21 22 24
Then in the 2nd Internal Table you have to put X like the following one:
A B C D E
11 X X
21 X X
here 11 and 21 are suppose 2 WBS element.(For 11 13 under C and 15 under E,For 21 22 under B 24 under D.Similarly for 11 Xs are under C and E and for 21 Xs are under B and D)
Hope I'm able to help you a little bit.
Regards,
Sarbajit.
03-16-2010 1:12 PM
ITAB is your internal table where you have your data. Now create internal table IT_WBS and
work area WA_WBS of type BAPI_BUS2054_CHG. And internal table IT_WBS_UPD and WA_WBS_UPD of
type BAPI_BUS2054_UPD.
LOOP AT ITAB into WA.
WA_WBS-WBS_ELEMENT = WA-WBS_ELEMENT.
WA_WBS-PROFIT_CTR = WA-PROFIT_CTR.
WA_WBS_UPD-WBS_ELEMENT = WA-WBS_ELEMENT.
WA_WBS_UPD-PROFIT_CTR = 'X'.
APPEND WA_WBS TO IT_WBS.
APPEND WA_WBS_UPD TO IT_WBS_UPD.
ENDLOOP.
Now Call the FMs in the order
BAPI_PS_INITIALIZATION
BAPI_BUS2054_CHANGE_MULTI
BAPI_PS_PRECOMMIT
BAPI_TRANSACTION_COMMIT
passing the above filled up table in the FM BAPI_BUS2054_CHANGE_MULTI .
Regards,
Sarbajit.
03-16-2010 1:26 PM
Hi ,
Do like this:
Take two files as input as it_wbsheader, it_wbsdetail.
it_wbsheader internal table will contain - project defination,wbs element.
it_wbsdetail internal table will contain - wbs element and profit center.
define one more internal table .Name it as it_updateddata as
it_updateddata LIKE STANDARD TABLE OF bapi_bus2054_chg WITH HEADER LINE.
Now after that,
LOOP AT it_wbsheader.
CLEAR:ibapi_bus2001_new,ibapi_bus2054_detail,ibapi_wbs_list.
ibapi_bus2054_detail-project_definition = it_wbsheader-projdef.
APPEND ibapi_bus2054_detail.
CLEAR ibapi_bus2054_detail.
ibapi_wbs_list-wbs_element = it_wbsheader-wbsno.
APPEND ibapi_wbs_list.
CLEAR: it_wbselement, it_wbselement[].
it_wbselement-wbsno = it_wbsheader-wbsno.
APPEND it_wbselement.
CLEAR it_wbselement.
CLEAR: it_getdetail,it_getdetail[].
CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
CALL FUNCTION 'BAPI_BUS2054_GETDATA'
EXPORTING
i_project_definition = it_wbsheader-projdef
I_LANGUAGE =
I_MAX_ROWS =
TABLES
it_wbs_element = it_wbselement
et_wbs_element = it_getdetail
et_return = return
EXTENSIONIN =
EXTENSIONOUT =
it_getdetail will contain the related info of that particular wbs element. Now update the internal table it_updateddata which was defined earlier with contents returned by this BAPI(Pass every thing).
READ TABLE it_getdetail WITH KEY wbs_element = it_wbsheader-wbsno.
IF sy-subrc = 0.
it_updateddata-wbs_element = it_getdetail-wbs_element.
it_updateddata-profit_center= it_getdetail-profit_center.
.
.
.
.other fields
APPEND it_updateddata.
CLEAR it_updateddata.
ENDIF.
Now it_updateddata should be updated with data from second input file
LOOP AT it_updateddata WHERE wbs_element = it_wbsheader-wbsno.
READ TABLE it_wbsdetail WITH KEY wbsno =
it_updateddata-wbs_element.
IF sy-subrc = 0.
it_updateddata-wbs_element = it_wbsdetail-wbsno.
it_updateddata-profit_center= it_wbsdetail-profit_center.
.
.
.
.
Other fields
MODIFY it_updateddata.
endif.
endloop.
****pass the updated data**********
CALL FUNCTION 'BAPI_BUS2054_CHANGE_MULTI'
EXPORTING
i_project_definition = it_wbsheader-projdef
TABLES
it_wbs_element = it_updateddata
it_update_wbs_element = ibapi_bus2054_upd
et_return = return
EXTENSIONIN =
LOOP AT return.
IF return-type = 'E'.
DATA msgtext(150).
msgtext = ''.
msgtext = return-message.
WRITE:/ msgtext.
ELSE.
DATA msgtext1(150).
msgtext1 = ''.
msgtext1 = return-message.
WRITE:/ msgtext1.
CALL FUNCTION 'BAPI_PS_PRECOMMIT'
TABLES
et_return = return_precommit.
WAIT UP TO 5 SECONDS.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
ENDLOOP.
ENDLOOP.
EXTENSIONOUT
After that update - ibapi_bus2054_upd - what ever the fields u passed earlier should be checked here.
CALL FUNCTION 'BAPI_BUS2054_CHANGE_MULTI'
EXPORTING
i_project_definition = it_wbsheader-projdef
TABLES
it_wbs_element = it_updateddata
it_update_wbs_element = ibapi_bus2054_upd
et_return = return
EXTENSIONIN =
EXTENSIONOUT =
CALL FUNCTION 'BAPI_PS_PRECOMMIT'
TABLES
et_return = return_precommit.
COMMIT WORK AND WAIT.
WAIT UP TO 5 SECONDS.
wait up to 10 seconds.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
ENDLOOP.
ENDLOOP.
Hope it is useful for you.
Best regards
Himayat
03-17-2010 8:27 AM
Hi all,
Thanks for all your replies. I was able to update multiple WBS elements belonging to the same project definition. I grouped the WBS elements by their project definition. WBS elements belonging to the 1st project definition were successfully updated. When the BAPI is called for the second time (this is for the second project definition in the loop), it will cause a dump because in the FORM CHK_PRECOMMIT chk_precommit_ok would now have the value 'N', meaning there's an error in the precommit.
Is it possible to update WBS elements for different project definitions (like what I did) or is BAPI_BUS2054_CHANGE_MULTI designed only for a single project definition?
Thanks in advance.
03-17-2010 8:38 AM
Hi,
Can you share your code?Also the error message.
Regards,
Sarbajit
03-17-2010 9:20 AM
Hi,
Please see code below:
LOOP at i_projdef INTO wa_projdef.
refresh: i_wbs_element,
i_UPDATE_WBS.
loop at i_wbselem INTO wa_wbselem WHERE pspid = wa_projdef-pspid.
populate i_wbs_element table with WBS elements belonging to the project
populate i_update_wbs with WBS elements belonging to project and pass 'X' to the field to be updated
endloop.
CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
CALL FUNCTION 'BAPI_BUS2054_CHANGE_MULTI'
EXPORTING
I_PROJECT_DEFINITION = wa_wbselem-pspid
TABLES
IT_WBS_ELEMENT = i_wbs_element
IT_UPDATE_WBS_ELEMENT = i_UPDATE_WBS.
CALL FUNCTION 'BAPI_PS_PRECOMMIT'
TABLES
ET_RETURN = i_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
IMPORTING
RETURN = wa_return.
ENDLOOP.
Error message returned after BAPI_PS_PRECOMMIT on the 2nd entry of i_projdef : Error in individual BAPIs or precommit: posting not possible
Thanks in advance.
03-17-2010 9:35 AM
Hi,
1>Do you sort the itabs (i_projdef,i_wbselem ) based on pspid.If not do then kindly sort the tables.
2>Just before the 'BAPI_PS_PRECOMMIT' put a WAIT FOR 1 SEC statement.Though its not a recommended practice but do it for the time being.May be this sort out the problem.
Regards,
Sarbajit.
03-19-2010 11:25 AM
Hi,
Are you still getting that dump? If not then kindly spend some time describing how do you solve that?
Waiting for the solution.
regards,
Sarbajit.
02-24-2015 5:37 AM
hi lourd bia,
Greetings of the Day!!!
i have the same issue with update multiple wbs element and user fields can you please share the code it will be very helpful to me.
Thanks in Advance:):)
regards,
bhavya.