BAPI_ALM_ORDER_MAINTAIN – 创建维修工单
FUNCTION ZFPM_034.
*“----------------------------------------------------------------------
"“本地接口:
*” IMPORTING
*” VALUE(I_NOTIF_NO) TYPE QMNUM OPTIONAL
*" VALUE(I_EQUIPMENT) TYPE EQUNR OPTIONAL
*" VALUE(I_ZNO) TYPE CHAR20 OPTIONAL
*" VALUE(I_AUART) TYPE AUFART OPTIONAL
*" VALUE(I_STEXT) TYPE AUFTEXT OPTIONAL
*" VALUE(I_PREQ_NAME) TYPE AFNAM OPTIONAL
*" VALUE(I_SERV_TEXT) TYPE SH_TEXT1 OPTIONAL
*" VALUE(I_SERV_PRICE) TYPE PREIS OPTIONAL
*" VALUE(I_WERGW) TYPE WERGW OPTIONAL
*" VALUE(I_GEWRK) TYPE GEWRK OPTIONAL
*" EXPORTING
*" VALUE(E_ORDERID) TYPE AUFNR
*" VALUE(RTYPE) TYPE BAPI_MTYPE
*" VALUE(RTMSG) TYPE BAPI_MSG
*" TABLES
*" IT_MATERIAL STRUCTURE ZSPM_F016 OPTIONAL
*" IT_EQUIPMENT STRUCTURE ZSPM_F034 OPTIONAL
*"----------------------------------------------------------------------
本接口功能是根据传入的参数建立维修工单;
本接口支持带有通知单建立维修工单和不带通知单根据设备直接建立维修工单;
ZFMPARAVALSAVE1 ‘ZFPM_034’."接口函数模块名称
ZFMPARAVALSAVE2 ‘B’.
BAPI用参数
DATA:
LT_METHODS TYPE STANDARD TABLE OF BAPI_ALM_ORDER_METHOD,
LS_METHODS LIKE LINE OF LT_METHODS,
LT_HEADER TYPE STANDARD TABLE OF BAPI_ALM_ORDER_HEADERS_I,
LS_HEADER LIKE LINE OF LT_HEADER,
LT_HEADER_UP TYPE STANDARD TABLE OF BAPI_ALM_ORDER_HEADERS_UP,
LS_HEADER_UP LIKE LINE OF LT_HEADER_UP,
LT_OPERATION TYPE STANDARD TABLE OF BAPI_ALM_ORDER_OPERATION,
LS_OPERATION LIKE LINE OF LT_OPERATION,
LT_OPERATION_UP TYPE STANDARD TABLE OF BAPI_ALM_ORDER_OPERATION_UP,
LS_OPERATION_UP LIKE LINE OF LT_OPERATION_UP,
LT_COMPONENT TYPE STANDARD TABLE OF BAPI_ALM_ORDER_COMPONENT,
LS_COMPONENT LIKE LINE OF LT_COMPONENT,
LT_COMPONENT_UP TYPE STANDARD TABLE OF BAPI_ALM_ORDER_COMPONENT_UP,
LS_COMPONENT_UP LIKE LINE OF LT_COMPONENT_UP,
LT_SERVICELINES TYPE STANDARD TABLE OF BAPI_ALM_SRV_SERVICE_LINE,
LS_SERVICELINES LIKE LINE OF LT_SERVICELINES,
LT_SERVICELINES_UP TYPE STANDARD TABLE OF BAPI_ALM_SRV_SERVICE_LINE_UP,
LS_SERVICELINES_UP LIKE LINE OF LT_SERVICELINES_UP,
LT_OBJECTLIST TYPE STANDARD TABLE OF BAPI_ALM_ORDER_OBJECTLIST,
LS_OBJECTLIST TYPE BAPI_ALM_ORDER_OBJECTLIST,
LT_RETURN TYPE STANDARD TABLE OF BAPIRET2,
LS_RETURN LIKE LINE OF LT_RETURN,
LT_ET_NUMBERS TYPE STANDARD TABLE OF BAPI_ALM_NUMBERS,
LS_ET_NUMBERS LIKE LINE OF LT_ET_NUMBERS.
DATA:
LS_MATERIAL TYPE ZSPM_F016,
LV_MESSAGE TYPE BAPI_MSG,
LV_MESSAGE_ALL TYPE BAPI_MSG.
下一个工序
DATA:
LV_OBJECTKEY TYPE BAPI_ALM_ORDER_METHOD-OBJECTKEY,
LV_ACTIVITY TYPE BAPI_ALM_ORDER_COMPONENT-ACTIVITY,
LV_REFNUMBER TYPE BAPI_ALM_ORDER_METHOD-REFNUMBER,
LV_REFNUMBER2 TYPE BAPI_ALM_ORDER_METHOD-REFNUMBER.
LV_OBJECTKEY = ‘%00000000001’ && ‘0010’.
LV_ACTIVITY = ‘0010’.
LV_REFNUMBER = 1.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
EXPORTING
INPUT = I_EQUIPMENT
IMPORTING
OUTPUT = I_EQUIPMENT.
----- 判断传入的通知单号是否为空 -------------------------------------------------------------------------------------------
IF I_NOTIF_NO IS INITIAL.
IF I_EQUIPMENT IS INITIAL.
IF I_WERGW IS INITIAL OR I_GEWRK IS INITIAL .
RTYPE = 'E'.
RTMSG = '设备号为空时,工厂,维护中心不能为空!'.
ZFMPARAVALSAVE2 'R'.
RETURN.
ENDIF.
ELSE.
判断设备号是否存在
SELECT SINGLE EQUNR
INTO @DATA(LV_EQUNR)
FROM EQUI
WHERE EQUNR = @I_EQUIPMENT.
IF SY-SUBRC <> 0.
RTYPE = 'E'.
RTMSG = '当前设备' && I_EQUIPMENT && '在系统中不存在!'.
ZFMPARAVALSAVE2 'R'.
RETURN.
ENDIF.
ENDIF.
ELSE.
取设备号
IF I_EQUIPMENT IS INITIAL.
SELECT SINGLE EQUNR
INTO I_EQUIPMENT
FROM QMIH
WHERE QMNUM = I_NOTIF_NO.
ENDIF.
ENDIF.
IF I_STEXT IS INITIAL .
RTYPE = ‘E’.
RTMSG = ‘工单描述不能为空’ . " && I_AUART && '在系统中不存在!
ZFMPARAVALSAVE2 ‘R’.
ENDIF.
IF I_AUART IS INITIAL .
RTYPE = ‘E’.
RTMSG = ‘工单类型不能为空’ . " && I_AUART && '在系统中不存在!
ZFMPARAVALSAVE2 ‘R’.
ENDIF .
----- 创建维修工单:①无通知单号/②有通知单号 --------------------------------------------------------------------------------
无通知单号:直接对设备创建维修工单
IF I_NOTIF_NO IS INITIAL.
CLEAR:LS_METHODS.
LS_METHODS-REFNUMBER = 1.
LS_METHODS-OBJECTTYPE = ‘HEADER’. "抬头固定为HEADER
LS_METHODS-METHOD = ‘CREATE’.
LS_METHODS-OBJECTKEY = ‘%00000000001’. "临时工单号为%00000000001
APPEND LS_METHODS TO LT_METHODS.
有通知单号:参考通知单创建工单
ELSE.
CLEAR:LS_METHODS.
LS_METHODS-REFNUMBER = 1.
LS_METHODS-OBJECTTYPE = ‘HEADER’. "抬头固定为HEADER
LS_METHODS-METHOD = ‘CREATETONOTIF’.
LS_METHODS-OBJECTKEY = ‘%00000000001’ && I_NOTIF_NO."临时工单号+通知单号(内码).
APPEND LS_METHODS TO LT_METHODS.
ENDIF.
根据设备种类判断工单类型
DATA:LV_ORDER_TYPE TYPE AUFART. "工单类型
SELECT SINGLE EQTYP
INTO @DATA(LV_EQTYP)
FROM EQUI
WHERE EQUNR = @I_EQUIPMENT.
IF LV_EQTYP EQ ‘A’.
LV_ORDER_TYPE = ‘LY01’.
ELSEIF LV_EQTYP EQ ‘B’.
LV_ORDER_TYPE = ‘LY05’.
ELSEIF LV_EQTYP EQ ‘C’.
LV_ORDER_TYPE = ‘LY06’.
ENDIF.
LV_ORDER_TYPE = I_AUART .
CLEAR:LS_HEADER,LS_HEADER_UP.
LS_HEADER-ORDER_TYPE = LV_ORDER_TYPE. "工单类型
LS_HEADER-EQUIPMENT = I_EQUIPMENT. "设备编码
LS_HEADER-SHORT_TEXT = I_STEXT. "工单描述
LS_HEADER-PLANPLANT = I_WERGW . " 工厂 PLANPLANT 1 类型 IWERK 计划工厂
LS_HEADER-PLANT = I_WERGW . " 工厂 PLANPLANT 1 类型 IWERK
LS_HEADER-MN_WK_CTR = I_GEWRK . " 维护任务的工作中心
APPEND LS_HEADER TO LT_HEADER.
更新组件物料
IF IT_MATERIAL[] IS NOT INITIAL.
工序
CLEAR:LS_METHODS.
LS_METHODS-REFNUMBER = 1.
LS_METHODS-OBJECTTYPE = ‘OPERATION’. "工序固定为OPERATION
LS_METHODS-METHOD = ‘CREATE’.
LS_METHODS-OBJECTKEY = ‘%00000000001’. "临时工单号为%00000000001
APPEND LS_METHODS TO LT_METHODS.
CLEAR:LS_OPERATION,LS_OPERATION_UP.
LS_OPERATION-ACTIVITY = ‘0010’. "工序号,首个工序默认为0010
LS_OPERATION-CONTROL_KEY = ‘PM01’.
LS_OPERATION-DESCRIPTION = I_STEXT && ‘:内部处理’.
LS_OPERATION_UP-ACTIVITY = ‘X’.
LS_OPERATION_UP-CONTROL_KEY = ‘X’.
LS_OPERATION_UP-DESCRIPTION = ‘X’.
APPEND LS_OPERATION TO LT_OPERATION.
APPEND LS_OPERATION_UP TO LT_OPERATION_UP.
CLEAR LS_MATERIAL.
LOOP AT IT_MATERIAL[] INTO LS_MATERIAL.
CLEAR:LS_COMPONENT,LS_COMPONENT_UP.
物料组件的Methods
CLEAR:LS_METHODS.
LS_METHODS-REFNUMBER = SY-TABIX.
LS_METHODS-OBJECTTYPE = ‘COMPONENT’.
LS_METHODS-METHOD = ‘CREATE’.
LS_METHODS-OBJECTKEY = ‘%00000000001’ && ‘0010’.
APPEND LS_METHODS TO LT_METHODS.
IF LS_MATERIAL-MATERIAL IS INITIAL."N-非库存项目
单位:外部-->内部
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
INPUT = LS_MATERIAL-QUANTITY_UNIT
LANGUAGE = SY-LANGU
IMPORTING
OUTPUT = LS_MATERIAL-QUANTITY_UNIT
EXCEPTIONS
UNIT_NOT_FOUND = 1
OTHERS = 2.
LS_COMPONENT-ACTIVITY = '0010'.
LS_COMPONENT-MATL_DESC = LS_MATERIAL-MATL_DESC. "物料描述
LS_COMPONENT-REQUIREMENT_QUANTITY_UNIT = LS_MATERIAL-QUANTITY_UNIT."单位
LS_COMPONENT-ITEM_CAT = LS_MATERIAL-ITEM_CAT . "'N'. "行项目类别,N-非库存项目
LS_COMPONENT-PREQ_NAME = I_PREQ_NAME. "采购申请人工号,对接传入钉钉审批的采购申请的功能
LS_COMPONENT-MRP_RELEVANT = '2'. "下达后才生采购申请
LS_COMPONENT-REQUIREMENT_QUANTITY = LS_MATERIAL-QUANTITY. "输入数量
LS_COMPONENT_UP-MATL_DESC = 'X'.
LS_COMPONENT_UP-REQUIREMENT_QUANTITY_UNIT = 'X'.
LS_COMPONENT_UP-ITEM_CAT = 'X'.
LS_COMPONENT_UP-PREQ_NAME = 'X'.
LS_COMPONENT_UP-MRP_RELEVANT = 'X'.
LS_COMPONENT_UP-REQUIREMENT_QUANTITY = 'X'.
APPEND LS_COMPONENT TO LT_COMPONENT.
APPEND LS_COMPONENT_UP TO LT_COMPONENT_UP.
ELSE. "L-库存项目
LS_COMPONENT-ACTIVITY = '0010'.
LS_COMPONENT-MATERIAL_LONG = LS_MATERIAL-MATERIAL. "物料编号
LS_COMPONENT-STGE_LOC = LS_MATERIAL-STGE_LOC. "库存地点
LS_COMPONENT-BATCH = LS_MATERIAL-BATCH. "批次编号
LS_COMPONENT-ITEM_CAT = LS_MATERIAL-ITEM_CAT . "'L'. "行项目类别,默认为 L-库存物资
IF LS_MATERIAL-ITEM_CAT = 'N'.
LS_COMPONENT-PREQ_NAME = I_PREQ_NAME.
LS_COMPONENT-MRP_RELEVANT = '2'. "下达后才生采购申请
ENDIF.
LS_COMPONENT-REQUIREMENT_QUANTITY = LS_MATERIAL-QUANTITY. "输入数量
LS_COMPONENT_UP-MATERIAL_LONG = 'X'.
LS_COMPONENT_UP-STGE_LOC = 'X'.
LS_COMPONENT_UP-BATCH = 'X'.
LS_COMPONENT_UP-ITEM_CAT = 'X'.
LS_COMPONENT_UP-REQUIREMENT_QUANTITY = 'X'.
APPEND LS_COMPONENT TO LT_COMPONENT.
APPEND LS_COMPONENT_UP TO LT_COMPONENT_UP.
ENDIF.
CLEAR:LS_MATERIAL.
ENDLOOP.
下一个工序
LV_OBJECTKEY = ‘%00000000001’ && ‘0020’.
LV_ACTIVITY = ‘0020’.
LV_REFNUMBER = 2.
ENDIF.
新增委外服务
IF I_SERV_TEXT IS NOT INITIAL.
CLEAR:LS_METHODS.
LS_METHODS-REFNUMBER = LV_REFNUMBER.
LS_METHODS-OBJECTTYPE = ‘OPERATION’.
LS_METHODS-METHOD = ‘CREATE’.
LS_METHODS-OBJECTKEY = ‘%00000000001’.
APPEND LS_METHODS TO LT_METHODS.
CLEAR:LS_OPERATION,LS_OPERATION_UP.
LS_OPERATION-ACTIVITY = LV_ACTIVITY. "工序号,首个工序默认为0010
LS_OPERATION-CONTROL_KEY = ‘PM03’.
LS_OPERATION-DESCRIPTION = I_STEXT && ‘:委外处理’.
LS_OPERATION-PREQ_NAME = I_PREQ_NAME. "采购申请人工号,对接传入钉钉审批的采购申请的功能
LS_OPERATION_UP-PREQ_NAME = ‘X’.
LS_OPERATION_UP-ACTIVITY = ‘X’.
LS_OPERATION_UP-CONTROL_KEY = ‘X’.
LS_OPERATION_UP-DESCRIPTION = ‘X’.
APPEND LS_OPERATION TO LT_OPERATION.
APPEND LS_OPERATION_UP TO LT_OPERATION_UP.
CLEAR:LS_METHODS.
LS_METHODS-REFNUMBER = 1.
LS_METHODS-OBJECTTYPE = ‘SERVICELINE’.
LS_METHODS-METHOD = ‘CREATE’.
LS_METHODS-OBJECTKEY = LV_OBJECTKEY.
APPEND LS_METHODS TO LT_METHODS.
CLEAR:LS_SERVICELINES,LS_SERVICELINES_UP.
LS_SERVICELINES-ACTIVITY = LV_ACTIVITY. " 对应的工序
LS_SERVICELINES-OUTLINE = 1. " 条目
LS_SERVICELINES-SRV_LINE = 10. " 作业编号
LS_SERVICELINES-SHORT_TEXT = I_STEXT. " 委外服务说明.
LS_SERVICELINES-GROSS_PRICE = I_SERV_PRICE. " 预估金额
LS_SERVICELINES-QUANTITY = 1. " 数量,默认为1
LS_SERVICELINES-UOM = ‘EA’. " 单位,默认为EA
LS_SERVICELINES-GL_ACCOUNT = ‘8012000000’." 总账科目,默认为8012000000-维修保养费
LS_SERVICELINES_UP-ACTIVITY = ‘X’.
LS_SERVICELINES_UP-OUTLINE = ‘X’.
LS_SERVICELINES_UP-SRV_LINE = ‘X’.
LS_SERVICELINES_UP-SHORT_TEXT = ‘X’.
LS_SERVICELINES_UP-QUANTITY = ‘X’.
LS_SERVICELINES_UP-UOM = ‘X’.
LS_SERVICELINES_UP-GL_ACCOUNT = ‘X’.
APPEND LS_SERVICELINES TO LT_SERVICELINES.
APPEND LS_SERVICELINES_UP TO LT_SERVICELINES_UP.
ENDIF.
如果既没有内部工序又没有外部工序
IF LT_OPERATION IS INITIAL.
工序
CLEAR:LS_METHODS.
LS_METHODS-REFNUMBER = 1.
LS_METHODS-OBJECTTYPE = ‘OPERATION’. "工序固定为OPERATION
LS_METHODS-METHOD = ‘CREATE’.
LS_METHODS-OBJECTKEY = ‘%00000000001’. "临时工单号为%00000000001
APPEND LS_METHODS TO LT_METHODS.
CLEAR:LS_OPERATION,LS_OPERATION_UP.
LS_OPERATION-ACTIVITY = ‘0010’. "工序号,首个工序默认为0010
LS_OPERATION-CONTROL_KEY = ‘PM01’.
LS_OPERATION-DESCRIPTION = I_STEXT.
LS_OPERATION-PREQ_NAME = I_PREQ_NAME.
LS_OPERATION_UP-ACTIVITY = ‘X’ .
LS_OPERATION_UP-CONTROL_KEY = ‘X’ .
LS_OPERATION_UP-DESCRIPTION = ‘X’ .
LS_OPERATION_UP-PREQ_NAME = ‘X’ .
APPEND LS_OPERATION TO LT_OPERATION.
APPEND LS_OPERATION_UP TO LT_OPERATION_UP.
ENDIF.
**** 对象清单****
IF IT_EQUIPMENT[] IS NOT INITIAL .
CLEAR :LV_REFNUMBER2 .
LOOP AT IT_EQUIPMENT INTO DATA(LS_EQUIPMENT) .
CLEAR:LS_METHODS.
LV_REFNUMBER2 = LV_REFNUMBER2 + 1 .
LS_METHODS-REFNUMBER = LV_REFNUMBER2 .
LS_METHODS-OBJECTTYPE = 'OBJECTLIST'. "抬头固定为HEADER
LS_METHODS-METHOD = 'CREATE'.
LS_METHODS-OBJECTKEY = '%00000000001'. "临时工单号为%00000000001
APPEND LS_METHODS TO LT_METHODS.
LS_OBJECTLIST-EQUIPMENT = LS_EQUIPMENT-EQUNR .
LS_OBJECTLIST-EQUIPMENT = |{ LS_OBJECTLIST-EQUIPMENT } | .
APPEND LS_OBJECTLIST TO LT_OBJECTLIST .
CLEAR LS_OBJECTLIST .
ENDLOOP.
ENDIF.
----- 工单保存 --------------------------------------------------------------------------------------------------------------
CLEAR:LS_METHODS.
LS_METHODS-METHOD = ‘SAVE’.
APPEND LS_METHODS TO LT_METHODS.
**----- 工单下达 --------------------------------------------------------------------------------------------------------------
*** CLEAR:LS_METHODS.
*** LS_METHODS-REFNUMBER = 1.
*** LS_METHODS-OBJECTTYPE = ‘HEADER’.
*** LS_METHODS-METHOD = ‘RELEASE’.
*** LS_METHODS-OBJECTKEY = ‘%00000000001’.
*** APPEND LS_METHODS TO LT_METHODS.
----- BAPI ------------------------------------------------------------------------------------------------------------------
CALL FUNCTION ‘BAPI_ALM_ORDER_MAINTAIN’
EXPORTING
IV_MMSRV_EXTERNAL_MAINTENACE =
TABLES
IT_METHODS = LT_METHODS
IT_HEADER = LT_HEADER
IT_HEADER_UP = LT_HEADER_UP
IT_OPERATION = LT_OPERATION
IT_OPERATION_UP = LT_OPERATION_UP
IT_COMPONENT = LT_COMPONENT
IT_COMPONENT_UP = LT_COMPONENT_UP
IT_SERVICELINES = LT_SERVICELINES
IT_SERVICELINES_UP = LT_SERVICELINES_UP
IT_OBJECTLIST = LT_OBJECTLIST
RETURN = LT_RETURN
ET_NUMBERS = LT_ET_NUMBERS.
根据BAPI执行结果,返回结果处理
CLEAR:LV_MESSAGE,LV_MESSAGE_ALL.
LOOP AT LT_RETURN INTO LS_RETURN WHERE TYPE CA ‘EA’.
CALL FUNCTION ‘MESSAGE_TEXT_BUILD’
EXPORTING
MSGID = LS_RETURN-ID
MSGNR = LS_RETURN-NUMBER
MSGV1 = LS_RETURN-MESSAGE_V1
MSGV2 = LS_RETURN-MESSAGE_V2
MSGV3 = LS_RETURN-MESSAGE_V3
MSGV4 = LS_RETURN-MESSAGE_V4
IMPORTING
MESSAGE_TEXT_OUTPUT = LV_MESSAGE.
IF LV_MESSAGE_ALL IS INITIAL.
LV_MESSAGE_ALL = LV_MESSAGE.
ELSE.
CONCATENATE LV_MESSAGE ‘/’ LV_MESSAGE_ALL INTO LV_MESSAGE_ALL."拼接输出的失败消息
ENDIF.
CLEAR:LS_RETURN.
ENDLOOP.
IF SY-SUBRC = 0.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.
RTYPE = ‘E’.
RTMSG = LV_MESSAGE_ALL.
ZFMPARAVALSAVE2 ‘R’.
ELSE.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
WAIT = ‘X’.
READ TABLE LT_ET_NUMBERS INTO LS_ET_NUMBERS INDEX 1.
E_ORDERID = LS_ET_NUMBERS-AUFNR_NEW."工单号
RTYPE = ‘S’.
RTMSG = ‘工单:’ && E_ORDERID && ‘创建成功!’."RTMSG = ‘传输成功’.
ZFMPARAVALSAVE2 ‘R’.
ENDIF.
ENDFUNCTION.