06-06-2015 8:48 PM
Dear guys,
I am working on vendor master creation using the Method VMD_EI_API=>maintain_BAPI. It was working fine for most of the scenarios. Recently when we tried to execute I am getting an error stating " Transaction code was not intended. Enter Xk01 or Xk02" which is almost stopping my development. I am not sure how a BAPI trying to call this. Before posting I checked all the respective codes posted, but it is also giving me the same error. Your help will be much appreciated. Please share the thoughts.
Thanks,
Kalyan
06-07-2015 7:27 AM
Hi Kalyan,
Pls check how your code is differentiating the difference between create and update.
Im my view for update in header structure we need to pass vendor number .
If possible pls paste the code.
Regards,
Lokeswar reddy byni.
06-07-2015 6:43 PM
Hi ,
Thanks for the reply. I do pass the vendor number. Please find the code below. Hope that will give some idea. Here I am trying to pass the data to existing vendor.
Sample code:
CLASS lcl_data DEFINITION.
PUBLIC SECTION.
METHODS: constructor
IMPORTING
i_ccode TYPE bukrs
i_ktokk TYPE ktokk
i_akont TYPE akont
i_name TYPE ad_name1,
create_vendor_data
EXPORTING
e_lifnr TYPE lifnr.
PRIVATE SECTION.
METHODS: prepare_data
RETURNING VALUE(re_flag) TYPE i.
* Data Declarations
DATA: gs_vmds_extern TYPE vmds_ei_main,
gs_succ_messages TYPE cvis_message,
gs_vmds_error TYPE vmds_ei_main,
gs_err_messages TYPE cvis_message,
gs_vmds_succ TYPE vmds_ei_main,
gv_ktokk TYPE ktokk,
gv_ccode TYPE bukrs,
gv_akont TYPE akont,
gv_name TYPE name1.
ENDCLASS. "lcl_data
*----------------------------------------------------------------------*
* CLASS lcl_data IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_data IMPLEMENTATION.
METHOD constructor.
me->gv_ccode = i_ccode.
me->gv_ktokk = i_ktokk.
me->gv_akont = i_akont.
me->gv_name = i_name.
ENDMETHOD. "constructor
METHOD prepare_data.
* Local Data Declaration
DATA: lt_contacts TYPE vmds_ei_contacts_t,
ls_contacts TYPE vmds_ei_contacts,
lt_vendors TYPE vmds_ei_extern_t,
ls_vendors TYPE vmds_ei_extern,
ls_address TYPE cvis_ei_address1,
lt_company TYPE vmds_ei_company_t,
ls_company TYPE vmds_ei_company,
ls_company_data TYPE vmds_ei_vmd_company,
ls_purchas_data TYPE vmds_ei_vmd_purchasing,
lt_purchasing TYPE vmds_ei_purchasing_t,
ls_purchasing TYPE vmds_ei_purchasing,
lt_purch_func TYPE vmds_ei_functions_t,
ls_purch_func TYPE vmds_ei_functions,
ls_message TYPE cvis_message,
lv_contactid TYPE bapicontact_01-contact.
* Clear the work area initially.
CLEAR gs_vmds_extern.
ls_vendors-header-object_task = 'M'. "Represents Insert or Create
ls_vendors-header-object_instance-lifnr = '0200014021'.
* Set the Name
ls_address-postal-data-name = gv_name. "Name of the Vendor
ls_address-postal-data-street = 'Flat 101, ABS Road'.
ls_address-postal-data-city = 'MSP'.
ls_address-postal-data-postl_cod1 = '400062'.
ls_address-postal-data-region = '13'.
ls_address-postal-data-country = 'IN'.
ls_address-postal-data-sort1 = gv_name.
ls_address-postal-data-langu = sy-langu.
** For all the fields where value was provided, set the flag value also to be 'X'
ls_address-postal-datax-name = 'X'.
ls_address-postal-datax-street = 'X'.
ls_address-postal-datax-postl_cod1 = 'X'.
ls_address-postal-datax-region = 'X'.
ls_address-postal-datax-sort1 = 'X'.
ls_address-postal-datax-country = 'X'.
ls_address-postal-datax-langu = 'X'.
ls_address-task = 'I'.
ls_address-postal-datax-city = 'X'.
** Set the Address for the Vendor
ls_vendors-central_data-address = ls_address.
* Set Contact Person
REFRESH: lt_contacts[].
CLEAR ls_contacts.
ls_contacts-task = 'I'. "Represents Creation of Contact person
ls_contacts-address_type_3-task = 'I'. "Represents Creation of Address for CP
* Specify how many Contact Person numbers are to be obtained
* This will simply provide us a contact person number
CALL FUNCTION 'BAPI_PARTNEREMPLOYEE_GETINTNUM'
EXPORTING
quantity = '1'
IMPORTING
contactid = lv_contactid.
ls_contacts-data_key-parnr = lv_contactid. "Contact Person Number
* Set the Name for Contact person
ls_contacts-address_type_3-postal-data-fullname = 'John Smith'.
ls_contacts-address_type_3-postal-data-firstname = 'John'.
ls_contacts-address_type_3-postal-data-lastname = 'Smith.
APPEND ls_contacts TO lt_contacts.
* Set the Contact Person details for the Vendor
ls_vendors-central_data-contact-contacts = lt_contacts[].
* Set the Account Group
ls_vendors-central_data-central-data-ktokk = gv_ktokk.
ls_vendors-central_data-central-data-stcd1 = 'VAT 1'.
ls_vendors-central_data-central-data-kunnr = ls_vendors-header-object_instance-lifnr.
ls_vendors-central_data-central-datax-kunnr = 'X'.
ls_vendors-central_data-central-datax-ktokk = 'X'.
ls_vendors-central_data-central-datax-stcd1 = 'X'.
ls_vendors-central_data-central-datax-brsch = 'X'.
* Set the Company Code and GL Account
REFRESH: lt_company[].
CLEAR ls_company.
ls_company-task = 'I'.
ls_company-data_key-bukrs = gv_ccode.
ls_company-data-akont = gv_akont. "Reconciliation Account
ls_company-data-zuawa = '018'. "Sort Key
* ls_company-data-fdgrv = 'M1'. "Cash Management Group
ls_company-data-zterm = '0001'. "Payment Terms
ls_company-data-zwels = 'C'.
ls_company-datax-zwels = 'X'.
ls_company-datax-akont = 'X'.
ls_company-datax-zuawa = 'X'.
* ls_company-datax-fdgrv = 'X'.
ls_company-datax-zterm = 'X'.
ls_company-data-reprf = 'X'.
ls_company-datax-reprf = 'X'.
APPEND ls_company TO lt_company.
ls_company_data-company = lt_company[].
ls_vendors-company_data = ls_company_data.
** Set the Purchasing Data
* ls_purchasing-task = 'I'.
* ls_purchasing-data_key-ekorg = '1000'. "Purchasing Organization
* ls_purchasing-data-kalsk = '01'. "Schema Group, Vendor
* ls_purchasing-data-webre = 'X'. "GR Based Invoice Verification
* ls_purchasing-datax-kalsk = 'X'.
* ls_purchasing-datax-webre = 'X'.
* Set the Partner function for Purchase Organization Data
* Ordering Address
* REFRESH: lt_purchasing[],
* lt_purch_func[].
* CLEAR ls_purch_func.
* ls_purch_func-task = 'I'.
* ls_purch_func-data_key-parvw = 'BA'.
** We set the Vendor being created as "Ordering Address"
* ls_purch_func-data-partner = ls_vendors-header-object_instance-lifnr.
* ls_purch_func-datax-partner = 'X'.
* APPEND ls_purch_func TO lt_purch_func[].
*
** Invoicing Party
* CLEAR ls_purch_func.
* ls_purch_func-task = 'I'.
* ls_purch_func-data_key-parvw = 'RS'.
** We set the Vendor being created as "Invoicing Party"
* ls_purch_func-data-partner = ls_vendors-header-object_instance-lifnr.
* ls_purch_func-datax-partner = 'X'.
* APPEND ls_purch_func TO lt_purch_func[].
*** Vendor
** CLEAR ls_purch_func.
** ls_purch_func-task = 'I'.
** ls_purch_func-data_key-parvw = 'LF'.
*** We set the Vendor being created as "Vendor in Purchasing Partner Function"
** ls_purch_func-data-partner = ls_vendors-header-object_instance-lifnr.
** ls_purch_func-datax-partner = 'X'.
** APPEND ls_purch_func TO lt_purch_func[].
**
*** Set the Purchasing Data - Partner functions
** ls_purchasing-functions-functions = lt_purch_func[].
** APPEND ls_purchasing TO lt_purchasing.
**
*** Set the Purchasing Data
** ls_purchas_data-purchasing = lt_purchasing[].
** ls_vendors-purchasing_data = ls_purchas_data.
APPEND ls_vendors TO lt_vendors.
**
*** Set the Final Vendor Data based on which it has to be created
* Note if multiple vendors are to be created...please maintain multiple entries in LT_VENDORS
gs_vmds_extern-vendors = lt_vendors[].
ENDMETHOD. "prepare_data
METHOD create_vendor_data.
* Local Data Declaration
DATA: lv_return TYPE i.
* Prepare the data to be used for Vendor Creation
lv_return = me->prepare_data( ).
* Do not proceed if the Vendor Data for creation was not prepared
IF lv_return IS NOT INITIAL.
EXIT.
ENDIF.
* Initialize all the data
vmd_ei_api=>initialize( ).
* Call the Method for creation of Vendor.
CALL METHOD vmd_ei_api=>maintain_bapi
EXPORTING
is_master_data = gs_vmds_extern
IMPORTING
es_master_data_correct = gs_vmds_succ
es_message_correct = gs_succ_messages
es_master_data_defective = gs_vmds_error
es_message_defective = gs_err_messages.
IF gs_err_messages-is_error IS INITIAL.
commit work.
.
* Set the Vendor Number to be returned
IF sy-subrc = 0.
WRITE: 'Vendor is created'.
ENDIF.
ENDIF.
ENDMETHOD. "create_vendor_data
ENDCLASS. "lcl_data IMPLEMENTATION
SELECTION-SCREEN BEGIN OF BLOCK tb1.
PARAMETERS: p_ccode TYPE bukrs,
p_akont TYPE akont,
p_ktokk TYPE ktokk,
p_name TYPE ad_name1.
SELECTION-SCREEN END OF BLOCK tb1.
DATA: lo_data TYPE REF TO lcl_data,
gv_lifnr TYPE lifnr.
START-OF-SELECTION.
* Create an instance of our class
CREATE OBJECT lo_data
EXPORTING
i_ccode = p_ccode
i_akont = p_akont
i_ktokk = p_ktokk
i_name = p_name.
* Create Vendor and obtain the resultant error message and Vendor number
CALL METHOD lo_data->create_vendor_data
IMPORTING
e_lifnr = gv_lifnr.
Thanks,
Kalyan
06-08-2015 5:59 AM
Try with the below code :
This may helpful...
FUNCTION YBPM_G_VENDOR_CREATE_CHANGE_IN.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IM_LIFNR) TYPE LIFNR OPTIONAL
*" VALUE(IM_BUKRS) TYPE BUKRS
*" VALUE(IM_EKORG) TYPE EKORG
*" VALUE(IM_KTOKK) TYPE KTOKK
*" VALUE(IM_TEST) TYPE XFELD
*" VALUE(IM_LFA1) TYPE LFA1
*" VALUE(IM_ADRC) TYPE ADRC
*" VALUE(IM_ADR6) TYPE ADR6
*" VALUE(IM_LFBK) TYPE LFBK
*" VALUE(IM_LFB1) TYPE LFB1
*" VALUE(IM_LFM1) TYPE LFM1
*" EXPORTING
*" VALUE(EX_VENDOR) TYPE LIFNR
*" TABLES
*" I_RETURN TYPE BAPIRET2_T
*" I_CONTACT STRUCTURE ZBPM_0090CONTACT_ST
*" I_SUBRANGE STRUCTURE WYT1T
*" I_ADRC STRUCTURE ADRC
*" I_WYT3 STRUCTURE WYT3
*" I_VERSIONS STRUCTURE BAPIAD1VD
*" I_TEL STRUCTURE ZBPM_0090TEL_ST
*" I_FAX STRUCTURE ZBPM_0090FAX_ST
*" I_EMAIL STRUCTURE ZBPM_0090EMAIL_ST
*" I_CONT_TEL STRUCTURE ZBPM_0090TELCONT_ST
*" I_CONT_FAX STRUCTURE ZBPM_0090FAXCONT_ST
*" I_CONT_EMAIL STRUCTURE ZBPM_0090EMAILCONT_ST
*" I_LFAZ STRUCTURE LFZA
*" I_LFBW STRUCTURE LFBW
*" I_MOB STRUCTURE ZBPM_0090TEL_ST
*" I_CONT_MOB STRUCTURE ZBPM_0090TELCONT_ST
*" IT_BANK STRUCTURE LFBK
*" I_URI STRUCTURE ZBPM_0090URI_ST
*"----------------------------------------------------------------------
DATA: li_wyt1 TYPE ty_t_fwyt1,
li_wyt1t TYPE ty_t_fwyt1t,
li_lfm2 TYPE ty_t_flfm2,
li_wyt3 TYPE TABLE OF fwyt3,
li_lflr TYPE TABLE OF flflr,
li_knvk TYPE TABLE OF fknvk,
lw_master TYPE vmds_ei_main,
lw_masterpas TYPE vmds_ei_main,
lw_correct TYPE cvis_message,
lw_masterdef TYPE vmds_ei_main,
*add for delete
lw_master2 TYPE vmds_ei_main,
*end add for delete.
lw_vendor TYPE vmds_ei_extern,
lw_vendor2 TYPE vmds_ei_extern,
lw_error TYPE cvis_message,
lw_error2 TYPE cvis_message,
lw_vend TYPE ty_vend,
lw_messages TYPE bapiret2,
lv_lifnr TYPE lifnr,
lv_adrnr TYPE lfa1-adrnr,
lw_return TYPE bapiret2,
lw_contact TYPE vmds_ei_contacts,
subrc TYPE sy-subrc
.
FIELD-SYMBOLS: <fs_vend> TYPE ty_vend.
CLEAR : gi_vend[],
gi_subr[],
gi_cont[],
li_knvk[],
li_wyt1[],
li_wyt1t[]
.
lw_vend-lifnr = im_lifnr.
lv_lifnr = im_lifnr.
lw_vend-bukrs = im_bukrs.
lw_vend-ekorg = im_ekorg.
lw_vend-central-ktokk = im_ktokk.
IF im_lifnr CP 'T*'.
CLEAR :lv_lifnr, lw_vend-lifnr."
ENDIF.
PERFORM validate USING im_lfa1
CHANGING lw_return.
IF lw_return IS INITIAL.
PERFORM prepare_data TABLES gi_cont
i_contact
i_subrange
i_adrc
i_wyt3
i_versions
i_lfbw
it_bank
USING im_lfa1
im_adrc
im_adr6
im_lfbk
im_lfb1
* im_lfbw
im_lfm1
CHANGING lw_vend
.
lw_vend-bukrs = im_bukrs.
lw_vend-ekorg = im_ekorg.
lw_vend-central-ktokk = im_ktokk.
IF lw_vend IS NOT INITIAL.
APPEND lw_vend TO gi_vend.
ENDIF.
LOOP AT gi_vend ASSIGNING <fs_vend>.
IF <fs_vend>-central IS NOT INITIAL.
CALL METHOD vmd_ei_api=>initialize.
CALL FUNCTION 'VMD_ADDR_POST_CLEAR'.
PERFORM general_data TABLES i_adrc
USING gi_cont
* gi_fax
i_fax[]
* gi_tel
i_tel[]
* gi_mail
i_email[]
i_uri[] "(+)DEV-MONRUEDB
gi_dline
lv_lifnr
i_mob[]
it_bank[]
CHANGING <fs_vend>
lw_vendor-central_data
lw_vendor-header-object_task.
* IF gi_cont[] IS NOT INITIAL.
IF i_contact[] IS NOT INITIAL.
PERFORM contact_person USING i_contact[]
* gi_fax
i_cont_fax[]
* gi_tel
i_cont_tel[]
* gi_mail
i_cont_email[]
* <fs_vend>-lifnr"(-)DEV-MONRUEDB
lv_lifnr "(+)DEV-MONRUEDB
im_test
i_cont_mob[]
CHANGING
lw_vendor-central_data-contact-contacts
li_knvk
subrc .
ENDIF.
ENDIF.
IF <fs_vend>-bukrs IS NOT INITIAL.
PERFORM company_data TABLES i_lfbw
USING <fs_vend>
lv_lifnr
CHANGING lw_vendor-company_data.
ENDIF.
IF <fs_vend>-ekorg IS NOT INITIAL.
PERFORM purchasing_data TABLES i_wyt3
USING <fs_vend>
lv_lifnr
im_ktokk
CHANGING lw_vendor-purchasing_data.
IF gi_subr[] IS NOT INITIAL.
.
PERFORM vendor_subrange USING gi_subr[]
lv_lifnr
CHANGING lw_vendor-central_data-subrange
.
ENDIF.
ENDIF.
IF lw_vendor IS NOT INITIAL .
* Get existing vendor no
SELECT SINGLE adrnr
INTO lv_adrnr
FROM lfa1
WHERE lifnr EQ im_lifnr.
IF sy-subrc EQ 0.
lw_vendor-header-object_task = 'U'.
ELSE.
* clear lw_vendor.
lw_vendor-header-object_task = 'I'.
ENDIF.
ENDIF.
IF lw_vendor IS NOT INITIAL.
lw_vendor-header-object_instance-lifnr = lv_lifnr." im_lifnr.
"Vendor no.
* lw_vendor-central_data-CONTACT-SORTL = IM_LFA1-SORTL.
* lw_vendor-central_data
READ TABLE lw_vendor-central_data-contact-contacts TRANSPORTING
NO FIELDS
WITH KEY task = 'U'.
IF sy-subrc EQ 0.
lw_vendor-central_data-contact-current_state = 'X'.
ENDIF.
lw_vendor2 = lw_vendor.
DELETE lw_vendor-central_data-contact-contacts
WHERE task EQ 'D'.
APPEND lw_vendor TO lw_master-vendors.
ENDIF.
* delete contact
IF lw_vendor2 IS NOT INITIAL.
READ TABLE lw_vendor2-central_data-contact-contacts
TRANSPORTING NO FIELDS
WITH KEY task = 'D'.
IF sy-subrc EQ 0.
PERFORM assign_contact_to_delete USING lw_vendor2
CHANGING lw_master2.
PERFORM delete_contact TABLES li_knvk[]
USING im_test
lw_master2
CHANGING lw_error2.
i_return[] = lw_error2-messages[].
ENDIF.
ENDIF.
* Create vendor
IF lw_master IS NOT INITIAL AND lw_error2-is_error IS INITIAL.
CALL METHOD vmd_ei_api=>maintain_bapi
EXPORTING
iv_test_run = ' '
iv_collect_messages = 'X'
is_master_data = lw_master
IMPORTING
es_master_data_correct = lw_masterpas
es_message_correct = lw_correct
es_master_data_defective = lw_masterdef
es_message_defective = lw_error.
IF lw_error-is_error IS INITIAL .
READ TABLE lw_masterpas-vendors INTO lw_vendor INDEX 1.
ex_vendor = lw_vendor-header-object_instance-lifnr.
IF i_lfaz[] IS NOT INITIAL.
PERFORM update_permitt TABLES i_lfaz
USING ex_vendor.
ENDIF.
IF im_test IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
PERFORM maintain_address TABLES i_adrc[]
USING ex_vendor.
* PERFORM maintain_contact TABLES i_contact
* USING im_lfa1-kunnr.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* wait = 'X'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
i_return[] = lw_error-messages[].
ENDIF.
ENDIF.
ENDLOOP.
ELSE.
APPEND lw_return TO i_return.
ENDIF.
ENDFUNCTION.
Regards,
Lokeswar Reddy Byni.
03-22-2016 8:35 AM
Hi Lokeshwar,
Can you please send me the list of the fields you have used in some "Z" structures in tables parameter of this FM. I have a similar requirement.
Thanks and Regards,
Mohammed Farooq
03-22-2016 8:35 AM
06-08-2015 2:39 PM
Could you set a break-point at start of static method VMD_EI_API=>SET_TRANSACTION_CODE?
Regards,
Raymond
06-08-2015 5:24 PM
Hi Raymond / Lokeshwar,
Thanks for helping me. In debugger it is not stopping at the method mentioned. I am getting the error at the below mentioned methods.
METHOD-->MAINTAIN_SINGLE : this is the method it is going through
vmd_ei_api_memory=>read_current_lfa1: Here it is failing to check the t code.
In the below , it is failing due to non receipt of the T code.
CALL METHOD vmd_ei_api=>complete_and_check
EXPORTING
is_lfa1_new = ls_lfa1_new
is_lfa1_old = ls_lfa1_old
iv_tcode = lv_tcode
iv_collect_messages = iv_collect_messages
IMPORTING
es_error = ls_error
CHANGING
cs_vend_flags = ls_vend_flags.
Hope this gives you to find some issue.
06-09-2015 7:30 AM
The tcode should have been set in the lines immediately before those ones, could you check in your systeme, and if not set, look for suitable OSS notes.
***********************************************************************
* Set TCODE
***********************************************************************
if ls_lfa1_old is initial.
* Insert
lv_tcode = gc_tcode_create.
lv_upd_lfa1 = 'I'.
else.
* in LFA1 no deletion is possible =>
* Update
lv_tcode = gc_tcode_change.
lv_upd_lfa1 = 'U'.
endif.
***********************************************************************
* Complete and check
***********************************************************************
call method vmd_ei_api=>complete_and_check
Nb: constants should be XK01 and XK02
Regards,
Raymond