SAP维修工单创建的函数

Posted SAP菜鸡

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SAP维修工单创建的函数相关的知识,希望对你有一定的参考价值。

网上查阅相关设备维修工单的函数时发现资料甚少,所以介绍下维修工单创建的函数BAPI_ALM_ORDER_MAINTAIN以及简单的创建方法和注意点。

函数本身结构并不复杂,基本我们需要创建的部分包括抬头、工序(服务、组件)等。

函数与创建工单不同的地方在于其传入表it_methods,这里面填写创建工单的各个步骤,在创建工单时下面三个方法必不可少:
  " Header
  ls_methods-refnumber    .
  ls_methods-objecttype   ‘HEADER‘ .
  ls_methods-objectkey    ‘%00000000001‘ .
  ls_methods-method       ‘CREATE‘ .
  APPEND ls_methods TO lt_methods .
  CLEAR ls_methods .
  " Operation
  ls_methods-refnumber    1.
  ls_methods-objecttype   ‘OPERATION‘ .
  ls_methods-objectkey    ‘%00000000001‘ .
  ls_methods-method       ‘CREATE‘.
  APPEND ls_methods TO lt_methods .
  CLEAR ls_methods .

  " Save
  ls_methods-method       ‘SAVE‘ .
  APPEND ls_methods TO lt_methods .
  CLEAR ls_methods .

对于不同的对象有不同的方法与之对应来实现创建更改删除等动作,之后按项目需要将抬头、工序等信息填写完整,其中服务与组件是和工序相关的,要保证活动编号一致才能正确的分配至工序。

 附上示例:

DATA:
    lt_return_o        TYPE STANDARD TABLE OF bapiret2,
    ls_return_o        TYPE bapiret2,
    lt_numbers         TYPE STANDARD TABLE OF bapi_alm_numbers,
    ls_numbers         TYPE bapi_alm_numbers,
    lt_methods         TYPE STANDARD TABLE OF bapi_alm_order_method,
    ls_methods         TYPE bapi_alm_order_method,
    lt_header_i        TYPE STANDARD TABLE OF bapi_alm_order_headers_i,
    ls_header_i        TYPE bapi_alm_order_headers_i,
    lt_header_up       TYPE STANDARD TABLE OF bapi_alm_order_headers_up,
    ls_header_up       TYPE bapi_alm_order_headers_up,
    lt_operation_i     TYPE STANDARD TABLE OF bapi_alm_order_operation,
    ls_operation_i     TYPE bapi_alm_order_operation,
    lt_operation_up    TYPE STANDARD TABLE OF bapi_alm_order_operation_up,
    ls_operation_up    TYPE bapi_alm_order_operation_up,
    lt_component_i     TYPE STANDARD TABLE OF bapi_alm_order_component,
    ls_component_i     TYPE bapi_alm_order_component,
    lt_component_up    TYPE STANDARD TABLE OF bapi_alm_order_component_up,
    ls_component_up    TYPE bapi_alm_order_component_up,
    lt_servicelines    TYPE STANDARD TABLE OF bapi_alm_srv_service_line,
    ls_servicelines    TYPE bapi_alm_srv_service_line,
    lt_servicelines_up TYPE STANDARD TABLE OF bapi_alm_srv_service_line_up,
    ls_servicelines_up TYPE bapi_alm_srv_service_line_up.

