понедельник, 25 ноября 2013 г.

Создание/обновление делового партнера (тр.BP) через BAPI

Ниже будет много кода с вызовами BAPI по редактированию делового партнера.
Перечень используемых BAPI:
BAPI_BUPA_FS_CREATE_FROM_DATA2
BAPI_BUPA_CENTRAL_CHANGE
BAPI_BUPA_ADDRESSES_GET
BAPI_BUPA_ADDRESS_ADD
BAPI_BUPA_ADDRESS_REMOVE
BAPI_INDUSTRYSECTOR_ADD
BAPI_INDUSTRYSECTORDETAILS_GET
BAPI_INDUSTRYSECTOR_REMOVE
BAPI_BUPA_TAX_ADD
BAPI_BUPA_TAX_GETDETAIL
BAPI_BUPA_TAX_REMOVE
BAPI_BUPA_BANKDETAIL_ADD
BAPI_BUPA_BANKDETAILS_GET
BAPI_BUPA_BANKDETAIL_REMOVE
BAPI_BUPA_ROLES_GET_2
BAPI_BUPA_ROLE_REMOVE
BAPI_BUPA_ROLE_ADD_2
ФМ Z_BP_CUSTOMER_CREATE,Z_BP_VENDOR_CREATE и Z_BP_VENDOR_CHANGE - пакетники на транзакции XD01, XK01 и XK02 соответственно.
А теперь сам код:

