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: 

save filename in application server

Former Member
0 Kudos

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

7 REPLIES 7

Former Member
0 Kudos

Hi

Use option FOR APPENDING instead of FOR UPDATE when you open your file:

OPEN DATASET FILE FOR APPENDING ...

Max

Message was edited by: max bianchi

Former Member
0 Kudos
DATA: v_filepht LIKE FILENAME-FILEINTERN, "Physical file for p_fnam2

* Open the file in application server
  OPEN DATASET v_filepht FOR OUTPUT IN TEXT MODE.
  IF sy-subrc <> 0.
    MESSAGE s185 WITH v_filepht.           " File opening error
    LEAVE LIST-PROCESSING.

  ENDIF.

   LOOP AT i_logfile INTO w_logfile.
    TRANSFER w_logfile TO v_filepht.
    CLEAR w_logfile.

  ENDLOOP.

   IF sy-subrc = 0.
    WRITE:/ text-055, v_filepht, text-056. " File successfully created
  ELSE.
    WRITE:/ text-057, v_filepht.           " Error creating file
  ENDIF.

 * Closing the file

  CLOSE DATASET v_filepht.

Try this one.

andreas_mann3
Active Contributor
0 Kudos

Hi,

append _2 :

CONCATENATE new_file_name '_2' INTO new_file_name.

Andreas

Former Member
0 Kudos

Hi

I'm sorry I didn't understand your real problem

CONCATENATE new_file_name '2' INTO new_file_name

SEPARATED BY '_'.

DO.

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

CLOSE DATASET new_file_name.

ELSE.

EXIT.

ENDIF.

CONCATENATE new_file_name '2' INTO new_file_name

SEPARATED BY '_'.

ENDDO.

Max

0 Kudos

hi max,

i had tried with ur solution it had worked but new problm has arised with that...now in one file if there are two records its writting all the records in onle line..

actually i need if the file is there on server(say for ex:sales.txt) then if i again upload the same file sales it should be written on server with name as sales.txt_2 and so on..

i am uploading file from desktop to application server..

plz its urgent for me...ur valuable inputs will really help me out..

thanks

0 Kudos

Hi

I don't understand your problem well:

If there is a file on server: should you insert a new file with the data of old file and new data?

if it's so:

DATA: WA(1000),

last_file(100).

CLEAR LAST_FILE.

DO.

OPEN DATASET new_file_name FOR UPDATE IN LEGACY TEXT MODE.

IF sy-subrc = 0.

  • Save the name of last file:

last_file = new_file_name.

CLOSE DATASET new_file_name.

ELSE.

EXIT.

ENDIF.

CONCATENATE new_file_name '2' INTO new_file_name

SEPARATED BY '_'.

ENDDO.

Now before downloading new data, you should transfer old data:

OPEN DATASET new_file_name FOR OUTPUT IN LEGACY TEXT MODE.

IF NOT LAST_FILE IS INITIAL.

OPEN DATASET LAST_FILE FOR UPDATE IN LEGACY TEXT MODE.

DO.

READ DATASET LAST_FILE INTO WA.

IF SY-SUBRC <> 0. EXIT. ENDIF.

TRANSFER WA TO new_file_name.

ENDDO.

CLOSE DATASET LAST_FILE.

ENDIF.

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

Max

Message was edited by: max bianchi

Message was edited by: max bianchi

0 Kudos

thanks max..

ur answer has given me good idea to move ahead..

thanks