一、复制标准项目模板实现项目立项

因为CJ20N录屏存在困难,所以想通过BDC实现复制项目模板创建项目立项行不通,因此需要通过BAPI解决。

因为项目立项包含:项目定义、WBS、网络、作业,因此需要分别调用四个BAPI实现该功能

二、CJ01 项目定义与WBS

输入项目定义编号和参数文件

传入必输字段,点击WBS元素总览

输入WBS层级,点击保存即可

创建项目BAPI

"-----------------------------@斌将军-----------------------------
DATA:gs_proj_bus2001_new TYPE bapi_bus2001_new,
gt_bapiret2 TYPE TABLE OF bapiret2,
gs_bapiret2 TYPE bapiret2. gs_proj_bus2001_new-project_definition = 'NPD-2022037'."is_proj-pspid. "项目编号
gs_proj_bus2001_new-description = '测试'."is_proj-post1. "PS: 短描述 (第一行文本)
gs_proj_bus2001_new-responsible_no = '80000667'."lv_vernr. "项目经理编号
gs_proj_bus2001_new-applicant_no = '81000003'."lv_vernr. "申请部门编号
gs_proj_bus2001_new-start = '20220225'."is_proj-plfaz. "开始日期
gs_proj_bus2001_new-finish = '20220428'."is_proj-plsez. "完成日期
gs_proj_bus2001_new-company_code = '2000'."is_proj-vbukr. "项目的公司代码
gs_proj_bus2001_new-profit_ctr = ''."is_proj-prctr. "利润中心
gs_proj_bus2001_new-project_profile = 'APS0001'."is_proj-profl. "项目参数文件
gs_proj_bus2001_new-plant = '2000'."is_proj-werks. "工厂
*IF is_proj-func_area IS NOT INITIAL.
* gs_proj_bus2001_new-func_area = is_proj-func_area. "功能控制范围
*ENDIF. CALL FUNCTION 'BAPI_PS_INITIALIZATION'. CALL FUNCTION 'BAPI_BUS2001_CREATE'
EXPORTING
i_project_definition = gs_proj_bus2001_new
TABLES
et_return = gt_bapiret2. LOOP AT gt_bapiret2 INTO gs_bapiret2 WHERE type CA 'AEX'.
ENDLOOP. IF sy-subrc EQ 0.
CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.
CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
EXPORTING
i_precommit_ok = 'Y'.
ENDIF.
CHECK sy-subrc NE 0.
CALL FUNCTION 'BAPI_PS_PRECOMMIT'
TABLES
et_return = gt_bapiret2. LOOP AT gt_bapiret2 INTO gs_bapiret2 WHERE type CA 'AEX'.
ENDLOOP. IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
IMPORTING
return = gs_bapiret2. CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'. CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
EXPORTING
i_precommit_ok = 'Y'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = gs_bapiret2.
* 项目定义创建成功
ENDIF.
"-----------------------------@斌将军-----------------------------

创建WBS的BAPI

