文章目录
显示
? 优质资源分享 ?
学习路线指引(点击解锁) | 知识定位 | 人群定位 |
---|---|---|
? Python实战微信订餐小程序 ? | 进阶级 | 本课程是python flask+微信小程序的完美结合,从项目搭建到腾讯云部署上线,打造一个全栈订餐系统。 |
?Python量化交易实战? | 入门级 | 手把手带你打造一个易扩展、更安全、效率更高的量化交易系统 |
一、复制标准项目模板实现项目立项
因为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,点击作业
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-SwBLEWQj-1657732734873)(https://img2022.cnblogs.com/blog/1225252/202207/1225252-20220713164401734-1870774438.png)]
创建作业,分配给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.
"-----------------------------@斌将军-----------------------------
转载请注明:xuhss » ABAP BAPI 复制标准项目模板实现项目立项