SAP BAPI to Update Batch Characteristics: ABAP Generator for BAPI_OBJCL_GETDETAIL and BAPI_OBJCL_CHANGE
This generator writes an ABAP report for SAP ECC 6.0 that reads a batch's classification with BAPI_OBJCL_GETDETAIL and, in CHANGE mode, updates one characteristic value with BAPI_OBJCL_CHANGE. It builds the batch object key for MCH1 or MCHA so the BAPI finds the right classification.
Fill in
Converted with CONVERSION_EXIT_MATN1_INPUT, so numeric materials get leading zeros.
Used in the key only when the object table is MCHA (plant-level batches).
MCH1 for material-level or client-level batches, MCHA for plant-level batches.
023 is the standard batch class type.
Declarations and object key
REPORT ZMM_BATCH_CLASS_VALUES.
* Read or change batch classification values (class type 023)
* Object table MCH1: MCH1 = batch unique per material or client,
* MCHA = batch unique per plant. Must match your batch level (OMCT).
CONSTANTS: gc_mode TYPE c LENGTH 6 VALUE 'READ',
gc_objtab TYPE bapi1003_key-objecttable VALUE 'MCH1'.
DATA: lv_matnr TYPE matnr,
lv_werks TYPE werks_d,
lv_charg TYPE charg_d,
lv_objkey TYPE bapi1003_key-object,
lv_classnum TYPE bapi1003_key-classnum,
lv_classtype TYPE bapi1003_key-classtype,
lv_status TYPE bapi1003_key-status,
lv_error TYPE c LENGTH 1,
lt_num TYPE STANDARD TABLE OF bapi1003_alloc_values_num,
lt_char TYPE STANDARD TABLE OF bapi1003_alloc_values_char,
lt_curr TYPE STANDARD TABLE OF bapi1003_alloc_values_curr,
lt_return TYPE STANDARD TABLE OF bapiret2,
ls_num TYPE bapi1003_alloc_values_num,
ls_char TYPE bapi1003_alloc_values_char,
ls_return TYPE bapiret2.
lv_werks = '1000'.
lv_charg = '0000012345'.
lv_classnum = 'Z_BATCH_CLASS'.
lv_classtype = '023'.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = '100245'
IMPORTING
output = lv_matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
WRITE: / 'Material number conversion failed'.
RETURN.
ENDIF.
* Fixed-length key: use offsets, CONCATENATE would drop trailing blanks
CLEAR lv_objkey.
lv_objkey(18) = lv_matnr.
IF gc_objtab = 'MCHA'.
lv_objkey+18(4) = lv_werks.
lv_objkey+22(10) = lv_charg.
ELSE.
lv_objkey+18(10) = lv_charg.
ENDIF.Read the batch classification (BAPI_OBJCL_GETDETAIL)
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = lv_objkey
objecttable = gc_objtab
classnum = lv_classnum
classtype = lv_classtype
keydate = sy-datum
language = sy-langu
IMPORTING
status = lv_status
TABLES
allocvaluesnum = lt_num
allocvalueschar = lt_char
allocvaluescurr = lt_curr
return = lt_return.
LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'.
WRITE: / ls_return-type, ls_return-message.
lv_error = 'X'.
ENDLOOP.
IF lv_error = 'X'.
RETURN.
ENDIF.
WRITE: / 'Object key:', lv_objkey, 'Status:', lv_status.
LOOP AT lt_char INTO ls_char.
WRITE: / ls_char-charact, ls_char-value_char.
ENDLOOP.
LOOP AT lt_num INTO ls_num.
WRITE: / ls_num-charact, ls_num-value_from.
ENDLOOP.Change one character value (BAPI_OBJCL_CHANGE) when mode is CHANGE
IF gc_mode = 'CHANGE'.
* The BAPI replaces the whole allocation: pass back every value you read
READ TABLE lt_char INTO ls_char WITH KEY charact = 'Z_HEAT_NUMBER'.
IF sy-subrc = 0.
ls_char-value_char = 'H-88231'.
ls_char-value_neutral = 'H-88231'.
MODIFY lt_char FROM ls_char INDEX sy-tabix.
ELSE.
CLEAR ls_char.
ls_char-charact = 'Z_HEAT_NUMBER'.
ls_char-value_char = 'H-88231'.
ls_char-value_neutral = 'H-88231'.
APPEND ls_char TO lt_char.
ENDIF.
CLEAR: lt_return, lv_error.
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
objectkey = lv_objkey
objecttable = gc_objtab
classnum = lv_classnum
classtype = lv_classtype
status = '1'
keydate = sy-datum
IMPORTING
classif_status = lv_status
TABLES
allocvaluesnumnew = lt_num
allocvaluescharnew = lt_char
allocvaluescurrnew = lt_curr
return = lt_return.
LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'.
WRITE: / ls_return-type, ls_return-message.
lv_error = 'X'.
ENDLOOP.
IF lv_error = 'X'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
WRITE: / 'Change rolled back'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
WRITE: / 'Changed', 'Z_HEAT_NUMBER', 'to', 'H-88231'.
ENDIF.
ENDIF.Paste the three blocks in order into one report in SE38 and run it in a development or quality client first. Verify on your system: the BAPI parameters in SE37 (some EHP levels add OBJECTKEY_LONG and the long value fields VALUE_CHAR_LONG and VALUE_NEUTRAL_LONG); your batch level in OMCT (stored in TCUCH) so you choose MCH1 or MCHA; the material length (18 characters unless long material numbers are active); and that the characteristic is of data type CHAR. Numeric and date characteristics go in ALLOCVALUESNUM, currency ones in ALLOCVALUESCURR.
Get this checked against your ECC release
Send us your EHP level and batch level setting and we will review the generated report and the BAPI parameters for your system.
Optional. The tool and every export work without this. No spam.
How to use it
Fill in the material in its external format, the batch, the plant, the batch class and class type 023, the characteristic name and the new value. Pick the object table that matches your batch level and leave mode on READ for the first run. The report converts the material with CONVERSION_EXIT_MATN1_INPUT, builds the object key, reads all assigned values and prints them. Switch to CHANGE once the read shows the expected characteristics. The change block updates or appends the value, passes the full value tables back to BAPI_OBJCL_CHANGE with status 1 (released), and commits with BAPI_TRANSACTION_COMMIT only if RETURN has no E or A messages.
Where batch classification lives in ECC
The batch level is set in OMCT and stored in TCUCH. With plant-level batches the batch master is MCHA and the classification object is MCHA with key MATNR (18) + WERKS (4) + CHARG (10). With material-level or client-level batches the master is MCH1 and the key is MATNR (18) + CHARG (10). Batch classes use class type 023. Values are stored in AUSP against an internal object number from INOB (INOB-CUOBJ, with OBTAB MCH1 or MCHA), which is why you call the BAPI with the readable key instead of writing AUSP. Check results in MSC3N on the Classification tab or in CL24N.
- MCHA key: MATNR + WERKS + CHARG
- MCH1 key: MATNR + CHARG
- Class type 023 for batch classes
- INOB maps the key to CUOBJ; AUSP holds the values
Version differences and gotchas
BAPI_OBJCL_CHANGE replaces the whole allocation: any value you do not pass back is deleted, which is why the report reads first and sends every table back. Reference characteristics such as LOBM_VFDAT take their value from batch master fields, so change the shelf life expiration date with BAPI_BATCH_CHANGE or MSC2N, not through the class. If the batch is not yet allocated to the class, the read returns an error; create the allocation in MSC2N or with BAPI_OBJCL_CREATE first. VALUE_NEUTRAL holds the language-independent value, so the report sets it and VALUE_CHAR to the same text. If long material numbers are active, the 18-character offsets are wrong and you should use OBJECTKEY_LONG.
Batch reports and movement types
Changing a characteristic value does not need a goods movement. Moving stock into a different batch is a transfer posting in MIGO, commonly movement type 309 (material to material, which also allows a batch change). For batch reporting, MB56 shows the batch where-used list, BMBC is the batch information cockpit for selection by characteristic values, and MCHB holds stock per batch and storage location. Use MSC3N to display one batch with its classification.
Frequently Asked Questions
Which BAPI updates batch characteristics in SAP?
BAPI_OBJCL_CHANGE with OBJECTTABLE MCH1 or MCHA, class type 023 and the batch object key. Read the current values with BAPI_OBJCL_GETDETAIL first, change the row you need and pass all value tables back, then call BAPI_TRANSACTION_COMMIT. For batch master fields such as VFDAT use BAPI_BATCH_CHANGE.
What is the object key for a batch in BAPI_OBJCL_GETDETAIL?
For MCH1 it is the 18-character internal material number followed by the 10-character batch. For MCHA it is material, then 4-character plant, then batch. Build it with fixed offsets so trailing blanks in alphanumeric material numbers are kept.
What are the BAPI table structures for classification values?
BAPI1003_ALLOC_VALUES_CHAR for character values (CHARACT, VALUE_CHAR, VALUE_NEUTRAL), BAPI1003_ALLOC_VALUES_NUM for numeric and date values (CHARACT, VALUE_FROM, VALUE_TO, VALUE_RELATION) and BAPI1003_ALLOC_VALUES_CURR for currency values. Messages come back in BAPIRET2. Check them in SE11 for your release.
Why does BAPI_OBJCL_CHANGE delete my other values?
The BAPI treats the tables you pass as the complete new allocation. If you send only the changed characteristic, all others are removed. Always read the allocation with BAPI_OBJCL_GETDETAIL, modify the row in place, and pass the numeric, character and currency tables back together.
If you want planners and quality staff to ask for batch characteristics and where-used chains in plain English on your own servers, read-only, we can set that up on top of ECC.
Related Tools
SAP Classification Values ABAP Generator
Enter a material and a class type and get an ABAP snippet that resolves the internal object number and lists every assigned characteristic and value.
SAPSAP Batch Management GMP T-Codes and Tables Reference
A lookup of SAP transactions, tables and movement types for batch genealogy, inspection and release.
SAPSAP Batch Shelf Life Expiry Stock SQL Query Generator (MCH1, MCHB)
Build a SQL query that lists batches whose shelf life expiry date falls in a chosen window, with stock by status, for chemical and specialty products.
SAPSAP BAPI_GOODSMVT_CREATE ABAP Code Generator
Fill in plant, material, quantity and movement type to get a working ABAP skeleton for posting a goods movement through the standard BAPI.
SAPSAP ECC 2027 Maintenance Exit Path Assessment
Twelve scored questions on EHP level, database, custom code, CVI, add-ons, budget and contract appetite that map your SAP ECC 6.0 system to one of four maintenance exit paths, with the dates that apply.
More Developer Tools tools
See all- SAP ECC Enhancement Transactions and Exit Tables Reference (SMOD, CMOD, SE18, MODSAP, SXC_EXIT)
- SAP ECC Data Dictionary and Repository Tables Reference (DD02L, DD03L, T100, E070, TSTC)
- SAP ECC ABAP Runtime Errors (ST22 Dumps) and Error Log Transactions Reference
- SAP ECC Background Job History ABAP Query Generator (TBTCO + TBTCP)
- SAP ECC Background Job Creation ABAP Generator (JOB_OPEN, SUBMIT, JOB_CLOSE)
- SAP ECC IDoc Segment Data Reader ABAP Generator (EDIDC, EDID4, EDIDS)
- SAP ECC Custom Inbound IDoc Function Module Skeleton Generator
- SAP ECC BAPI_SALESORDER_CHANGE ABAP Generator
- SAP ECC BAPI_PO_CHANGE ABAP Generator
Keep exploring
Free tools
- SAP ECC BAPI_PO_CHANGE ABAP GeneratorGenerate a working ABAP program that changes an SAP purchase order item with BAPI_PO_CHANGE, with POITEM/POITEMX, schedule line date conversion, test run and commit handling.
- SAP ECC BAPI_SALESORDER_CHANGE ABAP GeneratorGenerate a working ABAP program that updates an SAP sales order with BAPI_SALESORDER_CHANGE, with the correct X structures, schedule line handling, error check and commit or rollback.
- SAP ECC BAPI_MATERIAL_SAVEDATA Material Creation ABAP GeneratorFill in material type, plant, sales and valuation data and get a complete ABAP report that creates the material with BAPI_MATERIAL_SAVEDATA and commits it.
ERP fixes and how-tos
- How to Use BAPI_TRANSACTION_COMMIT CorrectlyBAPIs never commit their own update. Here is when to call BAPI_TRANSACTION_COMMIT with WAIT, and why a BAPI can run fine and still save nothing.
- SAP MM BAPI for PO Create and Change: BAPI_PO_CREATE1 and BAPI_PO_CHANGEHow to use BAPI_PO_CREATE1 and BAPI_PO_CHANGE: header, item and schedule structures, the X-structures, error handling in RETURN and the commit step.
- How to add AI to SAP ECC 6.0 on-prem without moving data to a cloudReference architecture for a private on-prem AI assistant on SAP ECC 6.0: RFC and BAPI reads, SLT replica, retrieval index, local LLM, permission mirroring.
Integrations
- How to automate email into SAP ECC 6.0Turn inbound emails into SAP ECC 6.0 transactions: customer POs into sales orders, supplier confirmations, RFQs and invoices, with review and BAPI posting.
- How to add AI agents to SAP ECC 6.0How to add AI agents to SAP ECC 6.0: a tool layer over BAPIs, RFC and IDocs, human approval before any posting, and an on-prem model that never leaves your network.