"-----------------------------@斌将军-----------------------------
DATA:lv_pspid TYPE bapi_bus2001_new-project_definition,
gt_wbs_bus2054_new TYPE TABLE OF bapi_bus2054_new,
gs_wbs_bus2054_new TYPE bapi_bus2054_new,
gt_bapiret2 TYPE TABLE OF bapiret2,
gs_bapiret2 TYPE bapiret2. CLEAR:gs_wbs_bus2054_new.
gs_wbs_bus2054_new-wbs_element = 'NPD-2022038'."gs_wbs-posid. "工作分解结构元素 (WBS 元素)
gs_wbs_bus2054_new-description = '第一层'."gs_wbs-post1. "PS: 短描述 (第一行文本)
gs_wbs_bus2054_new-responsible_no = '80000667'."lv_vernr. "项目经理编号
*gs_wbs_bus2054_new-profit_ctr = ''."gs_wbs-prctr. "利润中心
gs_wbs_bus2054_new-proj_type = '11'."gs_wbs-prart. "项目类型
gs_wbs_bus2054_new-wbs_account_assignment_element = 'X'."gs_wbs-belkz. "标志:科目分配元素
*gs_wbs_bus2054_new-wbs_billing_element = ''."gs_wbs-fakkz. "标识符: 开票元素
gs_wbs_bus2054_new-wbs_left = ''."gs_wbs-left_posid."左侧WBS
gs_wbs_bus2054_new-wbs_up = ''."gs_wbs-up_posid. "上级WBS
*gs_wbs_bus2054_new-user_field_char20_1 = ''."gs_wbs-usr00. "业务类别
*gs_wbs_bus2054_new-user_field_char20_2 = ''."gs_wbs-usr01. "CRM 商机编码
*gs_wbs_bus2054_new-user_field_char10_1 = ''."'X'. "产品
*gs_wbs_bus2054_new-statistical = ''."gs_wbs-xstat. "统计
*gs_wbs_bus2054_new-wbs_cctr_posted_actual = ''."gs_wbs-kostl. "CCtr 过账
APPEND gs_wbs_bus2054_new TO gt_wbs_bus2054_new. CLEAR:gs_wbs_bus2054_new.
gs_wbs_bus2054_new-wbs_element = 'NPD-2022038.001'."gs_wbs-posid. "工作分解结构元素 (WBS 元素)
gs_wbs_bus2054_new-description = '第二层'."gs_wbs-post1. "PS: 短描述 (第一行文本)
gs_wbs_bus2054_new-responsible_no = '80000667'."lv_vernr. "项目经理编号
*gs_wbs_bus2054_new-profit_ctr = ''."gs_wbs-prctr. "利润中心
gs_wbs_bus2054_new-proj_type = '11'."gs_wbs-prart. "项目类型
gs_wbs_bus2054_new-wbs_account_assignment_element = 'X'."gs_wbs-belkz. "标志:科目分配元素
*gs_wbs_bus2054_new-wbs_billing_element = ''."gs_wbs-fakkz. "标识符: 开票元素
gs_wbs_bus2054_new-wbs_left = ''."gs_wbs-left_posid."左侧WBS
gs_wbs_bus2054_new-wbs_up = 'NPD-2022038'."gs_wbs-up_posid. "上级WBS
*gs_wbs_bus2054_new-user_field_char20_1 = ''."gs_wbs-usr00. "业务类别
*gs_wbs_bus2054_new-user_field_char20_2 = ''."gs_wbs-usr01. "CRM 商机编码
*gs_wbs_bus2054_new-user_field_char10_1 = ''."'X'. "产品
*gs_wbs_bus2054_new-statistical = ''."gs_wbs-xstat. "统计
*gs_wbs_bus2054_new-wbs_cctr_posted_actual = ''."gs_wbs-kostl. "CCtr 过账
APPEND gs_wbs_bus2054_new TO gt_wbs_bus2054_new. CLEAR:gs_wbs_bus2054_new.
gs_wbs_bus2054_new-wbs_element = 'NPD-2022038.002'."gs_wbs-posid. "工作分解结构元素 (WBS 元素)
gs_wbs_bus2054_new-description = '第三层'."gs_wbs-post1. "PS: 短描述 (第一行文本)
gs_wbs_bus2054_new-responsible_no = '80000667'."lv_vernr. "项目经理编号
*gs_wbs_bus2054_new-profit_ctr = ''."gs_wbs-prctr. "利润中心
gs_wbs_bus2054_new-proj_type = '11'."gs_wbs-prart. "项目类型
gs_wbs_bus2054_new-wbs_account_assignment_element = 'X'."gs_wbs-belkz. "标志:科目分配元素
*gs_wbs_bus2054_new-wbs_billing_element = ''."gs_wbs-fakkz. "标识符: 开票元素
*gs_wbs_bus2054_new-wbs_left = 'NPD-2022037.001'."gs_wbs-left_posid."左侧WBS
gs_wbs_bus2054_new-wbs_up = 'NPD-2022038'."gs_wbs-up_posid. "上级WBS
*gs_wbs_bus2054_new-user_field_char20_1 = ''."gs_wbs-usr00. "业务类别
*gs_wbs_bus2054_new-user_field_char20_2 = ''."gs_wbs-usr01. "CRM 商机编码
*gs_wbs_bus2054_new-user_field_char10_1 = ''."'X'. "产品
*gs_wbs_bus2054_new-statistical = ''."gs_wbs-xstat. "统计
*gs_wbs_bus2054_new-wbs_cctr_posted_actual = ''."gs_wbs-kostl. "CCtr 过账
APPEND gs_wbs_bus2054_new TO gt_wbs_bus2054_new. lv_pspid = 'NPD-2022038'. CALL FUNCTION 'BAPI_PS_INITIALIZATION'. CALL FUNCTION 'BAPI_BUS2054_CREATE_MULTI'
EXPORTING
i_project_definition = lv_pspid
TABLES
it_wbs_element = gt_wbs_bus2054_new
et_return = gt_bapiret2. LOOP AT gt_bapiret2 INTO gs_bapiret2 WHERE type CA 'AE'.
ENDLOOP. IF sy-subrc EQ 0. CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'. CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
EXPORTING
i_precommit_ok = 'Y'. ENDIF.
CHECK sy-subrc NE 0.
CALL FUNCTION 'BAPI_PS_PRECOMMIT'
TABLES
et_return = gt_bapiret2. LOOP AT gt_bapiret2 INTO gs_bapiret2 WHERE type CA 'AE'.
ENDLOOP. IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
IMPORTING
return = gs_bapiret2. CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'. CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
EXPORTING
i_precommit_ok = 'Y'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = gs_bapiret2.
ENDIF.
"-----------------------------@斌将军-----------------------------

三、CN21创建网络和作业

分配给WBS,点击作业

创建作业,分配给WBS,点击保存即可

创建网络BAPI

"-----------------------------@斌将军-----------------------------
DATA:gs_net_bus2002_new TYPE bapi_bus2002_new,
gt_bapiret2 TYPE TABLE OF bapiret2,
gs_bapiret2 TYPE bapiret2. CLEAR : gs_net_bus2002_new.
gs_net_bus2002_new-project_definition = 'NPD-2022037'."is_network-pspid. "项目定义
gs_net_bus2002_new-wbs_element = 'NPD-2022037'."is_network-posid. "工作分解结构元素 (WBS 元素)
gs_net_bus2002_new-short_text = '网络测试'."is_network-ktext. "描述
* gs_net_bus2002_new-plant = ''."is_network-werks. "工厂
* gs_net_bus2002_new-mrp_controller = ''."is_network-dispo. "MRP控制者
CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
CALL FUNCTION 'BAPI_BUS2002_CREATE'
EXPORTING
i_network = gs_net_bus2002_new
TABLES
et_return = gt_bapiret2.
LOOP AT gt_bapiret2 INTO gs_bapiret2 WHERE type CA 'AEX'. ENDLOOP.
IF sy-subrc EQ 0.
CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.
CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
EXPORTING
i_precommit_ok = 'Y'.
ENDIF.
CHECK sy-subrc NE 0.
CALL FUNCTION 'BAPI_PS_PRECOMMIT'
TABLES
et_return = gt_bapiret2.
LOOP AT gt_bapiret2 INTO gs_bapiret2 WHERE type CA 'AEX'. ENDLOOP.
IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
IMPORTING
return = gs_bapiret2.
CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.
CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
EXPORTING
i_precommit_ok = 'Y'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = gs_bapiret2.
READ TABLE gt_bapiret2 INTO gs_bapiret2 WITH KEY id = 'CNIF_PI'
number = '003'.
IF sy-subrc EQ 0.
* ev_aufnr = gs_bapiret2-message_v2.
ENDIF.
ENDIF.
"-----------------------------@斌将军-----------------------------

