Skip to Content
author's profile photo Former Member
Former Member

BAPI : Update Email Address and make it as default in XD03.

Dear SAP Seniors,

I am updating the customer Master email address using BAPI_ADDRESSORG_CHANGE.

p_kunnr is customer number input to BAPI,

P_email is email address input to bapi.

If p_email is already exists in system, I do not want to insert a new record but want to modify p_email as default email address in customer master data.

my issues is when I am updating, the email is not set as default. let me know what I can do to set it as default.

Start of code...


I_OBJ_ID  = P_KUNNR.  

select * from Adr6 table into table it_adr6 
                       where ADDRNUMBER = p_adrnr. 
* ( I got p_adrnr from KNA1 table )                   

     
read table it_adr6 with key SMTP_ADDR = p_email.
  
if sy-subrc = 0.
    
    WA_BAPIADSMTP-STD_NO = 'X'.               
    WA_BAPIADSMTP-E_MAIL = p_email.
    WA_BAPIADSMTP-CONSNUMBER  = it_adr6-consnumber.   

    APPEND WA_BAPIADSMTP TO IT_BAPIADSMTP.     
    CLEAR WA_BAPIADSMTP.
    
    WA_BAPIADSMT_X-STD_NO = 'X'.
    WA_BAPIADSMT_X-E_MAIL = 'X'.
    WA_BAPIADSMT_X-UPDATEFLAG = 'U'.

    APPEND WA_BAPIADSMT_X TO IT_BAPIADSMT_X.    
    CLEAR WA_BAPIADSMT_X.
      
  else.
    WA_BAPIADSMTP-STD_NO = 'X'.               
    WA_BAPIADSMTP-E_MAIL = p_email.
    WA_BAPIADSMTP-CONSNUMBER  = 001.   
    
    APPEND WA_BAPIADSMTP TO IT_BAPIADSMTP.     
    CLEAR WA_BAPIADSMTP.
    
    WA_BAPIADSMT_X-UPDATEFLAG = 'I'

    APPEND WA_BAPIADSMT_X TO IT_BAPIADSMT_X.    
    CLEAR WA_BAPIADSMT_X. 


  endif.



CALL FUNCTION 'BAPI_ADDRESSORG_CHANGE'            
        EXPORTING
          OBJ_TYPE                          = I_OBJ_TYPE
          OBJ_ID                            = I_OBJ_ID
          OBJ_ID_EXT                        = ' '
          CONTEXT                           = 1
       IMPORTING
         ADDRESS_NUMBER                     = ADDRNUM
       TABLES
          BAPIADSMTP                        = IT_BAPIADSMTP
          BAPIADSMT_X                       = IT_BAPIADSMT_X
          RETURN                            = IT_RETURNS

This is working great, when I am insert a new email address for customer, However if the ADR6 table already has few email address and I want modify the exisitng email address which is not default to make as default, I am unable to do that. please suggest.

Edited by: Rob Burbank on Jun 22, 2010 3:10 PM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Mar 03, 2010 at 12:51 PM

    Hi Anitha,

    To use FM BAPI_ADDRESSORG_CHANGE first you must use FM BAPI_ADDRESSORG_GETDETAIL as Brad said. Number of entries of your IT_BAPIADSMTP have to be equal with your IT_BAPIADSMTPX.

    This is a sample:

    DATA: v_objty TYPE ad_ownertp,
          v_objid TYPE ad_objkey,
          v_contx TYPE ad_context VALUE '0001',
          v_addnr TYPE ad_addrnum.
    
    DATA: t_adsmtp TYPE TABLE OF bapiadsmtp WITH HEADER LINE,
          t_adsmtx TYPE TABLE OF bapiadsmtx WITH HEADER LINE,
          t_return TYPE TABLE OF bapiret2   WITH HEADER LINE.
    
    PARAMETERS p_kunnr TYPE kunnr.
    
    v_objty = 'KNA1'.
    v_objid = p_kunnr.
    
    CALL FUNCTION 'BAPI_ADDRESSORG_GETDETAIL'
      EXPORTING
        obj_type       = v_objty
        obj_id         = v_objid
        context        = v_contx
      IMPORTING
        address_number = v_addnr
      TABLES
        bapiadsmtp     = t_adsmtp
        return         = t_return.
    
    IF t_adsmtp[] IS INITIAL.
      CLEAR: t_adsmtp, t_adsmtx.
    
      t_adsmtp-std_no = 'X'.
      t_adsmtp-e_mail = 'a'.
      t_adsmtp-consnumber = '001'.
    
      t_adsmtx-updateflag = 'I'.
    
      APPEND: t_adsmtp, t_adsmtx.
    
      CLEAR: t_adsmtp, t_adsmtx.
    
      t_adsmtp-e_mail = 'b'.
      t_adsmtp-consnumber = '002'.
    
      t_adsmtx-updateflag = 'I'.
    
      APPEND: t_adsmtp, t_adsmtx.
    ELSE.
      LOOP AT t_adsmtp.
        CLEAR t_adsmtx.
    
        IF t_adsmtp-e_mail = 'a'.
    
          t_adsmtp-e_mail = 'c'.
    
          t_adsmtx-e_mail = 'X'.
          t_adsmtx-updateflag = 'U'.
    
          MODIFY t_adsmtp.
    
        ENDIF.
    
        IF t_adsmtp-e_mail = 'b'.
          t_adsmtx-updateflag = 'D'.
        ENDIF.
    
        APPEND t_adsmtx.
      ENDLOOP.
    
      CLEAR: t_adsmtp, t_adsmtx.
    
      t_adsmtp-e_mail = 'd'.
      t_adsmtp-consnumber = '003'.
      t_adsmtx-updateflag = 'I'.
      APPEND: t_adsmtp, t_adsmtx.
    ENDIF.
    CALL FUNCTION 'BAPI_ADDRESSORG_CHANGE'
      EXPORTING
        obj_type       = v_objty
        obj_id         = v_objid
        context        = v_contx
      IMPORTING
        address_number = v_addnr
      TABLES
        bapiadsmtp     = t_adsmtp
        bapiadsmt_x    = t_adsmtx
        return         = t_return.
    LOOP AT t_return WHERE type = 'E'
                        OR type = 'A'
                        OR type = 'X'.
      EXIT.
    ENDLOOP.
    IF sy-subrc = 0.
       "ROLLBACK
    ELSE.
       "COMMIT
    ENDIF.
    

    You run first time the code, customer no will have two new mail, a and b. At second time a will be c, b will deleted and d will inserted.

    Regards,

    Caner.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 17, 2009 at 06:45 PM

    It appears that you aren't making a check to determine which e-mail address is the standard one and that you aren't modifying the current 'standard' address to remove the setting if it exists. Also, if you're going to use the 'change' BAPI, it's generally easier to use the corresponding 'get' BAPI (BAPI_ADDRESSORG_GETDETAIL) to work with the data instead of performing direct selects.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.