SAP BAPI to Upload Exchange Rate

BAPI to upload exchange rate in SAP

 

CONSTANTS :
“Local Constants
c_to_fac TYPE i VALUE 1000, “to factor
c_from_fac TYPE i VALUE 1, “for factor
c_exc_value TYPE i VALUE 10000. “exchange value

DATA :
“Local WorkArea
ls_exchange TYPE bapi1093_0, “Exchange Rates to be Uploaded
“Local Table
lt_exchange TYPE TABLE OF bapi1093_0. “Exchange Rates to be Uploaded

“Mapping data to the table for Posting
LOOP AT pt_upload INTO DATA(ls_upload).
ls_exchange-rate_type = ls_upload-rate_type. “Rate Type
ls_exchange-from_curr = ls_upload-from_curr. “From currency
ls_exchange-to_currncy = ls_upload-to_currncy. “To-currency

“Date from Which Entry Is Valid
CALL FUNCTION ‘CONVERT_DATE_TO_INTERNAL’
EXPORTING
date_external = ls_upload-valid_from
IMPORTING
date_internal = ls_exchange-valid_from
EXCEPTIONS
date_external_is_invalid = 1
OTHERS = 2.

IF r_b1 = abap_true.
ls_exchange-exch_rate = ls_upload-exch_rate. “Direct Rate
ls_exchange-from_factor = c_from_fac.
ls_exchange-to_factor = c_from_fac.
ELSEIF r_b2 = abap_true.
“Checking the Value
IF ls_exchange-exch_rate GE c_exc_value.
ls_exchange-exch_rate_v = ls_upload-exch_rate / 1000. “In-Direct Rate
ls_exchange-from_factor_v = c_from_fac.
ls_exchange-to_factor_v = c_to_fac.
ELSE.
ls_exchange-exch_rate_v = ls_upload-exch_rate. “In-direct Rate
ls_exchange-from_factor_v = c_from_fac.
ls_exchange-to_factor_v = c_from_fac.
ENDIF. “Checking the Value
ENDIF.
“Append Internal Table
APPEND ls_exchange TO lt_exchange.
CLEAR ls_exchange.
ENDLOOP.

“Test Run Check
IF pv_trun IS INITIAL.
DATA(lv_flag) = abap_true.
ELSE.
CLEAR lv_flag.
ENDIF.

“BAPI for posting
IF lt_exchange IS NOT INITIAL.
CALL FUNCTION ‘BAPI_EXCHRATE_CREATEMULTIPLE’
EXPORTING
upd_allow = lv_flag
TABLES
exchrate_list = lt_exchange
return = pt_output.
ENDIF.

Leave a Reply

Your email address will not be published. Required fields are marked *