Currency Table update Automatically
In the following example we are updating the currency table TCURR (standard one) by a custom program. The purpose of this program is to update the TCURR table automatically by a background job so that user doesn’t need to enter manually in OB08. Hence the custom program will fetch data from an excel sheet which is located in the application server. The excel file is updated one and it is downloaded time to time from the RBI website. To generate this excel file we can use any web development technique.
Now our custom program will fetch that excel file data into its own internal table. We are using a BAPI (BAPI_EXCHANGERATE_CREATE) here. This BAPI passes a work area exch_rate which contains all information for required currency. The excel file looks like following.
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.
The report will not generate any output. We need to check TCURR table based on the following data.
Post a Comment