Skip to Content
0
Former Member
Jul 09, 2007 at 07:31 PM

upload/download currenct exchange program (issue: tcurr-gdatu)

303 Views

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.