创建作业BAPI

"-----------------------------@斌将军-----------------------------

DATA:lv_aufnr TYPE bapi_network_list-network.
DATA:gt_act_bus2002_new TYPE TABLE OF bapi_bus2002_act_new,
gs_act_bus2002_new TYPE bapi_bus2002_act_new,
gt_bapiret2 TYPE TABLE OF bapiret2,
gs_bapiret2 TYPE bapiret2. CLEAR:gs_act_bus2002_new.
gs_act_bus2002_new-activity = '0010'."gs_activity-vornr. "在网络和库网络中的作业编号
gs_act_bus2002_new-description = '封装测试'."gs_activity-ltxa1. "工序短文本
gs_act_bus2002_new-control_key = ''."gs_activity-steus. "控制码-内协(ZPS1)和成本(ZPS3)
gs_act_bus2002_new-wbs_element = 'NPD-2022037.001'."gs_activity-posid. "工作分解结构元素 (WBS 元素)
gs_act_bus2002_new-duration_normal = 2."gs_activity-posid. "工作分解结构元素 (WBS 元素)
gs_act_bus2002_new-work_cntr = ''."gs_activity-arbpl. "工作中心
gs_act_bus2002_new-work_activity = ''."gs_activity-arbei. "工作(时间单位H)
*-------------MOD ON 20200423--------Begin-----------------------------------
** gs_act_bus2002_new-calculation_key = gs_activity-indet. "用于计算的码
*IF gs_activity-steus = 'ZPS1' AND gs_activity-arbei IS INITIAL.
* gs_act_bus2002_new-calculation_key = 0. "用于计算的码
*ELSE.
* gs_act_bus2002_new-calculation_key = gs_activity-indet. "用于计算的码
*ENDIF.
*-------------MOD ON 20200423--------End-------------------------------------
*gs_act_bus2002_new-acttype = gs_activity-larnt. "活动类型
*gs_act_bus2002_new-cost_elem = gs_activity-sakto. "成本要素编码
*gs_act_bus2002_new-profit_ctr = gs_activity-prctr. "利润中心
*IF gs_activity-steus EQ 'ZPS3'.
* gs_act_bus2002_new-activity_costs = gs_activity-prkst. "作业中的成本
** ELSE.
** gs_act_bus2002_new-user_field_curr1 = gs_activity-prkst. "用户字段 - 值3
*ENDIF. APPEND gs_act_bus2002_new TO gt_act_bus2002_new. CLEAR:gs_act_bus2002_new.
gs_act_bus2002_new-activity = '0020'."gs_activity-vornr. "在网络和库网络中的作业编号
gs_act_bus2002_new-description = '项目产品设计'."gs_activity-ltxa1. "工序短文本
gs_act_bus2002_new-control_key = ''."gs_activity-steus. "控制码-内协(ZPS1)和成本(ZPS3)
gs_act_bus2002_new-wbs_element = 'NPD-2022037.001'."gs_activity-posid. "工作分解结构元素 (WBS 元素)
gs_act_bus2002_new-duration_normal = 2."gs_activity-posid. "工作分解结构元素 (WBS 元素)
gs_act_bus2002_new-work_cntr = ''."gs_activity-arbpl. "工作中心
gs_act_bus2002_new-work_activity = ''."gs_activity-arbei. "工作(时间单位H)
APPEND gs_act_bus2002_new TO gt_act_bus2002_new. CLEAR:gs_act_bus2002_new.
gs_act_bus2002_new-activity = '0030'."gs_activity-vornr. "在网络和库网络中的作业编号
gs_act_bus2002_new-description = '项目立项'."gs_activity-ltxa1. "工序短文本
gs_act_bus2002_new-control_key = ''."gs_activity-steus. "控制码-内协(ZPS1)和成本(ZPS3)
gs_act_bus2002_new-wbs_element = 'NPD-2022037.002'."gs_activity-posid. "工作分解结构元素 (WBS 元素)
gs_act_bus2002_new-duration_normal = 2."gs_activity-posid. "工作分解结构元素 (WBS 元素)
gs_act_bus2002_new-work_cntr = ''."gs_activity-arbpl. "工作中心
gs_act_bus2002_new-work_activity = ''."gs_activity-arbei. "工作(时间单位H)
APPEND gs_act_bus2002_new TO gt_act_bus2002_new. CLEAR:gs_act_bus2002_new.
gs_act_bus2002_new-activity = '0040'."gs_activity-vornr. "在网络和库网络中的作业编号
gs_act_bus2002_new-description = '项目评估'."gs_activity-ltxa1. "工序短文本
gs_act_bus2002_new-control_key = ''."gs_activity-steus. "控制码-内协(ZPS1)和成本(ZPS3)
gs_act_bus2002_new-wbs_element = 'NPD-2022037.002'."gs_activity-posid. "工作分解结构元素 (WBS 元素)
gs_act_bus2002_new-duration_normal = 2."gs_activity-posid. "工作分解结构元素 (WBS 元素)
gs_act_bus2002_new-work_cntr = ''."gs_activity-arbpl. "工作中心
gs_act_bus2002_new-work_activity = ''."gs_activity-arbei. "工作(时间单位H)
APPEND gs_act_bus2002_new TO gt_act_bus2002_new. CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
lv_aufnr = '4000088'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_aufnr
IMPORTING
output = lv_aufnr. CALL FUNCTION 'BAPI_BUS2002_ACT_CREATE_MULTI'
EXPORTING
i_number = lv_aufnr
TABLES
it_activity = gt_act_bus2002_new
et_return = gt_bapiret2. LOOP AT gt_bapiret2 INTO gs_bapiret2 WHERE type CA 'AE'.
ENDLOOP. IF sy-subrc EQ 0.
CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.
CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
EXPORTING
i_precommit_ok = 'Y'.
ENDIF. CHECK sy-subrc NE 0.
CALL FUNCTION 'BAPI_PS_PRECOMMIT'
TABLES
et_return = gt_bapiret2.
LOOP AT gt_bapiret2 INTO gs_bapiret2 WHERE type CA 'AE'.
ENDLOOP. IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
IMPORTING
return = gs_bapiret2. CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.
CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
EXPORTING
i_precommit_ok = 'Y'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
IMPORTING
return = gs_bapiret2.
ENDIF.
"-----------------------------@斌将军-----------------------------

