Application Development 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: 

GUI_DOWNLOAD

0 Kudos

Hi Guys,

I am downloading content into a .CSV file. I would like to have Heading for the columns in the first row using the function module GUI_DOWNLOAD. Could you tell me how I can achieve this.

Thanks & Regards,

ABAPer

1 ACCEPTED SOLUTION

former_member188685
Active Contributor
0 Kudos

you can do it two ways.

One Using append option. for this you need to call gui_download two times.

first column heading and second data to the same using the append option of the GUI_DOWNLOAD.

second one.

FIELDNAMES option, populate the column names to this FIELDNAME table and download at one short.

Just search in the forum for more details.

6 REPLIES 6

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

What release are you using?

Regards,

Rich Heilman

0 Kudos

ECC 6.0

0 Kudos

Hmm, there is a tables parameters called FIELDNAMES and it works whening downloading to XLS, but it doesn't seem to want to work with a CSV. Not sure why, but anyway, you can simply add the fields names as the first line of the internal table, like so.

DATA: lt_str TYPE TABLE OF string.
DATA: ls_str LIKE LINE OF lt_str.

* Add data
ls_str = 'ABC,123,abc'.  APPEND ls_str TO lt_str.
ls_str = 'ABC,123,abc'.  APPEND ls_str TO lt_str.

* Now add column headings, of course you could
* do this before adding data as well
ls_str = 'UpperABC,Numbers,LowerABC'. insert ls_str into lt_str INDEX 1.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename   = 'c:/test.csv'
  TABLES
    data_tab   = lt_str.

REgards,

Rich Heilman

former_member188685
Active Contributor
0 Kudos

you can do it two ways.

One Using append option. for this you need to call gui_download two times.

first column heading and second data to the same using the append option of the GUI_DOWNLOAD.

second one.

FIELDNAMES option, populate the column names to this FIELDNAME table and download at one short.

Just search in the forum for more details.

shadow
Participant
0 Kudos

Hi reddy,

u can go for that , just u have to use FIELDNAMES,

there is a parameters called FIELDNAMES GUI_UPLOAD. chek it.

Regard's

Shaik.

Former Member
0 Kudos

Hi,

Check this sample code


REPORT  z_file_download.
DATA: w_name(90) TYPE c.
DATA:
  BEGIN OF fs_flight,
    carrid   LIKE sflight-carrid,
    connid   LIKE sflight-connid,
    fldate   LIKE sflight-fldate,
    price    LIKE sflight-price,
    currency LIKE sflight-currency,
  END OF fs_flight.
DATA:
  BEGIN OF fs_head,
    carrid(10) TYPE c,
    connid(10) TYPE c,
    fldate(10) TYPE c,
    price(10) TYPE c,
    curr(10) TYPE c,
  END OF fs_head.
DATA:
  t_head LIKE
   TABLE OF
         fs_head.
DATA:
  t_flight LIKE
     TABLE OF
           fs_flight.

fs_head-carrid = 'CARRID'.
fs_head-connid = 'CONNID'.
fs_head-fldate = 'FLDATE'.
fs_head-price  = 'PRICE'.
fs_head-curr   = 'CURRENCY'.
APPEND fs_head TO t_head.
SELECT-OPTIONS:
  s_carrid FOR fs_flight-carrid.



START-OF-SELECTION.
  SELECT carrid
         connid
         fldate
         price
         currency
    FROM sflight
    INTO TABLE t_flight
   WHERE carrid IN s_carrid.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
*   BIN_FILESIZE                  =
    filename                      = 'D:\flight.xls'
   FILETYPE                      = 'ASC'
*   APPEND                        = ' '
    WRITE_FIELD_SEPARATOR         = 'X'
*   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_head
 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.



  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                = 'D:\flight.xls'
      filetype                = 'ASC'
      append                  = 'X'
      write_field_separator   = 'X'
    TABLES
      data_tab                = t_flight
    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 EQ 0.
    MESSAGE 'Download successful' TYPE 'I'.
  ENDIF.
  IF sy-subrc <> 0.
*  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


Regards

Abhijeet