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

How to download data into a text file format ?

Former Member
0 Likes
8,955

Hi, all.

My situation now is: I have a report pogram which can retrieve data from database, and I would like to export or download those data to outside as a text file (.txt) in my local computer.

So, does anyone know how to do it? i mean my report coding should add on or enhance with what coding in order to do like that.

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
5,082

Hi,

In se38 open your program --> click menu UTILITIES --> select MORE UTILITIES --> select UPLOAD/DOWNLOAD --> and click DOWNLOAD.

You will be asked for the popup for file path.

SAVE it as .txt file.

To download data form internal table use GUI_DOWNLOAD.


  DATA : c_file_path TYPE string.

  c_file_path = 'C:/TEST.TXT'.

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                = c_file_path "file path
      filetype                = 'DAT'
    TABLES
      data_tab                = <itab> "internal table name
    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
      OTHERS                  = 22.

  IF sy-subrc = 0.
    DATA : w_msg(100) TYPE c.
    CONCATENATE text-001 c_file_path INTO w_msg SEPARATED BY space. "file downloaded message
    MESSAGE w_msg TYPE 'S'.
  ELSE.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

Regards,

Tarun

Edited by: Tarun Gambhir on Mar 6, 2009 9:59 AM

Hi, all.

My situation now is: I have a report pogram which can retrieve data from database, and I would like to export or download those data to outside as a text file (.txt) in my local computer.

So, does anyone know how to do it? i mean my report coding should add on or enhance with what coding in order to do like that.

Thanks in advance.

5 REPLIES 5
Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
5,083

Hi,

In se38 open your program --> click menu UTILITIES --> select MORE UTILITIES --> select UPLOAD/DOWNLOAD --> and click DOWNLOAD.

You will be asked for the popup for file path.

SAVE it as .txt file.

To download data form internal table use GUI_DOWNLOAD.


  DATA : c_file_path TYPE string.

  c_file_path = 'C:/TEST.TXT'.

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                = c_file_path "file path
      filetype                = 'DAT'
    TABLES
      data_tab                = <itab> "internal table name
    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
      OTHERS                  = 22.

  IF sy-subrc = 0.
    DATA : w_msg(100) TYPE c.
    CONCATENATE text-001 c_file_path INTO w_msg SEPARATED BY space. "file downloaded message
    MESSAGE w_msg TYPE 'S'.
  ELSE.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

Regards,

Tarun

Edited by: Tarun Gambhir on Mar 6, 2009 9:59 AM

Read only

Former Member
0 Likes
5,082

Use function Modules

GUI_DOWNLOAD

WS_DOWNLOAD if u want data which is retrevied from Database

Edited by: Upender Verma on Mar 6, 2009 5:29 AM

Read only

former_member632729
Contributor
0 Likes
5,082

Hi Dude,

one you generate list output , you will find the option called List at application tool bar..-> Save / Send -> unconverted radio button then pass the file name and press enter ..

It generate the *.txt file..

Read only

Former Member
0 Likes
5,082

use this function module:


WS_DOWNLOAD

Read only

Former Member
0 Likes
5,082

Hi,

Use GUI_DOWNLOAD Function module.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

filename = 'FILEPATH'*

FILETYPE = 'ASC'

  • APPEND = ' '

WRITE_FIELD_SEPARATOR = 'X' (Field separator )

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • IMPORTING

  • FILELENGTH =

tables

data_tab = t_customer ( give internal tablename )

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

OTHERS = 22 .

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF. " IF SY-SUBRC