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: 

program to copy file adding date and timestamp to the file name.

Former Member
0 Kudos

Hi Friends

I have got one requirement to create a abap program which will copy file from one location to another location adding date stamp and time stamp to the file which is in destination folder. I have developed the program and it is working . Files is copying in the destination folder but without timestamp and datestamp. Could you please help me out how can i get time and datestamp in the file name.

Target location should be like this--BPC_BACKUP/ARCHIVE/TEST_18052018_154400.zip

Plz find the below code snippet.

type-pools: abap.

parameters: p_file1 like rlgrap-filename DEFAULT 'C:\Users\ashutosh-sh\Documents\BPC_BACKUP\TEST_ZIP\New Microsoft Excel Worksheet.xlsx' obligatory,

p_file2 like rlgrap-filename DEFAULT 'C:\Users\ashutosh-sh\Documents\TEST1\BPC_BACKUP\Archieve\test1.xlsx' obligatory.

* CONCATENATE C:\Users\ashutosh-sh\Documents\TRONOX1\BPC_BACKUP\Archieve\test1 sy-datum sy-uzeit into p_file2.
data: l_ret type abap_bool,

l_suc type i.

data: l_file1 type string,

l_file2 type string.

start-of-selection.

move: p_file1 to l_file1,

p_file2 to l_file2.

call method cl_gui_frontend_services=>file_exist

exporting

file = l_file1

receiving

result = l_ret

exceptions

cntl_error = 1

error_no_gui = 2

wrong_parameter = 3

not_supported_by_gui = 4

others = 5.

if sy-subrc eq 0.

call method cl_gui_frontend_services=>file_copy

exporting

source = l_file1

destination = l_file2

overwrite = 'X'

exceptions

cntl_error = 1

error_no_gui = 2

wrong_parameter = 3

disk_full = 4

access_denied = 5

file_not_found = 6

destination_exists = 7

unknown_error = 8

path_not_found = 9

disk_write_protect = 10

drive_not_ready = 11

not_supported_by_gui = 12

others = 13.

if sy-subrc eq 0.

write: 'File:', p_file1, ' successfully copied to: ',

p_file2.

endif.

* endif.

endif.

Thanks

Ashutosh

2 REPLIES 2

vrushpanpatil
Discoverer
0 Kudos

Put C:\Users\ashutosh-sh\Documents\TRONOX1\BPC_BACKUP\Archieve\test1 in single quote 'C:\Users\ashutosh-sh\Documents\TRONOX1\BPC_BACKUP\Archieve\test1' or pass it to the variable first.

lv_text = 'C:\Users\ashutosh-sh\Documents\TRONOX1\BPC_BACKUP\Archieve\test1'.

CONCATENATE lv_text sy-datum sy-uzeit into p_file2.

former_member564522
Active Participant

Hi

First split the filepath into file name and file extension.

Add date and time into file name and then concatenate back with file extension.

Regards

Himanshu