Application Development and Automation 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: 
Read only

function module for downloading

Former Member
0 Likes
1,657

hi friends,

i want function module to download the sap data in to flat file in particular format...

for example

1#harish#bombay

regard's

mahesh

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,161

Hi Uma,

If you want to download the data to flat file on presentation server use the function mdoule GUI_DOWNLOAD

Now the # you need is actually the horizontal tab separator in SAP represented by CL_ABAP_CHAR_UTILITIES=>HORIZONRAL_TAB.

So say you have an internal table <itab> with work area <wa> with 2 columns <field1> and <field2>.

You can create a single internal table with one field of type string and


loop at <itab> into <wa>.
concatenate <wa>-<field1> <wa>-<field2> into <wa_string> separated by cl_abap_char_utilities=>horizontal_tab.
append <wa_string> to <itab_string>.
endloop.

Then download the internal table <itab_string> using GUI_DOWNLOAD.

Cheers.

4 REPLIES 4
Read only

Former Member
0 Likes
1,161

hi,

try this program and <REMOVED BY MODERATOR>


tables:mara.

data:begin of i_header occurs 0,
     field(30) type c,
     end of i_header,

    begin of itab occurs 0,
     matnr type mara-matnr,
     ersda type mara-ersda,
     ernam type mara-ernam,
     laeda type mara-laeda,
     end of itab.
select matnr ersda ernam laeda from mara into corresponding fields of table itab.
REFRESH i_header.
  i_header-field = 'Material number'.
  append i_header.
  i_header-field = 'creation Date'.
  append i_header.
  i_header-field = 'name of person'.
  append i_header.
  i_header-field = 'last date'.
  append i_header.

  clear i_header.


CALL FUNCTION 'WS_DOWNLOAD'
 EXPORTING
*   BIN_FILESIZE                  = ' '
*   CODEPAGE                      = ' '
    FILENAME                     = 'D:\prsr\3.xls'
   FILETYPE                      = 'DAT'
*   MODE                          = ' '
*   WK1_N_FORMAT                  = ' '
*   WK1_N_SIZE                    = ' '
*   WK1_T_FORMAT                  = ' '
*   WK1_T_SIZE                    = ' '
*   COL_SELECT                    = ' '
*   COL_SELECTMASK                = ' '
*   NO_AUTH_CHECK                 = ' '
* IMPORTING
*   FILELENGTH                    =
  TABLES
    data_tab                      = itab
    FIELDNAMES                    = i_header
 EXCEPTIONS
*   FILE_OPEN_ERROR               = 1
*   FILE_WRITE_ERROR              = 2
*   INVALID_FILESIZE              = 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                        = 0
          .
IF sy-subrc <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Edited by: Alvaro Tejada Galindo on Feb 26, 2008 11:47 AM

Read only

Former Member
0 Likes
1,162

Hi Uma,

If you want to download the data to flat file on presentation server use the function mdoule GUI_DOWNLOAD

Now the # you need is actually the horizontal tab separator in SAP represented by CL_ABAP_CHAR_UTILITIES=>HORIZONRAL_TAB.

So say you have an internal table <itab> with work area <wa> with 2 columns <field1> and <field2>.

You can create a single internal table with one field of type string and


loop at <itab> into <wa>.
concatenate <wa>-<field1> <wa>-<field2> into <wa_string> separated by cl_abap_char_utilities=>horizontal_tab.
append <wa_string> to <itab_string>.
endloop.

Then download the internal table <itab_string> using GUI_DOWNLOAD.

Cheers.

Read only

Former Member
0 Likes
1,161

Hi,


* These variable are for file download.
DATA: ld_filename TYPE string,
      ld_path TYPE string,
      ld_fullpath TYPE string,
      ld_result TYPE i.

* Display save dialog window
  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
*      window_title      = ' '
      default_extension = 'XLS'
      default_file_name = 'accountsdata'
      initial_directory = 'c:\temp\'
    CHANGING
      filename          = ld_filename
      path              = ld_path
      fullpath          = ld_fullpath
      user_action       = ld_result.

* Check user did not cancel request
  CHECK ld_result EQ '0'.

  CALL FUNCTION 'GUI_DOWNLOAD'
   EXPORTING
        filename         = ld_fullpath
        filetype         = 'ASC'
*       APPEND           = 'X'
        write_field_separator = 'X'
*       CONFIRM_OVERWRITE = 'X'
   TABLES
        data_tab         = t_partner[]     "need to declare and populate
   EXCEPTIONS
        file_open_error  = 1
        file_write_error = 2
        OTHERS           = 3.

you can use the above code for download the file and save it into front end in excel format.

t_partner[] is an internal table to display the data.

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Feb 26, 2008 11:48 AM

Read only

Former Member
0 Likes
1,161

use the function module gui_download to download the data to the flat file.

use the function module gui_upload to upload the flat file