BAPI_ADDRESSORG_CHANGE ADR6 Güncelleme
Müşteri e-posta adreslerinin silme ve ekleme işlemleri için örnektir. Güncellemeyi mevcut satırı silme ve yeni satır ekleme ile yapabiliyoruz. Fonksiyona verilen argümanlar obj_type = `KNA1` , obj_id = `0010000001` ( müşteri numarası )
BAPIADSMTP ile BAPIADSMT_X tablolarının nasıl doldurulacağı aşağıdadır.
bapiadsmt_x-updateflag = `I` veya `D` olmaldır.
*&---------------------------------------------------------------------*
*& Form f_save
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form f_save.
data: ls_master type ty_master.
data: ls_master_adrnr type ty_master.
data: ls_adr6 type adr6.
data: ls_adr6_eski type adr6.
data: ls_adr6_yeni type adr6.
data: lv_xndx type int4.
data: ls_new_row type ty_master.
data: ls_old_row type ty_master.
data: lt_master_del type tty_master_adrnrposta .
data: lt_master_upd type tty_master_adrnrposta .
data: lt_master_ins type tty_master_adrnrposta .
data: lt_master_adnr type sorted table of ty_master with unique key adrnr kunnr.
loop at gt_master into ls_master.
check ls_master-durum ne icon_led_red.
clear ls_master_adrnr.
ls_master_adrnr-adrnr = ls_master-adrnr.
ls_master_adrnr-kunnr = ls_master-kunnr.
insert ls_master_adrnr into table lt_master_adnr.
clear ls_adr6_eski.
read table gt_adr6 into ls_adr6_eski with table key key_eposta
components addrnumber = ls_master-adrnr
smtp_addr = ls_master-eposta_eski.
clear ls_adr6_yeni.
read table gt_adr6 into ls_adr6_yeni with table key key_eposta
components addrnumber = ls_master-adrnr
smtp_addr = ls_master-eposta_yeni.
if ls_master-eposta_eski is initial
and ls_master-eposta_yeni is not initial.
insert ls_master into table lt_master_ins.
elseif ls_master-eposta_eski is not initial
and ls_master-eposta_yeni is initial. .
insert ls_master into table lt_master_del.
elseif ls_master-eposta_eski is not initial
and ls_master-eposta_yeni is not initial. .
if ls_adr6_eski-addrnumber is initial.
insert ls_master into table lt_master_ins.
else.
MOVE-CORRESPONDING ls_master to ls_new_row .
MOVE-CORRESPONDING ls_master to ls_old_row .
CLEAR ls_new_row-eposta_eski.
CLEAR ls_new_row-eposta_yeni.
CLEAR ls_old_row-eposta_eski.
CLEAR ls_old_row-eposta_yeni.
ls_old_row-eposta_eski = ls_master-eposta_eski.
ls_new_row-eposta_yeni = ls_master-eposta_yeni.
* insert ls_master into table lt_master_upd.
insert ls_old_row into table lt_master_del.
insert ls_new_row into table lt_master_ins.
endif.
endif.
endloop.
data: lt_bapiadsmtp like STANDARD TABLE OF bapiadsmtp WITH HEADER LINE,
lt_bapiadsmt_x like STANDARD TABLE OF bapiadsmtx WITH HEADER LINE.
loop at lt_master_adnr into ls_master_adrnr .
refresh: lt_bapiadsmtp ,
lt_bapiadsmt_x.
perform f_prepare_arg tables lt_bapiadsmtp lt_bapiadsmt_x using ls_master_adrnr `D` lt_master_del .
* perform f_prepare_arg tables lt_bapiadsmtp lt_bapiadsmt_x using ls_master_adrnr `U` lt_master_upd .
perform f_prepare_arg tables lt_bapiadsmtp lt_bapiadsmt_x using ls_master_adrnr `I` lt_master_ins .
perform f_addressorg_change tables lt_bapiadsmtp lt_bapiadsmt_x using ls_master_adrnr.
ENDLOOP.
endform. "f_save
*&---------------------------------------------------------------------*
*& Form f_prepare_arg
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->CHT_BAPIADSMTP text
* -->CHT_BAPIADSMT_X text
* -->PRM_MASTER text
* -->PRM_UPDATEFLAG text
* -->PRT_LIST text
*----------------------------------------------------------------------*
form f_prepare_arg tables cht_bapiadsmtp structure bapiadsmtp
cht_bapiadsmt_x structure bapiadsmtx
using prm_master type ty_master
prm_updateflag type ad_updflag
prt_list type tty_master_adrnrposta
.
data: ls_list type ty_master.
data: ls_adr6_eski type adr6.
data: ls_adr6_yeni type adr6.
loop at prt_list into ls_list where adrnr = prm_master-adrnr.
clear ls_adr6_eski.
read table gt_adr6 into ls_adr6_eski with table key key_eposta
components addrnumber = ls_list-adrnr
smtp_addr = ls_list-eposta_eski.
clear ls_adr6_yeni.
read table gt_adr6 into ls_adr6_yeni with table key key_eposta
components addrnumber = ls_list-adrnr
smtp_addr = ls_list-eposta_yeni.
clear cht_bapiadsmtp.
clear cht_bapiadsmt_x.
case prm_updateflag.
when `D`.
move-corresponding ls_adr6_eski to cht_bapiadsmtp.
cht_bapiadsmtp-e_mail = ls_list-eposta_eski.
cht_bapiadsmtp-email_srch = ls_adr6_eski-smtp_srch.
cht_bapiadsmtp-std_recip = ls_adr6_eski-dft_receiv .
cht_bapiadsmtp-std_no = ls_adr6_eski-flgdefault.
append cht_bapiadsmtp.
cht_bapiadsmt_x-updateflag = `D`.
append cht_bapiadsmt_x.
when `I`.
cht_bapiadsmtp-e_mail = ls_list-eposta_yeni.
append cht_bapiadsmtp.
cht_bapiadsmt_x-updateflag = `I`.
append cht_bapiadsmt_x.
when `U`.
move-corresponding ls_adr6_eski to cht_bapiadsmtp.
cht_bapiadsmtp-e_mail = ls_list-eposta_yeni.
cht_bapiadsmtp-email_srch = ls_adr6_eski-smtp_srch.
TRANSLATE cht_bapiadsmtp-email_srch TO UPPER CASE.
cht_bapiadsmtp-std_recip = ls_adr6_eski-dft_receiv .
cht_bapiadsmtp-std_no = ls_adr6_eski-flgdefault.
append cht_bapiadsmtp.
cht_bapiadsmt_x-updateflag = `U`.
append cht_bapiadsmt_x.
endcase.
endloop.
endform. "f_prepare_arg
*&---------------------------------------------------------------------*
*& Form f_ADDRESSORG_CHANGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PRM_MASTER text
*----------------------------------------------------------------------*
form f_addressorg_change tables cht_bapiadsmtp structure bapiadsmtp
cht_bapiadsmt_x structure bapiadsmtx
using prm_master type ty_master
.
data: lv_obj_type like bapi4001_1-objtype value `KNA1` .
data: lv_obj_id like bapi4001_1-objkey.
data: lv_obj_id_ext like bapi4001_1-extension value space.
data: lv_err type c.
data: lt_BAPIRET2 type STANDARD TABLE OF BAPIRET2 WITH HEADER LINE.
lv_obj_id = prm_master-kunnr.
CLEAR lv_err.
call function `BAPI_ADDRESSORG_CHANGE`
exporting
obj_type = lv_obj_type
obj_id = lv_obj_id
* OBJ_ID_EXT = ` `
* CONTEXT = 1
* ACCEPT_ERROR = ` `
save_address = `X`
IV_CHECK_ADDRESS = SPACE
* IV_TIME_DEPENDENT_COMM_DATA = ` `
* IMPORTING
* ADDRESS_NUMBER =
TABLES
* BAPIAD1VL =
* BAPIADTEL =
* BAPIADFAX =
* BAPIADTTX =
* BAPIADTLX =
BAPIADSMTP = cht_bapiadsmtp
* BAPIADRML =
* BAPIADX400 =
* BAPIADRFC =
* BAPIADPRT =
* BAPIADSSF =
* BAPIADURI =
* BAPIADPAG =
* BAPIAD_REM =
* BAPICOMREM =
* BAPIADUSE =
* BAPIAD1VL_X =
* BAPIADTEL_X =
* BAPIADFAX_X =
* BAPIADTTX_X =
* BAPIADTLX_X =
BAPIADSMT_X = cht_bapiadsmt_x
* BAPIADRML_X =
* BAPIADX40_X =
* BAPIADRFC_X =
* BAPIADPRT_X =
* BAPIADSSF_X =
* BAPIADURI_X =
* BAPIADPAG_X =
* BAPIAD_RE_X =
* BAPICOMRE_X =
* BAPIADUSE_X =
RETURN = lt_BAPIRET2
.
PERFORM f_check_bapiret2 tables lt_BAPIRET2 changing lv_err.
if lv_err is INITIAL.
call function `BAPI_TRANSACTION_COMMIT`
EXPORTING
WAIT = `X`
* IMPORTING
* RETURN =
.
endif.
endform. "f_ADDRESSORG_CHANGE