Monday, November 28, 2016

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.
      CLEARwa_internreturnexch_rate.
    ENDLOOP.
  ENDIF.

ENDFORM.

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












































14 comments:

CSAP said...

Thank for this great post SANDIP ROY.

Regards for Argentine!

Anonymous said...

Thanks for the great information in your blog on It was so nice article Thank you for valuable informationsap video tutorials

Anonymous said...

Thanks for Sharing this Information.You are providing very valuable information.sap video tutorials

Anonymous said...


Well it Was Very Good Information. Thanks for sharing this Information. sap video tutorials

Anonymous said...


Thank you for giving this best information. It’s a very nice topicsap video tutorials

Shalini said...

Hi, This is shalini from Chennai learned SAP Training in Chennai from mr.karthick. The training really was good and i got selected in leading mnc company as SAP Consultant.

You can contact 8122241286 for Best SAP Training in Chennai or reach www.thecreatingexperts.com

Anonymous said...


Good post! Thanks for sharing this Information.The information you Provided is much useful on sap video tutorials

Video Tutorials said...

Thankyou for information excellent blog have a great possiblesap video tutorials

sanayamohit said...

SAP Success Factors Real Time Hands on Training in Chennai...

Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286

Both Classroom/Online Training is Available!!!!!!

Shruti Ramalingam said...

From My search…Creating Experts provides Best SAP Training with real time projects assistance.

Most of the modules are equipped with advance level topics which the student can learn from the basics to the advance level stage.

They also provide placement assistance in leading MNC companies across the globe according to the current requirements.

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

And these are the Best SAP training institute which provides Real Time Hands on Training…

codedion Technologies-9003085882

creating Experts-8122241286

http://thecreatingexperts.com/sap-mm-training-in-chennai/

dinesh said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

Keerthi Suresh said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

ragu varan said...

Best SAP HANA Training in Chennai by leading HANA Consultant.
Reach at 9003085882
http://thecreatingexperts.com/category/sap-hana-training-in-chennai/

gilledashivani said...

Great information. the information provided is of great use as i got to learn new things. If you are looking for real time training in SAP ABAP, kindly contact sieve software
Sieve software offers real time training by industry experts with live projects and placement support.
SAP ABAP TRAINING IN HYDERABAD