ФМ Z_RFC_UPDATE_BP
FUNCTION z_rfc_update_bp. *"---------------------------------------------------------------------- *"*"Локальный интерфейс: *" IMPORTING *" VALUE(IS_BUSINESSPARTNER) TYPE ZSTBUSINESSPARTNER *" VALUE(IT_BPADRESSDATA) TYPE ZTTBP_ADDRESSDATA *" VALUE(IT_BPBANKDATA) TYPE ZTTBP_BANKDATA *" EXPORTING *" VALUE(E_TYPE) TYPE BAPI_MTYPE *" VALUE(E_MESSAGE) TYPE BAPI_MSG *"---------------------------------------------------------------------- CONSTANTS: abap_true TYPE c VALUE 'X', abap_false TYPE c VALUE ' '. DATA: lf_bp_exist TYPE c, l_businesspartner TYPE bapibus1006_head-bpartner, l_create_vendor TYPE c, l_create_customer TYPE c, et_return TYPE TABLE OF bapiret2, l_return TYPE TABLE OF bapiret2. CLEAR:et_return[],l_return,e_type,e_message. * Проверяем существование ДП PERFORM check_bp_exist USING is_businesspartner-bpext CHANGING lf_bp_exist l_businesspartner. IF lf_bp_exist EQ abap_false. * Если ДП не существует, создаем CLEAR l_return[]. PERFORM create_business_partner TABLES l_return USING is_businesspartner it_bpadressdata CHANGING l_businesspartner. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки при создании ДП PERFORM check_error_exist TABLES l_return USING 'CR_BP' CHANGING e_type e_message. * Добавляем адреса CLEAR l_return[]. PERFORM add_address TABLES l_return USING l_businesspartner is_businesspartner it_bpadressdata. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки при добавлении адреса PERFORM check_error_exist TABLES l_return USING 'ADDR_ADD' CHANGING e_type e_message. * Добавляем отрасли (Основной вид деятельности) CLEAR l_return[]. PERFORM add_industry_sector TABLES l_return USING l_businesspartner is_businesspartner. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки при добавлении отрасли PERFORM check_error_exist TABLES l_return USING 'IDSTR_ADD' CHANGING e_type e_message. * Налоговые номера CLEAR l_return[]. PERFORM add_taxnum TABLES l_return USING l_businesspartner is_businesspartner. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки при добавлении номеров PERFORM check_error_exist TABLES l_return USING 'TAXN_ADD' CHANGING e_type e_message. * Банковские реквизиты CLEAR l_return[]. PERFORM add_bank TABLES l_return USING l_businesspartner it_bpbankdata. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки PERFORM check_error_exist TABLES l_return USING 'BANK_ADD' CHANGING e_type e_message. ELSEIF lf_bp_exist EQ abap_true. * eсли ДП существует, обновляем данные * Обновляем роли ДП CLEAR l_return[]. PERFORM modify_bp_roles TABLES l_return USING l_businesspartner is_businesspartner CHANGING l_create_vendor l_create_customer. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки PERFORM check_error_exist TABLES l_return USING 'ROLE_UPD' CHANGING e_type e_message. * Обновляем общие данные CLEAR l_return[]. PERFORM modify_common_data TABLES l_return USING l_businesspartner is_businesspartner. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки PERFORM check_error_exist TABLES l_return USING 'COMM_UPD' CHANGING e_type e_message. * Обновляем адреса CLEAR l_return[]. PERFORM modify_address TABLES l_return USING l_businesspartner is_businesspartner it_bpadressdata. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки PERFORM check_error_exist TABLES l_return USING 'ADDR_UPD' CHANGING e_type e_message. * Обновляем отрасли CLEAR l_return[]. PERFORM modify_industry TABLES l_return USING l_businesspartner is_businesspartner. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки PERFORM check_error_exist TABLES l_return USING 'IDSTR_UPD' CHANGING e_type e_message. * Обновляем налоговые номера CLEAR l_return[]. PERFORM modify_taxnum TABLES l_return USING l_businesspartner is_businesspartner. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки PERFORM check_error_exist TABLES l_return USING 'TAXN_UPD' CHANGING e_type e_message. * Обновляем банковские реквизиты CLEAR l_return[]. PERFORM modify_bank TABLES l_return USING l_businesspartner it_bpbankdata. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки PERFORM check_error_exist TABLES l_return USING 'BANK_UPD' CHANGING e_type e_message. ENDIF. CLEAR l_return[]. l_return[] = et_return[]. DELETE l_return WHERE ( type EQ 'I' OR type EQ 'W' OR type EQ 'S'). IF l_return[] IS INITIAL. DELETE et_return WHERE type EQ 'W'. PERFORM bapi_commit. IF lf_bp_exist EQ abap_false. * Создаем кредитора CLEAR l_return[]. PERFORM create_vendor TABLES l_return USING l_businesspartner is_businesspartner. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки PERFORM check_error_exist TABLES l_return USING 'VEND_CRE' CHANGING e_type e_message. * Создаем дебитора CLEAR l_return[]. PERFORM create_customer TABLES l_return USING l_businesspartner is_businesspartner. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки PERFORM check_error_exist TABLES l_return USING 'CUST_CRE' CHANGING e_type e_message. ELSEIF lf_bp_exist EQ abap_true. * При добавлении новой роли в ДП проверяем наличие контрагента и, * в случае его отсутствия, создаем дебитора/кредитора PERFORM check_customer_exist USING l_businesspartner CHANGING l_create_customer. IF l_create_customer EQ 'X'. CLEAR l_return[]. PERFORM create_customer TABLES l_return USING l_businesspartner is_businesspartner. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки PERFORM check_error_exist TABLES l_return USING 'CUST_CRE' CHANGING e_type e_message. ENDIF. PERFORM check_vendor_exist USING l_businesspartner CHANGING l_create_vendor. IF l_create_vendor EQ 'X'. * Создаем кредитора CLEAR l_return[]. PERFORM create_vendor TABLES l_return USING l_businesspartner is_businesspartner. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки PERFORM check_error_exist TABLES l_return USING 'VEND_CRE' CHANGING e_type e_message. ELSE. * Обновляем данные кредитора CLEAR l_return[]. PERFORM change_vendor TABLES l_return USING l_businesspartner is_businesspartner. APPEND LINES OF l_return TO et_return. " Проверим наличия ошибки PERFORM check_error_exist TABLES l_return USING 'VEND_UPD' CHANGING e_type e_message. ENDIF. ENDIF. ELSE. PERFORM bapi_rollback. ENDIF. IF NOT e_type EQ 'E'. e_type = 'S'. IF lf_bp_exist EQ abap_false. CONCATENATE 'Деловой партнер' l_businesspartner 'успешно создан' INTO e_message SEPARATED BY space. ELSEIF lf_bp_exist EQ abap_true. CONCATENATE 'Деловой партнер' l_businesspartner 'успешно изменен' INTO e_message SEPARATED BY space. ENDIF. ENDIF. ENDFUNCTION. *&---------------------------------------------------------------------* *& Form check_bp_exist *&---------------------------------------------------------------------* FORM check_bp_exist USING iv_bpext TYPE bu_bpext CHANGING c_exist TYPE c c_bpartner TYPE bu_partner. CONSTANTS: abap_true TYPE c VALUE 'X', abap_false TYPE c VALUE ' '. CLEAR: c_bpartner,c_exist. SELECT SINGLE partner FROM but000 INTO c_bpartner WHERE bpext EQ iv_bpext. IF sy-subrc EQ 0. c_exist = abap_true. ELSE. c_exist = abap_false. ENDIF. ENDFORM. "check_bp_exist *&---------------------------------------------------------------------* *& Form create_business_partner *&---------------------------------------------------------------------* FORM create_business_partner TABLES et_return STRUCTURE bapiret2 USING is_businesspartner TYPE zstbusinesspartner it_bpadressdata TYPE zttbp_addressdata CHANGING c_bpartner TYPE bu_partner. DATA: l_partnercategory TYPE bapibus1006_head-partn_cat, l_partnergroup TYPE bapibus1006_head-partn_grp, l_centraldata TYPE bapibus1006_central, l_centraldata_person TYPE bapibus1006_central_person, l_centraldata_organ TYPE bapibus1006_central_organ, l_adressdata TYPE bapibus1006_address, l_strlen TYPE i, l_roles TYPE TABLE OF bapibusisb990_bproles WITH HEADER LINE, l_telefondata TYPE TABLE OF bapiadtel WITH HEADER LINE, l_email TYPE TABLE OF bapiadsmtp WITH HEADER LINE, l_return TYPE TABLE OF bapiret2. DATA: l_bpadress TYPE zstbp_addressdata. " Тип БП IF is_businesspartner-legal_enty IS INITIAL. l_strlen = STRLEN( is_businesspartner-taxtype_inn ). CASE l_strlen. WHEN 10. l_partnercategory = '2'." юридическое лицо WHEN 12. l_partnercategory = '1'." физическое лицо WHEN OTHERS. l_partnercategory = '2'." юридическое лицо ENDCASE. ELSE. IF is_businesspartner-legal_enty EQ '06'." ИП l_partnercategory = '1'." физическое лицо ELSE. l_partnercategory = '2'." юридическое лицо ENDIF. ENDIF. " Группировка деловых партнеров l_partnergroup = '0001'."«Контрагенты» " Общие данные CLEAR l_centraldata. IF l_partnercategory EQ '1'." ИП l_centraldata-partnertype = '1'." Частное лицо l_centraldata-partnerlanguage = 'R'. ELSE. l_centraldata-partnerlanguage = 'R'. l_centraldata-partnertype = '4'." Организация ENDIF. l_centraldata-partnerexternal = is_businesspartner-bpext. l_centraldata-searchterm1 = is_businesspartner-taxtype_inn. IF l_centraldata-searchterm1 IS INITIAL. l_centraldata-searchterm1 = is_businesspartner-taxtype_okpo. ENDIF. IF l_centraldata-searchterm1 IS INITIAL. l_centraldata-searchterm1 = is_businesspartner-taxtype_kpp. ENDIF. IF l_centraldata-searchterm1 IS INITIAL. l_centraldata-searchterm1 = is_businesspartner-taxtype_ogrn. ENDIF. " Персональные данные CLEAR l_centraldata_person. IF l_centraldata-partnertype EQ '1'. SPLIT is_businesspartner-supname AT space INTO l_centraldata_person-firstname l_centraldata_person-lastname . l_centraldata_person-correspondlanguage = 'R'. ENDIF. " Организация CLEAR l_centraldata_organ. IF l_centraldata-partnertype EQ '4'. l_centraldata_organ-name1 = is_businesspartner-supname+0(40). l_centraldata_organ-name2 = is_businesspartner-supname+40(40). l_centraldata_organ-name3 = is_businesspartner-supname+80(40). l_centraldata_organ-name4 = is_businesspartner-supname+120(40). l_centraldata_organ-legalform = is_businesspartner-legal_enty. ENDIF. " Адрес CLEAR: l_adressdata,l_bpadress. READ TABLE it_bpadressdata INTO l_bpadress WITH KEY adext_addr = '01'. IF sy-subrc EQ 0. l_adressdata-standardaddress = 'X'. l_adressdata-extaddressnumber = l_bpadress-adext_addr. l_adressdata-country = 'RU'. l_adressdata-langu = 'R'. IF l_bpadress-region IS INITIAL. l_adressdata-city = l_bpadress-adress+0(40). l_adressdata-street = l_bpadress-adress+40(60). l_adressdata-str_suppl1 = l_bpadress-adress+100(40). l_adressdata-str_suppl2 = l_bpadress-adress+140(40). l_adressdata-str_suppl3 = l_bpadress-adress+180(40). l_adressdata-house_no = l_bpadress-adress+220(10). l_adressdata-house_no2 = l_bpadress-adress+230(10). l_adressdata-room_no = l_bpadress-adress+240(10). ELSE. l_adressdata-region = l_bpadress-region. l_adressdata-city = l_bpadress-city1. l_adressdata-district = l_bpadress-city2. l_adressdata-home_city = l_bpadress-home_city. l_adressdata-postl_cod1 = l_bpadress-post_code1. l_adressdata-street = l_bpadress-street. l_adressdata-house_no = l_bpadress-house_num1. l_adressdata-house_no2 = l_bpadress-house_num2. l_adressdata-room_no = l_bpadress-roomnumber. ENDIF. ENDIF. " Телефон CLEAR: l_telefondata[],l_telefondata. IF NOT is_businesspartner-tel_number IS INITIAL. l_telefondata-country = 'RU'. l_telefondata-telephone = is_businesspartner-tel_number. APPEND l_telefondata. ENDIF. " E-mail CLEAR: l_email[],l_email. IF NOT is_businesspartner-smtp_addr IS INITIAL. l_email-std_no = 'X'. l_email-e_mail = is_businesspartner-smtp_addr. APPEND l_email. ENDIF. " Роли БП CLEAR: l_roles[], l_roles.. IF is_businesspartner-role1_leaseholder EQ 'X'. l_roles-partnerrole = 'FLCU00'." «Получатели ПЛ» APPEND l_roles. ENDIF. IF is_businesspartner-role2_supplier EQ 'X'. l_roles-partnerrole = 'FLVN00'." «Поставщики по ДЛ» APPEND l_roles. ELSEIF is_businesspartner-role2_othercompany EQ 'X'. l_roles-partnerrole = 'FLVN01'." «Прочие поставщики» APPEND l_roles. ENDIF. CLEAR: l_return[]. CALL FUNCTION 'BAPI_BUPA_FS_CREATE_FROM_DATA2' EXPORTING partnercategory = l_partnercategory partnergroup = l_partnergroup centraldata = l_centraldata centraldataperson = l_centraldata_person centraldataorganization = l_centraldata_organ addressdata = l_adressdata IMPORTING businesspartner = c_bpartner TABLES telefondata = l_telefondata[] e_maildata = l_email[] return = l_return[] roles = l_roles[]. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDFORM. "create_business_partner *&---------------------------------------------------------------------* *& Form add_address *&---------------------------------------------------------------------* FORM add_address TABLES et_return STRUCTURE bapiret2 USING iv_bpartner TYPE bu_partner is_bp TYPE zstbusinesspartner it_address TYPE zttbp_addressdata. DATA: l_address TYPE zstbp_addressdata, l_bapi_address TYPE bapibus1006_address, l_addressusage TYPE TABLE OF bapibus1006_addressusage WITH HEADER LINE, l_telefon TYPE TABLE OF bapiadtel WITH HEADER LINE, l_email TYPE TABLE OF bapiadsmtp WITH HEADER LINE, l_address_guid TYPE but020-guid, l_return TYPE TABLE OF bapiret2. CHECK NOT iv_bpartner IS INITIAL. LOOP AT it_address INTO l_address. CLEAR: l_bapi_address,l_addressusage[],l_addressusage, l_telefon[],l_telefon, l_email[],l_email. l_bapi_address-standardaddress = ''. l_bapi_address-extaddressnumber = l_address-adext_addr. l_addressusage-standardaddressusage = ''. CASE l_address-adext_addr. WHEN '01'." юридический CONTINUE. l_addressusage-standardaddressusage = 'X'. l_addressusage-addresstype = 'XXDEFAULT'."Стандартный адрес * l_bapi_address-standardaddress = 'X'. " Телефон IF NOT is_bp-tel_number IS INITIAL. l_telefon-telephone = is_bp-tel_number. APPEND l_telefon. ENDIF. " E-mail IF NOT is_bp-smtp_addr IS INITIAL. l_email-std_no = 'X'. l_email-e_mail = is_bp-smtp_addr. APPEND l_email. ENDIF. WHEN '02'." корреспонденция l_addressusage-addresstype = '0001'."Адрес для корреспонденции WHEN '03'." почтовый l_addressusage-addresstype = 'FIRMA'."Адрес фирмы ENDCASE. APPEND l_addressusage. l_bapi_address-country = 'RU'. l_bapi_address-langu = 'R'. IF l_address-region IS INITIAL. l_bapi_address-city = l_address-adress+0(40). l_bapi_address-street = l_address-adress+40(60). l_bapi_address-str_suppl1 = l_address-adress+100(40). l_bapi_address-str_suppl2 = l_address-adress+140(40). l_bapi_address-str_suppl3 = l_address-adress+180(40). l_bapi_address-house_no = l_address-adress+220(10). l_bapi_address-house_no2 = l_address-adress+230(10). l_bapi_address-room_no = l_address-adress+240(10). ELSE. l_bapi_address-region = l_address-region. l_bapi_address-city = l_address-city1. l_bapi_address-district = l_address-city2. l_bapi_address-home_city = l_address-home_city. l_bapi_address-postl_cod1 = l_address-post_code1. l_bapi_address-street = l_address-street. l_bapi_address-house_no = l_address-house_num1. l_bapi_address-house_no2 = l_address-house_num2. l_bapi_address-room_no = l_address-roomnumber. ENDIF. CLEAR: l_address_guid,l_return[]. CALL FUNCTION 'BAPI_BUPA_ADDRESS_ADD' EXPORTING businesspartner = iv_bpartner addressdata = l_bapi_address IMPORTING addressguid = l_address_guid TABLES bapiadtel = l_telefon[] bapiadsmtp = l_email[] addressusage = l_addressusage[] return = l_return[]. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDLOOP. ENDFORM. "add_address *&---------------------------------------------------------------------* *& Form add_industry_sector *&---------------------------------------------------------------------* FORM add_industry_sector TABLES et_return STRUCTURE bapiret2 USING iv_bpartner TYPE bu_partner is_bp TYPE zstbusinesspartner. DATA: l_return TYPE TABLE OF bapiret2. CLEAR: l_return[]. CHECK NOT iv_bpartner IS INITIAL. IF NOT is_bp-ind_sect IS INITIAL. CALL FUNCTION 'BAPI_INDUSTRYSECTOR_ADD' EXPORTING businesspartner = iv_bpartner industrysectorkeysystem = '0001' industrysector = is_bp-ind_sect defaultindustry = '' TABLES return = l_return[]. ENDIF. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDFORM. "add_industry_sector *&---------------------------------------------------------------------* *& Form add_taxnum *&---------------------------------------------------------------------* FORM add_taxnum TABLES et_return STRUCTURE bapiret2 USING iv_bpartner TYPE bu_partner is_bp TYPE zstbusinesspartner. DATA: l_taxtype TYPE bapibus1006tax-taxtype, l_taxnumber TYPE bapibus1006tax-taxnumber, l_return TYPE TABLE OF bapiret2. CHECK NOT iv_bpartner IS INITIAL. " ИНН IF NOT is_bp-taxtype_inn IS INITIAL. PERFORM bapi_bupa_tax_add TABLES l_return USING iv_bpartner 'RU1' is_bp-taxtype_inn. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDIF. " ОКПО IF NOT is_bp-taxtype_okpo IS INITIAL. PERFORM bapi_bupa_tax_add TABLES l_return USING iv_bpartner 'RU2' is_bp-taxtype_okpo. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDIF. " КПП IF NOT is_bp-taxtype_kpp IS INITIAL. PERFORM bapi_bupa_tax_add TABLES l_return USING iv_bpartner 'RU3' is_bp-taxtype_kpp. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDIF. " ОГРН IF NOT is_bp-taxtype_ogrn IS INITIAL. PERFORM bapi_bupa_tax_add TABLES l_return USING iv_bpartner 'RU5' is_bp-taxtype_ogrn. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDIF. ENDFORM. "add_taxnum *&---------------------------------------------------------------------* *& Form BAPI_BUPA_TAX_ADD *&---------------------------------------------------------------------* FORM bapi_bupa_tax_add TABLES et_return STRUCTURE bapiret2 USING bp TYPE bu_partner ttype TYPE bptaxtype tnum TYPE bptaxnum. CLEAR et_return[]. CALL FUNCTION 'BAPI_BUPA_TAX_ADD' EXPORTING businesspartner = bp taxtype = ttype taxnumber = tnum TABLES return = et_return[]. ENDFORM. "BAPI_BUPA_TAX_ADD *&---------------------------------------------------------------------* *& Form add_bank *&---------------------------------------------------------------------* FORM add_bank TABLES et_return STRUCTURE bapiret2 USING iv_bpartner TYPE bu_partner it_bank TYPE zttbp_bankdata. DATA: ls_bank TYPE zstbp_bankdata, l_bankdetailid TYPE bapibus1006_head-bankdetailid, l_bankdetaildata TYPE bapibus1006_bankdetail, l_return TYPE TABLE OF bapiret2. CHECK NOT iv_bpartner IS INITIAL. LOOP AT it_bank INTO ls_bank. CLEAR: l_bankdetaildata,l_bankdetailid,l_return[]. l_bankdetaildata-bank_key = ls_bank-bankl. l_bankdetaildata-ctrl_key = ls_bank-recnumber+0(2). l_bankdetaildata-bank_acct = ls_bank-recnumber+2(18). l_bankdetaildata-bank_ctry = 'RU'. CALL FUNCTION 'BAPI_BUPA_BANKDETAIL_ADD' EXPORTING businesspartner = iv_bpartner bankdetaildata = l_bankdetaildata IMPORTING bankdetailidout = l_bankdetailid TABLES return = l_return[]. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDLOOP. ENDFORM. "add_bank *&---------------------------------------------------------------------* *& Form bapi_commit *&---------------------------------------------------------------------* FORM bapi_commit. DATA: ls_ret TYPE bapiret2. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X' IMPORTING return = ls_ret. ENDFORM. "bapi_commit *&---------------------------------------------------------------------* *& Form bapi_ROLLBACK *&---------------------------------------------------------------------* FORM bapi_rollback. DATA: ls_ret TYPE bapiret2. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' IMPORTING return = ls_ret. ENDFORM. "bapi_ROLLBACK *&---------------------------------------------------------------------* *& Form modify_bp_roles *&---------------------------------------------------------------------* FORM modify_bp_roles TABLES et_return STRUCTURE bapiret2 USING iv_bpartner TYPE bu_partner is_bp TYPE zstbusinesspartner CHANGING ef_create_ven TYPE c ef_create_cus TYPE c. DATA: l_roles TYPE TABLE OF bapibus1006_bproles WITH HEADER LINE, l_return TYPE TABLE OF bapiret2. CLEAR:ef_create_ven, ef_create_cus. " Получим список ролей PERFORM bapi_bupa_roles_get_2 TABLES l_roles[] l_return USING iv_bpartner. IF NOT l_return[] IS INITIAL. * append lines of l_return[] to et_return. ENDIF. " Удаляем роли, для которых не установлен флаг LOOP AT l_roles. CASE l_roles-partnerrole. WHEN 'FLCU00'." «Получатели ПЛ» IF is_bp-role1_leaseholder EQ ''. PERFORM bapi_bupa_role_remove TABLES l_return USING iv_bpartner 'FLCU00'. ENDIF. WHEN 'FLVN00'." «Поставщики по ДЛ» IF is_bp-role2_supplier EQ ''. PERFORM bapi_bupa_role_remove TABLES l_return USING iv_bpartner 'FLVN00'. ENDIF. WHEN 'FLVN01'." «Прочие поставщики» IF is_bp-role2_othercompany EQ ''. PERFORM bapi_bupa_role_remove TABLES l_return USING iv_bpartner 'FLVN01'. ENDIF. ENDCASE. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return[] TO et_return. ENDIF. ENDLOOP. " Добавим новые роли IF is_bp-role1_leaseholder EQ 'X'. READ TABLE l_roles WITH KEY partnerrole = 'FLCU00'. IF NOT sy-subrc EQ 0. " «Получатели ПЛ» PERFORM bapi_bupa_role_add_2 TABLES l_return USING iv_bpartner 'FLCU00'. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return[] TO et_return. ENDIF. ef_create_cus = 'X'. ENDIF. ENDIF. IF is_bp-role2_supplier EQ 'X'. READ TABLE l_roles WITH KEY partnerrole = 'FLVN00'. IF NOT sy-subrc EQ 0. " «Поставщики по ДЛ» PERFORM bapi_bupa_role_add_2 TABLES l_return USING iv_bpartner 'FLVN00'. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return[] TO et_return. ENDIF. ef_create_ven = 'X'. ENDIF. ELSEIF is_bp-role2_othercompany EQ 'X'. READ TABLE l_roles WITH KEY partnerrole = 'FLVN01'. IF NOT sy-subrc EQ 0. " «Прочие поставщики» PERFORM bapi_bupa_role_add_2 TABLES l_return USING iv_bpartner 'FLVN01'. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return[] TO et_return. ENDIF. ef_create_ven = 'X'. ENDIF. ENDIF. ENDFORM. "modify_bp_roles *&---------------------------------------------------------------------* *& Form BAPI_BUPA_ROLES_GET_2 *&---------------------------------------------------------------------* FORM bapi_bupa_roles_get_2 TABLES et_roles STRUCTURE bapibus1006_bproles et_return STRUCTURE bapiret2 USING iv_bp TYPE bu_partner. CLEAR: et_roles[],et_return[]. CALL FUNCTION 'BAPI_BUPA_ROLES_GET_2' EXPORTING businesspartner = iv_bp TABLES businesspartnerroles = et_roles[] return = et_return[]. ENDFORM. "BAPI_BUPA_ROLES_GET_2 *&---------------------------------------------------------------------* *& Form BAPI_BUPA_ROLE_REMOVE *&---------------------------------------------------------------------* FORM bapi_bupa_role_remove TABLES et_return STRUCTURE bapiret2 USING iv_bp TYPE bu_partner iv_role TYPE bu_partnerrole. CLEAR et_return[]. CALL FUNCTION 'BAPI_BUPA_ROLE_REMOVE' EXPORTING businesspartner = iv_bp businesspartnerrole = iv_role TABLES return = et_return[]. ENDFORM. "BAPI_BUPA_ROLE_REMOVE *&---------------------------------------------------------------------* *& Form BAPI_BUPA_ROLE_ADD_2 *&---------------------------------------------------------------------* FORM bapi_bupa_role_add_2 TABLES et_return STRUCTURE bapiret2 USING iv_bp TYPE bu_partner iv_role TYPE bu_partnerrole. CLEAR et_return[]. CALL FUNCTION 'BAPI_BUPA_ROLE_ADD_2' EXPORTING businesspartner = iv_bp businesspartnerrole = iv_role TABLES return = et_return[]. ENDFORM. "BAPI_BUPA_ROLE_ADD_2 *&---------------------------------------------------------------------* *& Form modify_common_data *&---------------------------------------------------------------------* FORM modify_common_data TABLES et_return STRUCTURE bapiret2 USING iv_bpartner TYPE bu_partner is_bp TYPE zstbusinesspartner. DATA: l_centraldata TYPE bapibus1006_central, l_person TYPE bapibus1006_central_person, l_organization TYPE bapibus1006_central_organ, l_centraldata_x TYPE bapibus1006_central_x, l_person_x TYPE bapibus1006_central_person_x, l_organization_x TYPE bapibus1006_central_organ_x, l_return TYPE TABLE OF bapiret2. CLEAR: l_centraldata,l_person,l_organization,l_centraldata_x, l_person_x,l_organization_x. " Общие данные l_centraldata-searchterm1 = is_bp-taxtype_inn. IF l_centraldata-searchterm1 IS INITIAL. l_centraldata-searchterm1 = is_bp-taxtype_okpo. ENDIF. IF l_centraldata-searchterm1 IS INITIAL. l_centraldata-searchterm1 = is_bp-taxtype_kpp. ENDIF. IF l_centraldata-searchterm1 IS INITIAL. l_centraldata-searchterm1 = is_bp-taxtype_ogrn. ENDIF. IF is_bp-legal_enty EQ '06'." ИП l_centraldata-partnertype = '1'." Частное лицо l_centraldata-partnerlanguage = 'R'. ELSE. l_centraldata-partnertype = '4'." Организация l_centraldata-partnerlanguage = 'R'. ENDIF. l_centraldata-partnerexternal = is_bp-bpext. " Персональные данные IF l_centraldata-partnertype EQ '1'. SPLIT is_bp-supname AT space INTO l_person-firstname l_person-lastname . ENDIF. " Организация IF l_centraldata-partnertype EQ '4'. l_organization-name1 = is_bp-supname+0(40). l_organization-name2 = is_bp-supname+40(40). l_organization-name3 = is_bp-supname+80(40). l_organization-name4 = is_bp-supname+120(40). l_organization-legalform = is_bp-legal_enty. ENDIF. MOVE 'X' TO: l_centraldata_x-searchterm1, l_centraldata_x-partnertype, l_centraldata_x-partnerlanguage, l_centraldata_x-partnerexternal. IF l_centraldata-partnertype EQ '1'. MOVE 'X' TO: l_person_x-firstname, l_person_x-lastname. ENDIF. IF l_centraldata-partnertype EQ '4'. MOVE 'X' TO: l_organization_x-name1, l_organization_x-name2, l_organization_x-name3, l_organization_x-name4, l_organization_x-legalform. ENDIF. CLEAR l_return[]. CALL FUNCTION 'BAPI_BUPA_CENTRAL_CHANGE' EXPORTING businesspartner = iv_bpartner centraldata = l_centraldata centraldataperson = l_person centraldataorganization = l_organization centraldata_x = l_centraldata_x centraldataperson_x = l_person_x centraldataorganization_x = l_organization_x TABLES return = l_return[]. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return[] TO et_return. ENDIF. ENDFORM. "modify_common_data *&---------------------------------------------------------------------* *& Form modify_address *&---------------------------------------------------------------------* FORM modify_address TABLES et_return STRUCTURE bapiret2 USING iv_bpartner TYPE bu_partner is_bp TYPE zstbusinesspartner it_bpadressdata TYPE zttbp_addressdata. DATA: l_addr_list TYPE TABLE OF bapibus1006_addresses WITH HEADER LINE, l_addr_list_all TYPE TABLE OF bapibus1006_addresses WITH HEADER LINE. DATA: l_address TYPE zstbp_addressdata, l_addressdata TYPE bapibus1006_address, l_addressdata_x TYPE bapibus1006_address_x, l_tel TYPE TABLE OF bapiadtel WITH HEADER LINE, l_mail TYPE TABLE OF bapiadsmtp WITH HEADER LINE, l_addressusage TYPE TABLE OF bapibus1006_addressusage WITH HEADER LINE, l_tel_x TYPE TABLE OF bapiadtelx WITH HEADER LINE, l_mail_x TYPE TABLE OF bapiadsmtx WITH HEADER LINE, l_addressusage_x TYPE TABLE OF bapibus1006_addressusage_x WITH HEADER LINE, l_address_guid TYPE but020-guid, l_return TYPE TABLE OF bapiret2. PERFORM get_all_addresses TABLES l_addr_list[] l_addr_list_all[] l_return[] USING iv_bpartner. IF NOT l_return[] IS INITIAL. * append lines of l_return to et_return. ENDIF. PERFORM delete_all_addresses TABLES l_addr_list[] l_addr_list_all[] l_return[] USING iv_bpartner. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. LOOP AT it_bpadressdata INTO l_address. CLEAR: l_addressdata,l_addressdata_x, l_tel,l_mail,l_addressusage, l_tel[],l_mail[],l_addressusage[], l_tel_x,l_mail_x,l_addressusage_x, l_tel_x[],l_mail_x[],l_addressusage_x[]. l_addressdata-standardaddress = ''. l_addressdata-extaddressnumber = l_address-adext_addr. l_addressusage-standardaddressusage = ''. CASE l_address-adext_addr. WHEN '01'." юридический l_addressusage-standardaddressusage = 'X'. l_addressusage-addresstype = 'XXDEFAULT'."Стандартный адрес " Телефон IF NOT is_bp-tel_number IS INITIAL. l_tel-telephone = is_bp-tel_number. APPEND l_tel. ENDIF. " E-mail IF NOT is_bp-smtp_addr IS INITIAL. l_mail-std_no = 'X'. l_mail-e_mail = is_bp-smtp_addr. APPEND l_mail. ENDIF. WHEN '02'." корреспонденция l_addressusage-addresstype = '0001'."Адрес для корреспонденции WHEN '03'." почтовый l_addressusage-addresstype = 'FIRMA'."Адрес фирмы ENDCASE. APPEND l_addressusage. l_addressdata-country = 'RU'. l_addressdata-langu = 'R'. IF l_address-region IS INITIAL. l_addressdata-city = l_address-adress+0(40). l_addressdata-street = l_address-adress+40(60). l_addressdata-str_suppl1 = l_address-adress+100(40). l_addressdata-str_suppl2 = l_address-adress+140(40). l_addressdata-str_suppl3 = l_address-adress+180(40). l_addressdata-house_no = l_address-adress+220(10). l_addressdata-house_no2 = l_address-adress+230(10). l_addressdata-room_no = l_address-adress+240(10). ELSE. l_addressdata-region = l_address-region. l_addressdata-city = l_address-city1. l_addressdata-district = l_address-city2. l_addressdata-home_city = l_address-home_city. l_addressdata-postl_cod1 = l_address-post_code1. l_addressdata-street = l_address-street. l_addressdata-house_no = l_address-house_num1. l_addressdata-house_no2 = l_address-house_num2. l_addressdata-room_no = l_address-roomnumber. ENDIF. CLEAR: l_address_guid,l_return[]. CALL FUNCTION 'BAPI_BUPA_ADDRESS_ADD' EXPORTING businesspartner = iv_bpartner addressdata = l_addressdata IMPORTING addressguid = l_address_guid TABLES bapiadtel = l_tel[] bapiadsmtp = l_mail[] addressusage = l_addressusage[] return = l_return[]. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDLOOP. ENDFORM. "modify_address *&---------------------------------------------------------------------* *& Form get_all_addresses *&---------------------------------------------------------------------* FORM get_all_addresses TABLES et_addr STRUCTURE bapibus1006_addresses et_addrall STRUCTURE bapibus1006_addresses et_return STRUCTURE bapiret2 USING iv_bp TYPE bu_partner. CLEAR:et_addr[],et_addrall[],et_return[]. CALL FUNCTION 'BAPI_BUPA_ADDRESSES_GET' EXPORTING businesspartner = iv_bp TABLES addresses = et_addr[] addresses_all = et_addrall[] return = et_return[]. ENDFORM. "get_all_addresses *&---------------------------------------------------------------------* *& Form delete_all_addresses *&---------------------------------------------------------------------* FORM delete_all_addresses TABLES it_addr STRUCTURE bapibus1006_addresses it_addrall STRUCTURE bapibus1006_addresses et_return STRUCTURE bapiret2 USING iv_bp TYPE bu_partner. DATA: l_return TYPE TABLE OF bapiret2. CLEAR: et_return[]. LOOP AT it_addrall WHERE NOT standardaddress EQ 'X'. CLEAR l_return[]. CALL FUNCTION 'BAPI_BUPA_ADDRESS_REMOVE' EXPORTING businesspartner = iv_bp addressguid = it_addrall-addressguid TABLES return = l_return. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDLOOP. LOOP AT it_addrall WHERE standardaddress EQ 'X'. CLEAR l_return[]. CALL FUNCTION 'BAPI_BUPA_ADDRESS_REMOVE' EXPORTING businesspartner = iv_bp addressguid = it_addrall-addressguid TABLES return = l_return. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDLOOP. ENDFORM. "delete_all_addresses *&---------------------------------------------------------------------* *& Form modify_industry *&---------------------------------------------------------------------* FORM modify_industry TABLES et_return STRUCTURE bapiret2 USING iv_bpartner TYPE bu_partner is_bp TYPE zstbusinesspartner. DATA: l_industry_all TYPE TABLE OF bapibus1006_industrysector WITH HEADER LINE, l_return TYPE TABLE OF bapiret2. " Получаем перечвень отраслей для ДП CLEAR: l_industry_all[],l_return. CALL FUNCTION 'BAPI_INDUSTRYSECTORDETAILS_GET' EXPORTING businesspartner = iv_bpartner TABLES industrysectordetail = l_industry_all[] return = l_return. IF NOT l_return[] IS INITIAL. * append lines of l_return to et_return. ENDIF. " Удаляем отрасли LOOP AT l_industry_all. CLEAR l_return. CALL FUNCTION 'BAPI_INDUSTRYSECTOR_REMOVE' EXPORTING businesspartner = iv_bpartner industrysectorkeysystem = l_industry_all-industrysectorkeysystem industrysector = l_industry_all-industrysector TABLES return = l_return. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDLOOP. " Добавляем новые CLEAR l_return. PERFORM add_industry_sector TABLES l_return USING iv_bpartner is_bp. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDFORM. "modify_industry *&---------------------------------------------------------------------* *& Form modify_taxnum *&---------------------------------------------------------------------* FORM modify_taxnum TABLES et_return STRUCTURE bapiret2 USING iv_bpartner TYPE bu_partner is_bp TYPE zstbusinesspartner. DATA: l_taxnum_exist TYPE c, l_return TYPE TABLE OF bapiret2. CLEAR l_return[]. PERFORM delete_all_taxnum TABLES l_return USING iv_bpartner. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. CLEAR l_return[]. PERFORM add_taxnum TABLES l_return USING iv_bpartner is_bp. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDFORM. "modify_taxnum *&---------------------------------------------------------------------* *& Form delete_all_taxnum *&---------------------------------------------------------------------* FORM delete_all_taxnum TABLES et_return STRUCTURE bapiret2 USING iv_bpartner TYPE bu_partner. DATA: l_taxnum_exist TYPE c, l_return TYPE TABLE OF bapiret2. PERFORM check_taxnumtype_exist USING iv_bpartner 'RU1' CHANGING l_taxnum_exist. IF l_taxnum_exist EQ 'X'. PERFORM taxnum_delete TABLES l_return USING iv_bpartner 'RU1'. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDIF. PERFORM check_taxnumtype_exist USING iv_bpartner 'RU2' CHANGING l_taxnum_exist. IF l_taxnum_exist EQ 'X'. PERFORM taxnum_delete TABLES l_return USING iv_bpartner 'RU2'. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDIF. PERFORM check_taxnumtype_exist USING iv_bpartner 'RU3' CHANGING l_taxnum_exist. IF l_taxnum_exist EQ 'X'. PERFORM taxnum_delete TABLES l_return USING iv_bpartner 'RU3'. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDIF. PERFORM check_taxnumtype_exist USING iv_bpartner 'RU5' CHANGING l_taxnum_exist. IF l_taxnum_exist EQ 'X'. PERFORM taxnum_delete TABLES l_return USING iv_bpartner 'RU5'. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDIF. ENDFORM. "delete_all_taxnum *&---------------------------------------------------------------------* *& Form check_taxnumtype_exist *&---------------------------------------------------------------------* FORM check_taxnumtype_exist USING iv_bpartner TYPE bu_partner iv_type TYPE bptaxtype CHANGING c_exist TYPE c. DATA: lv_num TYPE bptaxnum. CLEAR lv_num. CALL FUNCTION 'BAPI_BUPA_TAX_GETDETAIL' EXPORTING businesspartner = iv_bpartner taxtype = iv_type IMPORTING taxnumber = lv_num. IF lv_num IS INITIAL. c_exist = ''. ELSE. c_exist = 'X'. ENDIF. ENDFORM. "check_taxnumtype_exist *&---------------------------------------------------------------------* *& Form taxnum_delete *&---------------------------------------------------------------------* FORM taxnum_delete TABLES et_return STRUCTURE bapiret2 USING iv_bpartner TYPE bu_partner iv_type TYPE bptaxtype. CLEAR et_return[]. CALL FUNCTION 'BAPI_BUPA_TAX_REMOVE' EXPORTING businesspartner = iv_bpartner taxtype = iv_type TABLES return = et_return[]. ENDFORM. "taxnum_delete *&---------------------------------------------------------------------* *& Form modify_bank *&---------------------------------------------------------------------* FORM modify_bank TABLES et_return STRUCTURE bapiret2 USING iv_bpartner TYPE bu_partner it_bank TYPE zttbp_bankdata. DATA: l_banks TYPE TABLE OF bapibus1006_bankdetails WITH HEADER LINE, l_return TYPE TABLE OF bapiret2. CLEAR l_return[]. PERFORM get_all_banks TABLES l_banks[] l_return USING iv_bpartner. IF NOT l_return[] IS INITIAL. * append lines of l_return to et_return. ENDIF. PERFORM delete_all_banks TABLES l_banks[] l_return USING iv_bpartner. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. CLEAR l_return. PERFORM add_bank TABLES l_return USING iv_bpartner it_bank[]. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDFORM. "modify_bank *&---------------------------------------------------------------------* *& Form get_all_banks *&---------------------------------------------------------------------* FORM get_all_banks TABLES et_banks STRUCTURE bapibus1006_bankdetails et_return STRUCTURE bapiret2 USING iv_bp TYPE bu_partner. CLEAR: et_banks[],et_return[]. CALL FUNCTION 'BAPI_BUPA_BANKDETAILS_GET' EXPORTING businesspartner = iv_bp TABLES bankdetails = et_banks[] return = et_return[]. ENDFORM. "get_all_banks *&---------------------------------------------------------------------* *& Form delete_all_banks *&---------------------------------------------------------------------* FORM delete_all_banks TABLES it_banks STRUCTURE bapibus1006_bankdetails et_return STRUCTURE bapiret2 USING iv_bp TYPE bu_partner. DATA: l_return TYPE TABLE OF bapiret2. CLEAR: et_return[]. LOOP AT it_banks. CLEAR l_return[]. CALL FUNCTION 'BAPI_BUPA_BANKDETAIL_REMOVE' EXPORTING businesspartner = iv_bp bankdetailid = it_banks-bankdetailid TABLES return = l_return. IF NOT l_return IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDLOOP. ENDFORM. "delete_all_banks *&---------------------------------------------------------------------* *& Form create_vendor *&---------------------------------------------------------------------* FORM create_vendor TABLES et_return STRUCTURE bapiret2 USING iv_bp TYPE bu_partner is_bp TYPE zstbusinesspartner. DATA: l_lifnr TYPE lifnr, l_akont TYPE akont, l_ktokk TYPE ktokk, l_return TYPE TABLE OF bapiret2, l_create TYPE c. l_create = ''. l_lifnr = iv_bp. IF is_bp-role2_supplier EQ 'X'." FLVN00 «Поставщики по ДЛ» l_akont = '0060110000'. l_ktokk = '0001'. l_create = 'X'. ELSEIF is_bp-role2_othercompany EQ 'X'." FLVN01 «Прочие поставщики» l_akont = '0060010000'. l_ktokk = '0002'. l_create = 'X'. ENDIF. " Если роли не добавлены, то создавать кредитора не надо IF l_create EQ 'X'. PERFORM bp_vendor_create TABLES l_return USING l_lifnr l_akont l_ktokk. ENDIF. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDFORM. "create_vendor *&---------------------------------------------------------------------* *& Form bp_vendor_create *&---------------------------------------------------------------------* FORM bp_vendor_create TABLES et_return STRUCTURE bapiret2 USING i_lifnr TYPE lifnr i_akont TYPE akont i_ktokk TYPE ktokk. DATA: l_return TYPE TABLE OF bapiret2. CALL FUNCTION 'Z_BP_VENDOR_CREATE' EXPORTING i_lifnr = i_lifnr i_akont = i_akont i_ktokk = i_ktokk TABLES et_return = l_return. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. CLEAR l_return[]. PERFORM bp_vendor_change TABLES l_return USING i_lifnr i_akont. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDFORM. "bp_vendor_create *&---------------------------------------------------------------------* *& Form bp_vendor_change *&---------------------------------------------------------------------* FORM bp_vendor_change TABLES et_return STRUCTURE bapiret2 USING i_lifnr TYPE lifnr i_akont TYPE akont. DATA: l_return TYPE TABLE OF bapiret2. CALL FUNCTION 'Z_BP_VENDOR_CHANGE' EXPORTING i_lifnr = i_lifnr i_akont = i_akont TABLES et_return = l_return. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDFORM. "bp_vendor_change *&---------------------------------------------------------------------* *& Form change_vendor *&---------------------------------------------------------------------* FORM change_vendor TABLES et_return STRUCTURE bapiret2 USING iv_bp TYPE bu_partner is_bp TYPE zstbusinesspartner. DATA: l_lifnr TYPE lifnr, l_akont TYPE akont, l_ktokk TYPE ktokk. DATA: l_return TYPE TABLE OF bapiret2. l_lifnr = iv_bp. IF is_bp-role2_supplier EQ 'X'." FLVN00 «Поставщики по ДЛ» l_akont = '0060110000'. ELSEIF is_bp-role2_othercompany EQ 'X'." FLVN01 «Прочие поставщики» l_akont = '0060010000'. ENDIF. PERFORM bp_vendor_change TABLES l_return USING l_lifnr l_akont. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDFORM. "change_vendor *&---------------------------------------------------------------------* *& Form create_customer *&---------------------------------------------------------------------* FORM create_customer TABLES et_return STRUCTURE bapiret2 USING iv_bp TYPE bu_partner is_bp TYPE zstbusinesspartner. DATA: l_kunnr TYPE kunnr, l_mahna TYPE mahna, l_return TYPE TABLE OF bapiret2, l_create TYPE c. l_create = ''. l_kunnr = iv_bp. IF is_bp-role1_leaseholder EQ 'X'. l_create = 'X'. ENDIF. IF l_create EQ 'X'. CALL FUNCTION 'Z_BP_CUSTOMER_CREATE' EXPORTING i_kunnr = l_kunnr TABLES et_return = l_return. ENDIF. IF NOT l_return[] IS INITIAL. APPEND LINES OF l_return TO et_return. ENDIF. ENDFORM. "create_customer *&---------------------------------------------------------------------* *& Form check_error_exist *&---------------------------------------------------------------------* FORM check_error_exist TABLES it_return STRUCTURE bapiret2 USING value(i_step) CHANGING e_type TYPE bapi_mtype e_message TYPE bapi_msg. READ TABLE it_return WITH KEY type = 'E'. CHECK sy-subrc EQ 0. e_type = 'E'. CASE i_step. WHEN 'CR_BP'. e_message = 'Ошибка при создании ДП'. WHEN 'ADDR_ADD'. e_message = 'Ошибка при добавлении адресных данных'. WHEN 'IDSTR_ADD'. e_message = 'Ошибка при добавлении отрасли'. WHEN 'TAXN_ADD'. e_message = 'Ошибка при добавлении налоговых номеров'. WHEN 'BANK_ADD'. e_message = 'Ошибка при добавлении банковских реквизитов'. WHEN 'ROLE_UPD'. e_message = 'Ошибка при изменении ролей ДП'. WHEN 'COMM_UPD'. e_message = 'Ошибка при изменении "Деловой Партнер: Общее"'. WHEN 'ADDR_UPD'. e_message = 'Ошибка при изменении адресных данных'. WHEN 'IDSTR_UPD'. e_message = 'Ошибка при изменении отрасли'. WHEN 'TAXN_UPD'. e_message = 'Ошибка при изменении налоговых номеров'. WHEN 'BANK_UPD'. e_message = 'Ошибка при изменении банковских реквизитов'. WHEN 'VEND_CRE'. e_message = 'Ошибка при создании кредитора'. WHEN 'CUST_CRE'. e_message = 'Ошибка при создании дебитора'. WHEN 'VEND_UPD'. e_message = 'Ошибка при обновлении данных кредитора'. ENDCASE. ENDFORM. "check_error_exist *&---------------------------------------------------------------------* *& Form check_customer_exist *&---------------------------------------------------------------------* FORM check_customer_exist USING i_bp TYPE bu_partner CHANGING e_cr TYPE c. DATA: l_bp TYPE kunnr. l_bp = i_bp. IF e_cr EQ 'X'. SELECT SINGLE kunnr FROM knb1 INTO l_bp WHERE kunnr EQ l_bp AND bukrs EQ 'CARC'. IF sy-subrc EQ 0. e_cr = ''. ENDIF. ENDIF. ENDFORM. "check_customer_exist *&---------------------------------------------------------------------* *& Form check_vendor_exist *&---------------------------------------------------------------------* FORM check_vendor_exist USING i_bp TYPE bu_partner CHANGING e_cr TYPE c. DATA: l_bp TYPE lifnr. l_bp = i_bp. IF e_cr EQ 'X'. SELECT SINGLE lifnr FROM lfb1 INTO l_bp WHERE lifnr EQ l_bp AND bukrs EQ 'CARC'. IF sy-subrc EQ 0. e_cr = ''. ENDIF. ENDIF. ENDFORM. "check_vendor_exist

Комментариев нет:

Отправить комментарий