2 weeks ago
Hi all
To overcome the 999 limitation of settlement rules per WBS element (we have a lot of assets), we created a function module to create a "child" WBS element dynamically (with appropriate journals between parent and child) to host 999 settlements.
Unfortunately, the commit transaction BAPI for the WBS create BAPI short dumps with a message type x crash which does not provide any useful information.
Category ABAP Programming Error
Runtime Errors MESSAGE_TYPE_X
ABAP Program SAPLPS_BAPI
Application Component PS-ST-INT
All checks and pre-commits don't raise any errors.
Is there a sequence error in the process?
FUNCTION Z_ZTX_SR_WBS.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(P_PWBS) TYPE PS_POSID
*" EXPORTING
*" VALUE(P_CWBS) TYPE PS_POSID
*" VALUE(P_RETURN) TYPE BAPIRET2
*"----------------------------------------------------------------------
*" This function module receives a parent WBS element, and returns a child WBS element with an ZTX investment profile and enough space to add a WBS element settlement rule.
*" If the child element does not exist or none of the children WBS elements have enough space for a settlement rule, it creates one.
DATA: lv_PWBS TYPE PS_POSNR,
ls_PWBS TYPE PRPS,
lt_CWBS TYPE TABLE OF PRPS,
ls_CWBS TYPE PRPS,
lv_IMPRF TYPE IM_PROFIL,
lv_CWBS TYPE PS_POSID,
lt_SR TYPE TABLE OF KONTY,
lv_SR_COUNT TYPE BR_LFDNR,
lv_CWBS_SENDER TYPE PS_POSID,
lv_wbs_count TYPE i,
lv_new_wbs_code TYPE STRING,
lv_new_wbs TYPE PS_POSID,
lv_project TYPE PS_PSPID,
lv_break TYPE i.
DATA: ls_cur_wbs TYPE BAPI_BUS2054_DETAIL,
lt_cur_wbs_it TYPE TABLE OF BAPI_WBS_LIST,
lt_cur_wbs_et TYPE TABLE OF BAPI_BUS2054_DETAIL,
ls_new_wbs TYPE BAPI_BUS2054_NEW,
lt_new_wbs TYPE TABLE OF BAPI_BUS2054_NEW,
lv_return_type TYPE BAPI_MTYPE,
lv_return_message TYPE BAPI_MSG,
lt_return TYPE TABLE OF BAPIRET2,
ls_return TYPE BAPIRET2.
DATA: ls_status TYPE BAPI_WBS_MNT_USER_STATUS,
lt_status TYPE TABLE OF BAPI_WBS_MNT_USER_STATUS,
ls_status_return TYPE BAPI_STATUS_RESULT,
lt_status_return TYPE TABLE OF BAPI_STATUS_RESULT,
lv_msg TYPE char1024.
CONSTANTS: lc_IMPRF TYPE IM_PROFIL VALUE 'JWIM',
lc_MAX_SR TYPE i VALUE 950. "Look for child WBS elements that have automated AUCs created by ZTX
" Retrieve ID of parent WBS
SELECT SINGLE *
INTO ls_PWBS
FROM PRPS
WHERE POSID = p_PWBS.
" Look for any children WBS
SELECT c~*
INTO CORRESPONDING FIELDS OF TABLE @LT_CWBS
FROM PRPS AS c
JOIN PRHI AS h ON h~POSNR = c~PSPNR
WHERE c~IMPRF = @LC_IMPRF
AND h~up = @LieneS_PWBS-PSPNR.
"check each WBS to see if there if there is space for another settlement rule.
LOOP AT lt_CWBS INTO ls_CWBS.
SELECT SINGLE MAX( LFDNR )
INTO lv_SR_COUNT
FROM COBRB
WHERE OBJNR = ls_CWBS-OBJNR.
IF lv_SR_COUNT < lc_MAX_SR. "If there are less than the max SR records, record WBS and quit loop.
lv_CWBS_SENDER = ls_CWBS-POSID. "WBS with available settlement rule lines availables
CONCATENATE 'ZTX child WBS ' lv_CWBS_SENDER ' found for settlement rule ' p_PWBS INTO lv_MSG.
CALL FUNCTION 'Z_ZTX_LOG'
EXPORTING p_MSG = lv_MSG.
EXIT.
ENDIF.
ENDLOOP.
" if a child WBS element (with available SR space) is not found...create one
IF lv_CWBS_SENDER = ''.
CLEAR ls_new_wbs.
lv_wbs_count = LINES( lt_CWBS ).
lv_wbs_count = lv_wbs_count + 1.
lv_new_wbs_code = lv_wbs_count.
CONCATENATE p_PWBS '-I' lv_new_wbs_code INTO lv_new_wbs.
APPEND p_PWBS to lt_cur_wbs_it.
"retrieve details of existing WBS so that you can copy the details into the new child one
CALL FUNCTION 'BAPI_BUS2054_GETDATA'
TABLES
IT_WBS_ELEMENT = lt_cur_wbs_it
ET_WBS_ELEMENT = lt_cur_wbs_et
EXCEPTIONS
others = 1.
" Copy the existing WBS details into the newly defined WBS element, rather than manually specifying every detail.
LOOP AT lt_cur_wbs_et INTO ls_cur_wbs.
MOVE-CORRESPONDING ls_cur_wbs TO ls_new_wbs.
ls_new_wbs-wbs_up = p_pwbs. " This specifies the current WBS as the parent to the new WBS
ls_new_wbs-wbs_element = lv_new_wbs. " Set newly defined WBS number
ls_new_wbs-invest_profile = lc_IMPRF. " Ensure the new WBS element has an ZTX defined investment profile to ensure automated AUC.
CONCATENATE ls_cur_wbs-description ' (ZTX I' lv_new_wbs_code ')' INTO ls_new_wbs-description. "The new WBS element has a description indicating ZTX interface
ENDLOOP.
APPEND ls_new_wbs TO lt_new_wbs.
SELECT SINGLE PSPID
INTO lv_project
FROM PROJ
WHERE PSPNR = ls_PWBS-PSPHI.
CONCATENATE 'ZTX child WBS element not found. Creating -' lv_new_wbs INTO lv_MSG.
CALL FUNCTION 'Z_ZTX_LOG'
EXPORTING p_MSG = lv_MSG.
CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
CALL FUNCTION 'BAPI_BUS2054_CREATE_MULTI'
EXPORTING
i_project_definition = lv_project
TABLES
IT_WBS_ELEMENT = lt_new_wbs
ET_RETURN = lt_return.
LOOP AT lt_return INTO ls_return.
if ls_return-type = 'S' OR ls_return-type = 'E'.
lv_return_type = ls_return-type.
lv_return_message = ls_return-message.
lv_CWBS_SENDER = lv_new_wbs.
p_return = ls_return.
CONCATENATE 'ZTX child WBS element created successfull -' lv_new_wbs INTO lv_MSG.
CALL FUNCTION 'Z_ZTX_LOG'
EXPORTING p_MSG = lv_MSG.
ENDIF.
ENDLOOP.
IF lv_return_type = 'S'.
CONCATENATE 'Precommit of -' lv_new_wbs INTO lv_MSG.
CALL FUNCTION 'Z_ZTX_LOG'
EXPORTING p_MSG = lv_MSG.
CALL FUNCTION 'BAPI_PS_PRECOMMIT'
TABLES
ET_RETURN = lt_return.
CONCATENATE 'BAPI_TRANSACTION_COMMIT -' lv_new_wbs INTO lv_MSG.
CALL FUNCTION 'Z_ZTX_LOG'
EXPORTING p_MSG = lv_MSG.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = ls_return.
CONCATENATE 'RETURNED FROM BAPI_TRANSACTION_COMMIT ' lv_new_wbs INTO lv_MSG.
CALL FUNCTION 'Z_ZTX_LOG'
EXPORTING p_MSG = lv_MSG.
ENDIF.
ENDIF.
lv_MSG = 'END OF steps to create WBS'.
CALL FUNCTION 'Z_ZTX_LOG'
EXPORTING p_MSG = lv_MSG.
P_CWBS = lv_CWBS_SENDER.
ENDFUNCTION.
User | Count |
---|---|
109 | |
15 | |
10 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.