Created
November 29, 2016 14:30
-
-
Save SidVal/63572a96107fe8ea8573e993702f614d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*&---------------------------------------------------------------------* | |
*& Desde sapabap-4.blogspot.com/2016/11/currency-table-update-automatically.html | |
*& Para www.Consultoria-SAP.com - 2016 | |
*&---------------------------------------------------------------------* | |
REPORT zsr_test NO STANDARD PAGE HEADING. | |
DATA: | |
it_intern TYPE TABLE OF alsmex_tabline, | |
wa_intern TYPE alsmex_tabline, | |
return LIKE bapiret2, | |
commit_return LIKE bapiret2, | |
exch_rate LIKE bapi1093_0, | |
currency_file TYPE string VALUE 'D:\SUM\SUM\abap\currency.xls'. | |
START-OF-SELECTION. | |
PERFORM fetch_data. | |
PERFORM call_bapi_to_update_tcurr. | |
*&---------------------------------------------------------------------* | |
*& Form FETCH_DATA | |
*&---------------------------------------------------------------------* | |
* Fetching Excel data from App Server into Internal Table | |
*----------------------------------------------------------------------* | |
FORM fetch_data . | |
OPEN DATASET currency_file FOR INPUT IN TEXT MODE ENCODING DEFAULT. | |
DO. | |
READ DATASET currency_file INTO wa_intern-value. | |
IF sy-subrc NE 0. | |
EXIT. | |
ENDIF. | |
APPEND wa_intern TO it_intern. | |
ENDDO. | |
CLOSE DATASET currency_file. | |
ENDFORM. | |
*&---------------------------------------------------------------------* | |
*& Form CALL_BAPI_TO_UPDATE_TCURR | |
*&---------------------------------------------------------------------* | |
* Calling BAPI to Update TCURR Directly | |
*----------------------------------------------------------------------* | |
FORM call_bapi_to_update_tcurr . | |
IF it_intern IS NOT INITIAL. | |
LOOP AT it_intern INTO wa_intern. | |
exch_rate-rate_type = 'M'. | |
CASE sy-tabix. | |
"First record is for US Dollar | |
WHEN '1'. | |
exch_rate-from_curr = 'USD'. | |
"Second record is for Euro | |
WHEN '2'. | |
exch_rate-from_curr = 'EUR'. | |
"Third record is for Yen | |
WHEN '3'. | |
exch_rate-from_curr = 'JPY'. | |
"Fourth record is for Pound | |
WHEN '4'. | |
exch_rate-from_curr = 'GBP'. | |
"Any further data will not be entered | |
WHEN OTHERS. | |
EXIT. | |
ENDCASE. | |
exch_rate-to_currncy = 'INR'. | |
exch_rate-valid_from = sy-datum. | |
exch_rate-exch_rate = wa_intern-value. | |
IF exch_rate-from_curr = 'JPY'. | |
"For YEN the ratio is different | |
exch_rate-from_factor = 100. | |
ELSE. | |
exch_rate-from_factor = 1. | |
ENDIF. | |
exch_rate-to_factor = 1. | |
CALL FUNCTION 'BAPI_EXCHANGERATE_CREATE' | |
EXPORTING | |
exch_rate = exch_rate | |
upd_allow = 'X' | |
chg_fixed = 'X' | |
IMPORTING | |
return = return. | |
IF return-type NE 'E' | |
OR return-type NE 'A'. | |
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' | |
EXPORTING | |
wait = 'X' | |
IMPORTING | |
return = commit_return. | |
ENDIF. | |
CLEAR: wa_intern, return, exch_rate. | |
ENDLOOP. | |
ENDIF. | |
ENDFORM. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment