Coding Sample BAPIFunction BAPI_ADDRESSORG_SAVEREPLICA

Trying to transfer Extra address fields of the customet master using the BAPI "BAPI_ADDRESSORG_SAVEREPLICA". 

How to used this BAPI?

Resolution: 

This BAPI can be used to transfer extra address fields of the customer master.

In this sample code we are trying to update some of the extra fields like, telephone number, fax details, mobile number and email address for a customer master.

Sample coding:

'BAPI_ADDRESSORG_SAVEREPLICA' - This BAPI can be used for address change of customer. 

  CLEAR: addr_no,addr_grp.
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = v_kunnr
    IMPORTING
      output = v_kunnr.

  SELECT SINGLE adrnr
                  FROM kna1
                  INTO addr_no
                  WHERE kunnr = v_kunnr.

  SELECT SINGLE addr_group
        FROM adrc
        INTO addr_grp
        WHERE addrnumber = addr_no.

  CLEAR: gi_bapiadfax, gi_bapiadsmtp ,gi_bapiad1vl,gi_bapiadtel,
         gi_bapiadfax[],gi_bapiadsmtp[],gi_bapiad1vl[],gi_bapiadtel[].

  gi_bapiad1vl-addr_group = addr_grp.

  ztitle = wa_final_output-title.

  CASE ztitle.
    WHEN 'MS.'.
      gi_bapiad1vl-title = '0001'.
    WHEN 'MR.'.
      gi_bapiad1vl-title = '0002'.
    WHEN 'COMPANY'.
      gi_bapiad1vl-title = '0003'.
    WHEN 'MR and MRS'.
      gi_bapiad1vl-title = '0004'.
    WHEN 'DR.'.
      gi_bapiad1vl-title = '0005'.
  ENDCASE.

  gi_bapiad1vl-name  = wa_final_output-name1.
  gi_bapiad1vl-name_2  =  wa_final_output-name2.
  gi_bapiad1vl-city = wa_final_output-ort01.
  gi_bapiad1vl-po_box_reg = wa_final_output-regio.
  gi_bapiad1vl-postl_cod1 = wa_final_output-pstlz.
  gi_bapiad1vl-street = wa_final_output-stras.
  gi_bapiad1vl-str_suppl1 = wa_final_output-str_suppl1.
  gi_bapiad1vl-country  = wa_final_output-land1.
  gi_bapiad1vl-langu  = 'EN'.
  gi_bapiad1vl-sort1  = wa_final_output-sort1.
  gi_bapiad1vl-sort2 = wa_final_output-sort2.
  gi_bapiad1vl-transpzone = wa_final_output-lzone.

  APPEND gi_bapiad1vl.
  CLEAR gi_bapiad1vl.

*********** Email ************************

  READ TABLE it_str_email INTO wa_str_email WITH KEY req_no = wa_final_output-req_no
                                                     serial_no = wa_final_output-serial_no.
  IF sy-subrc <> 0.
    gi_bapiadsmtp-e_mail = wa_final_output-smtp_addr.
      gi_bapiadsmtp-r_3_user = '3'. 
      gi_bapiadsmtp-std_recip = 'X'. 
    APPEND gi_bapiadsmtp.
    CLEAR gi_bapiadsmtp.
  ENDIF.

  IF NOT it_str_email[] IS INITIAL.
    LOOP AT it_str_email INTO wa_str_email WHERE req_no = wa_final_output-req_no
                                          AND serial_no = wa_final_output-serial_no
                                          AND ktokd = wa_final_output-ktokd
                                          AND bukrs = wa_final_output-bukrs
                                          AND vkorg = wa_final_output-vkorg
                                          AND vtweg = wa_final_output-vtweg
                                          AND spart = wa_final_output-spart.
      .
      IF NOT wa_str_email-smtp_addr IS INITIAL.
        gi_bapiadsmtp-e_mail = wa_str_email-smtp_addr.      "EMAIL
        gi_bapiadsmtp-consnumber = wa_str_email-consnumber.
      ELSE.
        gi_bapiadsmtp-e_mail = ' '. "'IN@LNT.COM'.
      ENDIF.
      APPEND gi_bapiadsmtp.
      CLEAR gi_bapiadsmtp.
    ENDLOOP.
  ENDIF.
