此博客为原创博客,都是个人工作经历所得,转载请注明出处

IW31创建维修工单

 

 

*&---------------------------------------------------------------------*
*& Report YCX_IW31
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ycx_iw31.

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.

  " 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 .


" 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.

 

posted @ 2021-01-03 11:49  Rainystuday  阅读(228)  评论(0编辑  收藏  举报