目录
服务主数据的创建和特性的维护... 1
一、 服务主数据相关TCOD:AC01 AC02 AC03. 2
二、 服务主数据前台创建过程... 2
三、 维护特性TCOD:CL01 CL02 CL03. 3
四、 服务主数据BAPI创建... 5
五、 服务主数据冻结和解冻... 6
六、 服务主数据创建修改和特性维护完整代码... 8
七、 服务主数据冻结解冻完整代码... 13
一、 服务主数据相关TCOD:AC01 AC02 AC03
二、 服务主数据前台创建过程
AC03进入,点击新建服务条目
填写相应必输项目:
点击保存,生成服务主数据
挂服务主数据分类信息
点击转到-分类
维护服务主数据分类信息
三、 维护特性TCOD:CL01 CL02 CL03
双击某行特性,查看其特现值
![服务主数据的创建和特性的维护BAPI(BAPI_SERVICE_CREATE、BAPI_OBJCL_CHANGE) 服务主数据的创建和特性的维护BAPI(BAPI_SERVICE_CREATE、BAPI_OBJCL_CHANGE)](https://i-blog.csdnimg.cn/blog_migrate/d0c6127e4892eeaaf6c0e630e211992f.jpeg)
创建过程(根据前台数据判断BAPI如何赋值)
![服务主数据的创建和特性的维护BAPI(BAPI_SERVICE_CREATE、BAPI_OBJCL_CHANGE) 服务主数据的创建和特性的维护BAPI(BAPI_SERVICE_CREATE、BAPI_OBJCL_CHANGE)](https://i-blog.csdnimg.cn/blog_migrate/2772c19f308d3b596ca4f612471c6053.jpeg)
![服务主数据的创建和特性的维护BAPI(BAPI_SERVICE_CREATE、BAPI_OBJCL_CHANGE) 服务主数据的创建和特性的维护BAPI(BAPI_SERVICE_CREATE、BAPI_OBJCL_CHANGE)](https://i-blog.csdnimg.cn/blog_migrate/64e86c5ecf131c574f0f7262c6ebce78.jpeg)
![服务主数据的创建和特性的维护BAPI(BAPI_SERVICE_CREATE、BAPI_OBJCL_CHANGE) 服务主数据的创建和特性的维护BAPI(BAPI_SERVICE_CREATE、BAPI_OBJCL_CHANGE)](https://i-blog.csdnimg.cn/blog_migrate/ee056a4be7d1e529e372329098d17426.jpeg)
"创建服务主数据BAPI
CALL FUNCTION 'BAPI_SERVICE_CREATE'
EXPORTING
im_service_data = lm_service_data
im_service_datax = lm_service_datax
TABLES
return = li_return[]
service_description = li_service_description[].
其中lm_service_data和lm_service_data内字段参考前台操作的必输项
"服务类别不能修改(可参考前台,点击修改时,查看哪些字段是可以修改的)
lm_service_datax-serv_cat = ''.
l_servicenumber = lw_fwzsj-asnum.
"修改服务主数据BAPI
CALL FUNCTION 'BAPI_SERVICE_CHANGE'
EXPORTING
servicenumber = l_servicenumber "作业编号
im_service_data = lm_service_data
im_service_datax = lm_service_datax
TABLES
return = li_return[]
service_description = li_service_description[].
"维护服务特性BAPI,不同类型特性值放在不同表中(创建,修改都可以使用此BAPI)
" BAPI_OBJCL_CHANGE 可以替代 BAPI_OBJCL_CREATE
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
objectkey = objectkeynew "作业编号
objecttable = 'ASMD'
classnum = classnumnew "类号,cl01创建的类号
classtype = '038'
TABLES
allocvaluesnumnew = li_allocvaluesnumnew "日期类型
allocvaluescharnew = li_allocvalueschar "char类型
allocvaluescurrnew = li_allocvaluescurrnew "金额类型
return = li_return.
五、 服务主数据冻结和解冻
"查找是否存在,如果存在是冻结状态还是解冻状态
SELECT SINGLE lvorm
FROM asmd
INTO l_lvorm
WHERE asnum = lw_input-asnum.
"解冻修改
im_service_data-del_ind = ''.
im_service_datax-del_ind = 'X'.
CALL FUNCTION 'BAPI_SERVICE_CHANGE'
EXPORTING
servicenumber = servicenumber
im_service_data = im_service_data
im_service_datax = im_service_datax
TABLES
return = return[]
service_description = i_service_description[].
"冻结
im_service_data-del_ind = 'X'.
im_service_datax-del_ind = 'X'.
CALL FUNCTION 'BAPI_SERVICE_CHANGE'
EXPORTING
servicenumber = servicenumber
im_service_data = im_service_data
im_service_datax = im_service_datax
TABLES
return = return[]
service_description = i_service_description[].
FUNCTION zmm00_fm_fwzsj_cj.
*"----------------------------------------------------------------------
*"*"局部接口:
*" TABLES
*" IT_FWZSJ STRUCTURE ZMM00T_001 OPTIONAL
*" ET_RETURN STRUCTURE Z00S_FWZSJ_RETURN OPTIONAL
*"----------------------------------------------------------------------
DATA:l_exist TYPE flag.
"服务主数据创建bapi所用
DATA: lm_service_data TYPE bapisrv_asmd,
lm_service_datax TYPE bapisrv_asmdx.
DATA li_return LIKE STANDARD TABLE OF bapiret2 WITH HEADER LINE.
DATA li_service_description LIKE STANDARD TABLE OF bapisrv_asmdt WITH HEADER LINE.
"特征值创建bapi所用
DATA: objectkeynew TYPE bapi1003_key-object,
classnumnew TYPE bapi1003_key-classnum,
li_allocvalueschar TYPE STANDARD TABLE OF bapi1003_alloc_values_char WITH HEADER LINE.
DATA: li_allocvaluesnumnew TYPE STANDARD TABLE OF bapi1003_alloc_values_num WITH HEADER LINE.
DATA: li_allocvaluescurrnew TYPE STANDARD TABLE OF bapi1003_alloc_values_curr WITH HEADER LINE.
DATA: lw_fwzsj LIKE zmm00t_001.
DATA: lw_return LIKE z00s_fwzsj_return.
DATA: l_servicenumber TYPE bapisrv_asmd-service .
"物料特性赋值
DEFINE mac_add_atwrt.
if &1 ne space.
li_allocvalueschar-value_char = &1. " 特性值
li_allocvalueschar-charact = &2. "特征编码
append li_allocvalueschar.
clear li_allocvalueschar.
endif.
END-OF-DEFINITION.
LOOP AT it_fwzsj INTO lw_fwzsj.
*"----------------------------------------------------------------------
*&服务主数据BAPI相关赋值
*"----------------------------------------------------------------------
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' "加前导零
EXPORTING
input = lw_fwzsj-asnum
IMPORTING
output = lw_fwzsj-asnum.
"判断是否已经存在
SELECT SINGLE asnum INTO lw_fwzsj-asnum
FROM asmd WHERE asnum = lw_fwzsj-asnum.
IF sy-subrc = 0.
l_exist = 'E'.
ELSE.
l_exist = space.
ENDIF.
CLEAR lm_service_data.
CLEAR lm_service_datax.
CLEAR li_service_description[].
lm_service_data-service = lw_fwzsj-asnum. "作业编号 = 物料号
lm_service_datax-service = lw_fwzsj-asnum.
"类号= 大类编码+中类编码+小类编码;例如9003002
CONCATENATE lw_fwzsj-classb lw_fwzsj-classm lw_fwzsj-classs INTO lw_fwzsj-class.
"物料组=G+类号,例如G9001001。
CONCATENATE 'G' lw_fwzsj-classb lw_fwzsj-classm lw_fwzsj-classs INTO lw_fwzsj-matkl_srv.
lm_service_data-matl_group = lw_fwzsj-matkl_srv. "物料组
lm_service_datax-matl_group = text-x00.
"6. 服务类别=中类编码+小类编号后两位;例如:服务主数据对应的分类为:9003002,则服务类别为:0302。
IF lw_fwzsj-astyp IS INITIAL.
CONCATENATE lw_fwzsj-classm lw_fwzsj-classs+1(2) INTO lw_fwzsj-astyp.
ENDIF.
lm_service_data-serv_cat = lw_fwzsj-astyp. "服务类别
lm_service_datax-serv_cat = text-x00.
lm_service_data-base_uom = lw_fwzsj-meins. "基本计量单位
lm_service_datax-base_uom = text-x00.
lm_service_data-val_class = '9000'. "评价分类
lm_service_datax-val_class = text-x00.
li_service_description-language = 1.
IF lw_fwzsj-asktx IS INITIAL.
lw_fwzsj-asktx = lw_fwzsj-kschls. "服务类别描述=小类名称
ENDIF.
li_service_description-short_text = lw_fwzsj-asktx. "服务短文本
APPEND li_service_description.
*"----------------------------------------------------------------------
*&特性相关赋值
*"----------------------------------------------------------------------
"填充特征值和特征描述
CLEAR li_allocvalueschar.
CLEAR li_allocvalueschar[].
mac_add_atwrt:
lw_fwzsj-atwrt1 lw_fwzsj-atnam1 ,
lw_fwzsj-atwrt2 lw_fwzsj-atnam2 ,
lw_fwzsj-atwrt3 lw_fwzsj-atnam3 ,
lw_fwzsj-atwrt4 lw_fwzsj-atnam4 ,
lw_fwzsj-atwrt5 lw_fwzsj-atnam5 ,
lw_fwzsj-atwrt6 lw_fwzsj-atnam6 ,
lw_fwzsj-atwrt7 lw_fwzsj-atnam7 ,
lw_fwzsj-atwrt8 lw_fwzsj-atnam8 ,
lw_fwzsj-atwrt9 lw_fwzsj-atnam9 ,
lw_fwzsj-atwrt10 lw_fwzsj-atnam10 ,
lw_fwzsj-atwrt11 lw_fwzsj-atnam11 ,
lw_fwzsj-atwrt12 lw_fwzsj-atnam12 .
objectkeynew = lw_fwzsj-asnum."作业编号号
classnumnew = lw_fwzsj-class. " "类号=大类编码+中类编码+小类编码;例如9003002
*"----------------------------------------------------------------------
*&BAPI调用
*"----------------------------------------------------------------------
"如果不存在
IF l_exist = space.
CALL FUNCTION 'BAPI_SERVICE_CREATE'"维护服务主数据BAPI
EXPORTING
im_service_data = lm_service_data
im_service_datax = lm_service_datax
TABLES
return = li_return[]
service_description = li_service_description[].
LOOP AT li_return WHERE type = 'E'.
ENDLOOP.
IF sy-subrc = 0.
ENDIF.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
CLEAR li_return[].
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
objectkey = objectkeynew
objecttable = 'ASMD'
classnum = classnumnew
classtype = '038'
TABLES
allocvaluesnumnew = li_allocvaluesnumnew "日期类型
allocvaluescharnew = li_allocvalueschar "char类型
allocvaluescurrnew = li_allocvaluescurrnew "金额;类型,不同类型数据不同的表
return = li_return.
SORT li_return BY type DESCENDING.
LOOP AT li_return WHERE type = 'E'.
ENDLOOP.
IF sy-subrc = 0.
ENDIF.
"存在则修改
IF l_exist = 'E'.
lm_service_datax-serv_cat = ''. "服务类别不能修改
l_servicenumber = lw_fwzsj-asnum.
CALL FUNCTION 'BAPI_SERVICE_CHANGE'
EXPORTING
servicenumber = l_servicenumber
im_service_data = lm_service_data
im_service_datax = lm_service_datax
TABLES
return = li_return[]
service_description = li_service_description[].
LOOP AT li_return WHERE type = 'E'.
""""""
ENDLOOP.
IF sy-subrc = 0.
ENDIF.
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
objectkey = objectkeynew
objecttable = 'ASMD'
classnum = classnumnew
classtype = '038'
TABLES
allocvaluesnumnew = li_allocvaluesnumnew "日期类型
allocvaluescharnew = li_allocvalueschar "char类型
allocvaluescurrnew = li_allocvaluescurrnew "金额;类型,不同类型数据不同的表
return = li_return.
SORT li_return BY type DESCENDING.
LOOP AT li_return WHERE type = 'E'.
ENDLOOP.
IF sy-subrc = 0.
ENDIF.
ENDIF."IF l_exist = text-x00.
ENDLOOP.
ENDFUNCTION.
七、 服务主数据冻结解冻完整代码
FUNCTION zmm00_fmfwzt_xg.
*"----------------------------------------------------------------------
*"*"局部接口:
*" TABLES
*" IT_FWZSJ STRUCTURE Z00S_FWZSJ_XG OPTIONAL
*" ET_RETURN STRUCTURE Z00S_FWZSJ_RETURN OPTIONAL
*"----------------------------------------------------------------------
DATA:
servicenumber TYPE bapisrv_asmd-service,
im_service_data TYPE bapisrv_asmd,
im_service_datax TYPE bapisrv_asmdx.
DATA:
return LIKE TABLE OF bapiret2 WITH HEADER LINE,
i_service_description LIKE TABLE OF bapisrv_asmdt.
DATA: l_lvorm TYPE asmd-lvorm.
DATA: lw_input LIKE z00s_fwzsj_cj,
lw_return LIKE z00s_fwzsj_return.
LOOP AT it_fwzsj INTO lw_input.
"服务编码
servicenumber = lw_input-asnum.
"查找是否存在,如果存在是冻结状态还是解冻状态
SELECT SINGLE lvorm
FROM asmd
INTO l_lvorm
WHERE asnum = lw_input-asnum.
"不存在报错,提示服务主数据不存在
IF sy-subrc <> 0.
ENDIF.
" 存在,解冻.
IF lw_input-statu_id = '01' AND l_lvorm = 'X'.
im_service_data-del_ind = ''.
im_service_datax-del_ind = text-x00.
"解冻修改
CALL FUNCTION 'BAPI_SERVICE_CHANGE'
EXPORTING
servicenumber = servicenumber
im_service_data = im_service_data
im_service_datax = im_service_datax
TABLES
return = return[]
service_description = i_service_description[].
LOOP AT return WHERE type = text-e00.
ENDLOOP.
IF sy-subrc = 0.
ENDIF.
"冻结
IF lw_input-statu_id = '02' AND l_lvorm IS INITIAL.
im_service_data-del_ind = 'X'.
im_service_datax-del_ind = 'X'.
"冻结
CALL FUNCTION 'BAPI_SERVICE_CHANGE'
EXPORTING
servicenumber = servicenumber
im_service_data = im_service_data
im_service_datax = im_service_datax
TABLES
return = return[]
service_description = i_service_description[].
LOOP AT return WHERE type = 'E'.
ENDLOOP.
IF sy-subrc = 0.
ENDIF.
ENDLOOP.
ENDFUNCTION.