Kur Çevrimi : BAPI_EXCHRATE_GETCURRENTRATES
TCURR tablosundan kur bilgilerini doğrudan çekme bulunamayan kur için BAPI kullanılarak en yakın tarihli kur bilgisini getirme kodları :
Not 1: TCURR tablosundaki gdatu için tarih çevrimi
convert date ls_rates-date
into inverted-date ls_rates-gdatu.
Not 2: TCURR tablosundan gelen kur Negatif ise ters kur girilmiş demektir.
types: begin of ty_exchangerate,
kurst type kurst_curr,
waers_bkpf type fcurr_curr,
waers_target type tcurr_curr,
date type date ,
kursf type ukurs_curr, "KURSF
gdatu type gdatu_inv,
end of ty_exchangerate.
types: tty_exchangerate type sorted table of ty_exchangerate with unique key kurst waers_bkpf waers_target date .
*&---------------------------------------------------------------------*
*& Form f_fill_exchangerates
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->CHT_RATES text
*----------------------------------------------------------------------*
form f_fill_exchangerates changing cht_rates type tty_exchangerate .
data: lt_tcurr type sorted table of tcurr with unique key kurst fcurr tcurr gdatu.
data: ls_tcurr type tcurr .
data: ls_rates type ty_exchangerate .
data: lv_xndx type int4.
data:
lt_from_curr_range like standard table of bapi1093_3,
lt_to_currncy_range like standard table of bapi1093_4,
lt_exch_rate_list like standard table of bapi1093_0,
lt_return like standard table of bapiret1.
data: ls_from_curr_range like bapi1093_3,
ls_to_currncy_range like bapi1093_4,
ls_exch_rate_list like bapi1093_0.
data: lv_date type datum.
if cht_rates[] is not initial.
select *
into table lt_tcurr
from tcurr for all entries in cht_rates
where kurst = cht_rates-kurst
and fcurr = cht_rates-waers_bkpf
and tcurr = cht_rates-waers_target
and gdatu = cht_rates-gdatu.
endif.
loop at cht_rates into ls_rates.
lv_xndx = sy-tabix.
clear ls_tcurr.
read table lt_tcurr into ls_tcurr
with table key kurst = ls_rates-kurst
fcurr = ls_rates-waers_bkpf
tcurr = ls_rates-waers_target
gdatu = ls_rates-gdatu.
if sy-subrc eq 0.
ls_rates-kursf = ls_tcurr-ukurs .
modify cht_rates from ls_rates index lv_xndx transporting kursf.
else.
* delete cht_rates index lv_xndx.
refresh : lt_from_curr_range ,
lt_to_currncy_range,
lt_exch_rate_list ,
lt_return .
clear ls_from_curr_range.
ls_from_curr_range-sign = `I`.
ls_from_curr_range-option = `EQ`.
ls_from_curr_range-low = ls_rates-waers_bkpf.
append ls_from_curr_range to lt_from_curr_range.
clear ls_from_curr_range.
ls_from_curr_range-sign = `I`.
ls_from_curr_range-option = `EQ`.
ls_from_curr_range-low = ls_rates-waers_target.
append ls_from_curr_range to lt_from_curr_range.
clear ls_to_currncy_range.
ls_to_currncy_range-sign = `I`.
ls_to_currncy_range-option = `EQ`.
ls_to_currncy_range-low = ls_rates-waers_bkpf.
append ls_to_currncy_range to lt_to_currncy_range.
clear ls_to_currncy_range.
ls_to_currncy_range-sign = `I`.
ls_to_currncy_range-option = `EQ`.
ls_to_currncy_range-low = ls_rates-waers_target.
append ls_to_currncy_range to lt_to_currncy_range.
lv_date = ls_rates-date.
call function `BAPI_EXCHRATE_GETCURRENTRATES`
exporting
date = lv_date
date_type = `V`
rate_type = p_kurst
* SHOW_PROTOCOL =
tables
from_curr_range = lt_from_curr_range
to_currncy_range = lt_to_currncy_range
exch_rate_list = lt_exch_rate_list
return = lt_return
.
sort lt_exch_rate_list by valid_from descending.
loop at lt_exch_rate_list into ls_exch_rate_list.
case ls_exch_rate_list-from_curr.
when ls_rates-waers_bkpf. ls_rates-kursf = ls_exch_rate_list-exch_rate .
when ls_rates-waers_target.
if ls_exch_rate_list-exch_rate ne 0.
ls_rates-kursf = 1 / ls_exch_rate_list-exch_rate .
endif.
endcase.
modify cht_rates from ls_rates index lv_xndx transporting kursf.
exit.
endloop.
endif.
endloop.
endform. "f_fill_exchangerates
form f_fill_exchangerate_search using prm_active_acc type ty_active_account
prt_item type zfi_vl_t_item_list
changing cht_rates type tty_exchangerate .
data: ls_item like line of prt_item.
data: ls_rates type ty_exchangerate.
loop at prt_item into ls_item.
clear ls_rates.
if ls_item-waers_bkpf ne prm_active_acc-waers_hwae3.
ls_rates-kurst = prm_active_acc-kurst.
ls_rates-waers_bkpf = ls_item-waers_bkpf.
ls_rates-waers_target = prm_active_acc-waers_hwae3.
ls_rates-date = prm_active_acc-date.
convert date ls_rates-date
into inverted-date ls_rates-gdatu.
insert ls_rates into table cht_rates.
clear ls_rates.
ls_rates-kurst = prm_active_acc-kurst.
ls_rates-waers_bkpf = prm_active_acc-waers_hwae3.
ls_rates-waers_target = ls_item-waers_bkpf.
ls_rates-date = ls_item-rate_date.
convert date ls_rates-date
into inverted-date ls_rates-gdatu.
insert ls_rates into table cht_rates.
endif.
endloop.
endform. "f_fill_exchangerate_search