*************Mobile**************************
  READ TABLE it_str_mobile INTO wa_str_mobile WITH KEY req_no = wa_final_output-req_no
                                                     serial_no = wa_final_output-serial_no.
  IF sy-subrc <> 0.
    gi_bapiadtel-telephone = wa_final_output-mobno.
    gi_bapiadtel-r_3_user = '3'.
    gi_bapiadtel-std_recip = 'X'.
    APPEND gi_bapiadtel.
    CLEAR gi_bapiadtel.
  ENDIF.

  IF NOT it_str_mobile[] IS INITIAL.
    LOOP AT it_str_mobile INTO wa_str_mobile WHERE req_no = wa_final_output-req_no
                                          AND serial_no = wa_final_output-serial_no
                                          AND ktokd = wa_final_output-ktokd
                                          AND bukrs = wa_final_output-bukrs
                                          AND vkorg = wa_final_output-vkorg
                                          AND vtweg = wa_final_output-vtweg
                                          AND spart = wa_final_output-spart..
      IF NOT wa_str_mobile-mobno IS INITIAL.
        gi_bapiadtel-telephone = wa_str_mobile-mobno.
        gi_bapiadtel-consnumber = wa_str_mobile-consnumber.
        GI_BAPIADTEL-COUNTRY = WA_STR_MOBILE-COUNTRY. 
        gi_bapiadtel-r_3_user = '3'.
        gi_bapiadtel-std_recip = 'X'.

      ELSE.
        gi_bapiadtel-telephone = '.'.
      ENDIF.
      APPEND gi_bapiadtel.
      CLEAR gi_bapiadtel.
    ENDLOOP.
  ENDIF.
*************Telephone************************
  READ TABLE it_str_tel INTO wa_str_tel WITH KEY req_no = wa_final_output-req_no
                                                     serial_no = wa_final_output-serial_no.
  IF sy-subrc <> 0.
    gi_bapiadtel-telephone = wa_final_output-telf1.
    gi_bapiadtel-extension = wa_final_output-tel_extens.
    APPEND gi_bapiadtel.
    CLEAR gi_bapiadtel.
  ENDIF.

  IF NOT it_str_tel[] IS INITIAL.
    LOOP AT it_str_tel INTO wa_str_tel WHERE req_no = wa_final_output-req_no
                                          AND serial_no = wa_final_output-serial_no
                                          AND ktokd = wa_final_output-ktokd
                                          AND bukrs = wa_final_output-bukrs
                                          AND vkorg = wa_final_output-vkorg
                                          AND vtweg = wa_final_output-vtweg
                                          AND spart = wa_final_output-spart..
      IF NOT wa_str_tel-telf1 IS INITIAL.
        gi_bapiadtel-telephone = wa_str_tel-telf1.
        gi_bapiadtel-extension = wa_str_tel-tel_extens.
        gi_bapiadtel-consnumber = wa_str_tel-consnumber.
        GI_BAPIADTEL-COUNTRY = wa_str_tel-COUNTRY. 
      ELSE.
        gi_bapiadtel-telephone = '.'.
      ENDIF.
      APPEND gi_bapiadtel.
      CLEAR gi_bapiadtel.
    ENDLOOP.
  ENDIF.
**************************************************
  IF NOT wa_final_output-telfx IS INITIAL.
    gi_bapiadfax-fax = wa_final_output-telfx.
    gi_bapiadfax-extension = wa_final_output-fax_extens.
  ELSE.
    gi_bapiadfax-fax = space.
    gi_bapiadfax-extension  = space.
  ENDIF.
  APPEND gi_bapiadfax.
  CLEAR gi_bapiadfax.

  objid = v_kunnr.

  CALL FUNCTION 'BAPI_ADDRESSORG_SAVEREPLICA'
    EXPORTING
      obj_type         = 'KNA1'
      obj_id           = objid
      iv_check_address = 'X'
    IMPORTING
      return           = return1
    TABLES
      bapiad1vl        = gi_bapiad1vl
      bapiadtel        = gi_bapiadtel
      bapiadfax        = gi_bapiadfax
      bapiadsmtp       = gi_bapiadsmtp.

  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

ENDFORM. 

ABAP Tips

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.