*&---------------------------------------------------------------------*
*& Report ZSRM_BP_CREATE
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
report zsrm_bp_create.
tables: but000, addr1_data, sza11_0100."bupa_crm101.
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.
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_main 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.
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.
clear gs_main.
* ls_vendors-header-object_instance-lifnr = '0000100048'.
* call method vmd_ei_api=>get_number
* exporting
* iv_ktokk = gv_ktokk
* importing
* ev_lifnr = ls_vendors-header-object_instance-lifnr
* es_error = ls_message.
data: gv_partner_guid type bu_partner_guid.
clear gv_partner_guid.
select single partner_guid from but000 into gv_partner_guid
where partner = but000-partner.
select single vendor from cvi_vend_link into ls_vendors-header-object_instance-lifnr
where partner_guid = gv_partner_guid.
ls_vendors-header-object_task = 'M'. "represents insert or create
ls_address-postal-data-name = gv_name. "name of the vendor
ls_address-postal-data-street = 'LSI Logic Storage System, Inc'.
ls_address-postal-data-postl_cod1 = '466303'.
ls_address-postal-data-region = '190'.
ls_address-postal-data-country = 'CN'.
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'.
* 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
* NOTE: If the note 1749700 is present in the system, then the contact person number can be left empty
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 DOE'.
ls_contacts-address_type_3-postal-data-firstname = 'JOHN'.
ls_contacts-address_type_3-postal-data-lastname = 'DOE'.
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-brsch = '18'. "industry key
* Set the DATAX flags
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-datax-akont = 'X'.
* ls_company-datax-zuawa = 'X'.
* ls_company-datax-fdgrv = 'X'.
ls_company-datax-zterm = '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 = 'Z001'. "purchasing organization
ls_purchasing-data-waers = 'USD'.
ls_purchasing-data-verkf = '刑刚'.
ls_purchasing-data-telf1 = '13925135205'.
* ls_purchasing-data-kalsk = '01'. "schema group, vendor
* ls_purchasing-data-webre = 'X'. "gr based invoice verification
ls_purchasing-datax-waers = 'X'.
ls_purchasing-datax-verkf = 'X'.
ls_purchasing-datax-telf1 = '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_main-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_main
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.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
message 'success' type 'S'.
* commit work.
* Set the Vendor Number to be returned
endif.
endmethod.
"create_vendor_data
endclass. "lcl_data implementation
* Tables
* Constants
constants cc_type_cpf like dfkkbptaxnum-taxtype value 'BR2'.
constants cc_type_cnpj like dfkkbptaxnum-taxtype value 'BR1'.
* Variables and Structures
data file_in like rlgrap-filename.
*data ls_sales type bapibus1006_sales_area.
data bapi_bptyp type bapibus1006_head.
data bapi_address type bapibus1006_address.
data bapi_data type bapibus1006_central.
data bapi_data_org type bapibus1006_central_organ.
data bapi_adtel type bapiadtel occurs 10 with header line.
data bapi_adfax type bapiadfax occurs 10 with header line.
data bapi_adsmtp type bapiadsmtp occurs 10 with header line.
data bapi_ret type bapiret2 occurs 10 with header line.
data bapi_guid type but020-guid.
data gv_role like bapibus1006_head-partnerrole.
*data bapi_sales_class type bapibus1006040_salesclass.
data bapi_tax type bapibus1006tax.
data gv_partner type but000-partner.
data gv_error(1).
* Record layout for PC file
data: begin of itab occurs 0,
group like but000-bu_group, "业务伙伴分组
name1 like but000-name_org1, "组织名称 1
name2 like but000-name_org2, "组织名称 2
name3 like but000-name_org3, "组织名称 3
name4 like but000-name_org4, "组织名称 4
searchterm1 like but000-bu_sort1, "业务伙伴的搜索词 1
searchterm2 like but000-bu_sort2, "业务伙伴的搜索词 2
street like addr1_data-street, "街道
house_num like addr1_data-house_num1, "门牌号
postl_cod1 like addr1_data-post_code1, "城市邮政编码
city like addr1_data-city1, "城市
country like addr1_data-country, "国家/地区代码
region like addr1_data-region, "地区(省/自治区/直辖市、市、县)
langu like addr1_data-langu, "语言代码
tel_number like sza11_0100-tel_number, "第一个电话号码:区号 + 号码
tel_extens like sza11_0100-tel_extens, "第一个电话号码:分机号
mob_number like sza11_0100-mob_number, "第一个移动电话号码:区号 + 电话号码
fax_number like sza11_0100-fax_number, "第一个传真号: 拨号 + 编号
fax_extens like sza11_0100-fax_extens, "第一个传真号: 分机号
smtp_addr like sza11_0100-smtp_addr, "电子邮件地址
bpext like but000-bpext, "外部系统中的业务伙伴编号
cpf like dfkkbptaxnum-taxnum, "业务合作伙伴税号
cnpj like dfkkbptaxnum-taxnum,
prospect(1),
* other_org(1),
* customer(1),
* consumer(1),
* competitor(1),
* property(1),
* department(1),
* prestador(1),
* sales_org like bupa_crm101-sales_org,
* channel like bupa_crm101-channel,
* division like bupa_crm101-division,
end of itab.
data: excel_tab like itab occurs 0 with header line.
* Cells in Flat Structure for Flexible Excel Upload
*data excel_tab like yexcelstruc occurs 0 with header line.
* Parameters selection
*selection-screen begin of block b1 with frame title text-001.
*parameters: p_filein like rlgrap-filename obligatory.
*selection-screen skip 1.
*selection-screen end of block b1.
*
** Events
*at selection-screen on value-request for p_filein.
*
* call function 'KD_GET_FILENAME_ON_F4'
* exporting
* static = 'X'
* changing
* file_name = p_filein.
* Program Init
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 = 'Z001'
i_akont = '2001000001'
i_ktokk = 'KRED'
i_name = 'test1234567890'.
*
* Upload Data from EXCEL
perform f_upload_excel.
* Create BP
if not itab[] is initial.
call function 'MESSAGES_INITIALIZE'.
perform f_create_bp.
endif.
*Create Vendor and obtain the resultant error message and Vendor number
call method lo_data->create_vendor_data
importing
e_lifnr = gv_lifnr.
if sy-subrc = 0.
endif.
end-of-selection.
* Display log
perform f_show_messages.
*&---------------------------------------------------------------------*
*& Form rollback_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form rollback_data .
call function 'BAPI_TRANSACTION_ROLLBACK'.
call function 'BUP_MEMORY_ADDRESS_INIT'.
call function 'BUP_MEMORY_CENTRAL_INIT'.
endform. "" rollback_data
*&---------------------------------------------------------------------*
*& Form f_upload_excel
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form f_upload_excel .
* Upload Data from EXCEL
* call function 'Y_UPLOAD_EXCEL_BY_OLE'
* exporting
* infile = p_filein
* max_col = '256'
* max_row = '65000'
* tables
* excel_tab = excel_tab
* exceptions
* inconsistent_parameters = 1
* error_create_object = 2
* error_call_method = 3
* error_get_property = 4
* error_opening_file = 5
* others = 6.
*
** Excel Upload Error
* if not sy-subrc is initial.
* message i019.
* exit.
* endif.
* Move Data Upload into the ITAB file
* clear itab. refresh itab.
* sort excel_tab.
* loop at excel_tab.
* at new zrow. clear itab. endat.
* case excel_tab-zcol.
* when 1. itab-group = excel_tab-zvalue.
* when 2. itab-name1 = excel_tab-zvalue.
* when 3. itab-name2 = excel_tab-zvalue.
* when 4. itab-name3 = excel_tab-zvalue.
* when 5. itab-name4 = excel_tab-zvalue.
* when 6. itab-searchterm1 = excel_tab-zvalue.
* when 7. itab-searchterm2 = excel_tab-zvalue.
* when 8. itab-street = excel_tab-zvalue.
* when 9. itab-house_num = excel_tab-zvalue.
* when 10. itab-postl_cod1 = excel_tab-zvalue.
* when 11. itab-city = excel_tab-zvalue.
* when 12. itab-country = excel_tab-zvalue.
* when 13. itab-region = excel_tab-zvalue.
* when 14. itab-langu = excel_tab-zvalue.
* when 15. itab-tel_number = excel_tab-zvalue.
* when 16. itab-tel_extens = excel_tab-zvalue.
* when 17. itab-mob_number = excel_tab-zvalue.
* when 18. itab-fax_number = excel_tab-zvalue.
* when 19. itab-fax_extens = excel_tab-zvalue.
* when 20. itab-smtp_addr = excel_tab-zvalue.
* when 21. itab-bpext = excel_tab-zvalue.
* when 22. itab-cpf = excel_tab-zvalue.
* when 23. itab-cnpj = excel_tab-zvalue.
* when 24. itab-sales_org = excel_tab-zvalue.
* when 25. itab-channel = excel_tab-zvalue.
* when 26. itab-division = excel_tab-zvalue.
* when 27. itab-prospect = excel_tab-zvalue.
* when 28. itab-other_org = excel_tab-zvalue.
* when 29. itab-customer = excel_tab-zvalue.
* when 30. itab-consumer = excel_tab-zvalue.
* when 31. itab-competitor = excel_tab-zvalue.
* when 32. itab-property = excel_tab-zvalue.
* when 33. itab-department = excel_tab-zvalue.
* when 34. itab-prestador = excel_tab-zvalue.
* endcase.
* at end of zrow.
* append itab.
* endat.
* endloop.
itab-group = '0001'.
itab-name1 = '测试创建BPwangxy_3'.
itab-name2 = ''.
itab-name3 = ''.
itab-name4 = ''.
itab-searchterm1 = 'SRM'.
itab-searchterm2 = ''.
itab-street = '金山大道'.
itab-house_num = '0123456789'.
itab-postl_cod1 = '511400'.
itab-city = '广州'.
itab-country = 'CN'.
itab-region = '190'.
itab-langu = '1'.
itab-tel_number = '010-1234567'.
itab-tel_extens = ''.
itab-mob_number = '13213330000'.
itab-fax_number = ''.
itab-fax_extens = ''.
itab-smtp_addr = '123128381728@google.com'.
itab-bpext = ''.
itab-cpf = ''.
itab-cnpj = ''.
itab-prospect = 'X'."add role
append itab.
* itab-other_org = ''.
* itab-customer = ''.
* itab-consumer = ''.
* itab-competitor = ''.
* itab-property = ''.
* itab-department = ''.
* itab-prestador = ''.
endform. "" f_upload_excel
*&---------------------------------------------------------------------*
*& Form f_create_bp
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form f_create_bp .
loop at itab.
* Header of colums in Excel Table
* if sy-tabix = 1 or sy-tabix = 2.
* continue.
* endif.
* Validation of the CNPJ
if not itab-cnpj is initial.
clear gv_partner.
select partner taxnum into (gv_partner,bapi_tax-taxnumber)
from dfkkbptaxnum up to 1 rows
where taxtype = cc_type_cnpj
and taxnum = itab-cnpj.
endselect.
if sy-subrc = 0.
call function 'MESSAGE_STORE'
exporting
arbgb = 'ZBR_CRM'
msgty = 'E'
msgv1 = itab-cnpj
msgv2 = gv_partner
txtnr = '001'
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
continue.
endif.
endif.
* Validation of the CPF
if not itab-cpf is initial.
clear gv_partner.
select partner taxnum into (gv_partner, bapi_tax-taxnumber)
from dfkkbptaxnum up to 1 rows
where taxtype = cc_type_cpf
and taxnum = itab-cpf.
endselect.
if sy-subrc = 0.
call function 'MESSAGE_STORE'
exporting
arbgb = 'ZBR_CRM'
msgty = 'E'
msgv1 = itab-cpf
msgv2 = gv_partner
txtnr = '001'
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
continue.
endif.
endif.
* BP Type
clear bapi_bptyp.
bapi_bptyp-partn_cat = '2'. ""Organization
bapi_bptyp-partn_grp = itab-group. ""Grouping
* Central Data
clear bapi_data.
bapi_data-searchterm1 = itab-searchterm1.
bapi_data-searchterm2 = itab-searchterm2.
bapi_data-partnerexternal = itab-bpext. ""External ID
* Organization Data
clear bapi_data_org.
bapi_data_org-name1 = itab-name1.
bapi_data_org-name2 = itab-name2.
bapi_data_org-name3 = itab-name3.
bapi_data_org-name4 = itab-name4.
* Address Data
clear bapi_address.
bapi_address-street = itab-street.
bapi_address-house_no = itab-house_num.
bapi_address-city = itab-city.
bapi_address-postl_cod1 = itab-postl_cod1.
bapi_address-country = itab-country.
bapi_address-region = itab-region.
bapi_address-langu = itab-langu.
* Telephone Data
clear bapi_adtel. refresh bapi_adtel.
if not itab-tel_number is initial or
not itab-tel_extens is initial.
bapi_adtel-telephone = itab-tel_number.
bapi_adtel-extension = itab-tel_extens.
bapi_adtel-r_3_user = '1'.
bapi_adtel-consnumber = 1.
bapi_adtel-std_no = 'X'.
append bapi_adtel.
endif.
* Mobile Phone
clear: bapi_adtel.
if not itab-mob_number is initial.
bapi_adtel-telephone = itab-mob_number.
bapi_adtel-r_3_user = '3'.
bapi_adtel-consnumber = 2.
append bapi_adtel.
endif.
* Fax Data
clear bapi_adfax. refresh bapi_adfax.
if not itab-fax_number is initial or
not itab-fax_extens is initial.
bapi_adfax-fax = itab-fax_number.
bapi_adfax-extension = itab-fax_extens.
bapi_adfax-consnumber = 1.
bapi_adfax-std_no = 'X'.
append bapi_adfax.
endif.
* Email Data
clear bapi_adsmtp. refresh bapi_adsmtp.
if not itab-smtp_addr is initial.
bapi_adsmtp-e_mail = itab-smtp_addr.
bapi_adsmtp-consnumber = 1.
bapi_adsmtp-std_no = 'X'.
append bapi_adsmtp.
endif.
* Save central data
clear but000.
clear bapi_ret. refresh bapi_ret.
call function 'BAPI_BUPA_CREATE_FROM_DATA'
exporting
partnercategory = bapi_bptyp-partn_cat
partnergroup = bapi_bptyp-partn_grp
centraldata = bapi_data
centraldataorganization = bapi_data_org
addressdata = bapi_address
importing
businesspartner = but000-partner
tables
telefondata = bapi_adtel
faxdata = bapi_adfax
e_maildata = bapi_adsmtp
return = bapi_ret.
* Verify return
clear gv_error.
loop at bapi_ret.
if bapi_ret-type = 'E'.
perform rollback_data.
clear: but000-partner.
gv_error = 'X'.
endif.
* Store message
call function 'MESSAGE_STORE'
exporting
arbgb = bapi_ret-id
msgty = bapi_ret-type
msgv1 = bapi_ret-message_v1
msgv2 = bapi_ret-message_v2
msgv3 = bapi_ret-message_v3
msgv4 = bapi_ret-message_v4
txtnr = bapi_ret-number
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
endloop.
* Error goto next record
if not gv_error is initial.
continue.
endif.
* Gets GUID for business partner
clear bapi_ret. refresh bapi_ret.
call function 'BAPI_BUPA_GET_NUMBERS'
exporting
businesspartner = but000-partner
importing
businesspartnerguidout = bapi_guid
tables
return = bapi_ret.
* Verify return
clear gv_error.
loop at bapi_ret.
if bapi_ret-type = 'E'.
perform rollback_data.
clear: but000-partner.
gv_error = 'X'.
endif.
* Store message
call function 'MESSAGE_STORE'
exporting
arbgb = bapi_ret-id
msgty = bapi_ret-type
msgv1 = bapi_ret-message_v1
msgv2 = bapi_ret-message_v2
msgv3 = bapi_ret-message_v3
msgv4 = bapi_ret-message_v4
txtnr = bapi_ret-number
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
endloop.
* Error goto next record
if not gv_error is initial.
continue.
endif.
* Natural Person
if not itab-cpf is initial.
clear bapi_ret. refresh bapi_ret.
but000-natpers = 'X'.
call function 'BAPI_BUPA_TAX_COMMON_CHANGE'
exporting
businesspartner = but000-partner
taxcommon = but000-natpers
tables
return = bapi_ret.
* Verify return
clear gv_error.
loop at bapi_ret.
if bapi_ret-type = 'E'.
perform rollback_data.
clear: but000-partner.
gv_error = 'X'.
endif.
* Store message
call function 'MESSAGE_STORE'
exporting
arbgb = bapi_ret-id
msgty = bapi_ret-type
msgv1 = bapi_ret-message_v1
msgv2 = bapi_ret-message_v2
msgv3 = bapi_ret-message_v3
msgv4 = bapi_ret-message_v4
txtnr = bapi_ret-number
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
endloop.
* Error goto next record
if not gv_error is initial.
continue.
endif.
endif.
* Tax Number CNPJ
if not itab-cnpj is initial.
clear bapi_tax.
bapi_tax-taxnumber = itab-cnpj.
bapi_tax-taxtype = cc_type_cnpj.
call function 'BAPI_BUPA_TAX_ADD'
exporting
businesspartner = but000-partner
taxtype = bapi_tax-taxtype
taxnumber = bapi_tax-taxnumber
tables
return = bapi_ret.
* Verify return
clear gv_error.
loop at bapi_ret.
if bapi_ret-type = 'E'.
perform rollback_data.
clear: but000-partner.
gv_error = 'X'.
endif.
* Store message
call function 'MESSAGE_STORE'
exporting
arbgb = bapi_ret-id
msgty = bapi_ret-type
msgv1 = bapi_ret-message_v1
msgv2 = bapi_ret-message_v2
msgv3 = bapi_ret-message_v3
msgv4 = bapi_ret-message_v4
txtnr = bapi_ret-number
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
endloop.
* Error goto next record
if not gv_error is initial.
continue.
endif.
endif.
* Tax Number CPF
if not itab-cpf is initial.
clear bapi_tax.
bapi_tax-taxnumber = itab-cpf.
bapi_tax-taxtype = cc_type_cpf.
call function 'BAPI_BUPA_TAX_ADD'
exporting
businesspartner = but000-partner
taxtype = bapi_tax-taxtype
taxnumber = bapi_tax-taxnumber
tables
return = bapi_ret.
* Verify return
clear gv_error.
loop at bapi_ret.
if bapi_ret-type = 'E'.
perform rollback_data.
clear: but000-partner.
gv_error = 'X'.
endif.
* Store message
call function 'MESSAGE_STORE'
exporting
arbgb = bapi_ret-id
msgty = bapi_ret-type
msgv1 = bapi_ret-message_v1
msgv2 = bapi_ret-message_v2
msgv3 = bapi_ret-message_v3
msgv4 = bapi_ret-message_v4
txtnr = bapi_ret-number
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
endloop.
* Error goto next record
if not gv_error is initial.
continue.
endif.
endif.
* Roles
* Prospect
if not itab-prospect is initial.
clear gv_role.
move 'FLVN00' to gv_role.
perform create_role using gv_role.
move 'FLVN01' to gv_role.
perform create_role using gv_role.
* move 'FS0000' to gv_role.
* perform create_role using gv_role.
* Error goto next record
if not gv_error is initial.
continue.
endif.
endif.
* Other Organizaton
* (Outro parceiro de negocio)
* if not itab-other_org is initial.
* clear gv_role.
* move 'ZBR001' to gv_role.
* perform create_role using gv_role..
** Error goto next record
* if not gv_error is initial.
* continue.
* endif.
* endif.
*
** Customer
** (Emissor da ordem, Pagador, Recebedor da fatura,
** Recebedor da Mercadoria)
* if not itab-customer is initial.
* clear gv_role.
* move 'CRM001' to gv_role.
* perform create_role using gv_role..
** Error goto next record
* if not gv_error is initial.
* continue.
* endif.
* endif.
*
** Consumer
* if not itab-consumer is initial.
* clear gv_role.
* move 'CRM006' to gv_role.
* perform create_role using gv_role.
** Error goto next record
* if not gv_error is initial.
* continue.
* endif.
* endif.
* Concorrente
* Propriedade
* Departamento
* Prestador de Serviço
* Define Sales Data
* clear bapi_ret. refresh bapi_ret.
* clear ls_sales.
* ls_sales-sales_organization = itab-sales_org.
* ls_sales-distribution_channel = itab-channel.
* ls_sales-division = itab-division.
* call function 'BAPI_BUPA_FRG0010_ADD'
* exporting
* businesspartner = but000-partner
* sales_area = ls_sales
* tables
* return = bapi_ret.
*
** Verify return
* clear gv_error.
* loop at bapi_ret.
* if bapi_ret-type = 'E'.
* perform rollback_data.
* clear: but000-partner.
* gv_error = 'X'.
* endif.
** Store message
* call function 'MESSAGE_STORE'
* exporting
* arbgb = bapi_ret-id
* msgty = bapi_ret-type
* msgv1 = bapi_ret-message_v1
* msgv2 = bapi_ret-message_v2
* msgv3 = bapi_ret-message_v3
* msgv4 = bapi_ret-message_v4
* txtnr = bapi_ret-number
* zeile = itab-bpext
* exceptions
* message_type_not_valid = 1
* not_active = 2
* others = 3.
* endloop.
** Error goto next record
* if not gv_error is initial.
* continue.
* endif.
* Business Partner Classification Sales
* clear bapi_ret. refresh bapi_ret.
* clear bapi_sales_class.
*
* bapi_sales_class-is_prospect = itab-prospect.
* bapi_sales_class-is_customer = itab-customer.
* bapi_sales_class-is_consumer = itab-consumer.
* bapi_sales_class-is_competitor = itab-competitor.
*
* if not bapi_sales_class is initial.
* call function 'BAPI_BUPA_FRG0040_CREATE'
* exporting
* businesspartner = but000-partner
* data = bapi_sales_class
* tables
* return = bapi_ret.
* endif.
*
** Verify return
* clear gv_error.
* loop at bapi_ret.
* if bapi_ret-type = 'E'.
* perform rollback_data.
* clear: but000-partner.
* gv_error = 'X'.
* endif.
** Store message
* call function 'MESSAGE_STORE'
* exporting
* arbgb = bapi_ret-id
* msgty = bapi_ret-type
* msgv1 = bapi_ret-message_v1
* msgv2 = bapi_ret-message_v2
* msgv3 = bapi_ret-message_v3
* msgv4 = bapi_ret-message_v4
* txtnr = bapi_ret-number
* zeile = itab-bpext
* exceptions
* message_type_not_valid = 1
* not_active = 2
* others = 3.
* endloop.
** Error goto next record
* if not gv_error is initial.
* continue.
* endif.
* Execute external Commit
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
call function 'BUP_MEMORY_ADDRESS_INIT'.
call function 'BUP_MEMORY_CENTRAL_INIT'.
* Sucess Message
call function 'MESSAGE_STORE'
exporting
arbgb = 'R1'
msgty = 'S'
msgv1 = but000-partner
msgv2 = bapi_ret-message_v2
msgv3 = bapi_ret-message_v3
msgv4 = bapi_ret-message_v4
txtnr = '425'
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
endloop.
endform. "" f_create_bp
*&---------------------------------------------------------------------*
*& Form create_role
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form create_role using p_gv_role.
* Create Role
clear bapi_ret. refresh bapi_ret.
call function 'BAPI_BUPA_ROLE_ADD_2'
exporting
businesspartner = but000-partner
businesspartnerrole = p_gv_role
tables
return = bapi_ret.
* Verify return
clear gv_error.
loop at bapi_ret.
if bapi_ret-type = 'E'.
perform rollback_data.
clear: but000-partner.
gv_error = 'X'.
endif.
* Store message
call function 'MESSAGE_STORE'
exporting
arbgb = bapi_ret-id
msgty = bapi_ret-type
msgv1 = bapi_ret-message_v1
msgv2 = bapi_ret-message_v2
msgv3 = bapi_ret-message_v3
msgv4 = bapi_ret-message_v4
txtnr = bapi_ret-number
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
endloop.
* Error goto next record
if not gv_error is initial.
exit.
endif.
endform. "" create_role
*---------------------------------------------------------------------*
* Form f_show_messages
* Show or print error messages
*----------------------------------------------------------------------*
form f_show_messages.
* Init
data li_fliste type table of smesg.
data lw_fliste type smesg.
data lv_color(1).
write ls_vendors-header-object_instance-lifnr.
* Results
clear: li_fliste.
call function 'MESSAGES_GIVE'
tables
t_mesg = li_fliste.
describe table li_fliste.
if not sy-tfill is initial.
format color 1 intensified.
write: /01 sy-vline, 03 text-003, 130 sy-vline.
uline.
write: /01 sy-vline, 03 text-006, 20 sy-vline,
22 text-004, 32 sy-vline, 34 text-005, 130 sy-vline.
uline.
clear lv_color.
loop at li_fliste into lw_fliste.
if lv_color is initial.
format color col_normal intensified off.
else.
format color col_normal intensified on.
endif.
write: /01 sy-vline,
03 lw_fliste-zeile,
20 sy-vline,
22 lw_fliste-msgty,
32 sy-vline,
34 lw_fliste-text,
130 sy-vline.
if lv_color is initial.
lv_color = 'X'.
else.
clear lv_color.
endif.
endloop.
uline.
endif.
endform. ""f_show_messages
*& Report ZSRM_BP_CREATE
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
report zsrm_bp_create.
tables: but000, addr1_data, sza11_0100."bupa_crm101.
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.
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_main 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.
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.
clear gs_main.
* ls_vendors-header-object_instance-lifnr = '0000100048'.
* call method vmd_ei_api=>get_number
* exporting
* iv_ktokk = gv_ktokk
* importing
* ev_lifnr = ls_vendors-header-object_instance-lifnr
* es_error = ls_message.
data: gv_partner_guid type bu_partner_guid.
clear gv_partner_guid.
select single partner_guid from but000 into gv_partner_guid
where partner = but000-partner.
select single vendor from cvi_vend_link into ls_vendors-header-object_instance-lifnr
where partner_guid = gv_partner_guid.
ls_vendors-header-object_task = 'M'. "represents insert or create
ls_address-postal-data-name = gv_name. "name of the vendor
ls_address-postal-data-street = 'LSI Logic Storage System, Inc'.
ls_address-postal-data-postl_cod1 = '466303'.
ls_address-postal-data-region = '190'.
ls_address-postal-data-country = 'CN'.
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'.
* 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
* NOTE: If the note 1749700 is present in the system, then the contact person number can be left empty
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 DOE'.
ls_contacts-address_type_3-postal-data-firstname = 'JOHN'.
ls_contacts-address_type_3-postal-data-lastname = 'DOE'.
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-brsch = '18'. "industry key
* Set the DATAX flags
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-datax-akont = 'X'.
* ls_company-datax-zuawa = 'X'.
* ls_company-datax-fdgrv = 'X'.
ls_company-datax-zterm = '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 = 'Z001'. "purchasing organization
ls_purchasing-data-waers = 'USD'.
ls_purchasing-data-verkf = '刑刚'.
ls_purchasing-data-telf1 = '13925135205'.
* ls_purchasing-data-kalsk = '01'. "schema group, vendor
* ls_purchasing-data-webre = 'X'. "gr based invoice verification
ls_purchasing-datax-waers = 'X'.
ls_purchasing-datax-verkf = 'X'.
ls_purchasing-datax-telf1 = '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_main-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_main
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.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
message 'success' type 'S'.
* commit work.
* Set the Vendor Number to be returned
endif.
endmethod.
"create_vendor_data
endclass. "lcl_data implementation
* Tables
* Constants
constants cc_type_cpf like dfkkbptaxnum-taxtype value 'BR2'.
constants cc_type_cnpj like dfkkbptaxnum-taxtype value 'BR1'.
* Variables and Structures
data file_in like rlgrap-filename.
*data ls_sales type bapibus1006_sales_area.
data bapi_bptyp type bapibus1006_head.
data bapi_address type bapibus1006_address.
data bapi_data type bapibus1006_central.
data bapi_data_org type bapibus1006_central_organ.
data bapi_adtel type bapiadtel occurs 10 with header line.
data bapi_adfax type bapiadfax occurs 10 with header line.
data bapi_adsmtp type bapiadsmtp occurs 10 with header line.
data bapi_ret type bapiret2 occurs 10 with header line.
data bapi_guid type but020-guid.
data gv_role like bapibus1006_head-partnerrole.
*data bapi_sales_class type bapibus1006040_salesclass.
data bapi_tax type bapibus1006tax.
data gv_partner type but000-partner.
data gv_error(1).
* Record layout for PC file
data: begin of itab occurs 0,
group like but000-bu_group, "业务伙伴分组
name1 like but000-name_org1, "组织名称 1
name2 like but000-name_org2, "组织名称 2
name3 like but000-name_org3, "组织名称 3
name4 like but000-name_org4, "组织名称 4
searchterm1 like but000-bu_sort1, "业务伙伴的搜索词 1
searchterm2 like but000-bu_sort2, "业务伙伴的搜索词 2
street like addr1_data-street, "街道
house_num like addr1_data-house_num1, "门牌号
postl_cod1 like addr1_data-post_code1, "城市邮政编码
city like addr1_data-city1, "城市
country like addr1_data-country, "国家/地区代码
region like addr1_data-region, "地区(省/自治区/直辖市、市、县)
langu like addr1_data-langu, "语言代码
tel_number like sza11_0100-tel_number, "第一个电话号码:区号 + 号码
tel_extens like sza11_0100-tel_extens, "第一个电话号码:分机号
mob_number like sza11_0100-mob_number, "第一个移动电话号码:区号 + 电话号码
fax_number like sza11_0100-fax_number, "第一个传真号: 拨号 + 编号
fax_extens like sza11_0100-fax_extens, "第一个传真号: 分机号
smtp_addr like sza11_0100-smtp_addr, "电子邮件地址
bpext like but000-bpext, "外部系统中的业务伙伴编号
cpf like dfkkbptaxnum-taxnum, "业务合作伙伴税号
cnpj like dfkkbptaxnum-taxnum,
prospect(1),
* other_org(1),
* customer(1),
* consumer(1),
* competitor(1),
* property(1),
* department(1),
* prestador(1),
* sales_org like bupa_crm101-sales_org,
* channel like bupa_crm101-channel,
* division like bupa_crm101-division,
end of itab.
data: excel_tab like itab occurs 0 with header line.
* Cells in Flat Structure for Flexible Excel Upload
*data excel_tab like yexcelstruc occurs 0 with header line.
* Parameters selection
*selection-screen begin of block b1 with frame title text-001.
*parameters: p_filein like rlgrap-filename obligatory.
*selection-screen skip 1.
*selection-screen end of block b1.
*
** Events
*at selection-screen on value-request for p_filein.
*
* call function 'KD_GET_FILENAME_ON_F4'
* exporting
* static = 'X'
* changing
* file_name = p_filein.
* Program Init
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 = 'Z001'
i_akont = '2001000001'
i_ktokk = 'KRED'
i_name = 'test1234567890'.
*
* Upload Data from EXCEL
perform f_upload_excel.
* Create BP
if not itab[] is initial.
call function 'MESSAGES_INITIALIZE'.
perform f_create_bp.
endif.
*Create Vendor and obtain the resultant error message and Vendor number
call method lo_data->create_vendor_data
importing
e_lifnr = gv_lifnr.
if sy-subrc = 0.
endif.
end-of-selection.
* Display log
perform f_show_messages.
*&---------------------------------------------------------------------*
*& Form rollback_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form rollback_data .
call function 'BAPI_TRANSACTION_ROLLBACK'.
call function 'BUP_MEMORY_ADDRESS_INIT'.
call function 'BUP_MEMORY_CENTRAL_INIT'.
endform. "" rollback_data
*&---------------------------------------------------------------------*
*& Form f_upload_excel
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form f_upload_excel .
* Upload Data from EXCEL
* call function 'Y_UPLOAD_EXCEL_BY_OLE'
* exporting
* infile = p_filein
* max_col = '256'
* max_row = '65000'
* tables
* excel_tab = excel_tab
* exceptions
* inconsistent_parameters = 1
* error_create_object = 2
* error_call_method = 3
* error_get_property = 4
* error_opening_file = 5
* others = 6.
*
** Excel Upload Error
* if not sy-subrc is initial.
* message i019.
* exit.
* endif.
* Move Data Upload into the ITAB file
* clear itab. refresh itab.
* sort excel_tab.
* loop at excel_tab.
* at new zrow. clear itab. endat.
* case excel_tab-zcol.
* when 1. itab-group = excel_tab-zvalue.
* when 2. itab-name1 = excel_tab-zvalue.
* when 3. itab-name2 = excel_tab-zvalue.
* when 4. itab-name3 = excel_tab-zvalue.
* when 5. itab-name4 = excel_tab-zvalue.
* when 6. itab-searchterm1 = excel_tab-zvalue.
* when 7. itab-searchterm2 = excel_tab-zvalue.
* when 8. itab-street = excel_tab-zvalue.
* when 9. itab-house_num = excel_tab-zvalue.
* when 10. itab-postl_cod1 = excel_tab-zvalue.
* when 11. itab-city = excel_tab-zvalue.
* when 12. itab-country = excel_tab-zvalue.
* when 13. itab-region = excel_tab-zvalue.
* when 14. itab-langu = excel_tab-zvalue.
* when 15. itab-tel_number = excel_tab-zvalue.
* when 16. itab-tel_extens = excel_tab-zvalue.
* when 17. itab-mob_number = excel_tab-zvalue.
* when 18. itab-fax_number = excel_tab-zvalue.
* when 19. itab-fax_extens = excel_tab-zvalue.
* when 20. itab-smtp_addr = excel_tab-zvalue.
* when 21. itab-bpext = excel_tab-zvalue.
* when 22. itab-cpf = excel_tab-zvalue.
* when 23. itab-cnpj = excel_tab-zvalue.
* when 24. itab-sales_org = excel_tab-zvalue.
* when 25. itab-channel = excel_tab-zvalue.
* when 26. itab-division = excel_tab-zvalue.
* when 27. itab-prospect = excel_tab-zvalue.
* when 28. itab-other_org = excel_tab-zvalue.
* when 29. itab-customer = excel_tab-zvalue.
* when 30. itab-consumer = excel_tab-zvalue.
* when 31. itab-competitor = excel_tab-zvalue.
* when 32. itab-property = excel_tab-zvalue.
* when 33. itab-department = excel_tab-zvalue.
* when 34. itab-prestador = excel_tab-zvalue.
* endcase.
* at end of zrow.
* append itab.
* endat.
* endloop.
itab-group = '0001'.
itab-name1 = '测试创建BPwangxy_3'.
itab-name2 = ''.
itab-name3 = ''.
itab-name4 = ''.
itab-searchterm1 = 'SRM'.
itab-searchterm2 = ''.
itab-street = '金山大道'.
itab-house_num = '0123456789'.
itab-postl_cod1 = '511400'.
itab-city = '广州'.
itab-country = 'CN'.
itab-region = '190'.
itab-langu = '1'.
itab-tel_number = '010-1234567'.
itab-tel_extens = ''.
itab-mob_number = '13213330000'.
itab-fax_number = ''.
itab-fax_extens = ''.
itab-smtp_addr = '123128381728@google.com'.
itab-bpext = ''.
itab-cpf = ''.
itab-cnpj = ''.
itab-prospect = 'X'."add role
append itab.
* itab-other_org = ''.
* itab-customer = ''.
* itab-consumer = ''.
* itab-competitor = ''.
* itab-property = ''.
* itab-department = ''.
* itab-prestador = ''.
endform. "" f_upload_excel
*&---------------------------------------------------------------------*
*& Form f_create_bp
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form f_create_bp .
loop at itab.
* Header of colums in Excel Table
* if sy-tabix = 1 or sy-tabix = 2.
* continue.
* endif.
* Validation of the CNPJ
if not itab-cnpj is initial.
clear gv_partner.
select partner taxnum into (gv_partner,bapi_tax-taxnumber)
from dfkkbptaxnum up to 1 rows
where taxtype = cc_type_cnpj
and taxnum = itab-cnpj.
endselect.
if sy-subrc = 0.
call function 'MESSAGE_STORE'
exporting
arbgb = 'ZBR_CRM'
msgty = 'E'
msgv1 = itab-cnpj
msgv2 = gv_partner
txtnr = '001'
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
continue.
endif.
endif.
* Validation of the CPF
if not itab-cpf is initial.
clear gv_partner.
select partner taxnum into (gv_partner, bapi_tax-taxnumber)
from dfkkbptaxnum up to 1 rows
where taxtype = cc_type_cpf
and taxnum = itab-cpf.
endselect.
if sy-subrc = 0.
call function 'MESSAGE_STORE'
exporting
arbgb = 'ZBR_CRM'
msgty = 'E'
msgv1 = itab-cpf
msgv2 = gv_partner
txtnr = '001'
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
continue.
endif.
endif.
* BP Type
clear bapi_bptyp.
bapi_bptyp-partn_cat = '2'. ""Organization
bapi_bptyp-partn_grp = itab-group. ""Grouping
* Central Data
clear bapi_data.
bapi_data-searchterm1 = itab-searchterm1.
bapi_data-searchterm2 = itab-searchterm2.
bapi_data-partnerexternal = itab-bpext. ""External ID
* Organization Data
clear bapi_data_org.
bapi_data_org-name1 = itab-name1.
bapi_data_org-name2 = itab-name2.
bapi_data_org-name3 = itab-name3.
bapi_data_org-name4 = itab-name4.
* Address Data
clear bapi_address.
bapi_address-street = itab-street.
bapi_address-house_no = itab-house_num.
bapi_address-city = itab-city.
bapi_address-postl_cod1 = itab-postl_cod1.
bapi_address-country = itab-country.
bapi_address-region = itab-region.
bapi_address-langu = itab-langu.
* Telephone Data
clear bapi_adtel. refresh bapi_adtel.
if not itab-tel_number is initial or
not itab-tel_extens is initial.
bapi_adtel-telephone = itab-tel_number.
bapi_adtel-extension = itab-tel_extens.
bapi_adtel-r_3_user = '1'.
bapi_adtel-consnumber = 1.
bapi_adtel-std_no = 'X'.
append bapi_adtel.
endif.
* Mobile Phone
clear: bapi_adtel.
if not itab-mob_number is initial.
bapi_adtel-telephone = itab-mob_number.
bapi_adtel-r_3_user = '3'.
bapi_adtel-consnumber = 2.
append bapi_adtel.
endif.
* Fax Data
clear bapi_adfax. refresh bapi_adfax.
if not itab-fax_number is initial or
not itab-fax_extens is initial.
bapi_adfax-fax = itab-fax_number.
bapi_adfax-extension = itab-fax_extens.
bapi_adfax-consnumber = 1.
bapi_adfax-std_no = 'X'.
append bapi_adfax.
endif.
* Email Data
clear bapi_adsmtp. refresh bapi_adsmtp.
if not itab-smtp_addr is initial.
bapi_adsmtp-e_mail = itab-smtp_addr.
bapi_adsmtp-consnumber = 1.
bapi_adsmtp-std_no = 'X'.
append bapi_adsmtp.
endif.
* Save central data
clear but000.
clear bapi_ret. refresh bapi_ret.
call function 'BAPI_BUPA_CREATE_FROM_DATA'
exporting
partnercategory = bapi_bptyp-partn_cat
partnergroup = bapi_bptyp-partn_grp
centraldata = bapi_data
centraldataorganization = bapi_data_org
addressdata = bapi_address
importing
businesspartner = but000-partner
tables
telefondata = bapi_adtel
faxdata = bapi_adfax
e_maildata = bapi_adsmtp
return = bapi_ret.
* Verify return
clear gv_error.
loop at bapi_ret.
if bapi_ret-type = 'E'.
perform rollback_data.
clear: but000-partner.
gv_error = 'X'.
endif.
* Store message
call function 'MESSAGE_STORE'
exporting
arbgb = bapi_ret-id
msgty = bapi_ret-type
msgv1 = bapi_ret-message_v1
msgv2 = bapi_ret-message_v2
msgv3 = bapi_ret-message_v3
msgv4 = bapi_ret-message_v4
txtnr = bapi_ret-number
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
endloop.
* Error goto next record
if not gv_error is initial.
continue.
endif.
* Gets GUID for business partner
clear bapi_ret. refresh bapi_ret.
call function 'BAPI_BUPA_GET_NUMBERS'
exporting
businesspartner = but000-partner
importing
businesspartnerguidout = bapi_guid
tables
return = bapi_ret.
* Verify return
clear gv_error.
loop at bapi_ret.
if bapi_ret-type = 'E'.
perform rollback_data.
clear: but000-partner.
gv_error = 'X'.
endif.
* Store message
call function 'MESSAGE_STORE'
exporting
arbgb = bapi_ret-id
msgty = bapi_ret-type
msgv1 = bapi_ret-message_v1
msgv2 = bapi_ret-message_v2
msgv3 = bapi_ret-message_v3
msgv4 = bapi_ret-message_v4
txtnr = bapi_ret-number
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
endloop.
* Error goto next record
if not gv_error is initial.
continue.
endif.
* Natural Person
if not itab-cpf is initial.
clear bapi_ret. refresh bapi_ret.
but000-natpers = 'X'.
call function 'BAPI_BUPA_TAX_COMMON_CHANGE'
exporting
businesspartner = but000-partner
taxcommon = but000-natpers
tables
return = bapi_ret.
* Verify return
clear gv_error.
loop at bapi_ret.
if bapi_ret-type = 'E'.
perform rollback_data.
clear: but000-partner.
gv_error = 'X'.
endif.
* Store message
call function 'MESSAGE_STORE'
exporting
arbgb = bapi_ret-id
msgty = bapi_ret-type
msgv1 = bapi_ret-message_v1
msgv2 = bapi_ret-message_v2
msgv3 = bapi_ret-message_v3
msgv4 = bapi_ret-message_v4
txtnr = bapi_ret-number
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
endloop.
* Error goto next record
if not gv_error is initial.
continue.
endif.
endif.
* Tax Number CNPJ
if not itab-cnpj is initial.
clear bapi_tax.
bapi_tax-taxnumber = itab-cnpj.
bapi_tax-taxtype = cc_type_cnpj.
call function 'BAPI_BUPA_TAX_ADD'
exporting
businesspartner = but000-partner
taxtype = bapi_tax-taxtype
taxnumber = bapi_tax-taxnumber
tables
return = bapi_ret.
* Verify return
clear gv_error.
loop at bapi_ret.
if bapi_ret-type = 'E'.
perform rollback_data.
clear: but000-partner.
gv_error = 'X'.
endif.
* Store message
call function 'MESSAGE_STORE'
exporting
arbgb = bapi_ret-id
msgty = bapi_ret-type
msgv1 = bapi_ret-message_v1
msgv2 = bapi_ret-message_v2
msgv3 = bapi_ret-message_v3
msgv4 = bapi_ret-message_v4
txtnr = bapi_ret-number
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
endloop.
* Error goto next record
if not gv_error is initial.
continue.
endif.
endif.
* Tax Number CPF
if not itab-cpf is initial.
clear bapi_tax.
bapi_tax-taxnumber = itab-cpf.
bapi_tax-taxtype = cc_type_cpf.
call function 'BAPI_BUPA_TAX_ADD'
exporting
businesspartner = but000-partner
taxtype = bapi_tax-taxtype
taxnumber = bapi_tax-taxnumber
tables
return = bapi_ret.
* Verify return
clear gv_error.
loop at bapi_ret.
if bapi_ret-type = 'E'.
perform rollback_data.
clear: but000-partner.
gv_error = 'X'.
endif.
* Store message
call function 'MESSAGE_STORE'
exporting
arbgb = bapi_ret-id
msgty = bapi_ret-type
msgv1 = bapi_ret-message_v1
msgv2 = bapi_ret-message_v2
msgv3 = bapi_ret-message_v3
msgv4 = bapi_ret-message_v4
txtnr = bapi_ret-number
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
endloop.
* Error goto next record
if not gv_error is initial.
continue.
endif.
endif.
* Roles
* Prospect
if not itab-prospect is initial.
clear gv_role.
move 'FLVN00' to gv_role.
perform create_role using gv_role.
move 'FLVN01' to gv_role.
perform create_role using gv_role.
* move 'FS0000' to gv_role.
* perform create_role using gv_role.
* Error goto next record
if not gv_error is initial.
continue.
endif.
endif.
* Other Organizaton
* (Outro parceiro de negocio)
* if not itab-other_org is initial.
* clear gv_role.
* move 'ZBR001' to gv_role.
* perform create_role using gv_role..
** Error goto next record
* if not gv_error is initial.
* continue.
* endif.
* endif.
*
** Customer
** (Emissor da ordem, Pagador, Recebedor da fatura,
** Recebedor da Mercadoria)
* if not itab-customer is initial.
* clear gv_role.
* move 'CRM001' to gv_role.
* perform create_role using gv_role..
** Error goto next record
* if not gv_error is initial.
* continue.
* endif.
* endif.
*
** Consumer
* if not itab-consumer is initial.
* clear gv_role.
* move 'CRM006' to gv_role.
* perform create_role using gv_role.
** Error goto next record
* if not gv_error is initial.
* continue.
* endif.
* endif.
* Concorrente
* Propriedade
* Departamento
* Prestador de Serviço
* Define Sales Data
* clear bapi_ret. refresh bapi_ret.
* clear ls_sales.
* ls_sales-sales_organization = itab-sales_org.
* ls_sales-distribution_channel = itab-channel.
* ls_sales-division = itab-division.
* call function 'BAPI_BUPA_FRG0010_ADD'
* exporting
* businesspartner = but000-partner
* sales_area = ls_sales
* tables
* return = bapi_ret.
*
** Verify return
* clear gv_error.
* loop at bapi_ret.
* if bapi_ret-type = 'E'.
* perform rollback_data.
* clear: but000-partner.
* gv_error = 'X'.
* endif.
** Store message
* call function 'MESSAGE_STORE'
* exporting
* arbgb = bapi_ret-id
* msgty = bapi_ret-type
* msgv1 = bapi_ret-message_v1
* msgv2 = bapi_ret-message_v2
* msgv3 = bapi_ret-message_v3
* msgv4 = bapi_ret-message_v4
* txtnr = bapi_ret-number
* zeile = itab-bpext
* exceptions
* message_type_not_valid = 1
* not_active = 2
* others = 3.
* endloop.
** Error goto next record
* if not gv_error is initial.
* continue.
* endif.
* Business Partner Classification Sales
* clear bapi_ret. refresh bapi_ret.
* clear bapi_sales_class.
*
* bapi_sales_class-is_prospect = itab-prospect.
* bapi_sales_class-is_customer = itab-customer.
* bapi_sales_class-is_consumer = itab-consumer.
* bapi_sales_class-is_competitor = itab-competitor.
*
* if not bapi_sales_class is initial.
* call function 'BAPI_BUPA_FRG0040_CREATE'
* exporting
* businesspartner = but000-partner
* data = bapi_sales_class
* tables
* return = bapi_ret.
* endif.
*
** Verify return
* clear gv_error.
* loop at bapi_ret.
* if bapi_ret-type = 'E'.
* perform rollback_data.
* clear: but000-partner.
* gv_error = 'X'.
* endif.
** Store message
* call function 'MESSAGE_STORE'
* exporting
* arbgb = bapi_ret-id
* msgty = bapi_ret-type
* msgv1 = bapi_ret-message_v1
* msgv2 = bapi_ret-message_v2
* msgv3 = bapi_ret-message_v3
* msgv4 = bapi_ret-message_v4
* txtnr = bapi_ret-number
* zeile = itab-bpext
* exceptions
* message_type_not_valid = 1
* not_active = 2
* others = 3.
* endloop.
** Error goto next record
* if not gv_error is initial.
* continue.
* endif.
* Execute external Commit
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
call function 'BUP_MEMORY_ADDRESS_INIT'.
call function 'BUP_MEMORY_CENTRAL_INIT'.
* Sucess Message
call function 'MESSAGE_STORE'
exporting
arbgb = 'R1'
msgty = 'S'
msgv1 = but000-partner
msgv2 = bapi_ret-message_v2
msgv3 = bapi_ret-message_v3
msgv4 = bapi_ret-message_v4
txtnr = '425'
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
endloop.
endform. "" f_create_bp
*&---------------------------------------------------------------------*
*& Form create_role
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form create_role using p_gv_role.
* Create Role
clear bapi_ret. refresh bapi_ret.
call function 'BAPI_BUPA_ROLE_ADD_2'
exporting
businesspartner = but000-partner
businesspartnerrole = p_gv_role
tables
return = bapi_ret.
* Verify return
clear gv_error.
loop at bapi_ret.
if bapi_ret-type = 'E'.
perform rollback_data.
clear: but000-partner.
gv_error = 'X'.
endif.
* Store message
call function 'MESSAGE_STORE'
exporting
arbgb = bapi_ret-id
msgty = bapi_ret-type
msgv1 = bapi_ret-message_v1
msgv2 = bapi_ret-message_v2
msgv3 = bapi_ret-message_v3
msgv4 = bapi_ret-message_v4
txtnr = bapi_ret-number
zeile = itab-bpext
exceptions
message_type_not_valid = 1
not_active = 2
others = 3.
endloop.
* Error goto next record
if not gv_error is initial.
exit.
endif.
endform. "" create_role
*---------------------------------------------------------------------*
* Form f_show_messages
* Show or print error messages
*----------------------------------------------------------------------*
form f_show_messages.
* Init
data li_fliste type table of smesg.
data lw_fliste type smesg.
data lv_color(1).
write ls_vendors-header-object_instance-lifnr.
* Results
clear: li_fliste.
call function 'MESSAGES_GIVE'
tables
t_mesg = li_fliste.
describe table li_fliste.
if not sy-tfill is initial.
format color 1 intensified.
write: /01 sy-vline, 03 text-003, 130 sy-vline.
uline.
write: /01 sy-vline, 03 text-006, 20 sy-vline,
22 text-004, 32 sy-vline, 34 text-005, 130 sy-vline.
uline.
clear lv_color.
loop at li_fliste into lw_fliste.
if lv_color is initial.
format color col_normal intensified off.
else.
format color col_normal intensified on.
endif.
write: /01 sy-vline,
03 lw_fliste-zeile,
20 sy-vline,
22 lw_fliste-msgty,
32 sy-vline,
34 lw_fliste-text,
130 sy-vline.
if lv_color is initial.
lv_color = 'X'.
else.
clear lv_color.
endif.
endloop.
uline.
endif.
endform. ""f_show_messages