BAPI_BATCH_CHANGE在更新后不自动更新批次特征

1、问题介绍

在CL03中看到分类特性配置了制造日期字段,并绑定了生产日期字段MCH1~HSDAT

MSC2N修改批次的生产日期字段时,自动修改了对应的批次特性

但是通过BAPI:BAPI_BATCH_CHANGE修改生产日期时,并没有更新到批次特性中

2、BAPI

根据官方提示,需要使用BAPI:BAPI_BATCH_SAVE_REPLICA来同步更新批次特性

在BAPI_BATCH_SAVE_REPLICA中可以传入基本数据视图中的生产日期

bash 复制代码
"--------------------@斌将军--------------------
CLEAR:ls_batchattributes,ls_batchattributesx.
ls_batchattributes-prod_date = sy-datum."生产日期
ls_batchattributesx-prod_date = 'X' ."生产日期
"--------------------@斌将军--------------------

同时维护批次特性的值

bash 复制代码
"--------------------@斌将军--------------------
CLEAR:ls_classvaluationschar.
ls_classvaluationschar-class_type = lv_klart.
*ls_classvaluationschar-objectkey = lv_objectkey.
ls_classvaluationschar-objectkey_long = lv_objek.
ls_classvaluationschar-objecttable = lv_obtab.
ls_classvaluationschar-charact = 'ZSC_BATCH_HSDAT'.
ls_classvaluationschar-value_char = sy-datum.
APPEND ls_classvaluationschar TO lt_classvaluationschar.
"--------------------@斌将军--------------------

完整代码参考

bash 复制代码
"--------------------@斌将军--------------------
REPORT ytest010.

DATA:lv_material TYPE bapibatchkey-material,
     lv_batch    TYPE bapibatchkey-batch,
     lv_plant    TYPE bapibatchkey-plant,
     lv_matnr    TYPE matnr. "40位

DATA:lv_objek TYPE cuobn,
     lv_obtab TYPE tabelle,
     lv_klart TYPE klassenart,
     lv_class TYPE klasse_d.

DATA:ls_batchattributes     TYPE  bapibatchatt,
     ls_batchattributesx    TYPE bapibatchattx,
     lt_classallocations    TYPE TABLE OF bapi3060_allocation,
     ls_classallocations    TYPE bapi3060_allocation,
     lt_classvaluationschar TYPE TABLE OF bapi3060_valuation_char,
     ls_classvaluationschar TYPE bapi3060_valuation_char,
     lt_classvaluationscurr TYPE TABLE OF bapi3060_valuation_curr,
     ls_classvaluationscurr TYPE bapi3060_valuation_curr,
     lt_classvaluationsnum  TYPE TABLE OF bapi3060_valuation_num,
     ls_classvaluationsnum  TYPE bapi3060_valuation_num,
     lt_return              TYPE TABLE OF bapiret2,
     ls_return              TYPE bapiret2.

lv_matnr = '41155126C'."物料
lv_batch = 'P001055009'."批次
lv_plant = 'SC10'."工厂

CLEAR:lv_objek,lv_obtab,lv_klart,lv_class.
*lv_matnr = lv_material.
CALL FUNCTION 'VB_BATCH_2_CLASS_OBJECT'
  EXPORTING
    i_matnr = lv_matnr
    i_charg = lv_batch
    i_werks = lv_plant
  IMPORTING
    e_objek = lv_objek
    e_obtab = lv_obtab
    e_klart = lv_klart
    e_class = lv_class.

