DBM Vehicle Creation & PO Creation

Vehicle Creation & PO Creation in Single Click. HYPERLINK

In SAP DBM creating a vehicle and its Purchase Order (PO) is a two Step process.

We can club the process into single step using the BAPI. SAP DBM Vehicle Upload and Vehicle PO creation.

Two BAPI which will be helpful in creation of Vehicle and its PO are as under:-

  1. /DBM/VM20_RFC_CREATE : Vehicle Creation BAPI, SAP DBM Vehicle Creation BAPI. This BAPI is useful for the transactions /DBM/VM and /DBM/MASSACTIONS.
  2. VELO09_SET_ACTION           : To execute an DBM actions, PO Creation in DBM (QORB).

Source Code Helpful:-

TYPES: BEGIN OF lty_guid,
return_guid TYPE vlc_guid,
END OF lty_guid.
DATA: lt_guid TYPE TABLE OF lty_guid,
ls_guid TYPE lty_guid.
DATA: return_guid TYPE vlc_guid,
lt_head_rfc TYPE TABLE OF /dbm/vlcactdata_head_rfc,
ls_head_rfc TYPE /dbm/vlcactdata_head_rfc,
lt_item_rfc TYPE TABLE OF /dbm/vlcactdata_item_rfc,
ls_item_rfc TYPE /dbm/vlcactdata_item_rfc.
DATA :lt_obj TYPE TABLE OF /dbm/iobj_data_single_com_rfc,
ls_obj TYPE /dbm/iobj_data_single_com_rfc.
DATA : returnmes LIKE bapi_matreturn2 OCCURS 0 WITH HEADER LINE.
DATA: lv_model_guid TYPE dbm_model_guid.

” Selecting Model data
SELECT SINGLE model_guid FROM /dbm/v_model
INTO lv_model_guid WHERE matnr = gs_output-mcodesd. (Pass Model Number)

ls_obj-modguid = lv_model_guid.
ls_head_rfc-dbm_bustype = ‘NEC’.
ls_head_rfc-werks = gs_output-werks.
ls_head_rfc-matnr = gs_output-mcodesd.
ls_head_rfc-spart = gs_output-/dbm/spart.

” Vehcile create program
CALL FUNCTION ‘/DBM/VM20_RFC_CREATE’
EXPORTING
is_vlcactdata_h_rfc = ls_head_rfc
* is_vlcactdata_i_rfc = ls_item_rfc
iv_category_id = ‘DBM_PASSENGERCAR’
is_iobj_data_single_com_rfc = ls_obj
IMPORTING
ev_vguid = return_guid
TABLES
et_return = returnmes.
READ TABLE returnmes WITH KEY type = ‘E’.
IF sy-subrc NE 0.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’.
* EXPORTING
* wait = ‘X’.
ls_guid-return_guid = return_guid.
APPEND ls_guid TO lt_guid.
CLEAR: ls_guid.
ELSE.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.
MESSAGE returnmes-message TYPE ‘E’ DISPLAY LIKE ‘I’.
ENDIF.
ENDDO.
*—“For PO Creation
IF lt_guid IS NOT INITIAL.
TYPES: BEGIN OF lty_ekpo,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
netpr TYPE netpr,
bwtar TYPE bwtar_d,
END OF lty_ekpo.

DATA: ls_ekpo TYPE lty_ekpo,
lt_ekpo TYPE TABLE OF lty_ekpo.

DATA: iv_ndp TYPE konv-kwert.
DATA: ev_netpr TYPE kwert.
DATA: vlcactdata_cs TYPE vlcactdata,
ls_veh TYPE vlcvehicle,
lt_veh TYPE TABLE OF vlcvehicle,
ls_vehicle TYPE vlcdiavehi,
lt_vehicle TYPE TABLE OF vlcdiavehi,
lv_vhvin TYPE vlc_vhvin.

DATA: ls_accdata TYPE vlcactdata_item_s.
DATA: lt_accdata TYPE vlcactdata_item_t.
DATA: lt_msgs TYPE vlch_mssg_pt.
DATA: ls_msgs TYPE vlch_mssg_ps.
CLEAR: lt_vehicle, lt_veh.
CLEAR: vlcactdata_cs.
CLEAR: lt_msgs.
REFRESH: lt_msgs.

” Vehvicle Data Selection
SELECT * FROM vlcvehicle
INTO CORRESPONDING FIELDS OF TABLE lt_veh
FOR ALL ENTRIES IN lt_guid WHERE
vguid = lt_guid-return_guid.

*—-Preparing Data to create PO
LOOP AT lt_veh INTO ls_veh.
MOVE-CORRESPONDING ls_veh TO ls_vehicle.
MOVE-CORRESPONDING ls_veh TO ls_accdata.
MOVE-CORRESPONDING ls_vehicle TO ls_accdata.
MOVE-CORRESPONDING ls_vehicle TO vlcactdata_cs.
vlcactdata_cs-ekorg = gs_output-ekorg.
vlcactdata_cs-ekgrp = gs_output-ekgrp.
vlcactdata_cs-bstyp = ‘F’.
vlcactdata_cs-bsart = gs_output-bsart.
vlcactdata_cs-currency = gs_output-waers.
vlcactdata_cs-eindt = gs_output-eindt.
vlcactdata_cs-lifnr = gs_output-lifnr.
ls_accdata-eindt_changed = gs_output-eindt.
ls_accdata-item_currency = gs_output-waers.
ls_accdata-netpr = ‘100000’.
ls_accdata-value_waers = gs_output-waers.

ls_vehicle-mmdatu = sy-datum.
ls_vehicle-mmtime = sy-uzeit.

APPEND ls_vehicle TO lt_vehicle.
APPEND ls_accdata TO lt_accdata.
APPEND ls_accdata TO vlcactdata_cs-actdata_item.
CLEAR: ls_veh, ls_vehicle, ls_accdata.
ENDLOOP.

REFRESH: lt_msgs.
“Create PO
CALL FUNCTION ‘VELO09_SET_ACTION’
EXPORTING
incoming_action_iv = ‘QORB’
commit_iv = ‘A’
TABLES
vlcdiavehi_ct = lt_vehicle
vlch_mssg_et = lt_msgs
CHANGING
vlcactdata_cs = vlcactdata_cs
EXCEPTIONS
action_not_defined = 1
no_authority = 2
interlinked_action_error = 3
crea_prepare_failed = 4
action_not_performed = 5
action_not_compl_performed = 6
OTHERS = 7.
*

 

Leave a Reply

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