学习内容描述:利用SAP的标准BAPI创建/修改利润中心
业务参考文档:SAP Profit Center 教程:创建,分组,过帐&计划 · Guru99 中文系列教程 · 看云
事务码:KE51
重点知识:标准BAPI的调用
1、创建:BAPI_PROFITCENTER_CREATE
DATA: ls_profitcenterid TYPE bapi0015id2.
DATA: ls_basicdata TYPE bapi0015_4.
DATA: ls_bukrs TYPE bapi0015_7.
DATA: ls_datab LIKE bapi0015_3-date. "有效起始日期
DATA: ls_datbi LIKE bapi0015_3-date. "有效截止日期
DATA: lt_bukrs TYPE STANDARD TABLE OF bapi0015_7.
DATA: lt_return TYPE STANDARD TABLE OF bapiret2.
DATA: ls_return TYPE bapiret2.
ls_profitcenterid-co_area = <fs_data>-c_kokrs. "控制范围
ls_profitcenterid-profit_ctr = <fs_data>-c_code. "利润中心
ls_basicdata-prctr_name = <fs_data>-c_name. "一般姓名
ls_basicdata-long_text = <fs_data>-c_ltext. "长文本
ls_basicdata-in_charge = <fs_data>-c_verak. "负责人
ls_basicdata-department = <fs_data>-c_abtei. "部门
ls_basicdata-prctr_hier_grp = <fs_data>-c_khinr. "利润中心组
ls_basicdata-segment = <fs_data>-c_segment. "部分报表段
ls_datab = <fs_data>-c_datab.
ls_datbi = <fs_data>-c_datbi.
ls_bukrs-comp_code = <fs_data>-c_bukrs.
ls_bukrs-assign_to_prctr = 'X'.
APPEND ls_bukrs TO lt_bukrs.
CALL FUNCTION 'BAPI_PROFITCENTER_CREATE'
EXPORTING
profitcenterid = ls_profitcenterid
validfrom = ls_datab
validto = ls_datbi
basicdata = ls_basicdata
* ADDRESS =
* COMMUNICATION =
* INDICATORS =
* TESTRUN =
* LANGUAGE =
IMPORTING
return = ls_return
* PROFITCENTER =
* CONTROLLINGAREA =
TABLES
companycodes = lt_bukrs.
2、修改:BAPI_PROFITCENTER_CHANGE
DATA: ls_contral TYPE bapi0015id2.
DATA: ls_basicdata TYPE bapi0015_4.
DATA: lt_return TYPE STANDARD TABLE OF bapiret2.
DATA: ls_return TYPE bapiret2.
DATA: lt_company TYPE STANDARD TABLE OF bapi0015_7.
DATA: ls_company TYPE bapi0015_7.
DATA: lt_companyx TYPE STANDARD TABLE OF bapi0015_7x.
DATA: ls_companyx TYPE bapi0015_7x.
DATA: ls_datab LIKE bapi0015_3-date. "有效起始日期
DATA: ls_datbi LIKE bapi0015_3-date. "有效截止日期
ls_contral-profit_ctr = <fs_data>-c_code. "利润中心
ls_contral-co_area = <fs_data>-c_kokrs. "控制范围
ls_basicdata-prctr_name = <fs_data>-c_name. "一般姓名
ls_basicdata-long_text = <fs_data>-c_ltext. "长文本
ls_basicdata-in_charge = <fs_data>-c_verak. "负责人
ls_basicdata-department = <fs_data>-c_abtei. "部门
ls_basicdata-prctr_hier_grp = <fs_data>-c_khinr. "利润中心组
ls_basicdata-segment = <fs_data>-c_segment. "部分报表段
ls_datab = <fs_data>-c_datab.
ls_datbi = <fs_data>-c_datbi.
ls_company-comp_code = <fs_data>-c_bukrs.
ls_company-assign_to_prctr = 'X'.
APPEND ls_company TO lt_company.
ls_companyx-comp_code = <fs_data>-c_bukrs.
ls_companyx-assign_to_prctr = 'X'.
APPEND ls_companyx TO lt_companyx.
CALL FUNCTION 'BAPI_PROFITCENTER_CHANGE'
EXPORTING
profitcenter = ls_contral-profit_ctr
controllingarea = ls_contral-co_area
validfrom = ls_datab
validto = ls_datbi
basicdata = ls_basicdata
* ADDRESS =
* COMMUNICATION =
* INDICATORS =
* TESTRUN = ' '
* LANGUAGE =
* BASICDATAX =
* ADDRESSX =
* COMMUNICATIONX =
* INDICATORSX =
IMPORTING
return = ls_return
TABLES
companycodes = lt_company
companycodesx = lt_companyx.
IF ls_return-type = 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ls_out-id = <fs_data>-id . "利润中心
ls_out-msg = ls_return-message. "消息
ls_out-status = '0'. "状态 0失败,1成功
APPEND ls_out TO lt_out.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ls_out-id = <fs_data>-id. " 利润中心
ls_out-msg = '利润中心修改成功'. "消息
APPEND ls_out TO lt_out.
ENDIF.
难点知识:无
收获与总结:
掌握bapi的调用。
反思与计划:下一篇成长中心组。
学习时间:20240829
学习天数:3年2个月