Downloading a text file from application server

Hi Freinds,
I am genarating a text file in our application server (Folder /usr/sap/dbi/) I need to download this text file in my destop pc or some other windows server.
What do I have to do? What is the procedure, Pls help.
If someone have sample code, pls send.
We are running SAP ECC5.0 on an iSeries (AS/400) Database DB2/400.
Regards
Thanura

Hi,
try this:
REPORT ZGRO_TEST.
DATA: DATEI_A(30) TYPE C VALUE '/tmp/matnr.txt'.
DATA: DATEI_PC TYPE STRING VALUE 'C:\MATNR.TXT'.
DATA: ITAB        TYPE TABLE OF MARA WITH HEADER LINE.
START-OF-SELECTION.
  PERFORM DATEI_EINLESEN.
  PERFORM DATEI_DOWNLOAD.
FORM DATEI_EINLESEN.
  OPEN DATASET DATEI_A FOR INPUT IN TEXT MODE.
  IF SY-SUBRC NE 0. STOP. ENDIF.
  DO.
    READ DATASET DATEI_A INTO ITAB.
    IF SY-SUBRC <> 0. EXIT. ENDIF.
    APPEND ITAB.
  ENDDO.
  CLOSE DATASET DATEI_A.
  IF SY-SUBRC NE 0. STOP. ENDIF.
ENDFORM.                    "DATEI_EINLESEN
FORM DATEI_DOWNLOAD.
Datei downloaden
  CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
    EXPORTING
      FILENAME                = DATEI_PC
      FILETYPE                = 'ASC'
    CHANGING
      DATA_TAB                = ITAB[]
    EXCEPTIONS
      FILE_WRITE_ERROR        = 1
      NO_BATCH                = 2
      GUI_REFUSE_FILETRANSFER = 3
      INVALID_TYPE            = 4
      NO_AUTHORITY            = 5
      UNKNOWN_ERROR           = 6
      HEADER_NOT_ALLOWED      = 7
      SEPARATOR_NOT_ALLOWED   = 8
      FILESIZE_NOT_ALLOWED    = 9
      HEADER_TOO_LONG         = 10
      DP_ERROR_CREATE         = 11
      DP_ERROR_SEND           = 12
      DP_ERROR_WRITE          = 13
      UNKNOWN_DP_ERROR        = 14
      ACCESS_DENIED           = 15
      DP_OUT_OF_MEMORY        = 16
      DISK_FULL               = 17
      DP_TIMEOUT              = 18
      FILE_NOT_FOUND          = 19
      DATAPROVIDER_EXCEPTION  = 20
      CONTROL_FLUSH_ERROR     = 21
      NOT_SUPPORTED_BY_GUI    = 22
      ERROR_NO_GUI            = 23
      OTHERS                  = 24.
  IF SY-SUBRC NE 0. STOP. ENDIF.
ENDFORM.                    "DATEI_DOWNLOAD
Regards, Dieter