*后边可以直接使用lv_objek值,
*不需要用BAPI_OBJCL_CONCATENATEKEY专门生成lv_objectkey
*lt_objectkeytable = VALUE #( ( key_field = 'MATNR' value_int = LV_material )
*                                ( key_field = 'WERKS' value_int = lv_plant )
*                                ( key_field = 'CHARG' value_int = lv_batch )
*                            ).
*
*"获取key值objectkey(物料和批次)
*REFRESH:lt_return.
*CLEAR:lv_objectkey.
*CALL FUNCTION 'BAPI_OBJCL_CONCATENATEKEY'
*  EXPORTING
*    objecttable    = lv_obtab "表名
*  IMPORTING
*    objectkey_conc = lv_objectkey
*  TABLES
*    objectkeytable = lt_objectkeytable
*    return         = lt_return.
*
*LOOP AT lt_return INTO ls_return WHERE type CA 'EAX'.
*  MESSAGE '获取特性失败:未查询到分类密钥' TYPE 'S' DISPLAY LIKE 'E'.
*ENDLOOP.

"修改批次数据
CLEAR:ls_batchattributes,ls_batchattributesx.
ls_batchattributes-prod_date = sy-datum."生产日期
ls_batchattributesx-prod_date = 'X' ."生产日期

"修改分类特性值
CLEAR:ls_classallocations.
ls_classallocations-class_type    = lv_klart.
*ls_classallocations-objectkey     = lv_objectkey.
ls_classallocations-objectkey_long   = lv_objek.
ls_classallocations-objecttable   = lv_obtab.
ls_classallocations-classnum      = lv_class.
ls_classallocations-classtype     = lv_klart.
ls_classallocations-standardclass = 'X'.
APPEND ls_classallocations TO lt_classallocations.

CLEAR:ls_classvaluationschar.
ls_classvaluationschar-class_type = lv_klart.
*ls_classvaluationschar-objectkey = lv_objectkey.
ls_classvaluationschar-objectkey_long = lv_objek.
ls_classvaluationschar-objecttable = lv_obtab.
ls_classvaluationschar-charact = 'ZSC_BATCH_HSDAT'.
ls_classvaluationschar-value_char = sy-datum.
APPEND ls_classvaluationschar TO lt_classvaluationschar.

CALL FUNCTION 'BAPI_BATCH_SAVE_REPLICA'
  EXPORTING
    material_long       = lv_matnr "长物料
*   material            = lv_material
    batch               = lv_batch
    plant               = lv_plant
    batchattributes     = ls_batchattributes
    batchattributesx    = ls_batchattributesx
  TABLES
    return              = lt_return
    classallocations    = lt_classallocations
    classvaluationschar = lt_classvaluationschar
    classvaluationscurr = lt_classvaluationscurr
    classvaluationsnum = lt_classvaluationsnum.

DATA:lv_check   TYPE char1,
     lv_message TYPE char255.

CLEAR:lv_message.
LOOP AT lt_return INTO ls_return WHERE type CA 'EAX'.
  lv_message = lv_message && ls_return-message.
  lv_check = 'E'.
ENDLOOP.
IF lv_check = 'E'.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  WRITE:lv_message.
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.
ENDIF.
"--------------------@斌将军--------------------
相关推荐
山茶花开时。12 天前
[SAP ABAP] 序列化与反序列化
开发语言·sap·abap
SAP学习成长之路19 天前
ADBC 查询语法介绍:EXECUTE_QUERY
java·服务器·开发语言·数据库·sap·abap·零售
需己以听的以听21 天前
4.模块化技术之子程序
sap·gui·abap·模块化·改行学it·子程序
HeathlX23 天前
ABAP - 系统集成之SAP的数据同步到OA(泛微E9)服务器数据库
数据库·abap
SAP学习成长之路1 个月前
SAP HANA 上进行 ABAP 开发:简介
开发语言·数据结构·数据库·sap·abap·代码规范
Fireworks_me1 个月前
SAP Native SQL 的简单说明
sql·abap
左甜甜1 个月前
ABAP OOALV模板
sap·abap·alv
Seele_10181 个月前
CPI 与SAP IDOC的连接
sap·abap·btp·cpi
SAP学习成长之路1 个月前
SAP 零售方案 CAR 系统的介绍与研究
大数据·开发语言·sap·abap·零售·car·bapi