供应商主数据导入和更新,BDC中没有email地址字段,只能使用函数,以下为相关资料:
加锁:
示例函数:
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* email地址不能通过BDC更新,所以开发本函数进行更新 CONSTANTS: cns_table_type TYPE ad_tabtype VALUE 'ADSMTP'. DATA: lv_address_number TYPE adr6-addrnumber. DATA:lt_adsmtp TYPE adsmtp OCCURS 0 , ls_adsmtp TYPE adsmtp, lt_aduse TYPE adsuse OCCURS 0 , ls_aduse TYPE adsuse. FIELD-SYMBOLS:<fs_adsmtp> TYPE adsmtp, <fs_aduse> TYPE adsuse.*********************************************************************** 检查供应商是否存在 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.*********************************************************************** 加锁 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 sy-msgv4. WAIT UP TO 1 SECONDS. ev_return = 'E'. ELSE. CLEAR ev_return. EXIT. "exit do ENDIF. ENDDO. IF ev_return EQ 'E'. RETURN. ENDIF.*********************************************************************** 读取已有的email CALL FUNCTION 'ADDR_COMM_GET' EXPORTING* ADDRESS_HANDLE = ' ' address_number = lv_address_number* DATE_FROM = '00010101'* 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 sy-msgv4. ENDIF.*********************************************************************** 准备新的email地址 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'. APPEND ls_adsmtp TO lt_adsmtp. ENDIF. IF lt_aduse[] IS NOT INITIAL. LOOP AT lt_aduse ASSIGNING <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_returncode TYPE szad_field-returncode, lt_error_table TYPE addr_error OCCURS 0, ls_error_table TYPE addr_error. CALL FUNCTION 'ADDR_COMM_MAINTAIN' EXPORTING* ADDRESS_HANDLE = ' ' address_number = lv_address_number* DATE_FROM = '00010101'* 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 sy-msgv4. 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 sy-msgv4. ev_return = 'E'. ROLLBACK WORK. ELSE. ev_return = 'S'. COMMIT WORK. ENDIF. ENDIF.***********************************************************************解锁 CALL FUNCTION 'DEQUEUE_EXLFA1' EXPORTING* MODE_LFA1 = 'E'* MANDT = SY-MANDT lifnr = iv_lifnr* X_LIFNR = ' '* _SCOPE = '3'* _SYNCHRON = ' '* _COLLECT = ' ' .ENDFUNCTION.