四、代码整合

通过整合四个BAPI,实现复制标准模板完成项目立项过程

"-----------------------------@斌将军-----------------------------
FUNCTION zps01_project_create.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(I_INPUT) TYPE ZSPS_CJXM
*" EXPORTING
*" VALUE(E_RETURN) TYPE BAPIRETURN
*"---------------------------------------------------------------------- DATA:gs_proj_bus2001_new TYPE bapi_bus2001_new,
gt_wbs_bus2054_new TYPE TABLE OF bapi_bus2054_new,
gs_wbs_bus2054_new TYPE bapi_bus2054_new,
gs_net_bus2002_new TYPE bapi_bus2002_new,
gt_act_bus2002_new TYPE TABLE OF bapi_bus2002_act_new,
gs_act_bus2002_new TYPE bapi_bus2002_act_new,
gt_bapiret2 TYPE TABLE OF bapiret2,
gs_bapiret2 TYPE bapiret2. DATA:lv_new_pspid TYPE proj-pspid,
lv_bz_pspid TYPE projs-pspid,
lv_ctumode TYPE ctu_params-dismode,
lv_update TYPE ctu_params-updmode,
lv_aufnr TYPE bapi_network_list-network,
lv_bzxm TYPE proj-pspid,
lv_prart TYPE char10,
lv_wtges TYPE char17,
lv_bzwbs TYPE ps_posid,
* lv_profl TYPE proj-profl,
lv_number TYPE numc3,
lv_check TYPE char1,
ls_return TYPE bapireturn,
lv_message TYPE char200,
lv_msg TYPE char200. IF i_input-pspid IS INITIAL.
e_return-type = 'E'.
e_return-message = '标准项目编码为空'.
RETURN.
ENDIF. IF i_input-vbukr IS INITIAL.
e_return-type = 'E'.
e_return-message = '公司代码为空'.
RETURN.
ENDIF. "获取项目类型相关配置信息
SELECT SINGLE
*
FROM zpst_prart
INTO @DATA(ls_prart)
WHERE bukrs = @i_input-vbukr
AND zprart = @i_input-prart. "获取项目经理与OA账号关联表数据
SELECT SINGLE
vernr,
verna
FROM tcj04
INTO @DATA(ls_cj04)
WHERE verna = @i_input-usr00. IF ls_cj04 IS INITIAL.
e_return-type = 'E'.
e_return-message = '项目经理' && i_input-usr01 && '不存在'.
RETURN.
ENDIF. CLEAR:lv_bz_pspid.
lv_bz_pspid = i_input-pspid."标准模板项目定义编号
CALL FUNCTION 'CONVERSION_EXIT_ABPSN_INPUT'
EXPORTING
input = lv_bz_pspid
IMPORTING
output = lv_bz_pspid. "获取相同项目类型,最大的项目编号
CLEAR:lv_prart.
lv_prart = i_input-prart && sy-datum+0(4) && '%'.
CLEAR:lv_new_pspid.
SELECT
MAX( pspid )
FROM proj
INTO lv_new_pspid
WHERE pspid LIKE lv_prart. IF lv_new_pspid IS INITIAL.
lv_number = 1.
ELSE.
lv_number = lv_new_pspid+7(3).
lv_number = lv_number + 1.
ENDIF. lv_new_pspid = i_input-prart && '-' && sy-datum+0(4) && lv_number."要创建的项目定义编号 * CLEAR:lv_profl.
* lv_profl = ."项目参数文件
* CASE i_input-prart.
* WHEN 'NPD' OR 'NPI' OR 'RDT' OR 'AUT' OR 'TRY'.
* lv_profl = '0001'.
* WHEN 'TEH' OR 'EXP' OR 'ITA'.
* lv_profl = '0002'.
* WHEN 'COS'.
* lv_profl = '0003'.
* WHEN 'FAC'.
* lv_profl = '0004'.
* WHEN OTHERS.
* ENDCASE.
* IF i_input-vbukr = '1000'.
* lv_profl = 'LRC' && lv_profl.
* ELSEIF i_input-vbukr = '2000'.
* lv_profl = 'APS' && lv_profl."项目参数文件
* ENDIF. SELECT SINGLE
*
FROM projs
INTO @DATA(ls_projs)
WHERE pspid = @lv_bz_pspid. IF sy-subrc EQ 0.
"--------------------------------创建项目--------------------------------------
CLEAR:gs_proj_bus2001_new.
gs_proj_bus2001_new-project_definition = lv_new_pspid. "项目编号
gs_proj_bus2001_new-description = i_input-post1. "PS: 短描述 (第一行文本)
gs_proj_bus2001_new-responsible_no = ls_cj04-vernr. "项目经理编号
gs_proj_bus2001_new-applicant_no = ls_projs-astnr."lv_vernr. "申请部门编号
gs_proj_bus2001_new-start = i_input-plfaz. "开始日期
gs_proj_bus2001_new-finish = i_input-plsez. "完成日期
* gs_proj_bus2001_new-company_code = '2000'."is_proj-vbukr. "项目的公司代码
gs_proj_bus2001_new-profit_ctr = ''."is_proj-prctr. "利润中心
gs_proj_bus2001_new-project_profile = ls_prart-profl."is_proj-profl. "项目参数文件
* gs_proj_bus2001_new-plant = '2000'."is_proj-werks. "工厂 "初始化
CALL FUNCTION 'BAPI_PS_INITIALIZATION'. "创建项目
REFRESH:gt_bapiret2.
CALL FUNCTION 'BAPI_BUS2001_CREATE'
EXPORTING
i_project_definition = gs_proj_bus2001_new
TABLES
et_return = gt_bapiret2. CLEAR:lv_check,lv_message.
LOOP AT gt_bapiret2 INTO gs_bapiret2 WHERE type CA 'AEX'.
lv_check = 'E'.
lv_message = lv_message && gs_bapiret2-message.
CLEAR:gs_bapiret2.
ENDLOOP. IF lv_check = 'E'.
"错误后初始化
CALL FUNCTION 'ZPS01_PS_FLAG'. e_return-type = 'E'.
e_return-message = lv_message.
RETURN.
ELSE.
CLEAR:ls_return.
"成功时提交
CALL FUNCTION 'ZPS01_PS_PRECOMMIT'
IMPORTING
e_return = ls_return.
IF ls_return-type = 'E'.
e_return-type = 'E'.
e_return-message = ls_return-message.
RETURN.
ENDIF. "--------------------------------创建WBS--------------------------------------
SELECT
pspnr,"标准 WBS: 内部项目号 (具有退出(根据 ID ))
posid,"标准项目中的 WBS 元素
post1,"PS: 短描述 (第一行文本)
psphi,"当前的内部项目号 - 标准 WBS
stufe"项目层次的等级
FROM prpss
INTO TABLE @DATA(lt_prpss)
WHERE psphi = @ls_projs-pspnr. SORT lt_prpss BY pspnr. IF lt_prpss IS NOT INITIAL.
LOOP AT lt_prpss INTO DATA(ls_prpss).
CLEAR:gs_wbs_bus2054_new.
IF sy-tabix = 1.
gs_wbs_bus2054_new-wbs_element = lv_new_pspid.
gs_wbs_bus2054_new-user_field_char20_1 = i_input-usr00.
gs_wbs_bus2054_new-description = i_input-post1."ls_prpss-post1."PS: 短描述 (第一行文本)
ELSE.
gs_wbs_bus2054_new-wbs_element = lv_new_pspid && '.' && ls_prpss-posid+10(3)."'NPD-2022037' '.' '001'"工作分解结构元素 (WBS 元素)
gs_wbs_bus2054_new-wbs_up = lv_new_pspid."gs_wbs-up_posid. "上级WBS
gs_wbs_bus2054_new-description = ls_prpss-post1."PS: 短描述 (第一行文本)
ENDIF. gs_wbs_bus2054_new-responsible_no = ls_cj04-vernr."项目经理编号
"gs_wbs_bus2054_new-profit_ctr = ''."gs_wbs-prctr. "利润中心
gs_wbs_bus2054_new-proj_type = ls_prart-prart. "项目类型
gs_wbs_bus2054_new-wbs_account_assignment_element = 'X'."gs_wbs-belkz. "标志:科目分配元素
"gs_wbs_bus2054_new-wbs_billing_element = ''."gs_wbs-fakkz. "标识符: 开票元素
gs_wbs_bus2054_new-wbs_left = ''."gs_wbs-left_posid."左侧WBS
"gs_wbs_bus2054_new-user_field_char20_1 = ''."gs_wbs-usr00. "业务类别
"gs_wbs_bus2054_new-user_field_char20_2 = ''."gs_wbs-usr01. "CRM 商机编码
"gs_wbs_bus2054_new-user_field_char10_1 = ''."'X'. "产品
"gs_wbs_bus2054_new-statistical = ''."gs_wbs-xstat. "统计
"gs_wbs_bus2054_new-wbs_cctr_posted_actual = ''."gs_wbs-kostl. "CCtr 过账
APPEND gs_wbs_bus2054_new TO gt_wbs_bus2054_new.
CLEAR:ls_prpss.
ENDLOOP. CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
"创建WBS
REFRESH:gt_bapiret2.
CALL FUNCTION 'BAPI_BUS2054_CREATE_MULTI'
EXPORTING
i_project_definition = lv_new_pspid
TABLES
it_wbs_element = gt_wbs_bus2054_new
et_return = gt_bapiret2. CLEAR:lv_check,lv_message.
LOOP AT gt_bapiret2 INTO gs_bapiret2 WHERE type CA 'AEX'.
lv_check = 'E'.
lv_message = lv_message && gs_bapiret2-message.
CLEAR:gs_bapiret2.
ENDLOOP. IF lv_check = 'E'.
"错误后初始化
CALL FUNCTION 'ZPS01_PS_FLAG'. e_return-type = 'E'.
e_return-message = lv_message.
RETURN.
ELSE.
CLEAR:ls_return.
"成功时提交
CALL FUNCTION 'ZPS01_PS_PRECOMMIT'
IMPORTING
e_return = ls_return.
IF ls_return-type = 'E'.
e_return-type = 'E'.
e_return-message = ls_return-message.
RETURN.
ENDIF. "--------------------------------创建网络--------------------------------------
CLEAR : gs_net_bus2002_new.
gs_net_bus2002_new-project_definition = lv_new_pspid."is_network-pspid. "项目定义
gs_net_bus2002_new-wbs_element = lv_new_pspid."is_network-posid. "工作分解结构元素 (WBS 元素)
gs_net_bus2002_new-profile = ls_prart-profid."is_network-ktext. "网络参数文件
CLEAR:ls_prpss.
* READ TABLE lt_prpss INTO ls_prpss WITH KEY stufe = 1."获取最上层WBS的描述
* IF sy-subrc EQ 0.
* gs_net_bus2002_new-short_text = ls_prpss-post1."is_network-ktext. "描述
* ENDIF.
gs_net_bus2002_new-short_text = i_input-post1."ls_prpss-post1."is_network-ktext. "描述
CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
"创建网络
REFRESH:gt_bapiret2.
CALL FUNCTION 'BAPI_BUS2002_CREATE'
EXPORTING
i_network = gs_net_bus2002_new
TABLES
et_return = gt_bapiret2. CLEAR:lv_check,lv_message.
LOOP AT gt_bapiret2 INTO gs_bapiret2 WHERE type CA 'AEX'.
lv_check = 'E'.
lv_message = lv_message && gs_bapiret2-message.
CLEAR:gs_bapiret2.
ENDLOOP. IF lv_check = 'E'.
"错误后初始化
CALL FUNCTION 'ZPS01_PS_FLAG'. e_return-type = 'E'.
e_return-message = lv_message.
RETURN.
ELSE.
"成功时提交
REFRESH:gt_bapiret2.
CALL FUNCTION 'BAPI_PS_PRECOMMIT'
TABLES
et_return = gt_bapiret2. CLEAR:lv_check,lv_message.
LOOP AT gt_bapiret2 INTO gs_bapiret2 WHERE type CA 'AEX'.
lv_check = 'E'.
lv_message = lv_message && gs_bapiret2-message.
CLEAR:gs_bapiret2.
ENDLOOP.
IF lv_check EQ 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. CALL FUNCTION 'ZPS01_PS_FLAG'.
ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'. READ TABLE gt_bapiret2 INTO gs_bapiret2 WITH KEY id = 'CNIF_PI'
number = '003'.
IF sy-subrc EQ 0.
lv_aufnr = gs_bapiret2-message_v2.
ENDIF.
ENDIF.
IF ls_return-type = 'E'.
e_return-type = 'E'.
e_return-message = ls_return-message.
RETURN.
ENDIF. "--------------------------------创建作业--------------------------------------
READ TABLE lt_prpss INTO ls_prpss WITH KEY stufe = 1."获取最上层WBS的描述 SELECT
plko~plnty,"
plko~plnnr,"
plko~plnal,"
plko~zaehl,"
plko~pspnr," plpo~plnkn,"
plpo~vornr,"
plpo~ltxa1,"
plpo~dauno,"
plpo~daune,"
plpo~pspnr AS zbzwbs"
FROM plko
INNER JOIN plpo ON plko~plnnr = plpo~plnnr
INTO TABLE @DATA(lt_plko)
WHERE plko~pspnr = @ls_prpss-pspnr
AND plko~plnty = '0'
AND plpo~plnty = '0'.
IF lt_plko IS NOT INITIAL.
LOOP AT lt_plko INTO DATA(ls_plko).
CLEAR:gs_act_bus2002_new.
gs_act_bus2002_new-activity = ls_plko-vornr. "在网络和库网络中的作业编号
gs_act_bus2002_new-description = ls_plko-ltxa1. "工序短文本
gs_act_bus2002_new-control_key = ''."gs_activity-steus. "控制码-内协(ZPS1)和成本(ZPS3)
CALL FUNCTION 'CONVERSION_EXIT_KONPT_OUTPUT'
EXPORTING
input = ls_plko-zbzwbs
IMPORTING
output = lv_bzwbs.
gs_act_bus2002_new-wbs_element = lv_new_pspid && lv_bzwbs+11."工作分解结构元素 (WBS 元素)
gs_act_bus2002_new-duration_normal = ls_plko-dauno. "工作时间
gs_act_bus2002_new-duration_normal_unit = ls_plko-daune. "工作时间单位
gs_act_bus2002_new-work_cntr = ''."gs_activity-arbpl. "工作中心
gs_act_bus2002_new-work_activity = ''."gs_activity-arbei. "工作(时间单位H)
APPEND gs_act_bus2002_new TO gt_act_bus2002_new.
CLEAR:ls_plko.
ENDLOOP. CALL FUNCTION 'BAPI_PS_INITIALIZATION'. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_aufnr
IMPORTING
output = lv_aufnr. CALL FUNCTION 'BAPI_BUS2002_ACT_CREATE_MULTI'
EXPORTING
i_number = lv_aufnr
TABLES
it_activity = gt_act_bus2002_new
et_return = gt_bapiret2.
CLEAR:lv_check,lv_message.
LOOP AT gt_bapiret2 INTO gs_bapiret2 WHERE type CA 'AEX'.
lv_check = 'E'.
lv_message = lv_message && gs_bapiret2-message.
CLEAR:gs_bapiret2.
ENDLOOP. IF lv_check = 'E'.
"错误后初始化
CALL FUNCTION 'ZPS01_PS_FLAG'. e_return-type = 'E'.
e_return-message = lv_message.
RETURN.
ELSE.
CLEAR:ls_return.
"成功时提交
CALL FUNCTION 'ZPS01_PS_PRECOMMIT'
IMPORTING
e_return = ls_return.
IF ls_return-type = 'E'.
e_return-type = 'E'.
e_return-message = ls_return-message.
RETURN.
ENDIF.
ENDIF.
ELSE.
e_return-type = 'E'.
e_return-message = '标准项目抬头WBS' && ls_prpss-pspnr && '的作业不存在'.
RETURN.
ENDIF.
ENDIF.
ENDIF.
ELSE.
e_return-type = 'E'.
e_return-message = '标准WBS不存在'.
RETURN.
ENDIF.
ENDIF.
ELSE.
e_return-type = 'E'.
e_return-message = '标准项目不存在'.
RETURN.
ENDIF. "如果预算为空,则不维护预算
IF i_input-wtges IS NOT INITIAL.
"维护预算
"设置成本控制范围
SET PARAMETER ID 'CAC' FIELD 'LRCG'.
"调用BDC
REFRESH:gt_bdcdata[].
PERFORM bdc_dynpro USING 'SAPMKBUD' '0200'.
PERFORM bdc_field USING 'BDC_OKCODE' '=MYENTER'.
PERFORM bdc_field USING 'BDC_CURSOR' 'PROJ-PSPID'.
PERFORM bdc_field USING 'PROJ-PSPID' lv_new_pspid."项目定义 PERFORM bdc_dynpro USING 'SAPLKBPP' '0320'.
PERFORM bdc_field USING 'BDC_OKCODE' '=POST'.
PERFORM bdc_field USING 'BDC_CURSOR' 'BPDY-WERT1(03)'.
CLEAR:lv_wtges.
lv_wtges = i_input-wtges.
CONDENSE lv_wtges NO-GAPS.
PERFORM bdc_field USING 'BPDY-WERT1(01)' lv_wtges."项目预算 lv_ctumode = 'N'. "N就是一步完成,A是分步enter完成
REFRESH gt_messtab[].
CALL TRANSACTION 'CJ30' USING gt_bdcdata
MODE lv_ctumode
UPDATE 'S'
MESSAGES INTO gt_messtab.
CLEAR:lv_message,gt_messtab.
LOOP AT gt_messtab.
CLEAR:lv_msg.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = gt_messtab-msgid
msgnr = gt_messtab-msgnr
msgv1 = gt_messtab-msgv1
msgv2 = gt_messtab-msgv2
msgv3 = gt_messtab-msgv3
msgv4 = gt_messtab-msgv4
IMPORTING
message_text_output = lv_msg.
CONCATENATE lv_message lv_msg INTO lv_message.
ENDLOOP. READ TABLE gt_messtab WITH KEY msgtyp = 'S'
msgid = 'BP'
msgnr = '043'.
IF sy-subrc = 0 .
e_return-type = 'S'.
e_return-message = '项目创建成功'.
e_return-message_v1 = lv_new_pspid.
ELSE.
e_return-type = 'E'.
e_return-message = '项目创建成功,但预算维护失败'.
e_return-message_v1 = lv_new_pspid.
ENDIF.
ELSE.
e_return-type = 'S'.
e_return-message = '项目创建成功'.
e_return-message_v1 = lv_new_pspid.
ENDIF.
ENDFUNCTION.
"-----------------------------@斌将军-----------------------------

