文章目录
- BAPI_BATCH_CHANGE:修改批次的特征值
- 实现步骤
- 定义变量
- 获取对象/类等
- 获取已维护特性值
- 新特性值更新
- 注意事项
- 最终效果
- 字段介绍
BAPI_BATCH_CHANGE:修改批次的特征值
现在有一个需求是要修改批次里面的某一个特征值,所以需要使用到BAPI_BATCH_CHANGE这个BAPI,除此之外,还有VB_BATCH_2_CLASS_OBJECT函数和BAPI_OBJCL_GETDETAIL。
实现步骤
定义变量
DATA e_objek TYPE cuobn.
DATA e_obtab TYPE tabelle.
DATA e_klart TYPE klassenart.
DATA e_class TYPE klasse_d.
DATA allocvaluesnum TYPE STANDARD TABLE OF bapi1003_alloc_values_num. "分配 BAPI - NUM、DATE、TIME 类型的值
DATA allocvalueschar TYPE STANDARD TABLE OF bapi1003_alloc_values_char. "分配 BAPI - CHAR、BOOL 类型的值
DATA allocvaluescurr TYPE STANDARD TABLE OF bapi1003_alloc_values_curr. "分配 BAPI - CURR 类型值
DATA return TYPE STANDARD TABLE OF bapiret2.
DATA: lt_numnew TYPE TABLE OF bapi1003_alloc_values_num,
lt_charnew TYPE TABLE OF bapi1003_alloc_values_char,
lt_currnew TYPE TABLE OF bapi1003_alloc_values_curr,
lt_returnnew TYPE TABLE OF bapiret2.
DATA: ls_char TYPE bapi1003_alloc_values_char,
ls_return TYPE bapiret2.
获取对象/类等
函数名称:VB_BATCH_2_CLASS_OBJECT
CALL FUNCTION 'VB_BATCH_2_CLASS_OBJECT'
EXPORTING
i_matnr = 'EWM_RAW_01' "物料
i_charg = '2022061302' "批次
i_werks = '1710' "工厂
IMPORTING
e_objek = e_objek
e_obtab = e_obtab
e_klart = e_klart
e_class = e_class
.
获取已维护特性值
BAPI名称:BAPI_OBJCL_GETDETAIL
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
"objectkey = e_objek "如果是物料是40位的,选这个会报错,要选OBJECTKEY_LONG
objecttable = e_obtab "对于分类的对象的数据库表名称
classnum = e_class "分类编号
classtype = e_klart "分类的类型
"keydate = sy-datum
* UNVALUATED_CHARS = ' '
* LANGUAGE = SY-LANGU
objectkey_long = e_objek "关键字字段
* IMPORTING
* STATUS = STATUS
* STANDARDCLASS = STANDARDCLASS
TABLES
allocvaluesnum = allocvaluesnum
allocvalueschar = allocvalueschar
allocvaluescurr = allocvaluescurr
return = return
.
新特性值更新
BAPI名称:BAPI_BATCH_CHANGE
lt_numnew[] = allocvaluesnum.
lt_charnew[] = allocvalueschar.
lt_currnew[] = allocvaluescurr.
lt_returnnew[] = return.
IF lt_charnew[] IS NOT INITIAL.
LOOP AT lt_charnew INTO ls_char.
ls_char-value_char = '1'. "特征值
ls_char-value_neutral = '1'. "特征值
ls_char-value_char_long = '1'. "特征值
ls_char-value_neutral_long = '1'. "特征值
MODIFY lt_charnew FROM ls_char.
ENDLOOP.
ELSE.
ls_char-charact = 'Z_SW_DW_BA'. "特征名
ls_char-value_char = '1'. "特征值
ls_char-value_neutral = '1'. "特征值
ls_char-value_char_long = '1'. "特征值
ls_char-value_neutral_long = '1'. "特征值
APPEND ls_char TO lt_charnew[].
ENDIF.
"--> 新特性值更新
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
* OBJECTKEY = OBJECTKEY
objecttable = e_obtab
classnum = e_class
classtype = e_klart
* STATUS = '1'
* STANDARDCLASS = STANDARDCLASS
* CHANGENUMBER = CHANGENUMBER
* KEYDATE = SY-DATUM
* NO_DEFAULT_VALUES = ' '
* KEEP_SAME_DEFAULTS = ' '
objectkey_long = e_objek
* IMPORTING
* CLASSIF_STATUS = CLASSIF_STATUS
TABLES
allocvaluesnumnew = lt_numnew
allocvaluescharnew = lt_charnew
allocvaluescurrnew = lt_currnew
return = lt_returnnew
.
LOOP AT return INTO ls_return WHERE type = 'E' OR type = 'A'.
WRITE: ls_return-message.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
EXIT.
ENDLOOP.
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.