要实现CJ30更新或者追加项目(WBS)的预算,可以使用如下函数: KBPP_EXTERN_UPDATE_CO
我现在要实现的是修改年度预算和增加总体的预算,如下步骤可以实现需要的功能:
1、 DATA: lt_bpak TYPE STANDARD TABLE OF bpak WITH HEADER LINE.
DATA:lt_bpak_n TYPE STANDARD TABLE OF bpak WITH HEADER LINE.
DATA: lt_retturn TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE.
2、 LOOP AT gt_itab.
CLEAR l_wtjhr.
DATA: l_pspnr LIKE prps-pspnr.
CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT'
EXPORTING
input = gt_itab-posid
IMPORTING
output = l_pspnr
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
SELECT SINGLE objnr INTO lt_bpak-e_objnr FROM prps WHERE pspnr = l_pspnr.
IF sy-subrc EQ 0.
lt_bpak-e_vorga = 'KBUD'.
lt_bpak-twaer = 'CNY'.
lt_bpak-wert = gt_itab-wtjhr.
lt_bpak-e_vorga = 'KBUD'.
SELECT wtjhr INTO l_wtjhr FROM bpja
WHERE objnr = lt_bpak-e_objnr
AND wrttp = '41'
AND vorga = 'KBUD'
AND twaer = 'CNY'
AND gjahr NE p_gjahr.
lt_bpak-wert = lt_bpak-wert + l_wtjhr.
CLEAR l_wtjhr.
ENDSELECT.
APPEND lt_bpak.
MOVE-CORRESPONDING lt_bpak TO lt_bpak_n.
lt_bpak_n-e_gjahr = p_gjahr.
lt_bpak_n-wert = gt_itab-wtjhr.
APPEND lt_bpak_n.
ENDIF.
CLEAR: lt_bpak,lt_bpak_n.
ENDLOOP.
**修改总体预算(一定要先修改总体的,不然增强年度预算的时候会检查总体预算不够,就会报错
CALL FUNCTION 'KBPP_EXTERN_UPDATE_CO'
EXPORTING
i_budget_activity = 'KBUD'
* i_budget_activ_sup_ret = 'X'
* I_COMMIT_DATA = 'X'
i_delta_amounts = ''
i_rollup_data = ''
* I_CHECK_PLAN_DATA = 'X'
* i_application = 'P'
i_commit_all = 'X'
* IMPORTING
* E_ERRORS_FOUND =
TABLES
it_bpak = lt_bpak[]
it_return = lt_retturn[]
EXCEPTIONS
no_update = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
**修改年度预算
REFRESH lt_retturn.
CALL FUNCTION 'KBPP_EXTERN_UPDATE_CO'
EXPORTING
i_budget_activity = 'KBUD'
* i_budget_activ_sup_ret = 'X'
* I_COMMIT_DATA = 'X'
i_delta_amounts = ''
i_rollup_data = ''
* I_CHECK_PLAN_DATA = 'X'
i_application = 'P'
i_commit_all = 'X'
* IMPORTING
* E_ERRORS_FOUND =
TABLES
it_bpak = lt_bpak_n[]
it_return = lt_retturn[]
EXCEPTIONS
no_update = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
注意点:
1、一定要先修改顶层WBS,再一层一层往下修改,不然的话,检查上层预算不够,就会报错
2、i_delta_amounts这个参数等于'X'的话,就是追加,等于'',就是修改
3、i_rollup_data这个参数等于'X'的话,就会自动往上层的WBS上加预算,等于'',就不会自动加
4、另外个人觉得这个函数写的有一点点问题,函数里面有个 SORT it_bpak BY e_ges DESCENDING .
但是,当我们是修改总体预算的时候,E_GES都是'X',那么排序的时候就会乱掉,有可能会把底层的WBS放到上面,上层的WBS放到下面,这个时候再修改预算的时候,尤其是一个新的wbs,就会报错说,下层WBS预算大于上层WBS预算,我找了很久参数,也没实现这个问题,于是自己把标准程序改了一下,变成了 SORT it_bpak BY e_ges DESCENDING E_OBJNR ASCENDING.