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.
7 comments:
Thank for this great post SANDIP ROY.
Regards for Argentine!
Thanks for Sharing this Information.You are providing very valuable information.sap video tutorials
Well it Was Very Good Information. Thanks for sharing this Information. sap video tutorials
Thank you for giving this best information. It’s a very nice topicsap video tutorials
Good post! Thanks for sharing this Information.The information you Provided is much useful on sap video tutorials
Thankyou for information excellent blog have a great possiblesap video tutorials
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!!!!!!
Post a Comment