本文主要是介绍批次属性创建BAPI在S/4一些变化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
批次属性变更同样是使用的以下三个BAPI:
VB_BATCH_2_CLASS_OBJECT:获取物料批次信息
BAPI_OBJCL_GETDETAIL:获取批次对象属性
BAPI_OBJCL_CHANGE:修改批次对象属性
在传统的ECC系统中,我们修改物料批次属性可能使用如下代码:
DATA P_CHARG TYPE CHARG_D.
DATA P_CHARACT TYPE CHAR30.
DATA E_OBJEK TYPE OBJNUM.
DATA E_OBTAB TYPE TABELLE.
DATA E_KLART TYPE KLASSENART.
DATA E_CLASS TYPE KLASSE_D.
DATA IT_NUM TYPE TABLE OF BAPI1003_ALLOC_VALUES_NUM.
DATA IT_CHAR TYPE TABLE OF BAPI1003_ALLOC_VALUES_CHAR.
DATA IT_CURR TYPE TABLE OF BAPI1003_ALLOC_VALUES_CURR.
DATA VALUE_CHAR TYPE CHAR30.
DATA:LV_CHAND(50) TYPE C.
DATA:LV_DENGJ(50) TYPE C.
DATA:LT_EKPO TYPE TABLE OF EKPO,
LS_EKPO LIKE LINE OF LT_EKPO.
TYPES:BEGIN OF TY_TPP311,
MANDT TYPE ZTPP311-MANDT,
ZSEHAO TYPE ZTPP311-ZSEHAO,
ZYSMCN TYPE ZTPP311-ZYSMCN,
END OF TY_TPP311.
DATA:LS_TPP311 TYPE TY_TPP311.
DATA:LT_NUM TYPE TABLE OF BAPI1003_ALLOC_VALUES_NUM,
LT_CHAR TYPE TABLE OF BAPI1003_ALLOC_VALUES_CHAR,
LS_CHAR TYPE BAPI1003_ALLOC_VALUES_CHAR,
LT_CURR TYPE TABLE OF BAPI1003_ALLOC_VALUES_CURR,
LS_CURR TYPE BAPI1003_ALLOC_VALUES_CURR,
LT_RETURN TYPE TABLE OF BAPIRET2,
LV_CHAR TYPE CHAR16.
CALL FUNCTION 'VB_BATCH_2_CLASS_OBJECT'
EXPORTING
I_MATNR = LS_MSEG-MATNR
I_CHARG = LS_MSEG-CHARG
I_WERKS = LS_MSEG-WERKS
IMPORTING
E_OBJEK = E_OBJEK
E_OBTAB = E_OBTAB
E_KLART = E_KLART
E_CLASS = E_CLASS.
IF SY-SUBRC = 0 AND LS_MSEG-BWART = '101'.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
OBJECTKEY = E_OBJEK
OBJECTTABLE = E_OBTAB
CLASSNUM = E_CLASS
CLASSTYPE = E_KLART
TABLES
ALLOCVALUESNUM = IT_NUM
ALLOCVALUESCHAR = IT_CHAR
ALLOCVALUESCURR = IT_CURR
RETURN = LT_RETURN.
IF SY-SUBRC EQ 0.
APPEND LINES OF IT_CHAR TO LT_CHAR.
APPEND LINES OF IT_NUM TO LT_NUM.
APPEND LINES OF IT_CURR TO LT_CURR.
READ TABLE LT_EKPO INTO LS_EKPO WITH KEY EBELN = LS_MSEG-EBELN
EBELP = LS_MSEG-EBELP.
IF SY-SUBRC EQ 0.
IF LS_EKPO-ZPOSNR = '000000'.
CLEAR LS_EKPO-ZPOSNR.
ENDIF.
CONCATENATE LS_EKPO-ZVBELN LS_EKPO-ZPOSNR INTO LV_CHAR.
CONDENSE LV_CHAR.
LS_CHAR-CHARACT = 'ZXSDD'.
LS_CHAR-VALUE_CHAR = LV_CHAR.
LS_CHAR-VALUE_NEUTRAL = LV_CHAR.
LS_CHAR-CHARACT_DESCR = '销售订单号'.
APPEND LS_CHAR TO LT_CHAR.
LS_CHAR-CHARACT = 'ZSEHAO'.
LS_CHAR-VALUE_CHAR = LS_EKPO-ZSH.
LS_CHAR-VALUE_NEUTRAL = LS_EKPO-ZSH.
LS_CHAR-CHARACT_DESCR = '色号'.
APPEND LS_CHAR TO LT_CHAR.
LS_CHAR-CHARACT = 'ZSP'.
LS_CHAR-VALUE_CHAR = LS_EKPO-ZSP.
LS_CHAR-VALUE_NEUTRAL = LS_EKPO-ZSP.
LS_CHAR-CHARACT_DESCR = '纱牌'.
APPEND LS_CHAR TO LT_CHAR.
LS_CHAR-CHARACT = 'ZSZ'.
LS_CHAR-VALUE_CHAR = LS_EKPO-ZSZ.
LS_CHAR-VALUE_NEUTRAL = LS_EKPO-ZSZ.
LS_CHAR-CHARACT_DESCR = '色组'.
APPEND LS_CHAR TO LT_CHAR.
* LS_CHAR-CHARACT = 'ZPZ'.
* LS_CHAR-VALUE_CHAR = LS_EKPO-ZPZ.
* LS_CHAR-VALUE_NEUTRAL = LS_EKPO-ZPZ.
* LS_CHAR-CHARACT_DESCR = '配置'.
* APPEND LS_CHAR TO LT_CHAR.
LS_CHAR-CHARACT = 'ZXH'.
LS_CHAR-VALUE_CHAR = LS_EKPO-ZXH.
LS_CHAR-VALUE_NEUTRAL = LS_EKPO-ZXH.
LS_CHAR-CHARACT_DESCR = '型号'.
APPEND LS_CHAR TO LT_CHAR.
LS_CHAR-CHARACT = 'ZCD'.
LS_CHAR-VALUE_CHAR = LS_EKPO-ZCD.
LS_CHAR-VALUE_NEUTRAL = LS_EKPO-ZCD.
LS_CHAR-CHARACT_DESCR = '产地'.
APPEND LS_CHAR TO LT_CHAR.
ENDIF.
SELECT
COUNT(*)
FROM ZTPP311
WHERE ZSEHAO = LS_EKPO-ZSH
AND ZYSMCN = LS_EKPO-ZYS.
IF SY-SUBRC NE 0.
LS_TPP311-MANDT = SY-MANDT.
LS_TPP311-ZSEHAO = LS_EKPO-ZSH.
LS_TPP311-ZYSMCN = LS_EKPO-ZYS.
MODIFY ZTPP311 FROM LS_TPP311.
* IF SY-SUBRC NE 0.
* ROLLBACK WORK.
* ELSE.
* COMMIT WORK.
* ENDIF.
ENDIF.
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
OBJECTKEY = E_OBJEK
OBJECTTABLE = E_OBTAB
CLASSNUM = E_CLASS
CLASSTYPE = E_KLART
STATUS = '1'
TABLES
ALLOCVALUESNUMNEW = LT_NUM
ALLOCVALUESCHARNEW = LT_CHAR
ALLOCVALUESCURRNEW = LT_CURR
RETURN = LT_RETURN.
在S/4中,以上的代码可能会出现变量类型不兼容的现象,需要调整一下入参的
参照变量,另外 e_objek_long_d 变量也需要输入了(之前是可以不传的),
否则会报"请输入批量“的错误。
DATA P_CHARG TYPE CHARG_D.
DATA P_CHARACT TYPE CHAR30.
DATA E_OBJEK TYPE CUOBN.
DATA E_OBTAB TYPE TABELLE.
DATA E_KLART TYPE KLASSENART.
DATA E_CLASS TYPE KLASSE_D.
DATA IT_NUM TYPE TABLE OF BAPI1003_ALLOC_VALUES_NUM.
DATA IT_CHAR TYPE TABLE OF BAPI1003_ALLOC_VALUES_CHAR.
DATA IT_CURR TYPE TABLE OF BAPI1003_ALLOC_VALUES_CURR.
DATA VALUE_CHAR TYPE CHAR30.
DATA:LV_CHAND(50) TYPE C.
DATA:LV_DENGJ(50) TYPE C.
DATA:LT_EKPO TYPE TABLE OF EKPO,
LS_EKPO LIKE LINE OF LT_EKPO.
DATA:LT_NUM TYPE TABLE OF BAPI1003_ALLOC_VALUES_NUM WITH HEADER LINE,
LT_CHAR TYPE TABLE OF BAPI1003_ALLOC_VALUES_CHAR WITH HEADER LINE,
LS_CHAR TYPE BAPI1003_ALLOC_VALUES_CHAR,
LT_CURR TYPE TABLE OF BAPI1003_ALLOC_VALUES_CURR WITH HEADER LINE,
LS_CURR TYPE BAPI1003_ALLOC_VALUES_CURR,
LT_RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE,
LV_CHAR TYPE CHAR16.
DATA l_matnr TYPE bapibatchkey-material VALUE '000000000001000003'.
DATA l_batch TYPE charg_d VALUE 'A11'.
DATA l_werks TYPE werks_d VALUE '2100'.
*CALL FUNCTION 'BAPI_BATCH_CREATE'
* EXPORTING
* material = l_matnr
* batch = l_batch
* plant = l_werks
* TABLES
* return = lt_return.
*
*IF sy-subrc EQ 0.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* wait = 'X'.
*ENDIF.
DATA:l_matnr1 TYPE matnr.
move l_matnr to l_matnr1.
CALL FUNCTION 'VB_BATCH_2_CLASS_OBJECT'
EXPORTING
i_matnr = l_matnr1
i_charg = l_batch
i_werks = l_werks
IMPORTING
e_objek = e_objek
e_obtab = e_obtab
e_klart = e_klart
e_class = e_class.
* DATA:
* l_objek_g TYPE BAPI1003_KEY-OBJECT,
* l_obtab_g TYPE BAPI1003_KEY-OBJECTTABLE,
* l_classnum_g TYPE BAPI1003_KEY-CLASSNUM,
* l_classtype_g TYPE BAPI1003_KEY-CLASSTYPE.
*
* l_objek_g = l_objek.
* l_obtab_g = l_obtab.
* l_classnum_g = l_class.
* l_classtype_g = l_klart.
DATA:e_objek_d TYPE BAPI1003_KEY-OBJECT,
e_obtab_d TYPE BAPI1003_KEY-OBJECTTABLE,
e_class_d TYPE BAPI1003_KEY-CLASSNUM,
e_klart_d TYPE BAPI1003_KEY-CLASSTYPE,
e_objek_long_d TYPE BAPI1003_KEY-OBJECT_LONG.
e_objek_d = e_objek.
e_obtab_d = e_obtab.
e_klart_d = e_klart.
e_class_d = e_class.
e_objek_long_d = e_objek.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = e_objek_d
objecttable = e_obtab_d
classnum = e_class_d
classtype = e_klart_d
objectkey_long = e_objek_long_d
TABLES
allocvaluesnum = lt_num
allocvalueschar = lt_char
allocvaluescurr = lt_curr
return = lt_return.
lt_char-charact = 'ZBATCH_QIGRADE'.
lt_char-value_char = 'A'.
lt_char-value_neutral = 'A'.
lt_char-charact_descr = '配套'.
APPEND lt_char.
*
* lt_char-charact = 'ZBATCH_QUALIFID'.
* lt_char-value_neutral = 'ABC'.
* APPEND lt_char.
lt_char-charact = 'ZBATCH_EXID'.
lt_char-value_char = 'S'.
lt_char-value_neutral = 'S'.
lt_char-charact_descr = '试验品'.
APPEND lt_char.
* lt_char-charact = 'ZBATCH_EXTERNALNUM'.
* lt_char-value_neutral = 'AAA'.
* APPEND lt_char.
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
objectkey = e_objek_d
objecttable = e_obtab_d
classnum = e_class_d
classtype = e_klart_d
objectkey_long = e_objek_long_d
TABLES
allocvaluesnumnew = lt_num
allocvaluescharnew = lt_char
allocvaluescurrnew = lt_curr
return = lt_return.
IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
这篇关于批次属性创建BAPI在S/4一些变化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!