2016 May 10 7:43 AM
Hi experts,
I'm working with BAPI_OBJCL_CHANGE to change batch characteristic value via program.
It works when characteristic value is empty before (new value is written into db).
But doesn't work when characteristic has a value before (isn't changed then..).
Does anyone know this issue?
Thanks
2016 May 10 9:39 AM
Hi Uwe,
please share a snippet of your code to help you.
This bapi is pretty simple once you know the right class and table to refer to and you remember to convert floats
The following code is working perfectly in my system to update a date characteristic
DATA: okey TYPE bapi1003_key-object,
otable TYPE bapi1003_key-objecttable VALUE 'MCH1',
classnum TYPE bapi1003_key-classnum VALUE 'PF',
classtype TYPE bapi1003_key-classtype VALUE '023'.
DATA: numnews TYPE TABLE OF bapi1003_alloc_values_num,
numnew TYPE bapi1003_alloc_values_num,
charnews TYPE TABLE OF bapi1003_alloc_values_char,
currnews TYPE TABLE OF bapi1003_alloc_values_curr,
bret TYPE TABLE OF bapiret2,
ret TYPE bapiret2.
DATA: atwrt TYPE atwrt.
CHECK ck_test IS INITIAL.
numnew-charact = 'ZDATAUM'.
atwrt = out-budat.
CALL FUNCTION 'CTCV_CONVERT_DATE_TO_FLOAT'
EXPORTING
date = atwrt
IMPORTING
float = numnew-value_from.
APPEND numnew TO numnews.
okey(18) = out-matnr.
okey+18(10) = out-charg.
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
objectkey = okey
objecttable = otable
classnum = classnum
classtype = classtype
TABLES
allocvaluesnumnew = numnews
allocvaluescharnew = charnews
allocvaluescurrnew = currnews
return = bret.
LOOP AT bret INTO ret WHERE type = 'E' OR type = 'A'.
out-message = ret-message.
EXIT.
ENDLOOP.
IF sy-subrc = 0.
out-status = icon_failure.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
out-status = icon_checked.
out-message = 'Batch classification updated'(001).
ENDIF.
2016 May 10 10:43 AM
Hi Simone,
below you'll find my code.
I must admit that I've been debugging in BAPI_OBJCL_CHANGE and found out this (Picture):
Here's my code, thank you.
llt.
*
CLEAR: get_objectkey,
get_objecttable,
get_classnum,
get_classtype,
get_keydate,
get_unvaluated_chars,
get_language,
get_status,
get_standardclass,
it_get_valnum,
it_get_valchar,
it_get_valcurr,
it_get_return.
CONCATENATE upd_matnr upd_charg into get_objectkey.
move 'MCH1' to get_objecttable.
move p_klasse to get_classnum.
move '023' to get_classtype.
move sy-datum to get_keydate.
move 'X' to get_unvaluated_chars.
move sy-langu to get_language.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
OBJECTKEY = get_objectkey
OBJECTTABLE = get_objecttable
CLASSNUM = get_classnum
CLASSTYPE = get_classtype
UNVALUATED_CHARS = get_unvaluated_chars
LANGUAGE = get_language
TABLES
ALLOCVALUESNUM = it_get_valnum
ALLOCVALUESCHAR = it_get_valchar
ALLOCVALUESCURR = it_get_valcurr
RETURN = it_get_return.
move get_objectkey to put_objectkey.
move get_objecttable to put_objecttable.
move get_classnum to put_classnum.
move get_classtype to put_classtype.
move '1' to put_status.
move ' ' to put_standardclass.
move ' ' to put_changenumber.
move sy-datum to put_keydate.
move 'X' to put_nodefvalues.
move 'X' to put_keepdefvalues.
move ' ' to put_class_status.
move it_get_valnum to it_put_valnum.
move it_get_valchar to it_put_valchar.
move it_get_valcurr to it_put_valcurr.
move it_get_return to it_put_return.
READ table it_put_valchar with key charact = 'ZO_FERT_EINSTUFUNG'
into wa_put_valchar.
move upd_quali to wa_put_valchar-value_char.
MODIFY table it_put_valchar FROM wa_put_valchar
TRANSPORTING value_char.
* Zurückschreiben der Chargenmerkmale (jetzt inkl. Einstufung)
*
CLEAR: it_put_return.
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
OBJECTKEY = put_objectkey
OBJECTTABLE = put_objecttable
CLASSNUM = put_classnum
CLASSTYPE = put_classtype
* STATUS = put_status
* STANDARDCLASS = put_standardclass
* CHANGENUMBER = put_changenumber
* KEYDATE = put_keydate
* NO_DEFAULT_VALUES = put_nodefvalues
* KEEP_SAME_DEFAULTS = put_keepdefvalues
* CLASSIF_STATUS = put_class_status
TABLES
ALLOCVALUESNUMnew = it_put_valnum
ALLOCVALUESCHARnew = it_put_valchar
ALLOCVALUESCURRnew = it_put_valcurr
RETURN = it_put_return.
*WICHTIG: Transaction Commit
COMMIT WORK.
CALL FUNCTION 'BUFFER_REFRESH_ALL'.
2016 May 10 11:14 AM
Hi Uwe, i'm missing a point: why do you read the old values?
Just try to fill IT_PUT_VALCHAR without reading the classification before, even forcing the value fix for the moment.
IT_PUT_RETURN which records contains? and IT_PUT_VALCHAR? It could be you already used IT_PUT_VALCHAR but you forgot to clear/refresh it?
2016 May 10 12:37 PM
This is because I read here (or another forum) that you always have to transmit all existing characteristics when using this bapi. Otherwise they'll be deleted from db.
Therefore I have to read them all at first..
Just debugging..
2016 May 10 1:48 PM
Hi Simone,
SOLVED. puh, hard stuff...
Error was a value in this field in communication structure:
-value_neutral. Therein was the old value from GET-Bapi and the CHANGE-Bapi could not recognize that a change has to be done.
After clearing like below it works.
Thank you very much for helping me.
Uwe
| move upd_quali | to wa_put_valchar-value_char. |
* Extrem WICHTIG !!! sonst erkennt der Fuba die Änderung nicht!
| Move ' ' | to wa_put_valchar-value_neutral. |
MODIFY table it_put_valchar FROM wa_put_valchar
| TRANSPORTING value_char value_neutral. |