SAP ABAP - Update Material MRP3 Characteristics
SELECT matnr, werks, cuobj, stdpd
INTO TABLE @DATA(lt_marc)
FROM marc
WHERE matnr = @lv_matnr.
LOOP AT lt_marc REFERENCE INTO DATA(lr_marc).
DATA : lt_cucfg TYPE TABLE OF e1cucfg,
lt_cuins TYPE TABLE OF e1cuins,
lt_cuval TYPE TABLE OF e1cuval,
lt_cucom TYPE TABLE OF e1cucom,
lt_cucfg_w TYPE TABLE OF e1cucfg,
lt_cuins_w TYPE TABLE OF e1cuins,
lt_cuval_w TYPE TABLE OF e1cuval,
lt_cucom_w TYPE TABLE OF e1cucom,
lt_cucfg_v TYPE TABLE OF e1cucfg,
lt_cuins_v TYPE TABLE OF e1cuins,
lt_cuval_v TYPE TABLE OF e1cuval,
lt_cucom_v TYPE TABLE OF e1cucom,
lt_return TYPE bapiret2_t,
ls_bapi_return TYPE bapiret2,
lt_bapi_return TYPE TABLE OF bapi_matreturn2.
CALL FUNCTION 'CUXM_GET_CONFIGURATION'
EXPORTING
instance = lr_marc->cuobj
werks = lr_marc->werks
IMPORTING
et_return = lt_return
TABLES
t_e1cucfg = lt_cucfg
t_e1cuins = lt_cuins
t_e1cuval = lt_cuval
t_e1cucom = lt_cucom
EXCEPTIONS
instance_not_found = 1
internal_error = 2
instance_is_a_classification = 3
OTHERS = 4.
IF sy-subrc <> 0.
CONTINUE.
ENDIF.
IF lt_cuval[] IS NOT INITIAL.
lt_atnams[] = VALUE #( FOR wa IN lt_cuval
( atnam = wa-charc )
).
SELECT * FROM cabn
INTO TABLE @DATA(lt_cabn)
FOR ALL ENTRIES IN @lt_atnams
WHERE atnam = @lt_atnams-atnam.
ENDIF.
lt_cucfg_v[] = lt_cucfg_w[] = lt_cucfg[].
lt_cuins_v[] = lt_cuins_w[] = lt_cuins[].
lt_cuval_v[] = lt_cuval_w[] = lt_cuval[].
lt_cucom_v[] = lt_cucom_w[] = lt_cucom[].
IF NOT line_exists( lt_return[ type = 'E' ] ) OR
line_exists( lt_return[ type = 'A' ] ).
LOOP AT lt_cuval_w REFERENCE INTO DATA(lr_cuval)
WHERE inst_id = '00000001'.
READ TABLE lt_cabn REFERENCE INTO DATA(lr_cabn)
WITH KEY atnam = lr_cuval->charc.
IF sy-subrc = 0.
CASE lr_cabn->atfor.
WHEN 'NUM' OR 'CURR'.
lr_cuval->value = <set value with atflv format>
lr_cuval->value_long = <set value with atflv format>
CONDENSE : lr_cuval->value,lr_cuval->value_long.
WHEN OTHERS.
lr_cuval->value = <set value with atwrt format>
lr_cuval->value_long = <set value with atwrt format>
CONDENSE : lr_cuval->value,lr_cuval->value_long.
ENDCASE.
ENDIF.
ENDLOOP.
ENDIF.
CALL FUNCTION 'MATERIAL_SAVE_CONFIGURATION'
EXPORTING
material = lr_marc->matnr
plant = lr_marc->werks
conf_matl_plant = lr_marc->stdpd
IMPORTING
return = ls_bapi_return
TABLES
e1cucfg_w = lt_cucfg_w
e1cuins_w = lt_cuins_w
e1cuval_w = lt_cuval_w
e1cucom_w = lt_cucom_w
returnmessages = lt_bapi_return.
CALL FUNCTION 'ZKRZ_FM_UPDATE_MAT_CONF_JOB' STARTING NEW TASK 'ABC'
EXPORTING
iv_matnr = lr_marc->matnr
iv_werks = lr_marc->werks.
ENDLOOP.
We have to submit program 'RCUUPDMATVAR' for updating all standard tables
( T-Code : CUUPDMV ) .
If we dont use it, you can see correct value on Material MRP3 view ( MM03/MM02) but
some table hasnt updated correctly.
We should create a background job with some delay. Because, FM MATERIAL_SAVE_CONFIGURATION is locking material master with some time.
Without delay, program is giving lock material error.
With this idea, I created a FM 'ZKRZ_FM_UPDATE_MAT_CONF_JOB'
FUNCTION zkrz_fm_update_mat_conf_job.
*"----------------------