Change Classification data – BAPI_OBJCL_CHANGE
If you have a requirement to change the classification ( of batch or material or customer), this is how you can do it (along with a sample program).
- First, find the object key combination. (Hint – It is the combination of the key field which you use to find the classification data. Eg for material classification it is the full material number, for batch, it is material number + plant + batch number).
- Find the characteristic name for the value you want to change. (Hint – Look up examples for which the data is already populated and then find the ATNAM).
- Find the class name. Use the existing data to find the class name from the classification tables.
- The main classification data tables are AUSP and CABN.
- Find the mandatory characteristics and populate their value irrespective they are changing or not.
Now the sample program. As usual, the program is just a shell program and not an actual executable program:
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = lv_object
(Combination of the primary key for the actual object)
objecttable = lc_table (Usually, the header table of the actual object - MARA for material, MARC for material plant data)
classnum = lc_class (Find from existing data)
classtype = lc_classtype (Find from the existing data)
TABLES
allocvaluesnum = lt_num
(contains the numerical value)
allocvalueschar = lt_value
(contains the misc value)
allocvaluescurr = lt_curr
(contains the currency value)
return = lt_message.
Add or edit your characterstic value to appropriate table. Remember to check where your charactertic appear in these tables (lt_num, lt_Value and lt_curr) from the existing example.
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
objectkey = lv_object
objecttable = lc_Table
classnum = lc_class
classtype = lc_classtype
TABLES
allocvaluesnumnew = lt_num
(with edited value)
allocvaluescharnew = lt_value
(with edited value)
allocvaluescurrnew = lt_curr
(with edited value)
return = lt_message.
READ TABLE lt_message WITH KEY type = 'S' TRANSPORTING NO FIELDS.
IF sy-subrc NE 0.
" Error Handling
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
Please remember that ALLOC tables are not optional in the FM. You may skip the values which are not mandatory and not changing.
So this it is for today. Please leave comments if something does not work or if you find it useful.