" Header ls_methods-refnumber = 1 . ls_methods-objecttype = HEADER . ls_methods-objectkey = %00000000001 . ls_methods-method = CREATE . APPEND ls_methods TO lt_methods . CLEAR ls_methods . " Operation ls_methods-refnumber = 1. ls_methods-objecttype = OPERATION . ls_methods-objectkey = %00000000001 . ls_methods-method = CREATE. APPEND ls_methods TO lt_methods . CLEAR ls_methods . LOOP AT lt_component INTO ls_component. " Operation ls_methods-refnumber = sy-tabix. ls_methods-objecttype = COMPONENT . ls_methods-objectkey = %000000000010010 . ls_methods-method = CREATE. APPEND ls_methods TO lt_methods . CLEAR ls_methods . ENDLOOP. IF ls_header-tbtwr IS NOT INITIAL. " Servicelines ls_methods-refnumber = 1 . ls_methods-objecttype = SERVICELINE . ls_methods-objectkey = %000000000010010 . ls_methods-method = CREATE . APPEND ls_methods TO lt_methods . CLEAR ls_methods . ENDIF. " Save ls_methods-method = SAVE . APPEND ls_methods TO lt_methods . CLEAR ls_methods . CLEAR:lt_header_i,ls_header_i,lt_header_up,ls_header_up. ls_header_i-orderid = %00000000001. " 订单号 ls_header_i-order_type = *. " 订单类型 ls_header_i-planplant = *. " 维护计划工厂 ls_header_i-mn_wk_ctr = *. " 维护任务的工作中心 SELECT * FROM crhd UP TO 1 ROWS INTO ls_crhd WHERE arbpl = *.ENDSELECT. IF sy-subrc = 0. ls_header_i-plant = ls_crhd-werks. " 与工作中心职责相关联的工厂 ENDIF. ls_header_i-equipment = *. " 设备号 ls_header_i-plangroup = *. " 计划员组 ls_header_i-short_text = *. " 描述 APPEND ls_header_i TO lt_header_i. ls_header_up-orderid = %00000000001. ls_header_up-mn_wk_ctr = X. ls_header_up-plant = X. ls_header_up-equipment = X. ls_header_up-plangroup = X. ls_header_up-short_text = X. APPEND ls_header_up TO lt_header_up. ls_operation_i-activity = 0010. " 活动编号 IF ls_header-tbtwr IS NOT INITIAL. ls_operation_i-control_key = *. " 控制码 ELSE. ls_operation_i-control_key = *. " 控制码 ENDIF. ls_operation_i-description = *. " 工序短文本 ls_operation_i-plant = *. " 工厂 ls_operation_i-work_cntr = *. " 工作中心 ls_operation_i-matl_group = *. " 物料组 ls_operation_i-pur_group = *. " 采购组 ls_operation_i-purch_org = *. " 采购组织 APPEND ls_operation_i TO lt_operation_i. CLEAR ls_operation_i. ls_operation_up-activity = X. ls_operation_up-control_key = X. ls_operation_up-description = X. ls_operation_up-plant = X. ls_operation_up-work_cntr = X. ls_operation_up-matl_group = X. ls_operation_up-pur_group = X. ls_operation_up-purch_org = X. APPEND ls_operation_up TO lt_operation_up. CLEAR ls_operation_up. IF ls_header-tbtwr IS NOT INITIAL. CLEAR:lt_servicelines,ls_servicelines,lt_servicelines_up,ls_servicelines_up. ls_servicelines-activity = 0010. " 活动编号 ls_servicelines-srv_line = 0000000010. " 行号 ls_servicelines-short_text = *.         " 短文本 ls_servicelines-quantity = *. " 数量带标记 ls_servicelines-uom = *. " 基本计量单位 ls_servicelines-gross_price = *.            " 总价 ls_servicelines-net_price = *.          " 净价 APPEND ls_servicelines TO lt_servicelines. ls_servicelines_up-activity = 0010. ls_servicelines_up-srv_line = 0000000010. ls_servicelines_up-short_text = X. ls_servicelines_up-quantity = X. ls_servicelines_up-uom = X. ls_servicelines_up-gross_price = X. ls_servicelines_up-net_price = X. APPEND ls_servicelines_up TO lt_servicelines_up. ENDIF. CLEAR:lt_component_i,ls_component_i,lt_component_up,ls_component_up. LOOP AT lt_component INTO ls_component. ls_component_i-item_number = *. " BOM 项目号 ls_component_i-item_text1 = *.            " 描述 ls_component_i-plant = *.           " 工厂 ls_component_i-requirement_quantity = *.        " 需求数量 ls_component_i-requirement_quantity_unit = *.         " 单位 ls_component_i-pur_group = *.          " 采购组 ls_component_i-purch_org = *.     " 采购组织 ls_component_i-matl_group = *.      " 物料组 ls_component_i-item_cat = *. " 项目类别 APPEND ls_component_i TO lt_component_i. CLEAR ls_component_i. ls_component_up-item_number = X. ls_component_up-item_text1 = X. ls_component_up-plant = X. ls_component_up-requirement_quantity = X. ls_component_up-requirement_quantity_unit = X. ls_component_up-pur_group = X. ls_component_up-purch_org = X. ls_component_up-matl_group = X. ls_component_up-item_cat = X. APPEND ls_component_up TO lt_component_up. CLEAR ls_component_up. ENDLOOP. * 创建维修工单 CALL FUNCTION BAPI_ALM_ORDER_MAINTAIN TABLES it_methods = lt_methods it_header = lt_header_i it_header_up = lt_header_up it_operation = lt_operation_i it_operation_up = lt_operation_up it_component = lt_component_i it_component_up = lt_component_up return = lt_return_o et_numbers = lt_numbers it_servicelines = lt_servicelines it_servicelines_up = lt_servicelines_up. READ TABLE lt_return_o TRANSPORTING NO FIELDS WITH KEY type = E. IF sy-subrc = 0. CALL FUNCTION BAPI_TRANSACTION_ROLLBACK.ELSE. CALL FUNCTION BAPI_TRANSACTION_COMMIT EXPORTING wait = X.ENDIF.

 

以上是关于SAP维修工单创建的函数的主要内容,如果未能解决你的问题,请参考以下文章

SAP HanaXFILE:SAP Hana CDS 开发简介

SAP中转储单和采购订单的区别是啥?

SAP BAPI创建交货单拆单原因调查

SAP BAPI创建交货单拆单原因调查

SAP BAPI创建交货单拆单原因调查

sap冲销销售订单后如何生成新的销售单