程序中因为多次调用提交和初始化逻辑,因此封装成一个函数

初始化函数

"-----------------------------@斌将军-----------------------------
FUNCTION zps01_ps_flag.
*"----------------------------------------------------------------------
*"*"本地接口:
*"---------------------------------------------------------------------- CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'. CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
EXPORTING
i_precommit_ok = 'Y'. ENDFUNCTION.
"-----------------------------@斌将军-----------------------------

BAPI提交函数

"-----------------------------@斌将军-----------------------------
FUNCTION zps01_ps_precommit.
*"----------------------------------------------------------------------
*"*"本地接口:
*" EXPORTING
*" REFERENCE(E_RETURN) TYPE BAPIRETURN
*"---------------------------------------------------------------------- DATA:gt_return TYPE TABLE OF bapiret2,
gs_return TYPE bapiret2.
DATA:lv_check TYPE char1,
lv_message TYPE char200. CALL FUNCTION 'BAPI_PS_PRECOMMIT'
TABLES
et_return = gt_return. CLEAR:lv_check,lv_message.
lv_check = 'S'.
LOOP AT gt_return INTO gs_return WHERE type CA 'AEX'.
lv_check = 'E'.
lv_message = lv_message && gs_return-message.
CLEAR:gs_return.
ENDLOOP.
IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. CALL FUNCTION 'ZPS01_PS_FLAG'.
ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF. e_return-type = lv_check.
e_return-message = lv_message.
ENDFUNCTION.
"-----------------------------@斌将军-----------------------------

