Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

uploading a file from presentation server to database table(TCURR)

Former Member
0 Kudos

Hi I written a program to upload and download a file from presentaion server for the data base table TCURR, i'm able to downlaod to a file and write a report, but when i tried to upload this file to TCURR data base table, I'm unable to change the date gdatu to sap format, in TCURR-GDATU, here is my code, please any one can insert the code to slove this problem

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(10) type c,

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

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.

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: tcurr-kurst to itab-kurst, "Exchange Rate Type

tcurr-fcurr to itab-fcurr, "From Currency

tcurr-tcurr to itab-tcurr, "To Currency

tcurr-ukurs to itab-ukurs, "Exchange Rate

tcurr-ffact to itab-ffact, "From Factor

tcurr-tfact to itab-tfact. "To Factor

WRITE tcurr-gdatu TO itab-gdatu.

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 itab-gdatu ,

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Have you seen in debug which is the format of the field gdatu??

'Cause if it is automatically converted into 01.01.2007 format it's only necessary to do this:

concatenate file-gdatu6(4) file-gdatu3(2) file-gdatu(2) into data.

then move data where you need.

3 REPLIES 3

Former Member
0 Kudos

Have you seen in debug which is the format of the field gdatu??

'Cause if it is automatically converted into 01.01.2007 format it's only necessary to do this:

concatenate file-gdatu6(4) file-gdatu3(2) file-gdatu(2) into data.

then move data where you need.

Former Member
0 Kudos

Hi,

date for is different in display format and database format.

Use approprate conversion routine to conversion.

Reward points if helpful

Regards.

Srikanta Gope

Former Member
0 Kudos

Dear sudhir,

you need to specifically change the dateformat passed in the internal table into the internal format as the date which is passed out will be in external format.

so you will need to use a Function Module for changin the external date format into an internal date format.

Hope this solves you problem

\Thanks

venugopal

Reward if useful. it will be a long way to go ahead.