[BAPI]如何修改工单状态-BAPI_ALM_ORDER_MAINTAIN详解编程语言

1,BAPI简介

可以通过调用BAPI BAPI_ALM_ORDER_MAINTAI来更改工单的状态,具体使用到的参数是IT_METHODS。

[BAPI]如何修改工单状态-BAPI_ALM_ORDER_MAINTAIN详解编程语言

IT_METHODS的定义如下:

[BAPI]如何修改工单状态-BAPI_ALM_ORDER_MAINTAIN详解编程语言

各个字段含义如下:

REFNUMBER:是objecttype参数中填入的相关对象对应的内表行数,
OBJECTTYPE:对象类型,类型如下:

  • HEADER Order header
  • PARTNER Partner data
  • USERSTATUS User status
  • OPERATION Operation data
  • RELATION Relationships
  • COMPONENT Component
  • TEXT Long texts
  • SRULE Settlement rule
  • OBJECTLIST Object list
  • OLISTRELATION Object list link
  • TASKLIST General maintenance task list
  • PRT Production resources/tools
  • SERVICEOUTLINE Service package outline
  • SERVICELINE Service package service line
  • SERVICELIMIT Service package limit
  • SERVICECONTRACTLIMIT Service package contract limit
  • ESTIMATEDCOST Estimated costs per value category
  • (empty) General BAPI functions (Save)

METHOD:方法,可以实现创建、修改、删除、保存等功能以及工单的状态-lock、unlock、TECHNICALCOMPLETE等,具体代码如下:

  • CREATE :Create objects
  • CREATETONOTIF: Create with reference to a notification
  • CHANGE : Change objects
  • DELETE :Delete objects
  • RELEASE : Release
  • ATPCHECK :Availability check
  • CALCULATE : Calculate
  • SCHEDULE :Schedule
  • DELETEDSEX : Delete the status for external scheduling at operation level
  • ADD :Add (only possible for object TASKLIST)
  • SAVE : Save all data
  • DIALOG : Dialog call
  • TRACE :Write trace file to the specified file on the front end
  • DO_NOT_EXECUTE : Do not execute
  • DO_NOT_EXEC_NOTIF_CLOSE :Do not execute and complete notifications
    Note: This also automatically completes any outstanding tasks in the notifications.
  • DO_NOT_EXEC_NOTIF_DEALLOC :Do not execute and remove assigned notifications from order
    Note: Notifications assigned to the order header are not removed, but rather automatically completed.
  • LOCK :Lock-锁定
  • UNLOCK :Unlock-解锁
  • TECHNICALCOMPLETE :Technically complete-技术完成
  • CANCEL_TECHNICAL_COMPLETION : Cancel technical completion-撤销技术完成
  • TECO_WITH_NOTIF :Technically complete with notifications
    Note: If a reference date is transferred, the notification with the reference date is also completed. The tasks of the notification are not automatically completed.
  • CANCEL_TECO_WITH_NOTIF : Reset technical completion and put assigned notifications in process again
  • COMPLETE_BUSINESS :Complete (business)-业务完成
  • CANCEL_BUSINESS_COMPLETION :Cancel business completion
  • BUS_COMPL_WITH_NOTIF :Complete (business) with notifications
  • SET_DEL_FLAG :Set deletion flag-设置删除标识
  • RESET_DEL_FLAG :Reset deletion flag
  • SET_DLFL_WITH_NOTIF : Also set deletion flag for assigned notifications
  • RESET_DLFL_WITH_NOTIF :Reset deletion flag and put assigned notifications in process again

OBJECTKEY: 外部对象码,详细如下:

  • 0-12 Order number 工单号
  • 13-16 Operation number 工序号
  • 17-20 Suboperation number 子工序号
  • 13-24 Notification number (only for method CREATETONOTIF)

注意:每个object对象只能对应特定的method,详细对应关系如下:

  • HEADER
    CREATE, CHANGE, RELEASE,  ATPCHECK, CALCUALTE, SCHEDULE, CREATETONOTIF, DO_NOT_EXECUTE, LOCK, UNLOCK, TECHNICALCOMPLETE, CANCEL_TECHNICAL_COMPLETION, COMPLETE_BUSINESS, CANCEL_BUSINESS_COMPLETION, SET_DEL_FLAG, RESET_DEL_FLAG
  • OPERATION
    CREATE, CHANGE, DELETE, DELETEDSEX
  • PARTNER, RELATION, USERSTATUS, TEXT, SRULE, OBJECTLIST, PRT
    CREATE, CHANGE, DELETE
  • OLISTRELATION
    CREATE, DELETE
  • TASKLIST
    ADD
  • COMPONENT
    CREATE, CHANGE, REASSIGN, DELETE
  • ESTIMATEDCOST
    CHANGE
  • (empty)
    SAVE, DIALOG, TRACE

2,例子代码

一个简单的例子,用来将工单的状态更新为技术完成。

REPORT ztest_change_status. 
 
DATA:lv_aufnr   TYPE aufk-aufnr, 
     lv_result  TYPE string, 
     lt_methods TYPE TABLE OF bapi_alm_order_method, 
     ls_methods TYPE bapi_alm_order_method, 
     lt_return  TYPE bapiret2_t, 
     ls_return  TYPE bapiret2. 
 
lv_aufnr = '200000000123'. 
 
 
ls_methods-refnumber  = 1. 
ls_methods-objecttype = 'HEADER'. 
ls_methods-method     = 'TECO_WITH_NOTIF'.  "技术完成 
ls_methods-objectkey  = lv_aufnr. 
APPEND ls_methods TO lt_methods. 
 
IF lt_methods IS NOT INITIAL. 
  CLEAR ls_methods. 
  ls_methods-method     = 'SAVE'. 
  APPEND ls_methods TO lt_methods. 
 
  REFRESH:lt_return. 
  CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN' 
    TABLES 
      it_methods = lt_methods 
      return     = lt_return. 
 
  READ TABLE lt_return INTO ls_return WITH KEY  type = 'E'. 
  IF sy-subrc = 0. 
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. 
    MESSAGE ls_return-message TYPE 'S' DISPLAY LIKE 'E'. 
  ELSE. 
 
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' 
      EXPORTING 
        wait = 'X'. 
    MESSAGE '工单状态更新成功' TYPE 'S'. 
  ENDIF. 
 
ENDIF.

3,测试

程序运行前,tcode IW33查看工单状态为释放REL

[BAPI]如何修改工单状态-BAPI_ALM_ORDER_MAINTAIN详解编程语言

程序运行后,工单状态为技术完成TECO

[BAPI]如何修改工单状态-BAPI_ALM_ORDER_MAINTAIN详解编程语言

其他,工单的技术完成状态可以通过IW32撤销,

[BAPI]如何修改工单状态-BAPI_ALM_ORDER_MAINTAIN详解编程语言

以上。

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/19314.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论