SAP DBM Model Create BAPI

DBM Model Create BAPI HYPERLINK

Model Creation BAPIĀ /DBM/VM23_INT_CHANGE

“Type declaration
TYPES: BEGIN OF lty_adr6,
addrnumber TYPE ad_addrnum,
persnumber TYPE ad_persnum,
smtp_addr TYPE ad_smtpadr,
END OF lty_adr6,

BEGIN OF lty_usr21,
bname TYPE xubname,
addrnumber TYPE ad_addrnum,
persnumber TYPE ad_persnum,
END OF lty_usr21,

BEGIN OF lty_kna1,
kunnr TYPE kunnr,
adrnr TYPE adrnr,
END OF lty_kna1,

BEGIN OF lty_mvke,
kondm TYPE kondm,
provg TYPE provg,
END OF lty_mvke.

“Declaration of local tables, structures
DATA: ls_vmod TYPE /dbm/v_model,
ls_vmod_mara TYPE /dbm/v_mara,
ls_mara TYPE mara,
ls_vmodt TYPE /dbm/v_modelt,
lt_vmodt TYPE TABLE OF /dbm/v_modelt,
lt_vmod_opt TYPE TABLE OF /dbm/v_moptions,
lt_vmod_optt TYPE TABLE OF /dbm/v_moptionst,
lt_return TYPE TABLE OF bapiret2,
lv_maktx TYPE maktx,
lv_matnr TYPE matnr,
ls_return TYPE bapiret2,
lv_vmake TYPE kondm,
ls_mvke TYPE lty_mvke.

“declaration of local tables and workareas
DATA: lt_adr6 TYPE TABLE OF lty_adr6,
lt_usr21 TYPE TABLE OF lty_usr21,
ls_adr6 TYPE lty_adr6,
ls_usr21 TYPE lty_usr21,
ls_usr21_cust TYPE lty_usr21,
ls_adr6_cust TYPE lty_adr6,
ls_kna1_cust TYPE lty_kna1,

“Mail declaration
lt_err_handl TYPE TABLE OF zdbm_error_handl,
ls_err_handl TYPE zdbm_error_handl,
lv_documnet_data TYPE sodocchgi1,
lt_object_text TYPE TABLE OF solisti1,
ls_object_text TYPE solisti1,
lt_receivers_list TYPE TABLE OF somlreci1,
ls_receivers_list TYPE somlreci1,

lv_status1 TYPE c,
lv_status2 TYPE c,
lv_status3 TYPE c,
lv_status4 TYPE c,
lv_prod_guid TYPE comt_product_guid,
lv_modline TYPE dbm_modline.

“Fetch material details
SELECT SINGLE *
FROM mara
INTO ls_mara
WHERE matnr = iv_matnr.
IF sy-subrc = 0.
ls_vmod_mara-division = ls_mara-spart. “division
MOVE-CORRESPONDING ls_mara TO ls_vmod_mara.
ENDIF.

“Fetch material catalog based on division value
CASE ls_vmod_mara-division.
WHEN ’02’.
ls_vmod-mcatalog = ‘ETLD’.
WHEN ’03’.
ls_vmod-mcatalog = ‘ETMD’.
WHEN ’04’.
ls_vmod-mcatalog = ‘ETHD’.
WHEN ’05’.
ls_vmod-mcatalog = ‘EBLD’.
WHEN ’06’.
ls_vmod-mcatalog = ‘EBMD’.
WHEN ’07’.
ls_vmod-mcatalog = ‘EBHD’.
WHEN ‘P9’.
ls_vmod-mcatalog = ‘EPR8’.
ENDCASE.

“fetch Vehicle Make Code
SELECT SINGLE kondm provg
FROM mvke
INTO CORRESPONDING FIELDS OF ls_mvke
WHERE matnr = iv_matnr.

SELECT SINGLE iobjguid
FROM vlcvehicle
INTO lv_prod_guid
WHERE matnr = iv_matnr.
IF sy-subrc = 0.
SELECT SINGLE modline
FROM dbm_v_imodel
INTO lv_modline
WHERE product_guid = lv_prod_guid.
ENDIF.

ls_vmod-modline = lv_modline. “Modline
ls_vmod-vmake = ls_mvke-kondm. “vehicle Make code
ls_vmod-labval_ty = ls_mvke-provg. “LV main type
ls_vmod-mcodesd = iv_matnr. “Model Sales Code
ls_vmod-active = ‘X’.
ls_vmod-matnr = iv_matnr. “Material.
ls_vmod-mcodecs = iv_matnr. “Model Service Code
* ls_vmod-lifnr = ‘10001’. “dealer code
ls_vmod-lifnr = ‘10001’. “dealer code
ls_vmod-vmake = iv_kondm.
ls_vmod-purcprice = ‘1.00’.
ls_vmod-purcprice_c = ‘INR’.
ls_vmod-SALEPRICE = ‘1.00’.
ls_vmod-SALEPRICE_c = ‘INR’.
ls_vmod-LABVAL_TY = iv_provg.
* ls_vmod-MODLINE = ‘TIPPER’.
“Fetch material description
SELECT SINGLE maktx
FROM makt
INTO lv_maktx
WHERE matnr = iv_matnr
AND spras = ‘E’.
IF sy-subrc = 0.
ls_vmodt-motext1 = lv_maktx. ” ‘91.15 E FSD RHD STD GB’.
ENDIF.
ls_vmodt-spras = ‘E’.

* in case of tipper
data : lv_provg TYPE provg.
clear : lv_provg.
select single provg
from ZMM_TIPPER_GRP into lv_provg
where provg = iv_provg.

if sy-subrc = 0.
ls_vmod-modline = ‘TIPPER’.
endif.
APPEND ls_vmodt TO lt_vmodt.

“creation of vehicle model
CALL FUNCTION ‘/DBM/VM23_INT_CHANGE’
EXPORTING
is_vmod = ls_vmod
is_vmod_mara = ls_vmod_mara
iv_mat_mode = ‘3’
iv_create_allowed = ‘X’
iv_check_data = ‘X’
* IV_TESTRUN = ‘ ‘
* IS_VMOD_LT =
* IT_VMOD_OPT_LT =
* IMPORTING
* EV_MODEL_GUID =
* EV_MATERIAL =
TABLES
it_vmodt = lt_vmodt
it_vmod_opt = lt_vmod_opt
it_vmod_optt = lt_vmod_optt
et_return = lt_return
EXCEPTIONS
message_occured = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

“To commit BAPI
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
.

 

Leave a Reply

Your email address will not be published. Required fields are marked *