Skip to Content
0
Nov 22, 2013 at 04:55 AM

Short dump while updating User Status of a Project and corresponding WBS

402 Views

All,

I have a requirement where the user status for project and corresponding WBS element needs to be changed more than once in one execution.

While doing so, I get a short dump - Error in individual BAPIs or precommit: posting not possible

During the first loop count, it works fine but get a shortdump for 2nd loop count. This is for ONE project.

Please help.

IF NOT lt_proj[] IS INITIAL.

* Get the Project Status

LOOP AT lt_proj INTO ls_proj.

CALL FUNCTION 'BAPI_BUS2001_GET_STATUS'

EXPORTING

project_definition = ls_proj-pspid

TABLES

e_user_status = lt_user_status.

* Only one status out of BAPI

READ TABLE lt_user_status INTO ls_user_status INDEX 1.

* Compare the user status from the BAPI with the one in Z Table

* READ TABLE lt_ztps_miles INTO ls_ztps_miles WITH KEY stsma = ls_proj-stspr.

LOOP AT lt_ztps_miles INTO ls_ztps_miles WHERE stsma = ls_proj-stspr.

* IF sy-subrc = 0.

IF ls_ztps_miles-zj_txt04 NE ls_user_status-user_status.

* Call Initialization

CALL FUNCTION 'BAPI_PS_INITIALIZATION'.

* Update the header user status via BAPI and populate the log table

CALL FUNCTION 'BAPI_BUS2001_SET_STATUS'

EXPORTING

project_definition = ls_proj-pspid

set_user_status = ls_ztps_miles-zj_txt04

TABLES

e_result = lt_result.

* Get all the lower level WBS elements for this project from table PRPS

CALL FUNCTION 'BAPI_PROJECT_GETINFO'

EXPORTING

project_definition = ls_proj-pspid

TABLES

e_wbs_element_table = lt_wbs_element_tab.

LOOP AT lt_wbs_element_tab INTO ls_wbs_element_tab.

ls_wbs_user_status-wbs_element = ls_wbs_element_tab-wbs_element.

ls_wbs_user_status-set_user_status = ls_ztps_miles-zj_txt04.

APPEND ls_wbs_user_status TO lt_wbs_user_status.

CLEAR : ls_wbs_element_tab, ls_wbs_user_status.

ENDLOOP.

CALL FUNCTION 'BAPI_BUS2054_SET_STATUS'

TABLES

i_wbs_user_status = lt_wbs_user_status.

* Populate the LOG

READ TABLE lt_result INTO ls_result WITH KEY message_type = 'E'.

IF sy-subrc = 0. "Failure

ls_log-pspnr = ls_proj-pspnr.

ls_log-before_status = ls_user_status-user_status.

ls_log-after_status = ls_user_status-user_status.

ls_log-update_status = c_failure.

APPEND ls_log TO lt_log.

ELSE."Success

ls_log-pspnr = ls_proj-pspnr.

ls_log-before_status = ls_user_status-user_status.

ls_log-after_status = ls_ztps_miles-zj_txt04.

ls_log-update_status = c_success.

APPEND ls_log TO lt_log.

ENDIF.

ENDIF.

* Call Commit Work

READ TABLE lt_log INTO ls_log WITH KEY update_status = c_success.

IF sy-subrc = 0.

* Call Pre-Committ

CALL FUNCTION 'BAPI_PS_PRECOMMIT'

TABLES

et_return = itab_return1.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

WAIT UP TO 2 SECONDS.

ENDIF.

CLEAR : ls_ztps_miles, lt_result ,lt_wbs_element_tab, lt_log.

REFRESH : lt_result ,lt_wbs_element_tab, lt_log.

* ENDIF.

ENDLOOP.

CLEAR : ls_proj, lt_user_status, ls_user_status, ls_ztps_miles, lt_result, ls_result, ls_log.

REFRESH: lt_user_status, lt_result.

ENDLOOP.

ENDIF.