Similar Messages

  • Download text file from application server to client server.

    Hi all,
    I am facing a format issue while downloading text file from application server to the client machine.
    The issue is that, say I have 6 to 10 lines in my text file in application server. but when i store it on the hard drive,
    it shoes all the data in a single line. Where as i need to download data in same format as in application server.
    Awaiting for your responses.
    Regards,
    Jose

    Hi,
    If we want to upload file data from the application server to the internal table, there is no function module or class static method which we can use, we must wirte the code by ourselves.
    1. For the file data which has no seperator between field columns.
    PARAMETERS p_file  TYPE dxfile-filename.
    START-OF-SELECTION.
    OPEN DATASET p_file IN TEXT MODE ENCODING DEFAULT FOR INPUT.
      DO.
        READ DATASET p_file INTO gds_data.
        IF sy-subrc <> 0.
          EXIT.
        ENDIF.
        APPEND gds_data TO gdt_data.
      ENDDO.
    CLOSE DATASET p_file.2. For the file data which has tab separator between field columns.
    DATA: gds_field_split type gts_data.
    FIELD-SYMBOLS: <fs_field> TYPE gts_data.
    PARAMETERS p_file  TYPE dxfile-filename.
    START-OF-SELECTION.
    OPEN DATASET prf_file IN TEXT MODE ENCODING DEFAULT FOR INPUT.
      DO.
        READ DATASET p_file INTO gds_field.
        SPLIT gds_field  AT cl_abap_char_utilities=>horizontal_tab
             INTO TABLE gdt_field_split.
       LOOP AT gdt_field_split  into gds_field_split.
           gdf_index = gdf_index + 1.
           ASSIGN COMPONENT gdf_index OF STRUCTURE
                 gds_data to <fs_field>.
          IF sy-subrc = 0.
              <fs_field> = gds_field_split.
          ENDIF.
       ENDLOOP.
        APPEND gds_data TO gdt_data.
      ENDDO.
    CLOSE DATASET p_file.
    Thanks & regards,
    ShreeMohan

  • Error in Downloading the Text file on Application Server

    Hi All,
              I am working on ECC6.0. I have written a program in whcih I am downloading the text file on
              application server in UTF-8 format. However when I am opening this file in Excel I am getting
              garbage value for some characters(as Excel does not support UTF-8 format). So now I
              want to download the data on application server in text file in non unicode format(Like ANSI or
              other non unicode format) which is supported by excel. When I am writing the code as
              OPEN DATASET DN_FILE FOR OUTPUT IN LEGACY TEXT MODE it is giving me dump saying
              CHARACTER CONVERSION FROM CODE PAGE '4102' to CODEPAGE '1100' NOT POSSIBLE.
              Same in case if I add the code OPEN DATASET DN_FILE FOR OUTPUT IN LEGACY TEXT
              MODE CODE PAGE '8000' is also giving dump.
              So please let me know how can I download the file in non unicode format ?
              Any help would be greatly appricated.
    Thanks & Regards
    Jitendra Gujarathi.

    OPEN DATASET l_filename FOR INPUT IN TEXT MODE  ENCODING NON-UNICODE IGNORING CONVERSION ERRORS.
    CHECK sy-subrc EQ 0.
      DO.
        CLEAR wa_file_content.
        READ DATASET l_filename INTO wa_file_content.
        IF sy-subrc EQ 0.
          APPEND wa_file_content TO it_file_content.
        ELSE.
          EXIT.
        ENDIF.
      ENDDO.
      CLOSE  DATASET l_filename.
      t_filedata[] = it_file_content[].
    can you use like this.

  • Sending EMail "Text-File" from Application Server!

    Hi Experts,
    how can I sending a Text-File from Application Server via Email?
    Is there existing a Function Modul?
    With Kind regards
    Ersin
    Moderator message: sending emails = FAQ, please search before posting.
    Edited by: Thomas Zloch on Nov 25, 2010 4:23 PM

    STF (Search the forum)!  This type of question has been asked...and answered....many times.

  • How to download a text file from the server

    hi everyone,
    can anyone tell me how to download and read a text file from the server and saved in into resource folder.
    with regards
    pallavi

    its really easy
    To read from server, use something like:
    HttpConnection connector = null;
    InputStream inp_stream = null;
    OutputStream out_stream = null;
    void CloseConnection()
         if(inp_stream!=null)inp_stream.close();
         inp_stream=null;
         if(out_stream!=null)out_stream.close();
         out_stream=null;
         connector.close();
         connector = null;
    public void getResponse(String URL,String params)
      try
         if(connector==null)connector = (HttpConnection)Connector.open(URL);//URL of your text file / php script
         connector.setRequestMethod(HttpConnection.POST);
         connector.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.1");
         connector.setRequestProperty("content-type", "application/x-www-form-urlencoded");
         //connector.setRequestProperty("charset","windows-1251");
         //*** If you need to send ("arg1=value&arg2=value") arguments to script use this:
         out_stream = connector.openOutputStream();
         byte postmsg[] = params.getBytes();
         out_stream.write(postmsg);
         int rc = connector.getResponseCode();//in any case here connection will be opened & closed
         if (rc != HttpConnection.HTTP_OK)
              CloseConnection();
              throw new IOException("HTTP response code: " + rc);
         inp_stream = connector.openInputStream();
         int pack_len = inp_stream.available();
         byte answ[]=new byte[pack_len];
         inp_stream.read(answ);
         CloseConnection();
         ProcAnswer(answ);//process received data
      catch(Exception ex)
         System.err.println("ERROR IN getResponse(): "+ex);
    } And you can read from resource file like
    public void loadFile(String filename)
        DataInputStream dis = new DataInputStream(getClass().getResourceAsStream("/"+filename));
        String str="";
        try
             while (true)
                ch = dis.read();//read character
                if(ch=='\r')continue;//if file made in windows
                if(ch=='\n' || ch==-1)//end of line or end of file
                    if(str.length()==0)continue;//if empty line
                    //do some thing with "str"
                    if(ch==-1)break;//it was last line
                    str="";//next line
                    continue;
                 str+=(char)ch;
           dis.close();
       catch (Exception e)
           System.err.println("ERROR in loadFile() " + e);
    }Welcome! =)
    Edited by: MorskoyZmey on Aug 14, 2008 3:40 AM

  • I am facing problem to get text file from application sever

    Hi This is lokesh.
    Actually my requirement is to craete sales orders by getting file from other server.for that i have used shell script to connect that server.Ok i am connecting to that different server(not sap server) successfully.
    But my problem is getting text file from application SERVER.
    That different server people will send the file name as 'DDHHMMSS' (Days,Hours,Minutes,Seconds).
    Just suppose if they will send today means that file name will come as 20103025. and with in half an hour if they again send that file file means that file name as '20110025'.
    like that file name is always varies.So how can i read that type of text files from the application server.
    and one more thing that is there chance to read morethan one text file from application server.
    Pls guide me if u know the solution.PLs this requirement is urgent.
    Regards,
    Lokeshgoud

    Hi..,
    <b>Just execute this program ... this is for the files received in JUST 3 MINS...</b>
    change it according to your requirement !!
    data time type sy-uzeit value '100000'. <i>"<<----start time</i>
    data file(8) type c value '20'.
    do 180 times. <i>" <<----- for 3 minutes</i>
    add sy-index to time.
    concatenate file time into file.
    write / file.
    OPEN DATASET FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
    IF SY-SUBRC EQ 0.
    PERFORM READ_DATASET.
    ENDIF.
    file = '20'.
    time = '100000'.
    ENDDO.
    <b>form read_dataset.
    read the file here with the file name <b>FILE</b>.
    endform.</b>
    regards,
    sai ramesh

  • How to download file from application server

    Hi Experts,
                  I developed report and execute in background mode. for this i used Open dataset transfer and close dataset . i got the requried output . But in this case user want downloaded file on presentation server so can anyone tell me How to download file from application server?
    i know it is possible through Tcode CG3Y. but i want code in program.

    This code will download a file to your Client package by package, so it will also work for huge files.
    *& Report  ZBI_DOWNLOAD_APPSERVER_FILE
    REPORT  zbi_download_appserver_file.
    PARAMETERS: lv_as_fn TYPE sapb-sappfad
    DEFAULT '/usr/sap/WBP/DVEBMGS00/work/ZBSPL_R01.CSV'.
    PARAMETERS: lv_cl_fn TYPE string
    DEFAULT 'C:\Users\atsvioli\Desktop\Budget Backups\ZBSPL_R01.CSV'.
    START-OF-SELECTION.
      CONSTANTS blocksize TYPE i VALUE 524287.
      CONSTANTS packagesize TYPE i VALUE 8.
      TYPES ty_datablock(blocksize) TYPE x.
      DATA lv_fil TYPE epsf-epsfilnam.
      DATA lv_dir TYPE epsf-epsdirnam.
      DATA ls_data TYPE ty_datablock.
      DATA lt_data TYPE STANDARD TABLE OF ty_datablock.
      DATA lv_block_len TYPE i.
      DATA lv_package_len TYPE i.
      DATA lv_subrc TYPE sy-subrc.
      DATA lv_msgv1 LIKE sy-msgv1.
      DATA lv_processed_so_far TYPE p.
      DATA lv_append TYPE c.
      DATA lv_status TYPE string.
      DATA lv_filesize TYPE p.
      DATA lv_percent TYPE i.
      "Determine size
      SPLIT lv_as_fn AT '/' INTO lv_dir lv_fil.
      CALL FUNCTION 'EPS_GET_FILE_ATTRIBUTES'
        EXPORTING
          file_name      = lv_fil
          dir_name       = lv_dir
        IMPORTING
          file_size_long = lv_filesize.
      "Open the file on application server
      OPEN DATASET lv_as_fn FOR INPUT IN BINARY MODE MESSAGE lv_msgv1.
      IF sy-subrc <> 0.
        MESSAGE e048(cms) WITH lv_as_fn lv_msgv1 RAISING file_read_error.
        EXIT.
      ENDIF.
      lv_processed_so_far = 0.
      DO.
        REFRESH lt_data.
        lv_package_len = 0.
        DO packagesize TIMES.
          CLEAR ls_data.
          CLEAR lv_block_len.
          READ DATASET lv_as_fn INTO ls_data MAXIMUM LENGTH blocksize LENGTH lv_block_len.
          lv_subrc = sy-subrc.
          IF lv_block_len > 0.
            lv_package_len = lv_package_len + lv_block_len.
            APPEND ls_data TO lt_data.
          ENDIF.
          "End of file
          IF lv_subrc <> 0.
            EXIT.
          ENDIF.
        ENDDO.
        IF lv_package_len > 0.
          "Put file to client
          IF lv_processed_so_far = 0.
            lv_append = ' '.
          ELSE.
            lv_append = 'X'.
          ENDIF.
          CALL FUNCTION 'GUI_DOWNLOAD'
            EXPORTING
              bin_filesize         = lv_package_len
              filename             = lv_cl_fn
              filetype             = 'BIN'
              append               = lv_append
              show_transfer_status = abap_false
            TABLES
              data_tab             = lt_data.
          lv_processed_so_far = lv_processed_so_far + lv_package_len.
          "Status display
          lv_percent = lv_processed_so_far * 100 / lv_filesize.
          lv_status = |{ lv_percent }% - { lv_processed_so_far } bytes downloaded of { lv_filesize }|.
          CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
            EXPORTING          "percentage = lv_percent - will make it fash
              text = lv_status.
        ENDIF.
        "End of file
        IF lv_subrc <> 0.
          EXIT.
        ENDIF.
      ENDDO.
      "Close the file on application server
      CLOSE DATASET lv_as_fn.

  • Error in PDF Conversion while downloading file from application server

    Hi,
    I am facing a problem in which i have to download file from application server which is a PDF file (output of SAP Script). I am downloading this file using following code in BSP technology:
    * event handler for data retrieval
    EMPCD = REQUEST->GET_FORM_FIELD( 'emp' ).
    MONTH = REQUEST->GET_FORM_FIELD( 'mn' ).
    YEAR  = REQUEST->GET_FORM_FIELD( 'yr' ).
    W_IND = 'N' .
    DATA : wa_zform16 type  zform16.
    DATA : file_path type string.
    DATA : l_pdf_len type string.
    DATA STR TYPE STRING.
    DATA: OUTPUT    TYPE STRING ,
          L_XSTRING TYPE XSTRING ,
          APP_TYPE  TYPE STRING.
    DATA: PDF_TABLE TYPE  RCL_BAG_TLINE.
    DATA PHY_NAME_OUT     TYPE SAPB-SAPPFAD.
    concatenate '/usr/sap/put/form16/' EMPCD '_' YEAR '.PDF'  into file_path
    *PHY_NAME_OUT = '/usr/sap/put/form16/01000200_2007.PDF'.
    PHY_NAME_OUT = file_path.
    OPEN DATASET PHY_NAME_OUT FOR INPUT IN TEXT MODE ENCODING default.
    IF SY-SUBRC IS INITIAL.
      DO.
        READ DATASET PHY_NAME_OUT INTO STR.
        IF SY-SUBRC IS INITIAL.
          CONCATENATE
              OUTPUT
              STR
              CL_ABAP_CHAR_UTILITIES=>CR_LF
          INTO OUTPUT.
        ELSE.
          EXIT.
        ENDIF.
      ENDDO.
      APP_TYPE = 'APPLICATION/PDF'.
      CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
        EXPORTING
          TEXT     = OUTPUT
                MIMETYPE = 'APPLICATION/PDF'
    *            MIMETYPE = 'APPLICATION/PDF;charset=utf-16le'
        IMPORTING
          BUFFER   = L_XSTRING.
      CALL METHOD CL_BSP_UTILITY=>DOWNLOAD
        EXPORTING
          OBJECT_S            = L_XSTRING
          CONTENT_TYPE        = APP_TYPE
          CONTENT_DISPOSITION = 'attachment;filename=webforms.pdf'
          RESPONSE            = _M_RESPONSE
          NAVIGATION          = NAVIGATION.
    Result of this code is : there is a pop up asking to open or save pdf format and process is complete, but i have problem in downloaded file.
    At the time of creation i have put BMP image for signature in PDF file and it is working fine but when i upload that file in Application server and then download it with above used code it save the PDF file but when i open that file so whereever i have used signature that page gives error and could not display that scanned signature.
    Can anyone please help me in this regard.
    or is there any possibility from which i can download that file just like File transfer from BSP.
    Keep in mind that i am using BSP technology so all GUI based function module to download file are not working.
    waiting for your reply.....
    Regards,
    Gagan

    Hi Raja,
    I have standard sap form for TDS Certificate on which i have include an BMP image for digital signature and download that script into pdf format.While i download that PDF looks ok but it is not working in BSP.
    Regards,
    Gagan

  • How to display a file from Application server without downloading it to local drive

    I want to dispaly a file from Application server without downloading it to my local system.
    i tried the below method but it didn't work.
         CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE
          EXPORTING
            APPLICATION            = L_FILE
            DEFAULT_DIRECTORY      = L_DIR

    Hi,
    Use open dataset to read file from application server.
    try like this sample code:
    data : p_file like ibipparms-path.
    data : rec(350) type c.
    data:  g_delimiter(1) type c value ','.
    maintain the file path in p_file. then
    open dataset p_file for input in text mode encoding default.
       IF SY-SUBRC = 0.
    do n times.
    READ dataset p_file into rec.
    split rec at g_delimiter into your internal table fields like it-id it-name it-age.
    append it.
    clear it.
    enddo.
    close dataset p_file.
    Now you have the data in internal table it.

  • Download PDF file from Application Server in BSP

    Hello,
    We have a requirement on which we want to download a PDF file stored in Application server using BSP application. I have used function module  ARCHIVFILE_SERVER_TO_CLIENT but this FM will help only if i want to download file from GUI it won't work in BSP application.
    Further i have used class CL_BSP_UTILITY and download method to download file from application server but it is not working in desired manner.
    I am attaching my code for your reference:
    DATA: BUTTON_EVENT TYPE REF TO CL_HTMLB_EVENT_BUTTON ,
               EVENT TYPE REF TO IF_HTMLB_DATA.
    DATA: LS_HOURS LIKE LINE OF GT_HOURS.
    DATA STR TYPE STRING.
    DATA: OUTPUT TYPE STRING ,
              L_XSTRING TYPE XSTRING ,
               APP_TYPE TYPE STRING. 
    EVENT = CL_HTMLB_MANAGER=>GET_EVENT( REQUEST ).
    DATA PHY_NAME_OUT     TYPE SAPB-SAPPFAD.
    IF EVENT IS NOT INITIAL AND EVENT->EVENT_NAME = HTMLB_EVENTS=>BUTTON .
      BUTTON_EVENT ?= EVENT .
      CASE EVENT->EVENT_SERVER_NAME.
        WHEN 'test' .
          IF GT_HOURS IS NOT INITIAL.
            PHY_NAME_OUT = '/usr/sap/put/form16//01000200_2007.PDF'.
          OPEN DATASET PHY_NAME_OUT FOR INPUT IN TEXT MODE ENCODING DEFAULT.
            IF SY-SUBRC IS INITIAL.
              DO.
                READ DATASET PHY_NAME_OUT INTO STR.
                IF SY-SUBRC IS INITIAL.
                CONCATENATE
                    OUTPUT
                    str
                    cl_abap_char_utilities=>cr_lf
    INTO output SEPARATED BY space. "cl_abap_char_utilities=>horizontal_tab
                ELSE.
                  EXIT.
                ENDIF.
              ENDDO.
            ENDIF.
    *LOOP AT gt_hours INTO ls_hours.
    *CONCATENATE
    *OUTPUT
    *ls_hours-hour
    *cl_abap_char_utilities=>cr_lf
    *INTO output SEPARATED BY space. "cl_abap_char_utilities=>horizontal_tab
    *ENDLOOP.
            APP_TYPE = 'APPLICATION/PDF;charset=utf-16le'.
            CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
              EXPORTING
                TEXT     = OUTPUT
                MIMETYPE = 'APPLICATION/PDF;charset=utf-16le'
              IMPORTING
                BUFFER   = L_XSTRING.
            CONCATENATE CL_ABAP_CHAR_UTILITIES=>BYTE_ORDER_MARK_LITTLE
            L_XSTRING
            INTO L_XSTRING IN BYTE MODE.
            CALL METHOD CL_BSP_UTILITY=>DOWNLOAD
            EXPORTING
            OBJECT_S = L_XSTRING
            CONTENT_TYPE = APP_TYPE
            CONTENT_DISPOSITION = 'attachment;filename=webforms.pdf'
            RESPONSE = _M_RESPONSE
            NAVIGATION = NAVIGATION.
          ENDIF.
      ENDCASE.
    ENDIF.
    From this code i am able to download PDF file but it is not opening in local machine.
    If any other way to download file then please suggest.
    waiting for ur reply.
    Regards,
    Gagan

    Hi,
    you do the file reading wrong:
    have a look at:
    Local declarations.
      data:
        components          type stringtab,
        component           type string,
        path                type text255,
        file                type text255,
        line_length         type i,
       filecontent_binary type sdokcntbin,
        rows                type sytabix,
        content             type sdokcntbin,
        exception           type ref to cx_sy_file_access_error,
        exception_tmf       type ref to cx_sy_too_many_files ,
        block_size          type i value 1022,
        length              type i.
      field-symbols:
        <hex_container>     type x.
      constants:
        c_dms_blk_size      type i value 2550.
      clear file_size.
      try.
          open dataset file_name  for input in binary mode message message.
        catch cx_sy_file_open  into exception.
          case exception->textid.
            when '4182174D03030063000000000A1551B1'. raise access_error.
            when '41825AD355C3005E000000000A1551B1'. raise open_error.
            when '47E8B03AECE5BA07E10000000A114829'. raise already_open.
            when others.
          endcase.
        catch cx_sy_file_authority into exception.
          case exception->textid.
            when '4182174D03030063000000000A1551B1'. raise access_error.
            when 'A70BB8396F051547E10000000A11447B'. raise authority_error.
            when others.
          endcase.
        catch cx_sy_too_many_files into exception_tmf.
          case exception_tmf->textid.
            when '8708B73915F6B645E10000000A11447B'. raise too_many_files.
            when others.
          endcase.
      endtry.
      do.
        try.
            read dataset file_name into filecontent_binary-line.
            if sy-subrc <> 0.
              add  line_length to file_size.
              append filecontent_binary to file_content_binary.
              exit.
            else.
              add  line_length to file_size.
              append filecontent_binary to file_content_binary.
            endif.
          catch cx_sy_file_open_mode into exception.
            case exception->textid.
              when '9207B73915F6B645E10000000A11447B'. raise cx_sy_file_open_mode.
              when '9807B73915F6B645E10000000A11447B'. raise read_only.
              when '9E07B73915F6B645E10000000A11447B'. raise not_open.
              when '409D273A2D824360E10000000A11447B'. raise incompatible_mode.
              when others.
            endcase.
        endtry.
      enddo.
      try.
          close dataset file_name.
        catch cx_sy_file_close into exception.
          case exception->textid.
            when '4182174D03030063000000000A1551B1'. raise access_error.
            when 'C10BB8396F051547E10000000A11447B'. raise close_error.
            when others.
          endcase.
        catch cx_sy_file_access_error into exception.
          case exception->textid.
            when '4182174D03030063000000000A1551B1'. raise access_error.
            when others.
          endcase.
      endtry.
    Get file size.
      split file_name at '/' into table components.
      describe table components lines sy-tfill.
      read table components into component index sy-tfill.
      path = file_name.
      replace component in path with ''.
      file = component.
      call function '/EUH/MMS_GET_FILE_SIZE'
        exporting
          dir_name  = path
          file_name = file
        importing
          file_size = file_size.
    and function /euh/mms_get_file_size.
    ""Local Interface:
    *"  IMPORTING
    *"     VALUE(DIR_NAME) TYPE  TEXT255
    *"     VALUE(FILE_NAME) TYPE  TEXT255
    *"  EXPORTING
    *"     VALUE(FILE_SIZE) TYPE  SDOK_FSIZE
    *"  EXCEPTIONS
    *"      NO_AUTHORITY
    *"      ACTIVITY_UNKNOWN
    *"      NOT_A_DIRECTORY
    *"      NO_MEDIA_IN_DRIVE
    *"      TOO_MANY_ERRORS
    *"      TOO_MANY_FILES
    *"      BRACKET_ERROR_IN_FILENAME
    *"      NO_SUCH_PARAMETER
      types: begin of files,
               line like ocs_file,
             end of files.
      data: file type files,
         f_subrc like sy-subrc value 0,
         errno(3)    type c,
         errmsg(40)  type c,
         pos                        type i,
         len                        type i,
         parameter(120)             type c,
         help1(120)                 type c,
         help2(120)                 type c,
         error_counter              type i.
      data:
        dir_list  like  ocs_file occurs 0 with header line.
    CASE sy-subrc.
       WHEN 1. f_subrc = 64.
       WHEN 2. f_subrc = 65.
       WHEN 0.
      search dir_name for 'SY-HOST'.    "Is SY-HOST used in directory name?
      if sy-subrc = 0.
        pos = sy-fdpos + 7.
        move dir_name(sy-fdpos) to help1.
        move dir_name+pos to help2.
        concatenate help1 sy-host help2 into dir_name.
      endif.
      do 12 times.                                 " To avoid endless loop
        if dir_name cs '$('.           " Replace parameter by their value
          pos = sy-fdpos + 2.
          if dir_name cs ')'.
            len = sy-fdpos - pos.
            if len le 0.
              f_subrc = 4. exit.
            else.
              parameter = dir_name+pos(len).
              call 'C_SAPGPARAM' id 'NAME'  field parameter
                               id 'VALUE' field parameter.
              if sy-subrc = 0.
                len = pos + len + 1.
                pos = pos - 2.
                if pos > 0.
                  move dir_name(pos) to help1.
                else.
                  help1 = ''.
                endif.
                pos = strlen( dir_name ).
                if pos > len.
                  move dir_name+len to help2.
                else.
                  help2 = ''.
                endif.
                concatenate help1 parameter help2 into dir_name.
              else.
                f_subrc = 8. exit.
              endif.
            endif.
          else.
            exit.
          endif.
        else.
          exit.
        endif.
      enddo.
      shift dir_name right deleting trailing '/\ '.
      shift dir_name left deleting leading space.
      call 'C_DIR_READ_FINISH'                      " this is from RSWATCH0
            id 'ERRNO'  field errno
            id 'ERRMSG' field errmsg.
      call 'C_DIR_READ_START'
            id 'DIR'    field dir_name
            id 'FILE'   field file_name
            id 'ERRNO'  field errno
            id 'ERRMSG' field errmsg.
      case sy-subrc.
        when 1.
          case errno.
            when 2 or 20.  f_subrc = f_subrc + 66.
            when ' '. f_subrc = f_subrc + 67.
          endcase.
        when 0.
          clear error_counter.
          do.
            clear file.
            clear dir_list.
            call 'C_DIR_READ_NEXT'
                id 'TYPE'   field file-line-type
                id 'NAME'   field file-line-name
                id 'LEN'    field file-line-len
                id 'OWNER'  field file-line-owner
                id 'MTIME'  field file-line-mtime
                id 'MODE'   field file-line-acc_mode
                id 'ERRNO'  field errno
                id 'ERRMSG' field errmsg.   "sy-subrc = 3 is e.g. if return
            if sy-subrc = 0 or sy-subrc = 3."data do not fit into variables
              perform p6_to_date_time_tz(rstr0400) using
                    file-line-mtime
                    file-line-mod_time
                    file-line-mod_date.
              file_size = file-line-len.
              dir_list = file-line.
              append dir_list.
            elseif sy-subrc = 1.                 " nothing (more) found
              exit.
            else.
              if error_counter > 50.
                call 'C_DIR_READ_FINISH'
                    id 'ERRNO'  field errno
                    id 'ERRMSG' field errmsg.
                pos =  f_subrc mod 2.
                if pos = 0. f_subrc = f_subrc + 1. endif.
                exit.
              endif.
              add 1 to error_counter.
            endif.
            if sy-index > 1000.
              pos =  f_subrc mod 4.
              if pos = 0. f_subrc = f_subrc + 2. endif.
              exit.
            endif.
          enddo.
          call 'C_DIR_READ_FINISH'
               id 'ERRNO'  field errno
               id 'ERRMSG' field errmsg.
          if sy-opsys(3) = 'Win' and not ( file_name cs '*' ).
            describe table dir_list lines len.
            if len = 0.
              help1 = file_name.
              translate help1 to upper case.
              translate help1 using
                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
              call 'C_DIR_READ_START'
                    id 'DIR'    field dir_name
                    id 'FILE'   field help1.
              if sy-subrc = 0.
                clear error_counter.
                do.
                  clear file.
                  clear dir_list.
                  call 'C_DIR_READ_NEXT'
                      id 'TYPE'   field file-line-type
                      id 'NAME'   field file-line-name
                      id 'LEN'    field file-line-len
                      id 'OWNER'  field file-line-owner
                      id 'MTIME'  field file-line-mtime
                      id 'MODE'   field file-line-acc_mode
                      id 'ERRNO'  field errno
                      id 'ERRMSG' field errmsg.
                  if sy-subrc = 0 or sy-subrc = 3.
                    help2 = file_name.
                    translate help2 to upper case.
                    help1 = file-line-name.
                    translate help1 to upper case.
                    if help1 = help2.
                      perform p6_to_date_time_tz(rstr0400) using
                         file-line-mtime
                         file-line-mod_time
                         file-line-mod_date.
                      dir_list = file-line.
                      append dir_list.
                    endif.
                  elseif sy-subrc = 1.
                    exit.
                  else.
                    if error_counter > 50.
                      call 'C_DIR_READ_FINISH'
                          id 'ERRNO'  field errno
                          id 'ERRMSG' field errmsg.
                      pos =  f_subrc mod 2.
                      if pos = 0. f_subrc = f_subrc + 1. endif.
                      exit.
                    endif.
                    add 1 to error_counter.
                  endif.
                  if sy-index > 1000.
                    pos =  f_subrc mod 4.
                    if pos = 0. f_subrc = f_subrc + 2. endif.
                    exit.
                  endif.
                enddo.
                call 'C_DIR_READ_FINISH'
                     id 'ERRNO'  field errno
                     id 'ERRMSG' field errmsg.
              endif.
            endif.
          endif.
      endcase.
    ENDCASE.
    CASE f_subrc.
       WHEN 1 OR 3.             RAISE too_many_errors.
       WHEN 2.                  RAISE too_many_files.
       WHEN 4 OR 5 OR 6 OR 7 OR 70 OR 71.
         RAISE bracket_error_in_filename.
       WHEN 8 OR 9 OR 10 OR 11 OR 74 OR 75.
         RAISE no_such_parameter.
       WHEN 64.                 RAISE no_authority.
       WHEN 65.                 RAISE activity_unknown.
       WHEN 66.                 RAISE not_a_directory.
       WHEN 67.                 RAISE no_media_in_drive.
    ENDCASE.
    endfunction.
    Now you will be able to get the filesize and the file in SDOK format sdokbin.
    Okay.
    You have to build an request and push the content to the user like:
      call method server->response->set_header_field( name = 'Content-Type' value = value ).
      describe field file_content_binary-line length line_length in byte mode.
      bytes_rest = file-size.
      loop at file_content_binaries assigning <file_content_binary>.
        move <file_content_binary>-line to data.
        if bytes_rest <= 0. "mismatch between line values and size
          exit.
        endif.
        if bytes_rest >= line_length.
          call method server->response->append_data( data = data
            length = line_length ).
        else.
          call method server->response->append_data( data = data
            length = bytes_rest ).
        endif.
        bytes_rest = bytes_rest - line_length.
      endloop.
    This will work.
    You can set the header fields like you want. Have also a look at sicf node contentserver
    and its handler: CL_HTTP_EXT_CSIF

  • Downloading file from application server to presentation server

    Hi,
          We have a requirment to download file from application server to presentation server.  The problem is while down loading, some of the filds showing some junk values. Instead of that junk values we have some Russian texts there.  These Russian texts only coming as junk all other data is correct.  The file in the appplication server is in .dbf format. We are downloading using WS_DOWNLOAD. file type is BIN and code page we didn't specified.
    Thanks in Advance
    Jijeesh.P.G
    Message was edited by: Jijeesh.P.G
            Jijeesh P G

    hi jijeesh,
       Welcome to SDN.
    u can use to download file from application server to presentation server using the t/c CG3Y. in that it will ask the source file path and the target file path.
    if u want to find the source file path in the application server, u can use the transaction AL11 to find that one.
    Regards....
    Arun.
    Reward points if useful.

  • Urgent : Download file from Application Server via Process Chain.

    Hi Experts,
    My requirement is to download the file from Application Server to local work station using an ABAP Program .
    I want including the above ABAP program in a process chain to execute  the program daily,
    I tried to use ARCHIVFILE_SERVER_TO_CLIENT and GUI_DOWNLOAD but unfortunately both the above FM doesn't support to run through Process chain.
    Can any one of you help me to send the code which selects a file from application server, downloads to local system and deletes it.
    Thank you very much for spending your precious time in this regard.

    Hi Sailekha,
    Regarding your case ..
    I suggest you to create the program where it run this function: WS_DOWNLOAD.
    After it, the program is run by your process chain.
    Hopefully it can help you a lot.
    Regards,
    Niel.
    thanks for the points you choose to assign.

  • How to download a file from application server to presentation server

    Hi experts,
    I want to download a file from application server to presentaion server, file contaims three fields customer name, customer email id and status..
    help me out i m new into sap.

    Dear Aditya,
    Please check below thread
    http://scn.sap.com/thread/1010164
    it will help you.
    BR
    Atul

  • How to download a pdf file from the server from an strut application?

    Hi,
    I wan to download a pdf file from the server side to local system. Please help me how i use the down load option.

    Read up on the Struts download action [1].
    And next time, please post in the relevant forum, one of the web-tier ones [2].
    [1] http://wiki.apache.org/struts/StrutsFileDownload
    [2] http://forum.java.sun.com/category.jspa?categoryID=20
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    ----------------------------------------------------------------

  • Read Tab delimited File from Application server

    Hi Experts,
    I am facing problem while reading file from Application server.
    File in Application server is stored as follows, The below file is a tab delimited file.
    ##K#U#N#N#R###T#I#T#L#E###N#A#M#E#1###N#A#M#E#2###N#A#M#E#3###N#A#M#E#4###S#O#R#T#1###S#O#R#T#2###N#A#M#E#_#C#O###S#T#R#_#S#U#P#P#L#1###S#T#R#_#S#U#P#P#L#2###S#T#R#E#E#T###H#O#U#S#E#_#N#U#M#1
    i have downloaded this file from Application server using Transaction CG3Y. the Downloaded file is a tab delimited file and i could not see "#' in the file,
    The code is as Below.
    c_split  TYPE abap_char1 VALUE cl_abap_char_utilities=>horizontal_tab.
    here i am using IGNORING CONVERSION ERRORS in order to avoid Conversion Error Short Dump.
    OPEN DATASET wa_filename-file FOR INPUT IN TEXT MODE ENCODING DEFAULT IGNORING CONVERSION ERRORS.
          IF sy-subrc = 0.
            WRITE : /,'...Processing file - ', wa_filename-file.   
           DO.
          Read the contents of file
              READ DATASET wa_filename-file INTO wa_file-data.
              IF sy-subrc = 0.
                SPLIT wa_file-data AT c_split INTO wa_adrc_2-kunnr
                                                   wa_adrc_2-title
                                                   wa_adrc_2-name1
                                                   wa_adrc_2-name2
                                                   wa_adrc_2-name3
                                                   wa_adrc_2-name4
                                                   wa_adrc_2-name_co
                                                   wa_adrc_2-city1
                                                   wa_adrc_2-city2
                                                   wa_adrc_2-regiogroup
                                                   wa_adrc_2-post_code1
                                                   wa_adrc_2-post_code2
                                                   wa_adrc_2-po_box
                                                   wa_adrc_2-po_box_loc
                                                   wa_adrc_2-transpzone
                                                   wa_adrc_2-street
                                                   wa_adrc_2-house_num1
                                                   wa_adrc_2-house_num2
                                                   wa_adrc_2-str_suppl1
                                                   wa_adrc_2-str_suppl2
                                                   wa_adrc_2-country
                                                   wa_adrc_2-langu
                                                   wa_adrc_2-region
                                                   wa_adrc_2-sort1
                                                   wa_adrc_2-sort2
                                                   wa_adrc_2-deflt_comm
                                                   wa_adrc_2-tel_number
                                                   wa_adrc_2-tel_extens
                                                   wa_adrc_2-fax_number
                                                   wa_adrc_2-fax_extens
                                                   wa_adrc_2-taxjurcode.
    WA_FILE-DATA is having below values
    ##K#U#N#N#R###T#I#T#L#E###N#A#M#E#1###N#A#M#E#2###N#A#M#E#3###N#A#M#E#4###S#O#R#T#1###S#O#R#T#2###N#A#M#E#_#C#O###S#T#R#_#S#U#P#P#L#1###S#T#R#_#S#U#P#P#L#2###S#T#R#E#E#T###H#O#U#S#E#_#N#U#M#1
    And this is split by tab delimited and moved to other variables as shown above.
    Please guide me how to read the contents without "#' from the file.
    I have tried all possible ways and unable to get solution.
    Thanks,
    Shrikanth

    Hi ,
    In ECC 6 if all the unicode patches are applied then UTF 16 will defintly work..
    More over i would suggest you to ist replace # with some other  * or , and then try to see in debugging if any further  # appears..
    and no # appears then try to split now.
    if even now the # appears after replace statement then try to find out what exactly is it... wheather it is a horizantal tab etc....
    and then again try to replace it and then split..
    Please follow the process untill all the # are replaced...
    This should work for you..
    Let me know if you further face any issue...
    Regards
    Satish Boguda

Maybe you are looking for