ABAP BAPI 复制标准项目模板实现项目立项的更多相关文章

  1. VS2019 自定义项目模板

    前言: 使用"宇宙最强IDE"开发项目时,都需要根据不同情况选择一个项目模板,来满足开发需求:如下 VS为我们提供了基础的项目模板,但现有项目模板未包含基础功能如:日志输出.审计日 ...

  2. AIR32F103(三) Linux环境基于标准外设库的项目模板

    目录 AIR32F103(一) 合宙AIR32F103CBT6开发板上手报告 AIR32F103(二) Linux环境和LibOpenCM3项目模板 AIR32F103(三) Linux环境基于标准外 ...

  3. [Xcode使用 - 3] 复制Xcode5.1.1中的项目模板到Xcode6.1

         由于Xcode6中精简了许多的项目和文件模板,导致开发非常不方便,所以这里简单介绍了怎么复制旧版本Xcode中的模板到新的Xcode中      这里要复制的是项目模板Empty Appli ...

  4. Cookiecutter: 更好的项目模板工具:(3)高级用法

    本文中的Hook就是钩子,钩子就是Hook 使用生成前/生成后钩子脚本 你可以在项目生成之前和/或之后运行Python或Shell脚本. 像这样把它们放进Hook里: cookiecutter-som ...

  5. Cookiecutter: 更好的项目模板工具:(2)安装及基础使用

    安装 通过python包管理工具 命令行输入 $pip install cookiecutter 或者 # mac os经常会禁止用户全局安装python包 $pip install --user c ...

  6. Cookiecutter: 更好的项目模板工具:(1)简介及可用资源汇总

    原文档地址:https://cookiecutter.readthedocs.io/en/latest/ 本系列只介绍cookiecutter的基础使用,而且会删除与功能使用无关的部分.深度使用及了解 ...

  7. 分享我的CleanArchitecture for Razor Page项目模板

    这个项目是参考和整合了jasontaylordev/CleanArchitecture 和 blazorhero/CleanArchitecture 代码基础上,重构出来的新的项目,这两个项目都是非常 ...

  8. Vue.js——60分钟browserify项目模板快速入门

    概述 在之前的一系列vue.js文章,我们都是用传统模式引用vue.js以及其他的js文件的,这在开发时会产生一些问题. 首先,这限定了我们的开发模式是基于页面的,而不是基于组件的,组件的所有代码都直 ...

  9. vs创建项目模板和项模板

    原文地址:https://msdn.microsoft.com/zhcn/library/xkh1wxd8(v=vs.140).aspx 如何:创建项目模板 Visual Studio 2015   ...

