1、問題介紹
在CL03中看到分類特性配置了製造日期欄位,並繫結了生產日期欄位MCH1~HSDAT
MSC2N修改批次的生產日期欄位時,自動修改了對應的批次特性
但是透過BAPI:BAPI_BATCH_CHANGE修改生產日期時,並沒有更新到批次特性中
2、BAPI
根據官方提示,需要使用BAPI:BAPI_BATCH_SAVE_REPLICA來同步更新批次特性
在BAPI_BATCH_SAVE_REPLICA中可以傳入基本資料檢視中的生產日期
"--------------------@斌將軍-------------------- CLEAR:ls_batchattributes,ls_batchattributesx. ls_batchattributes-prod_date = sy-datum."生產日期 ls_batchattributesx-prod_date = 'X' ."生產日期 "--------------------@斌將軍--------------------
同時維護批次特性的值
"--------------------@斌將軍-------------------- 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. "--------------------@斌將軍--------------------
完整程式碼參考
"--------------------@斌將軍-------------------- 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. "--------------------@斌將軍--------------------
定期更文,歡迎關注