on 10-04-2005 5:09 AM
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...
hi can anyone plz help in this...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Anu,
I am assuming that there should be some problem in this part of the code.
You are opening a file and if sy-subrc eq 0 then you are concatenating 2 to the existing file and then trying to close the new file with out opening it also and you have not closed the file which has already opened.
Use separate variables for both the file names and try again.
*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.
Regards,
For each file, do the following 3 steps.
OPEN DATASET myfile.
DO.
READ DATASET myfile.
IF SY-SUBRC = 0.
*-- file already exists, append _2 to the file name
CLOSE DATASET myfile.
CONCATENATE myfile '_2' into myfile.
ELSE.
*-- file doesn't exist
EXIT.
ENDIF.
ENDDO.
Could not help noticing, after your WS_UPLOAD(this is obsolete, do not use this), you are doing a CONVERSION EXIT for itab-soldto without looping at the internal table.
Regards,
Srinivas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi srinivas
i do not know how many files with the same name user can upload...
and secondly i am uploading file from desktop to application server... and i have to save file on app. server. and the file if exsists then ii have to append _2 ...if user upload file with same name the it should agian append _2 and so on...so plz can u suggest what should i do...
thanks
Hi Anu,
This code does exactly that. The logic is simple.
Let us say the user entered 3 files file1, file1 and file1 in the select option. Now let assume that file1 already exists in the application server. Now here is logic.
Loop at select-option.
*-- Upload the file from desktop.
*-- prepare the name for application server file
*-- check if the file already exists in the application
* server, by doing the following
OPEN DATASET appserverfilename.
DO.
READ DATASET appserverfilename.
IF SY-SUBRC = 0.
*-- file already exists, append '_2' to the file name
CLOSE DATASET appserverfilename.
CONCATENATE appserverfilename '_2' into appserverfilename.
ELSE.
*-- file doesn't exist
EXIT.
ENDIF.
ENDDO.
*-- move the contents of the file uploaded into the
* application server file by using TRANSFER as in your
* code.
Endloop.
Now if we trace this code with our example, when you are looping at the select option for the first time, the file name is fiel1. You prepare the application server name by your logic and let us say it is file1. Now the OPEN DATASET file1 will open the file. In the DO loop, we will try to read the file using READ DATASET file1. If sy-subrc = 0, then the file1 already exists in application server. Then we will append the 2 to it. Now our file name will be file12. We are still in the DO loop. We will now do READ DATASET file1_2. Let us assume even this is there. We will go ahead and append 2 again. Now the file name is file12_2. Another pass through the DO loop and the READ DATASET will now result sy-subrc <> 0. That means no file with this name. We exit the DO loop and write the internal table contents to this file.
Heop this clears your doubt. If you have any issues, please paster your complete code.
Srinivas
User | Count |
---|---|
99 | |
12 | |
11 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.