cancel
Showing results for 
Search instead for 
Did you mean: 

Web dynpro for ABAP - Download a file

Former Member
0 Kudos

Hi guys,

How to download desktop file data into application server in the Web dynpro application?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Little Unclear ? you want to upload data to Netweaver server using WD4A ??

Or

You want to download data from server to your desktop.

if its download then check this thread:

[]

Greetings

Prashant

Former Member
0 Kudos

Hi,

I want to upload desktop file data into internal table of web dynpro application...

The link which you have given is to download from internal table to desktop.

Thanks in advance.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

For uploading of files you should use the fileUpload UI element.

http://help.sap.com/saphelp_nw70ehp1/helpdata/en/b3/be7941601b1d09e10000000a155106/frameset.htm

It will place the content of the file into a XSTRING context attribute. It is then up to you how you want to process the file. The process for turning it into an internal table will depend upon what type of file from the PC it is.

Former Member
0 Kudos

Hi RajKumar,

I am uploading excel file in my case, & ensure that columns in my excel are exactly present in the internal table structure that i use.

Declare context node FILE

with Attributes:

Filename type String

MimeType type String

FILE type xstring.

Place 'Fileupload UI element' on you view , bind DATA property to Attribute u2018FILEu2019 created in the context node.

Create a Button lets call UPLOAD. on its click action put the following code.

method upload_file .
  data: s_cont type string,
        x_cont type xstring,
        convt type ref to cl_abap_conv_in_ce,
        item_file type xstringval.
  data: input_string type string,
        fields  type string_table,
        fields2  type string_table,
        tbl_fields  type string_table,
        s_table type string_table,
        ls_table like line of s_table,
        ls like line of fields,
        lv_num_cols type i.

  data: lt_data type table of ZMYREC, "here
        ls_data like line of lt_data,
        lv_data type string.

  field-symbols: <wa_table> like line of s_table.
  wd_this->m_elem_file->get_attribute(
    exporting
      name =  `FILE`
    importing
      value = item_file ).
  convt = cl_abap_conv_in_ce=>create( input = item_file ).
  convt->read( importing data = s_cont ).

  "Column headers
  split s_cont at cl_abap_char_utilities=>cr_lf into table s_table.
  read table s_table into ls_table index 1.

  "Delete column header
  delete s_table index 1.
  split ls_table at cl_abap_char_utilities=>horizontal_tab into table fields.

  lv_num_cols = lines( fields ).
  refresh fields.


  loop at s_table assigning <wa_table>.
    split <wa_table> at cl_abap_char_utilities=>horizontal_tab into :
     ls_data-recordid
     ls_data-bstkd                                                                    
     ls_data-kunnr                                                                    
     ls_data-matnr                                                                    
     ls_data-candno                                                                   
     ls_data-fname                                                                    
     ls_data-inits                                                                    
     ls_data-lname                                                                    
     ls_data-gesch.                                                                    
     append ls_data to lt_data.
     clear ls_data.

  endloop.


wd_this->m_node_data->bind_table(
   exporting
      new_items            = lt_data
      set_initial_elements = abap_true ).


endmethod.

Greetings

Prashant

P.S. Poinst welcome

Former Member
0 Kudos

Hi Prasant and Thomas,thanks a lot for ur valuable input.Actually I am new for webdynpro ABAP and I tried Prasant code and getting Dump (character set conversion not possible). I am getting the dump in this location.

convt = cl_abap_conv_in_ce=>create( input = lv_file ).

convt->read( importing data = s_cont ).

i am giving my code here..


data:  s_cont type string,
        x_cont type xstring,
        convt type ref to cl_abap_conv_in_ce.

data:   input_string type string,
        fields  type string_table,
        fields2  type string_table,
        tbl_fields  type string_table,
        s_table type string_table,
        ls_table like line of s_table,
        ls like line of fields,
        lv_num_cols type i.

 TYPES:BEGIN OF x_final1,
      pspnr     TYPE prps-posid,
      matnr     TYPE mara-matnr,
      desc      TYPE prps-objnr,
      vbeln     TYPE vbap-vbeln,
      ebeln     TYPE ekpo-ebeln,
      END OF x_final1.

DATA:lt_data TYPE STANDARD TABLE OF x_final1,
     ls_data TYPE x_final1,
     lv_data TYPE string.

   field-symbols: <wa_table> like line of s_table.

   DATA lo_nd_file TYPE REF TO if_wd_context_node.
   DATA lo_el_file TYPE REF TO if_wd_context_element.
   DATA ls_file TYPE wd_this->element_file.
   DATA lv_file type xstring.

*  navigate from <CONTEXT> to <FILE> via lead selection

   lo_nd_file = wd_context->get_child_node( name = wd_this->wdctx_file ).

*  get element via lead selection
   lo_el_file = lo_nd_file->get_element(  ).

*  get single attribute
   lo_el_file->get_attribute(
     EXPORTING
       name =  `FILE`
     IMPORTING
       value = lv_file ).


 convt = cl_abap_conv_in_ce=>create( input = lv_file ).
  convt->read( importing data = s_cont ).

  "Column headers
  split s_cont at cl_abap_char_utilities=>cr_lf into table s_table.
  read table s_table into ls_table index 1.

  "Delete column header
  delete s_table index 1.
  split ls_table at cl_abap_char_utilities=>horizontal_tab into table fields.

  lv_num_cols = lines( fields ).
  refresh fields.


  loop at s_table assigning <wa_table>.
    split <wa_table> at cl_abap_char_utilities=>horizontal_tab into :
      ls_data-pspnr
      ls_data-matnr
      ls_data-desc
      ls_data-vbeln
      ls_data-ebeln  .
     append ls_data to lt_data.
     clear ls_data.

  endloop.

lv_file is containing data in bytes.and i am not able to get the original data in the s_table

Please help me.Thanks in advance.

Former Member
0 Kudos

Hi Rajkumar,

In my case i am using a TabDelimeted file as input. I have an Excel with columns and data. Now from file->save as option i save this file as TEXT (Tab Delimeted) option. then this file is ready for upload.

If you are uploading excel , saving it as tab-delimeted should solve your problem.

Greetings

Prashant

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

What kind of file are you uploading? I suspect by the error that it is a binary formatted file - which is casing the dump when converting to text.

Former Member
0 Kudos

Hi prasant and thomas thank u so much, the problem was i didnt save the file as ttab delimited.

now it is working fine..Now my requirement is to uploaad the data to application server,will DATA SET works.

one more thing..suppose if i user files other than excel,what method i have to use.,

Please Help me ,thanks in advance..

Former Member
0 Kudos

Hi Prasant and Thomas.

Data SET is working ,is it possible to do FTP the file to application server.

Thanks in Advance,..

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

If you are just wanting to store it in the application server, then most of the logic above is not necessary nor would it work for files other than text tab delimited. Just keep the xstring content and write it directly into the filesystem using the DATASET commands.

Why would you want to use FTP if you are writting to the filesystem of the ABAP application server? DATASET commands would be far more efficient. You would only need to use FTP if you want to write to a remote file system that can't be mounted to the ABAP application server. In this case you can use FTP. Look at the function group SFTP for the function modules that you must call. Also look at the programs in the SFTP package.

Former Member
0 Kudos

Hi guys,

I got the answer. Thanks a lot.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

why don't you use the [FileUpload|http://help.sap.com/saphelp_erp2005/helpdata/DE/b3/be7941601b1d09e10000000a155106/frameset.htm] Component?

Regards

Daniel