Save filename in application server

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

Similar Messages

  • Function Module to find the Path of the file in the Application Server

    Hi All,
            Any function module available to find the path of the file stored in the application server. Please let me know.
    Thanks.

    Check this code:
      DATA: dl_file TYPE ibipparms-path.    " File name
      CONSTANTS: c_dir       TYPE  rlgrap-filename.
    * F4 filename for Application server
        CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
          EXPORTING
            directory        = c_dir
            filemask         = ' '
          IMPORTING
            serverfile       = dl_file
          EXCEPTIONS
            canceled_by_user = 1
            OTHERS           = 2.
        IF sy-subrc <> 0.
          MESSAGE e000 WITH 'Error while getting the file name'(006).
          EXIT.
        ELSE.
          p_file =  dl_file.
        ENDIF.
    Thanks & Regards,
    Siri.
    Message was edited by:
            Srilatha T

  • Opening a file stored at application server

    Experts,
        I have put a document on application server using DATASET .
       Now I want to open the same file from there only.
       ho to do that.
    Thnx in Advance
    Chetan

    Hi Chetan ,
    U can use following code to open the file u created in application server.
    1.
    data: <dataset_name>(25)  value '.\tmp\file_sarang_01.txt'.
    open dataset <dataset_name> for input in text mode encoding UTF-8
    read dataset <dataset_name> into itab_wa.
    Append itab_wa to itab.
    close dataset <dataset_name>
    loop at itab.
    write: itab-field1 , itab-field2 .
    endloop.
    2.  U can use transaction CG3Y  , to save file from application server to presentation server directly.(A short cut for u)
    I hope this solves ur problem
    Reagrds.
    Note: Reward if useful

  • Transfer file in application server to another file

    Hello guys I have another major hurdle I am encountering for a little task I am doing.
    I need to send a downloaded file within the SAP application server to another file automatically using ABAP via Background Processing(most preferable a directory in the <b>newtwork</b>).
    What I need to do is, after saving a list from an abap report and saves in the application server (which I have already done), I need it to transport to a the web server. All done in background.
    I really appreciate the help you guys have given to me thus far. Thank you guys and take care.

    Hi
    U have to use unix command for same
    i have seen some function module just check it out
    SXPG_CALL_SYSTEM you can check the user's authorization for the specified command and run the command. The command runs on the host system on which the function module is executed. The function module is RFC capable. It can therefore be run on the host system at which a user happens to be active or on another designated host system at which an R/3 server is active.
    <b>SXPG_COMMAND_CHECK</b> Check whether the user is authorized to execute the specified command on the target host system with the specified arguments.
    <b>SXPG_COMMAND_DEFINITION_GET</b> Read the definition of a single external OS command from the R/3 System's database.
    <b>
    SXPG_COMMAND_EXECUTE</b> Check a user's authorization to use a command, as in SXPG_COMMAND_CHECK. If the authorization check is successful, then execute the command on the target host system.
    <b>SXPG_COMMAND_LIST_GET</b> Select a list of external OS command definitions.
    <b>RZL_READ_DIR_LOCAL</b> Read a directory on the Application Server
    <b>SUBST_GET_FILE_LIST</b> Return table with file list for the given directory (pattern allowed)
    regards
    vinod

  • Save the o/p of the query in Application Server, Filename with Timestamp

    Dear Experts,
    I have a scenario that on 1st of every month, a query needs to execute and save the output of that query in Application Server, Filename along with Timestamp.
    For ex: Production_19/09/2011
    So, I Created a Query Extract in RSCRM_REPORT and gave the path name and scheduled. The output of the query is saved successfully in Application Server.
    But I need Timestamp along with Filename.
    Please help me out with the timestamp issues, how could I include Timestamp with Filename (Query Name).
    Thanks,
    SAP BI

    Hi chaith,
    You can achieve the result with out any code. You have to use the APD concept to extract the query to a file.
    check the following link which help you to create a logical path
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/60e86545-9940-2d10-9f89-eb5bce1f9228?quicklink=index&overridelayout=true
    you can use the path in the APD.
    Regards,
    Ranganath

  • How to save CSV file in application server while making infospoke

    How to save CSV file in application server to be used as destination while making infospoke.
    Please give the steps.........

    Hi
    If you want to load your flatfile from Application server,then you need to trasfer your file from your desktop(Computer) to Application server by using FTP.
    Try using ARCHIVFILE_CLIENT_TO_SERVER Function module.
    You Just need to give thesource path and the target path
    goto SE37 t-code , which is Function module screen, give the function name ARCHIVFILE_CLIENT_TO_SERVER, on click F8 Execute button.
    for path variable give the file path where it resides like C:\users\xxx\desktop\test.csv
    for target path give the directory path on Application server: /data/bi_data
    remember the directory in Server starts with /.
    U have to where to place the file.
    Otherwise use 3rd party tools to connect to ur appl server like : Core FTP and Absolute FTP in google.
    Otherwise...
    Goto the T.code AL11. From there, you can find the directories available in the Application Server.
    For example, if you wanna save the file in the directory "DIR_HOME", then you can find the path of the directories in the nearby column. With the help of this, you can specify the target path. Specify the target path with directory name followed by the filename with .CSV extension.
    Hope this helps
    regards
    gaurav

  • Need to save a file on Application server, receiving error.

    Hello,
    I want to save a file on Application server.
    I have data in the final output table gt_out_chng.
    I want to write a file in the application server and this is the
    code that written,
    data : MY_NEW_FILE type file.
            MY_NEW_FILE = '/tmp/test.txt'.
    data: gv_output(255) type c,
          P_FILE TYPE rlgrap-filename.
       p_file = 'F:\USR\SAP\PUT'.
    CONCATENATE p_file '\' sy-datum sy-uzeit '.txt'
                                 INTO p_file.
    OPEN DATASET 'P_FILE' IN TEXT MODE FOR OUTPUT
                                      ENCODING DEFAULT.
    IF SY-SUBRC = 0.
    LOOP AT GT_OUT_CHNG INTO WA_OUTPUT_TAB.
    TRANSFER WA_OUTPUT_TAB TO 'P_FILE'.
    CLEAR  WA_OUTPUT_TAB.
    ENDLOOP.
    ENDIF.
    CLOSE DATASET 'P_FILE'.
    i am receiving an error message as follows :
    "WA_OUTPUT_TAB" cannot be a table, a reference,
    a string, or contain any of these objects.
    Please correct the code if found any errors..
    Any suggestions will be apprecaited!
    Regards,
    Kittu
    Edited by: Kittu on May 15, 2009 10:27 AM

    Hello,
    Instead of using the following,
    OPEN DATASET 'P_FILE' IN TEXT MODE FOR OUTPUT ENCODING DEFAULT.
    use this,
    OPEN DATASET P_FILE IN TEXT MODE FOR OUTPUT ENCODING DEFAULT.
    P_FILE is your variable, do not put it in quotes
    Edit: The same thing applies for your transfer and close statements
    Edited by: Kris Donald on May 15, 2009 2:05 PM

  • How to save 4 versions of a file in the application server

    Hi,
       I have to write a program which will extract few data from SAP and write it in a file in the SAP application server. This program will be run once every month.
    I need to save 4 versions of the files, current and 3 prior.  These versions should cycle off the oldest once a new version has been created.
    Could anyone help me how to do this?
    Thank you!
    Regards,
    Sunitha.

    Hi Sunitha,
    The best way is to write a unix script in the unix server to do the job for you. Once The file is written in the server then leave the job from the unix side to get this done.
    This is the best option i think. Writing a script is not a big task. You can call the script from ABAP or from an external daemon in the unix server. We have many such programs in our org.
    Hope this helps
    Cheers
    VJ

  • Sap query output to save on application server

    Hi All,
    I have one requirement, want to save the output of sap query on application server as a text file?
    Is there any work around?
    Regards
    Vasumathi
    Edited by: komma vasumathi on Nov 5, 2009 10:32 AM

    Hi Vasumathi,
    Application server path cannot be accessed unless otherwise using OPEN DATASET. More over, Infoset cannot be executed directly. It can be accessed through SAP Query only.
    Writing Logic for 2 or 3 tables with Inner Join will not be a big deal. Writing Abap program will be optimum for you FTP requirement.
    1. create a folder in AL11 as \sap\common\
    2.  create z program and Declare sel-screen parameters : selopt1, selopt2
    3. Query : Select Afield1 Afield2 Bfield1 Bfield2 from table1 as A inner join table2 as  B on Afield1 eq Bfield1 where Afield1 in selopt1 and Afield2 in selopt2  into corresponding fields of table itab.
    4. creating file  at application sever
          w_fileloc = '\sap\common\file.txt'
         OPEN DATASET w_fileloc FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
        . Loop itab into wa_itab.
          Transfer wa_itab to w_fileloc.
         clear w_fileloc.
        endloop.
    5. goto AL11 and check the file file.txt in  folder \sap\common
    Please let me know if you need more information or close this thread by offiering the points( If you are satisfied).
    Regards,
    Sakthivel N

  • Save the image in the application server directly

    Hi,
          I have developed a report which displays piechart as the output and saves the image on the presentation server. For that i have used the following code.
       when 'SAVE'.
    DATA : D TYPE GFW_EXP_DATA,
    R TYPE SYMSGNO.
    DATA: S TYPE STRING,
    N TYPE I.
    CALL METHOD GP_INST->IF_GRAPHIC_PROXY~EXPORT
    EXPORTING
    FORMAT =
    IF_GRAPHIC_PROXY=>co_format_bmp
    WIDTH = 50
    HEIGHT = 200
    name = 'C:\Documents and Settings.........'
    IMPORTING
    CONTENT_TYPE = S
    CONTENT_LENGTH = N
    CONTENT = D
    RETVAL = R
    I have a requirement where i have to save the output of the screen(piechart)  in the application server directly with out using the presentaion server.
    Is there any method to do so.
    Thanks and regards,
    Parvatha Reddy

    Hi parvatha ,
    your question is really good.
    Well i really haven't come across your scenario i many years . But my suggestion is to  can use java code to achieve the same .
    Or try to use hexadecimal type in your normal class to read the pie-chart and use transfer with same type .

  • In what tables does Data in Application Server save ?

    Dear Gurus,
    In what tables does Data in Application Server save ?
    Does the code we write is saved in some tables (or) saved in
    repository ??
    what is a repository ???
    what are the tables where repository data is saved ????

    >
    Srikar M wrote:
    > Dear Gurus,
    >
    > In what tables does Data in Application Server save ?
    All of them
    >
    Srikar M wrote:
    > Does the code we write is saved in some tables (or) saved in
    > repository ??
    Both
    >
    Srikar M wrote:
    > what is a repository ???
    >
    The place where workbench objects are saved
    >
    Srikar M wrote:
    > what are the tables where repository data is saved ????
    Many and various.  Some not accessible via ABAP.

  • Save PDF-file on the application server

    Hello experts,
    I convert my Smartform to a PDF-File. I copied the code from  Suresh Kumar Parvathaneni (REPORT zsuresh_test). At first, thank you Suresh Kumar for that!
    Now, I would like to save the PDF-File on the application server and not local.
    Could you tell me how to do this. Especially, where do I have to put the abap-code in the given code from Suresh Kumar.
    I thank you very much for your help in advance.
    With kind regards.
    gokselin

    Hi,
    You can use the OPEN DATASET statment.
    Probably you must be having an output table which you are downloading to the local machine.You can use the same and loop at it. and if the OPEN dataset returned sy-subrc 0, use the TRANSFER statment.
    Remember the data will be binary for pdf. So you have to open the dataset in binary mode.
    regards,
    Advait

  • Save string data type text in the application server file opened in binary

    Hi All,
    My requirement is to save the string "abcd    23432423   asdada" to the text file in the application server.
    I have written like this. but its not getting saved properly in the text file. Please help.
      constants X_LINESIZE type I value 128.
      types X_LINETYPE type X length X_LINESIZE.
    data: WA_TAB_X type X_LINETYPE.
      data: str1(64) type C.
      data: WA_TAB_X_HDR1 type xstring.
      str1 = 'abcd    23432423   asdada'.
      CONVERT TEXT STR1 INTO SORTABLE CODE WA_TAB_X_HDR1.
      concatenate F_FILENAME1 SY-SYSID F_FILENAME2 '/' TAB_REGUT-TSNAM '.TXT' into F_FILENAME1.
      open dataset F_FILENAME1 for output in binary mode .
      if SY-SUBRC = 0.
        transfer WA_TAB_X_HDR to F_FILENAME1.
        loop at TAB_X into WA_TAB_X.
          transfer WA_TAB_X to F_FILENAME1.
        endloop.
      endif.
      close dataset F_FILENAME1.
    Edited by: madhuri sonawane on Jun 2, 2009 4:05 PM

    HI,
    constants X_LINESIZE type I value 128.
      types X_LINETYPE type X length X_LINESIZE.
    data: WA_TAB_X type X_LINETYPE.
      data: str1(64) type C.
      data: WA_TAB_X_HDR1 type xstring.
    data : file (1000) type c.
      str1 = 'abcd    23432423   asdada'.
      CONVERT TEXT STR1 INTO SORTABLE CODE WA_TAB_X_HDR1.
      concatenate F_FILENAME1 SY-SYSID F_FILENAME2 '/' TAB_REGUT-TSNAM '.TXT' into F_FILENAME1.
      open dataset file for output in binary mode .
      if SY-SUBRC = 0.
        transfer WA_TAB_X_HDR to file.
        loop at TAB_X into WA_TAB_X.
          transfer WA_TAB_X to file
        endloop.
      endif.
      close dataset file.
    regards,
    Munibabu.k

  • Save on application server

    hi.......
    Can u any one explain how to transfer data to application server.......

    Here is an example.
    report zrich_0001.
    parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.
    data: begin of itab occurs 0,
          field1(20) type c,
          field2(20) type c,
          field3(20) type c,
          end of itab.
    data: str type string.
    constants: con_tab type x value '09'.
    * if you have a newer version, then you can use this instead.
    *constants:
    *    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
    start-of-selection.
    itab-field1 = 'ABC'.
    itab-field2 = 'DEF'.
    itab-field3 = 'GHI'.
    append itab.
    itab-field1 = '123'.
    itab-field2 = '456'.
    itab-field3 = '789'.
    append itab.
      open dataset d1 for output in text mode.
      loop at itab.
        concatenate itab-field1 itab-field2 itab-field2 into str
                      separated by con_tab.
        transfer str to d1.
      endloop.
      close dataset d1.
    Regards,
    Rich Heilman

  • Web DynPro - Save Adobe Form on Application Server

    Hello Seniors,
    We are working on a WebDynPro ABAP Application where in we need to display an Adobe from in a browser and the upload it to the Application Server automatically. We are able to display the form in the browser but are stuck up on how to upload the Adobe Form to the application server. Could you please let me know if there is a way on how to upload the Adobe form to the application server automatically. Your help is highly appreciated..
    Thank you,
    Srini M.

    Hi,
    Duplicate Post,
    Upload Adobe Form to Aplication Server from WebDynPro automatically
    Cheers,
    Kris.

