Hi all,
i am uploading multiples files from desktop to application server and its working good. But user can upload same file name more than 4 or 5 times together.And i have to write the file on server by appending _2 _2 _2 for every new file. Right now i am able to do for one file name(.i.e. the file if already exsist its appending _2 with the new file name). but if i am uploading the same file third or fourth time its not writting the file on server. I have to just append _2 _2 with file that already exsist.
here is the code that i had built up...
DATA: BEGIN OF t_itab OCCURS 0,
soldto(10) TYPE c,
enumber(10) TYPE c,
ename(35) TYPE c,
land1(35) TYPE c,
name2(35) TYPE c,
matnr(18) TYPE c,
quantity(13) TYPE c,
shipdate like sy-datum,
invoiceno(35) TYPE c,
scost(13) TYPE c,"DECIMALS 2,
ucost(13) TYPE c,"DECIMALS 2,
dlno(10) TYPE c,
END OF t_itab.
************************************************************************
DATA DECLARATION *
************************************************************************
DATA :file TYPE string.
DATA :in_file(150) TYPE c.
DATA: stripped TYPE rlgrap-filename.
DATA: file_path TYPE rlgrap-filename.
DATA: new_file_name TYPE rlgrap-filename.
DATA :l_date(10) TYPE c,
x_date TYPE d.
DATA: xtitle1(132),
xtitle2 LIKE xtitle1,
xtitle3 LIKE xtitle1,
xtitle4 LIKE xtitle1.
CONSTANTS:EMAIL_KEY(20) TYPE c VALUE 'DISTY_POS_ERRORS'.
***********************************************************************
P A R A M E T E R S *
***********************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS s_uload FOR rlgrap-filename VISIBLE LENGTH 128
NO INTERVALS.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_uload-low.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = 'ZSR00340'
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = s_uload-low.
AT SELECTION-SCREEN ON BLOCK b1.
IF s_uload IS INITIAL.
MESSAGE e000(0k) WITH 'Please enter the file path'.
ENDIF.
TOP-OF-PAGE.
CALL FUNCTION 'Z_REPORT_HEADERS'
EXPORTING
columns = 140
period = space
rpt_name = 'ZSR00340'
rpt_title1 = sy-title
RPT_TITLE2 =
RPT_TITLE3 =
COMP_CODE =
IMPORTING
text01 = xtitle1
text02 = xtitle2
text03 = xtitle3
text04 = xtitle4.
WRITE: / xtitle1,
/ xtitle2,
/ xtitle3.
IF NOT xtitle4 = space.
WRITE: / xtitle4.
ENDIF.
ULINE.
FORMAT COLOR COL_HEADING ON INTENSIFIED OFF .
************************************************************************
START-OF-SELECTION *
************************************************************************
START-OF-SELECTION.
LOOP AT s_uload.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = s_uload-low
filetype = 'DAT'
HEADLEN = ' '
LINE_EXIT = ' '
TRUNCLEN = ' '
USER_FORM = ' '
USER_PROG = ' '
DAT_D_FORMAT = ' '
IMPORTING
FILELENGTH =
TABLES
data_tab = t_itab
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
no_authority = 10
OTHERS = 11
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
PERFORM sub_send_mail." using g_text.
EXIT.
ENDIF.
*function to get customer name as ten digit
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = t_itab-soldto
IMPORTING
output = t_itab-soldto.
Function to prefix the Filename
CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
full_name = s_uload-low
IMPORTING
stripped_name = stripped
file_path = file_path.
*format date as mmddyyyy from yyyymmdd
x_date = sy-datum.
CONCATENATE x_date4(2) x_date6(2) x_date+0(4) INTO l_date.
CLEAR new_file_name.
*conactenated the directory with system and with the path name
CONCATENATE '/xapp' sy-sysid 'disti/pos/' INTO in_file
SEPARATED BY '/'.
CONCATENATE in_file 'POS' l_date t_itab-soldto
INTO new_file_name SEPARATED BY '_'.
REPLACE FIRST OCCURRENCE OF '_' IN new_file_name WITH ''.
*check for exsistency of file
OPEN DATASET new_file_name FOR UPDATE IN LEGACY TEXT MODE.
IF sy-subrc = 0.
*if exists then append '2' again with the new filename
CONCATENATE new_file_name '2' INTO new_file_name
SEPARATED BY '_'.
CLOSE DATASET new_file_name.
ENDIF.
*to write data on server
OPEN DATASET new_file_name FOR OUTPUT IN LEGACY TEXT MODE.
*looping on Internal table to write all data
LOOP AT t_itab.
TRANSFER t_itab TO new_file_name .
ENDLOOP.
*if successfully uploaded then success message
IF sy-subrc EQ 0.
WRITE:/ 'Files are uploaded'.
ENDIF.
CLOSE DATASET new_file_name.
so cananyone plz suggest what should i do for appending _2 with the file that is already there on server...