07-09-2007 8:31 PM
hi all i did a program for uplaod and down load currenct exchange program and writes a report, when i select download in selection screen, it wirte to a file in my C dirve, the date in the file is in sap format(TCURR-GDATU) i need to the date in normal form in the file. please insert your code to get this issue solve in my program or please give the more efficient way to do this program , my program is
REPORT zfvtcurr_update LINE-SIZE 132
LINE-COUNT 60
MESSAGE-ID zg
NO STANDARD PAGE HEADING.
************************************************************************
T A B L E S *
************************************************************************
TABLES: tcurr. "Currency Exchange Rates
************************************************************************
P A R A M E T E R S *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
PARAMETERS: p_upload RADIOBUTTON GROUP grp1,
p_dnload RADIOBUTTON GROUP grp1 DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK blk1.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.
SELECT-OPTIONS: s_kurst FOR tcurr-kurst DEFAULT 'M',
s_fcurr FOR tcurr-fcurr DEFAULT 'USD',
s_tcurr FOR tcurr-tcurr DEFAULT 'MXN'.
SELECTION-SCREEN END OF BLOCK blk2.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK blk3 WITH FRAME TITLE text-003.
PARAMETERS:
p_filnm(128) DEFAULT 'C:\tcurr.txt'.
SELECTION-SCREEN END OF BLOCK blk3.
************************************************************************
V A R I A B L E S A N D C O N S T A N T S *
************************************************************************
DATA: w_char10(10) TYPE c, "Work Field
w_date LIKE sy-datum. "Inverted Date
Internal Tables
DATA: BEGIN OF itab OCCURS 0, "Input / Output File
kurst LIKE tcurr-kurst, "Exchange Rate Type
fcurr LIKE tcurr-fcurr, "From Currency
tcurr LIKE tcurr-tcurr, "To Currency
gdatu LIKE tcurr-gdatu, "Effective Date
ukurs(11) TYPE c, "Exchange Rate
ffact(11) TYPE c, "From Factor
tfact(11) TYPE c, "To Factor
END OF itab.
DATA: BEGIN OF itab1 OCCURS 0, "Input / Output File
mandt LIKE tcurr-mandt, "Client
kurst LIKE tcurr-kurst, "Exchange Rate Type
fcurr LIKE tcurr-fcurr, "From Currency
tcurr LIKE tcurr-tcurr, "To Currency
gdatu LIKE tcurr-gdatu, "Effective Date
ukurs LIKE tcurr-ukurs, "Exchange Rate
ffact LIKE tcurr-ffact, "From Factor
tfact LIKE tcurr-tfact, "To Factor
END OF itab1.
data: begin of itab2 occurs 0,
date like sy-datum,
end of itab2.
DATA: w_tcurr(6) TYPE n.
DATA: w_file TYPE string. "CDSK904243
************************************************************************
T O P - O F - P A G E *
************************************************************************
TOP-OF-PAGE.
WRITE: /01(15) sy-cprog,
60 'Continental Teves',
100 'Page:',
113 sy-pagno.
WRITE: /01(12) sy-uname,
100 'Time:',
110 sy-uzeit.
IF p_upload = 'X'.
w_char10 = 'UpLoad'.
ELSE.
w_char10 = 'DownLoad'.
ENDIF.
WRITE: /55 'Currency Exchange Rate -', w_char10,
100 'Date:',
110 sy-datum MM/DD/YYYY.
SKIP 1.
WRITE: /10 'From',
20 'To'.
WRITE: /01 'ExType',
10 'Curr',
20 'Curr',
30 'Eff Date',
48 'Rate'.
ULINE.
************************************************************************
S T A R T - O F - S E L E C T I O N *
************************************************************************
Processing Flow:
START-OF-SELECTION.
Translate File Name to Lower Case
TRANSLATE p_filnm TO LOWER CASE.
Determine if Upload or Download
IF p_upload = 'X'.
PERFORM upload_source_file.
PERFORM process_upload.
PERFORM update_tcurr.
PERFORM write_report.
ELSE.
PERFORM select_data.
DESCRIBE TABLE itab LINES w_tcurr.
IF w_tcurr > 0.
PERFORM download_source_file.
PERFORM write_report.
ELSE.
WRITE:
/1 '**************************************************',
/1 '* No Entries found for Selection Criteria !!! *',
/1 '**************************************************'.
ENDIF.
ENDIF.
************************************************************************
U P L O A D _ S O U R C E _ F I L E *
************************************************************************
FORM upload_source_file.
Begin CDSK904243
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p_filnm
filetype = 'ASC'
TABLES
data_tab = itab
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
OTHERS = 8.
w_file = p_filnm.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = w_file
filetype = 'ASC'
TABLES
data_tab = itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
End CDSK904243
CASE sy-subrc.
WHEN '0'.
WHEN '1'.
MESSAGE e028(zh).
WHEN '2'.
MESSAGE e024(zh).
WHEN OTHERS.
MESSAGE e026(zh).
ENDCASE.
ENDFORM. " UPLOAD_SOURCE_FILE
************************************************************************
D O W N L O A D _ S O U R C E _ F I L E *
************************************************************************
FORM download_source_file.
Begin CDSK904243
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = p_filnm
filetype = 'ASC'
TABLES
data_tab = itab
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
OTHERS = 8.
w_file = p_filnm.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = w_file
filetype = 'ASC'
TABLES
data_tab = itab
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
End CDSK904243
CASE sy-subrc.
WHEN '0'.
WHEN '1'.
MESSAGE e023(zh).
WHEN OTHERS.
MESSAGE e026(zh).
ENDCASE.
ENDFORM. " DOWNLOAD_SOURCE
************************************************************************
P R O C E S S _ U P L O A D *
************************************************************************
FORM process_upload.
LOOP AT itab.
MOVE-CORRESPONDING itab TO itab1.
MOVE sy-mandt TO itab1-mandt.
APPEND itab1.
CLEAR itab1.
ENDLOOP.
ENDFORM. " PROCESS_UPLOAD
************************************************************************
U P D A T E _ T C U R R *
************************************************************************
FORM update_tcurr.
MODIFY tcurr FROM TABLE itab1.
COMMIT WORK.
IF sy-subrc = 0.
ELSE.
WRITE: /5 'Error ! ! ! - Update Error'.
ENDIF.
ENDFORM. " UPDATE_TCURR
************************************************************************
S E L E C T _ D A T A *
************************************************************************
FORM select_data.
SELECT * FROM tcurr WHERE kurst IN s_kurst
AND fcurr IN s_fcurr
AND tcurr IN s_tcurr.
*
MOVE-CORRESPONDING tcurr TO itab.
move: tcurr-kurst to itab-kurst, "Exchange Rate Type
tcurr-fcurr to itab-fcurr, "From Currency
tcurr-tcurr to itab-tcurr, "To Currency
tcurr-gdatu to itab-gdatu, "Effective Date
tcurr-ukurs to itab-ukurs, "Exchange Rate
tcurr-ffact to itab-ffact, "From Factor
tcurr-tfact to itab-tfact. "To Factor
APPEND itab.
CLEAR itab.
ENDSELECT.
ENDFORM. " SELECT_DATA
************************************************************************
W R I T E _ R E P O R T *
************************************************************************
FORM write_report.
LOOP AT itab.
CONVERT INVERTED-DATE itab-gdatu INTO DATE w_date.
WRITE: /01 itab-kurst,
10 itab-fcurr,
20 itab-tcurr,
30 w_date MM/DD/YYYY,
45 itab-ukurs.
CLEAR w_date.
ENDLOOP.
DESCRIBE TABLE itab LINES w_tcurr.
SKIP 1.
IF p_upload = 'X'.
WRITE: /01 'Total Currency Rate Records Uploaded =', w_tcurr.
ELSE.
WRITE: /01 'Total Currency Rate Records Downloaded =', w_tcurr.
ENDIF.
07-09-2007 9:46 PM
Hello
Try something like this:
FORM select_data.
SELECT * FROM tcurr WHERE kurst IN s_kurst
AND fcurr IN s_fcurr
AND tcurr IN s_tcurr.
*
MOVE-CORRESPONDING tcurr TO itab.
move: tcurr-kurst to itab-kurst, "Exchange Rate Type
tcurr-fcurr to itab-fcurr, "From Currency
tcurr-tcurr to itab-tcurr, "To Currency
tcurr-gdatu to itab-gdatu, "Effective Date ->> OUT
tcurr-ukurs to itab-ukurs, "Exchange Rate
tcurr-ffact to itab-ffact, "From Factor
tcurr-tfact to itab-tfact. "To Factor
->> NEW
WRITE tcurr-gdatu to itab-gdatu MMDDYY. "Effective Date
APPEND itab.
CLEAR itab.
ENDSELECT.
ENDFORM. " SELECT_DATA
07-09-2007 8:37 PM
07-09-2007 8:56 PM
hi srinivas thak you, can you please be more clear , in order to get the normal date in a file
07-09-2007 8:40 PM
07-09-2007 9:46 PM
Hello
Try something like this:
FORM select_data.
SELECT * FROM tcurr WHERE kurst IN s_kurst
AND fcurr IN s_fcurr
AND tcurr IN s_tcurr.
*
MOVE-CORRESPONDING tcurr TO itab.
move: tcurr-kurst to itab-kurst, "Exchange Rate Type
tcurr-fcurr to itab-fcurr, "From Currency
tcurr-tcurr to itab-tcurr, "To Currency
tcurr-gdatu to itab-gdatu, "Effective Date ->> OUT
tcurr-ukurs to itab-ukurs, "Exchange Rate
tcurr-ffact to itab-ffact, "From Factor
tcurr-tfact to itab-tfact. "To Factor
->> NEW
WRITE tcurr-gdatu to itab-gdatu MMDDYY. "Effective Date
APPEND itab.
CLEAR itab.
ENDSELECT.
ENDFORM. " SELECT_DATA
07-09-2007 10:01 PM
Hi thak you, i made the changes according to you, but there is no change
07-09-2007 11:07 PM
07-09-2007 11:27 PM
The field is stored as a 9s-complement (i.e. 99999999 - date), and the domain has a conversion exit on it that undertakes the necessary logic... you should therefore re-use the appropriate function module "conversion_exit_?????_input" or "conversion_exit_?????_output" when referencing this field. You can find the name of the conversion exit from the domain i.e. go to SE11, double click the field name to show the data element, double click the domain and you'll see the name of the conversion routine there (F1 on the field shuld describe how these are used). Therefore in your code, you'll need something like:
call function 'CONVERSION_EXIT_INVDT_INPUT' "check this matches field's conversion exit
exporting
input = l_source_data
importing
output = l_formatted_data.
07-09-2007 11:38 PM
WRITE will take care of your conversion exit aspect. The only issue with this one is that it gives you an output that is 10 characters in length. If you need a different format, you then have to take the offsets.
WRITE tcurr-gdatu TO v_char10_date.
07-10-2007 1:52 PM
the date should be in MM/DD/YYYY in the file, i tried to put write statement but it dosent work, please see my internal table and select qurrey and report logic, and please let me know how to slove this issue.
DATA: BEGIN OF itab OCCURS 0, "Input / Output File
kurst LIKE tcurr-kurst, "Exchange Rate Type
fcurr LIKE tcurr-fcurr, "From Currency
tcurr LIKE tcurr-tcurr, "To Currency
gdatu LIKE TCURR-GDATU,
ukurs(11) TYPE c, "Exchange Rate
ffact(11) TYPE c, "From Factor
tfact(11) TYPE c, "To Factor
END OF itab.
FORM select_data.
SELECT * FROM tcurr WHERE kurst IN s_kurst
AND fcurr IN s_fcurr
AND tcurr IN s_tcurr.
move: tcurr-kurst to itab-kurst, "Exchange Rate Type
tcurr-fcurr to itab-fcurr, "From Currency
tcurr-tcurr to itab-tcurr, "To Currency
tcurr-gdatu to itab-gdatu MM/DD/YYYY, "Effective Date
tcurr-ukurs to itab-ukurs, "Exchange Rate
tcurr-ffact to itab-ffact, "From Factor
tcurr-tfact to itab-tfact. "To Factor
APPEND itab.
CLEAR itab.
ENDSELECT.
ENDFORM. " SELECT_DATA
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = w_file
filetype = 'ASC'
TABLES
data_tab = itab
EXCEPTIONS
file_write_error = 1
FORM write_report.
LOOP AT itab.
CONVERT INVERTED-DATE itab-gdatu INTO DATE w_date.
WRITE: /01 itab-kurst,
10 itab-fcurr,
20 itab-tcurr,
30 w_date MM/DD/YYYY ,
45 itab-ukurs.
CLEAR w_date.
ENDLOOP.
DESCRIBE TABLE itab LINES w_tcurr.
SKIP 1.
IF p_upload = 'X'.
WRITE: /01 'Total Currency Rate Records Uploaded =', w_tcurr.
ELSE.
WRITE: /01 'Total Currency Rate Records Downloaded =', w_tcurr.
ENDIF.
ENDFORM. " WRITE_REPORT
in the report i got the MM/DD/YYYY format but i could able to get the same date in file. please let me know what to do to get the solution.
07-10-2007 5:27 PM
Hi,
<b>1. </b>Your internal table contains date in an inverted format hence after download your file contains inverted date. So, before passing data to the internal table itab, change the inverted date to normal date. You need to change the declaration as shown below.
DATA: BEGIN OF itab OCCURS 0, "Input / Output File
kurst LIKE tcurr-kurst, "Exchange Rate Type
fcurr LIKE tcurr-fcurr, "From Currency
tcurr LIKE tcurr-tcurr, "To Currency
<b>gdatu(10) LIKE c,</b>
ukurs(11) TYPE c, "Exchange Rate
ffact(11) TYPE c, "From Factor
tfact(11) TYPE c, "To Factor
END OF itab.
FORM select_data.
SELECT * FROM tcurr WHERE kurst IN s_kurst
AND fcurr IN s_fcurr
AND tcurr IN s_tcurr.
move: tcurr-kurst to itab-kurst, "Exchange Rate Type
tcurr-fcurr to itab-fcurr, "From Currency
tcurr-tcurr to itab-tcurr, "To Currency
<b>CALL FUNCTION CONVERSION_EXIT_INVDT_OUTPUT
IMPORTING
input = tcurr-gdatu
EXPORTING
output = itab-gdatu.</b>"Effective Date
tcurr-ukurs to itab-ukurs, "Exchange Rate
tcurr-ffact to itab-ffact, "From Factor
tcurr-tfact to itab-tfact. "To Factor
APPEND itab.
CLEAR itab.
ENDSELECT.
ENDFORM. " SELECT_DATA
<b>2. </b>Now, you internal table itab has date in a proper format, hence there is no need of CONVERT INVERTED-DATE itab-gdatu INTO DATE w_date.
Reward points if the answer is helpful.
Regards,
Mukul
07-11-2007 11:08 AM
Hi , thank you very much, i added your code, but it works when i took off the FUNCTION MODULE in between the move statements, and placed the srinivas adavi logic, i.e write statement, so finally i got the solution, thank you very to you and our friends.
07-10-2007 12:41 AM
Hi,
Use FM <b>CONVERSION_EXIT_INVDT_OUTPUT</b>.
Date in table TCURR is stored in an inverted format using FM CONVERSION_EXIT_INVDT_INPUT. Before downloading it to a file, convert the inverted date to a normal date using CONVERSION_EXIT_INVDT_OUTPUT.
CALL FUNCTION CONVERSION_EXIT_INVDT_OUTPUT
IMPORTING
input = inverted_date
EXPORTING
output = normal_date.
Reward points if the answer is helpful.
Regards,
Mukul