banner ads

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.


  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'.

  PERFORM fetch_data.
  PERFORM call_bapi_to_update_tcurr.

*&      Form  FETCH_DATA
*       Fetching Excel data from App Server into Internal Table
FORM fetch_data .


    READ DATASET currency_file INTO wa_intern-value.
    IF sy-subrc NE 0.
    APPEND wa_intern TO it_intern.

  CLOSE DATASET currency_file.

*       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.

      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.
        exch_rate-from_factor 1.

      exch_rate-to_factor 1.

          exch_rate exch_rate
          upd_allow 'X'
          chg_fixed 'X'
          return    return.

      IF   return-type NE 'E'
        OR return-type NE 'A'.

            wait   'X'
            return commit_return.


The report will not generate any output. We need to check TCURR table based on the following data.

No comments