生产订单结算规则新增、修改、删除——K_SRULE_SAVE_UTASK

效果(不同类型的生产订单结算方式会不一样):

①将生产订单建立默认带出的MAT类型结算规则的结算百分率改成0,

②新增G/L结算类型结算规则

 

代码:

*&---------------------------------------------------------------------*
*& Report ZPPRTEST
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZPPRTEST.
DATA: lt_cobrb_update LIKE TABLE OF cobrb,
      ls_cobrb_update LIKE LINE OF lt_cobrb_update,
      lt_cobrb_insert LIKE TABLE OF cobrb,
      ls_cobrb_insert LIKE LINE OF lt_cobrb_insert.

SELECT  * INTO TABLE lt_cobrb_update
            FROM cobrb
            WHERE objnr = 'OR000020040327'
            AND lfdnr = '001'.

LOOP AT lt_cobrb_update INTO ls_cobrb_update.
  ls_cobrb_insert = ls_cobrb_update.
  "MAT结算规则的结算百分比 = 0
  ls_cobrb_update-prozs = 0.
  MODIFY lt_cobrb_update FROM ls_cobrb_update.
ENDLOOP.

"新增的结算规则
ls_cobrb_insert-lfdnr = '002'. "顺序号码
ls_cobrb_insert-prozs = 100. "百分比
ls_cobrb_insert-dfreg = space. "预设规则
ls_cobrb_insert-avorg = 'KOAO'. "结算交易
ls_cobrb_insert-konty = 'SK'.  "科目指派种类
ls_cobrb_insert-werks = space. "工厂
ls_cobrb_insert-gsber = 'NCIP'. "业务范围
ls_cobrb_insert-hkont = '6188200007'. "总账科目
ls_cobrb_insert-prctr = 'PC21'. "利润中心
ls_cobrb_insert-kostl = 'DR0000'. "成本中心
ls_cobrb_insert-matnr = space. "物料
ls_cobrb_insert-rec_objnr1 = 'SK20006188200007NCIP'. "结算接收者物件号码
ls_cobrb_insert-extnr = '002'. "分发规则号码
APPEND ls_cobrb_insert TO lt_cobrb_insert.

CALL FUNCTION 'K_SRULE_SAVE_UTASK'
 TABLES
   t_cobrb_insert          = lt_cobrb_insert
   t_cobrb_update        = lt_cobrb_update
 EXCEPTIONS
   SRULE_UTASK_ERROR       = 1
   OTHERS                  = 2.

IF sy-subrc <> 0.
  WRITE '修改失败'.
ELSE.
  WRITE '修改成功'.
ENDIF.

 

posted @ 2020-07-13 22:36  鲸与海  阅读(3626)  评论(0编辑  收藏  举报