12-17-2009 2:51 PM
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
03-03-2010 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.
12-17-2009 6: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.
03-03-2010 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.
06-22-2010 8:00 PM
Genis,
First accept my apologies for not getting back to your reply. secondly your explanation on the issue is great and it is very helpful. I am sure many more forum people will be benefited by your solution.
Regards
Anu
05-25-2011 10:46 AM
10-28-2020 1:13 PM
Good explanation. I am also had the same issue. After applying this solution my issue is solved.