Kur Çevrimi 2
Kur bilgilerinin toplu olarak alınması için dönüştürülecek para birimleri tarih bilgisi ile birlikte gt_curr_search tablosunda biriktirilir. Toplu halde BAPI_EXCHRATE_GETCURRENTRATES fonksiyonuna gönderilir ve kur değerleri alınır. Valid From değeri geçmişe yönelik olabilir (Geçerli olan son girilen tarih) aşağıdaki kodda düzeltmesi de mevcuttur.
Formların hızlı çalışabilmesi için global tablolar kullanılmıştır.
parameters: p_pbrpr type waers DEFAULT `TRY`,
p_kurst type kurst default `M`.
types: begin of ty_currency_coll,
rate_type type kurst_curr,
valid_from type datum,"Fix dönem son günü.
from_curr type fcurr_curr,
to_currncy type tcurr_curr,
end of ty_currency_coll.
types: tty_currency_coll type sorted table of ty_currency_coll
with unique key rate_type valid_from from_curr to_currncy .
types: ty_currency_rate type bapi1093_0.
types: tty_currency_rate type sorted table of ty_currency_rate
with unique key rate_type from_curr to_currncy valid_from.
data: gt_curr_search type tty_currency_coll.
data: gt_rate_full type tTy_currency_rate.
form f_insert_currency USING prm_from type waers
prm_date type datum.
CHECK prm_from ne p_pbrpr.
data: ls_curr_search type ty_currency_coll.
ls_curr_search-rate_type = p_kurst.
ls_curr_search-from_curr = prm_from .
ls_curr_search-to_currncy = p_pbrpr .
ls_curr_search-valid_from = prm_date.
insert ls_curr_search into table gt_curr_search.
endform.
form f_fill_currs using cht_curr_search type tty_currency_coll
changing cht_rate_full type tty_currency_rate.
data: ls_curr_search type ty_currency_coll.
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.
loop at cht_curr_search into ls_curr_search .
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_curr_search-from_curr.
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_curr_search-to_currncy.
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_curr_search-from_curr.
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_curr_search-to_currncy.
append ls_to_currncy_range to lt_to_currncy_range.
call function `BAPI_EXCHRATE_GETCURRENTRATES`
exporting
date = ls_curr_search-valid_from
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 .
loop at lt_exch_rate_list into ls_exch_rate_list.
ls_exch_rate_list-valid_from = ls_curr_search-valid_from."Ayın 30unda kur yok ise 24.deki kur alınır. aramada 30 çıksın (basisdate 30)
insert ls_exch_rate_list into table cht_rate_full.
endloop.
endloop.
endform. "f_fill_currs
form f_get_curr USING prm_from type FCURR_CURR
prm_to type TCURR_CURR
prm_date type GDATU_CUR
CHANGING chn_EXCH_RATE Type UKURSP .
data: ls_exch_rate_list type ty_currency_rate.
clear chn_EXCH_RATE.
if prm_from = prm_to.
chn_EXCH_RATE = 1.
else.
clear ls_exch_rate_list.
read table gt_rate_full into ls_exch_rate_list
with table key rate_type = p_kurst
from_curr = prm_from
to_currncy = prm_to
valid_from = prm_date.
if sy-subrc eq 0.
chn_EXCH_RATE = ls_exch_rate_list-exch_rate.
else.
clear ls_exch_rate_list.
read table gt_rate_full into ls_exch_rate_list
with table key rate_type = p_kurst
from_curr = prm_to "ters
to_currncy = prm_from
valid_from = prm_date.
if sy-subrc eq 0.
if ls_exch_rate_list-exch_rate ne 0.
chn_EXCH_RATE = 1 / ls_exch_rate_list-exch_rate.
endif.
endif.
endif.
endif.
ENDFORM.