The supplier's primary data is imported and updated. BDC does not have an email address field and can only use functions. The following information is required:
Lock:
Http://help.sap.com/saphelp_nw70/helpdata/EN/12/ad79815c5811d3b4ea006094192fe3/content.htm
Http://www.sapnet.ru/viewtopic.php? P = 202
Http://help.sap.com/saphelp_sm32/helpdata/en/e9/9fd7cc7f0eeb4d823b9f1d8fb9f0b4/content.htm
Example function:
Function Zr000mm_vendor_email_update.
*"----------------------------------------------------------------------
* "*" Local interface:
* "Importing
* "Reference (iv_lifnr) type lifnr
* "Reference (iv_email) type ad_smtpadr optional
* "Exporting
* "Reference (ev_return) Type C
* "Exceptions
* "Error_no_vendor
*"----------------------------------------------------------------------
* Added by zhumk @ 20110913
* The email address cannot be updated through BDC, so this function is developed for updates.
Constants: Cns_table_typeTypeAd_tabtypeValue 'Adsmtp'.
Data: Lv_address_numberTypeAdr6-addrnumber.
Data: Lt_adsmtpTypeAdsmtpOccurs 0,
Ls_adsmtpTypeAdsmtp,
Lt_aduseTypeAdsuseOccurs 0,
Ls_aduseTypeAdsuse.
Field-Symbols: <fs_adsmtp>TypeAdsmtp,
<Fs_aduse>TypeAdsuse.
***************************** **************************************** *
* check whether the supplier exists
select single adrnr
into lv_address_number
from lfa1
where lifnr = iv_lifnr.
If sy-subrc Ne 0 .
ev_return = 'E' .
raise error_no_vendor.
endif .
**************************************** ******************************
* Lock
Do 5 Times.
Call Function 'Enqueue _ exlfa1'
Exporting
* Mode_lfa1 = 'E'
* Mandt = SY-MANDT
Lifnr = iv_lifnr
* X_lifnr =''
* _ Scope = '2'
* _ Wait =''
* _ Collect =''
Exceptions
Foreign_lock = 1
System_failure = 2
Others = 3
.
If Sy-subrc <> 0 .
* Message ID sy-msgid type sy-msgty number sy-msgno
* With sy-msgv1 sy-msgv2 sy-msgv3.
Wait Up To 1 Seconds.
Ev_return = 'E' .
Else .
Clear Ev_return.
Exit . "Exit do
Endif .
Enddo.
IfEv_returnEQ 'E'.
Return.
Endif.
**************************************** ******************************
* Read existing emails
Call Function 'Addr _ comm_get'
Exporting
* Address_handle =''
Address_number = lv_address_number
* Date_from = '000000'
* Language = SY-LANGU
Table_type = cns_table_type
* Iv_current_state = 'X'
* Importing
* Returncode =
Tables
Comm_table = lt_adsmtp
* Error_table =
Et_usage = lt_aduse
Exceptions
Parameter_error = 1
Address_not_exist = 2
Internal_error = 3
Others = 4
.
If Sy-subrc <> 0 .
* Message ID sy-msgid type sy-msgty number sy-msgno
* With sy-msgv1 sy-msgv2 sy-msgv3.
Endif .
**************************************** ******************************
* Prepare a new email address.
If Lt_adsmtp [] Is Not Initial .
Read Table Lt_adsmtp Assigning <Fs_adsmtp> Index 1 .
<Fs_adsmtp>-smtp_addr = iv_email.
<Fs_adsmtp>-smtp_srch = iv_email ( 20 ).
Translate <Fs_adsmtp>-smtp_srch To Upper Case .
<Fs_adsmtp>-updateflag = 'U' .
Else .
Clear Ls_adsmtp.
Ls_adsmtp-consnumber = 001 .
Ls_adsmtp-flgdefault = 'X' .
Ls_adsmtp-home_flag = 'X' .
Ls_adsmtp-smtp_addr = iv_email.
Ls_adsmtp-smtp_srch = iv_email ( 20 ).
Translate Ls_adsmtp-smtp_srch To Upper Case .
Ls_adsmtp-updateflag = 'I' .
AppendLs_adsmtpToLt_adsmtp.
Endif.
If Lt_aduse [] Is Not Initial .
Loop At Lt_aduseAssigning <Fs_aduse>.
<Fs_aduse>-updateflag = 'U' .
Endloop .
Else .
Clear Ls_aduse.
Ls_aduse-consnumber = '001' .
Ls_aduse-comm_usage = 'Ad _ default' . "Ad_home
Ls_aduse-def_usage = 'X' .
Ls_aduse-updateflag = 'I' .
Append Ls_aduse To Lt_aduse.
clear ls_aduse.
ls_aduse-consnumber = '001' .
ls_aduse-comm_usage = 'ad _ home' .
ls_aduse-def_usage = 'X' .
ls_aduse-updateflag = 'I .
append ls_aduse to lt_aduse.
endif .
Data: Lv_returncodeTypeSzad_field-returncode,
Lt_error_tableTypeAddr_errorOccurs 0,
Ls_error_tableTypeAddr_error.
Call Function 'Addr _ comm_maintain'
Exporting
* Address_handle =''
Address_number = lv_address_number
* Date_from = '000000'
* Language = SY-LANGU
Table_type = cns_table_type
* Substitute_all_comm_data =''
* Accept_telnr_call =''
* Consider_consnumber_for_insert =''
* Check_address = 'X'
* Iv_time_dependence =''
Importing
Returncode = lv_returncode
Tables
Comm_table = lt_adsmtp
Error_table = lt_error_table
* Comm_table_out =
It_usage = lt_aduse
* Et_usage_out =
Exceptions
Parameter_error = 1
Address_not_exist = 2
Internal_error = 3
Others = 4
.
If Sy-subrc <> 0 .
* Message ID sy-msgid type sy-msgty number sy-msgno
* With sy-msgv1 sy-msgv2 sy-msgv3.
Ev_return ='E' .
Return .
Else .
Call Function 'Addr _ single_save'
Exporting
Address_number = lv_address_number
* Person_number =''
* Address_type = 1
* Execute_in_update_task =''
Exceptions
Address_not_exist = 1
Person_not_exist = 2
Address_number_missing = 3
Reference_missing = 4
Internal_error = 5
Database_error = 6
Parameter_error = 7
Others = 8
.
If Sy-subrc <> 0 .
* Message ID sy-msgid type sy-msgty number sy-msgno
* With sy-msgv1 sy-msgv2 sy-msgv3.
Ev_return = 'E' .
Rollback Work .
Else .
Ev_return = 'S' .
Commit Work .
Endif .
Endif.
**************************************** ******************************
* Unlock
Call Function 'Destue _ exlfa1'
Exporting
* Mode_lfa1 = 'E'
* Mandt = SY-MANDT
Lifnr = iv_lifnr
* X_lifnr =''
* _ Scope = '3'
* _ Synchron =''
* _ Collect =''
.
Endfunction.