Maybe you are looking for

  • Upgrade HFM 9.2.0.3 to 11.1.1.3

    Hello, I'm new to the subject hfm, like to know what are the benefits of carrying out an upgrade of HFM 9.2.0.3 to 11.1.1.3???, is recommended??? and why not upgrade of 9.2.0.3 to 11.1.2??? is much the change in architecture that makes it very diffic

  • Viewing M2T files with PE7

    Greetings - I am trying for the first time to work with some HD video and am having many problems. The first is this:  I can import the files into Photoshop Elements 7 organizer just fine....but I never get a real image clip generated as a thumbnail.

  • Scan Save to File error

    When scanning to file, I get this error message: an error occurred saving the images to the chosen location.  Please make sure you have write permission in the chosen file location.  Error 8, [ (2 106,0) ].  Have installed the latest drivers; set sha

  • XDK download for 8.1.7

    Technet only has XDK downloads for 9i. Is it still possible to get the PLSQL XDK for 8.1.7? Or is the 9i XDK backwardsly compatible? (Given the massive changes made to XML support in 9i, I'm not hopeful). cheers, APC

  • Blue Lights! Processor load maxed?

    Another newbie question that I can't seem to find already dealt with. If it has been, a friendly pointer to the FAQ or solution is all I need. My single processor G5 Xserve (1gig RAM, 2x80gig HD) is humming along just fine, except that today I notice