‎2010 Feb 22 4:03 PM
I need to create a batch and include the characteristic values. I've found FM VB_CREATE_BATCH, which includes the segment CHAR_OF_BATCH, but this doesnt appear to allow me to assing values to the characteristics. Does anyone know of a way to do this?
‎2010 Feb 22 4:15 PM
Hi,
You need to follow the below steps here.
1. Lock the Material and Plant combination
CALL FUNCTION 'ENQUEUE_MATERIAL'
EXPORTING
matnr = lv_matnr
werks = lv_werks
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
2. Create Batch by calling BAPI
CALL FUNCTION 'BAPI_BATCH_CREATE'
EXPORTING
material = lv_matnr
batch = lv_charg
plant = lv_werks
batchstoragelocation = lv_lgort
batchattributes = lw_batch_attr (here prod_date should be the production date of batch)
TABLES
return = lt_rettab.
3. Create Key
* Fetch Object key by passing Material, Plant and Batch
* Fill Material Number
lw_object-key_field = 'MATNR'.
lw_object-value_int = lv_matnr.
APPEND lw_object TO lt_object.
CLEAR : lw_object.
* Fill Plant
lw_object-key_field = 'WERKS'.
lw_object-value_int = lv_werks.
APPEND lw_object TO lt_object.
CLEAR : lw_object.
* Fill Batch
lw_object-key_field = 'CHARG'.
lw_object-value_int = lv_charg.
APPEND lw_object TO lt_object.
CLEAR : lw_object.
* Concatenate Object Key
CALL FUNCTION 'BAPI_OBJCL_CONCATENATEKEY'
EXPORTING
objecttable = 'MCH1'
IMPORTING
objectkey_conc = lv_object
TABLES
objectkeytable = lt_object
return = lt_rettab.to be continued...
‎2010 Feb 22 4:15 PM
4. Fetch Batch Characteristics, these will be empty for new batches
* Fetch object characterstics.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = lv_object
objecttable = 'MCH1'
classnum = this is class name 'Z_MATERIAL_CHEESE' etc
classtype = this is class type '023' etc values
keydate = sy-datum
unvaluated_chars = 'X'
language = sy-langu
TABLES
allocvaluesnum = lt_alloc_num
allocvalueschar = lt_alloc_char
allocvaluescurr = lt_alloc_curr
return = lt_rettab.
5. Modify the above num, char and curr internal tables with your values
6. Create Batch characteristics
CALL FUNCTION 'BAPI_OBJCL_CREATE'
EXPORTING
objectkeynew = lv_object
objecttable = 'MCH1'
classnum = this is class name 'Z_MATERIAL_CHEESE' etc
classtype = this is class type '023' etc values
keydate = sy-datum
no_default_values = 'X'
TABLES
allocvaluesnum = lt_alloc_num
allocvalueschar = lt_alloc_char
allocvaluescurr = lt_alloc_curr
return = lt_rettab.Go through each of the above mentioned BAPIs documentation and proceed. I followed this way in so many developments. Hope this helps you !!!
Regards,
Ganga
‎2013 Nov 11 4:38 PM
Dear Ganga Bhavani Reguri,
I have tried your way. It didn't work. Maybe there is something that I have missed. However, I have tried this one. It worked. http://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=195789188
The difference is that yours uses FUNCTION 'BAPI_OBJCL_CONCATENATEKEY' to get object key, while the other one uses FUNCTION 'VB_BATCH_2_CLASS_OBJECT'.
Best regards,
Arwen