随机推荐

  1. es篇-es基础

    点赞再看,养成习惯,微信搜索「小大白日志」关注这个搬砖人. 文章不定期同步公众号,还有各种一线大厂面试原题.我的学习系列笔记. es基础知识 es和solr一样,都是基于Lucene的全文检索数据库 ...

  2. Java随想1

      1If(条件){输出} Else{ } 2Switch确定范围 定值 Switch(i1){ Case 值: 输出 Break 3Do while循环 定值 Do{ 输出 运算 }while(范围 ...

  3. 解决PLSQL developer 乱码问题

    今天打开 PLSQL developer 登录数据库后,查看数据的时候,发现表里面的中文数据全部变成了 ???  这样的东西,  打开表看表的 中文描述信息 , 一样 显示问号. 什么鬼啊?  第一次 ...

  4. 手机USB共享网络是个啥

    智能手机一般都提供了USB共享网络的功能,将手机通过USB线与电脑连接,手机端开启『USB共享网络』,电脑就能通过手机上网. 手机端开启『USB共享网络』: 电脑端出现新的网络连接: 通过设备管理器看 ...

  5. java、selenium、图片滑块验证,底部附本地可测试代码

    准备 本地Chrome版本对应WebDriver驱动:http://chromedriver.storage.googleapis.com/index.html maven包 <!-- sele ...

  6. 没想到吧!这个可可爱爱的游戏居然是用 ECharts 实现的!

    摘要:echarts 是一个很强大的图表库,除了我们常见的图表功能,还可以自定义图形,这个功能让我们可以很简单地在画布上绘制一些非常规的图形,基于此,我们来玩一些花哨的:做一个 Flappy Bird ...

  7. AQS源码三视-JUC系列

    AQS源码三视-JUC系列 前两篇文章介绍了AQS的核心同步机制,使用CHL同步队列实现线程等待和唤醒,一个int值记录资源量.为上层各式各样的同步器实现画好了模版,像已经介绍到的ReentrantL ...

  8. Vulnhub-earth

    1.信息收集 1.1找到目标主机ip vulnhub靶场通用的技巧 这里我们靶场是nat模式的 所以肯定就是在我们自己设置的一个网段范围内,我这里nat本机的地址是10.1.1.1 所处的网段就是10 ...

  9. 讨论两种Redis中Token的存储方式

    摘要:本文讨论一个问题:存储token时,token与对应用户id谁来作为key? 问题起源问题起源于要给公司的后台管理系统添加权限管理,选用的是开源框架shiro,而原本系统上是采用token做了登 ...

  10. 重新认识 MSBuild - 1

    前言 很多人一谈到 MSBuild,脑子里就会出现 "XML"."只能用 VS 的属性框图形界面操作"."可定制性和扩展性差" 和 &quo ...