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: 

Download data in CSV

Former Member
0 Kudos

Hi ALL,

Please let me know how i can download CSV tab delimited file from SAP when i downloaded the data is coming in sigle cell not in multiple fields.

Thanks Regards,

Noor

8 REPLIES 8

rainer_hbenthal
Active Contributor
0 Kudos

your tab deleimiter seems to be not a tab(09)

Former Member
0 Kudos

Hi

search the forum with GUI_DOWNLOAD.

In that set the import parameter write field seperator.

Regards

Karthik D

Former Member
0 Kudos

Hi Noor,

Use FM GUI_DOWNLOAD check the parameter , WRITE_FIELD_SEPARATOR

Regards

Dinesh

yang_aiolos
Active Participant
0 Kudos

normally,it would not be like that,it will seperate in several cols.give me you code.

satsrockford
Active Participant

Former Member
0 Kudos

Hi Noor uddin ,

I you want to download the file in CSV format you can do that i am sending you a sample code for the same i hope this will solve your problems .

Please find the code below : --

&----


*& Report ZCRPT_PP_013

*&

&----


*&

*&

&----


REPORT zcrpt_pp_013.

  • no standard page heading

  • line-size 80

  • line-count 65(0)

  • message-id ...

----


  • Dev. Class : *

  • Report Name : *

  • Program Type : *

  • Created by : *

  • Created on : *

  • Transaction Code : *

  • Module Name : *

  • Object ID : *

  • Description : *

  • SAP Release : 4.6 C *

  • Change Request : *

----


TYPE-POOLS : slis, truxs.

----


  • 1 : Tables Defination *

----


TABLES : mseg,mara,makt,mard,t001w.

----


  • 2 : Selection Screen *

----


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: s_matnr FOR mard-matnr.

PARAMETERS : p_werks LIKE mard-werks.

SELECTION-SCREEN END OF BLOCK b1.

*SELECTION-SCREEN BEGIN OF BLOCK m WITH FRAME.

*PARAMETERS: p_file TYPE rlgrap-filename.

*SELECTION-SCREEN END OF BLOCK m.

----


  • 3 : Internal Table Declaration *

----


DATA : BEGIN OF it_mara OCCURS 0,

place1(12),

place2(12),

matnr LIKE mard-matnr,

maktx LIKE makt-maktx,

labst LIKE mard-labst,

werks like mard-werks,

place3(12),

date(10) ,

END OF it_mara.

DATA: it_mara1 TYPE truxs_t_text_data.

DATA : layout TYPE slis_layout_alv,

event TYPE slis_t_event ,

wa_event TYPE slis_alv_event,

variant TYPE disvariant.

DATA : alvly TYPE slis_layout_alv.

DATA : alvev TYPE slis_t_event.

DATA : fcat TYPE slis_t_fieldcat_alv.

DATA : w_fcat TYPE slis_fieldcat_alv.

----


  • : Start of Selection *

----


START-OF-SELECTION.

perform build_layout.

PERFORM select.

PERFORM process.

PERFORM display.

END-OF-SELECTION.

************************************************************************

  • *

  • F o r m R o u t i n e s S t a r t s H e r e *

  • *

************************************************************************

&----


*& Form SELECT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM select .

SELECT matnr werks FROM mard

INTO CORRESPONDING FIELDS OF TABLE it_mara

WHERE matnr IN s_matnr

AND werks LIKE p_werks.

LOOP AT it_mara.

SELECT SUM( labst ) FROM mard INTO it_mara-labst

WHERE matnr = it_mara-matnr

AND werks = it_mara-werks.

SELECT SINGLE maktx INTO it_mara-maktx FROM makt

WHERE matnr = it_mara-matnr.

MODIFY it_mara TRANSPORTING maktx labst.

ENDLOOP.

ENDFORM. "SELECT

&----


*& Form PROCESS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM process .

LOOP AT it_mara.

WRITE sy-datum TO it_mara-date USING EDIT MASK '__/__/____'.

WRITE 'VIKROLI' TO it_mara-place1.

WRITE 'VIKROLI' TO it_mara-place2.

WRITE 'Stock' TO it_mara-place3.

  • WRITE '2101' TO it_mara-werks.

MODIFY it_mara TRANSPORTING place1 place2 labst place3 date.

ENDLOOP.

DELETE ADJACENT DUPLICATES FROM it_mara COMPARING ALL FIELDS.

DELETE it_mara WHERE labst EQ ' '.

CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'

EXPORTING

I_FIELD_SEPERATOR = ';'

  • I_LINE_HEADER =

  • I_FILENAME =

  • I_APPL_KEEP = ' '

TABLES

i_tab_sap_data = it_mara

CHANGING

I_TAB_CONVERTED_DATA = it_mara1

EXCEPTIONS

CONVERSION_FAILED = 1

OTHERS = 2

.

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 = 'C:\Documents and Settings\coconut1\Desktop\ticket\FG_VIKROLI.csv'

  • FILETYPE = 'ASC'

  • WRITE_FIELD_SEPARATOR = ','

  • IMPORTING

  • FILELENGTH =

tables

data_tab = it_mara1

  • FIELDNAMES =

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.

ENDFORM. " PROCESS

&----


*& Form DISPLAY

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display .

w_fcat-fieldname = 'PLACE1'.

w_fcat-tabname = 'it_mara'.

w_fcat-col_pos = 1.

w_fcat-outputlen = '10' .

APPEND w_fcat TO fcat.

CLEAR w_fcat.

w_fcat-fieldname = 'PLACE2'.

w_fcat-tabname = 'it_mara'.

w_fcat-col_pos = 2.

w_fcat-outputlen = '10' .

APPEND w_fcat TO fcat.

CLEAR w_fcat.

w_fcat-fieldname = 'MATNR'.

w_fcat-tabname = 'it_mara'.

w_fcat-col_pos = 3.

w_fcat-outputlen = '15' .

APPEND w_fcat TO fcat.

CLEAR w_fcat.

w_fcat-fieldname = 'MAKTX'.

w_fcat-tabname = 'it_mara'.

w_fcat-col_pos = 4.

w_fcat-outputlen = '40' .

APPEND w_fcat TO fcat.

CLEAR w_fcat.

w_fcat-fieldname = 'LABST'.

w_fcat-tabname = 'it_mara'.

w_fcat-col_pos = 5.

w_fcat-outputlen = '15' .

APPEND w_fcat TO fcat.

CLEAR w_fcat.

w_fcat-fieldname = 'PLACE3'.

w_fcat-tabname = 'it_mara'.

w_fcat-col_pos = 6.

w_fcat-outputlen = '15' .

APPEND w_fcat TO fcat.

CLEAR w_fcat.

w_fcat-fieldname = 'DATE'.

w_fcat-tabname = 'it_mara'.

w_fcat-col_pos = 7.

w_fcat-outputlen = '15' .

APPEND w_fcat TO fcat.

CLEAR w_fcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

i_callback_program = sy-repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

is_layout = alvly

it_fieldcat = fcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

i_save = 'X'

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • I_HTML_HEIGHT_TOP = 0

  • I_HTML_HEIGHT_END = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • IR_SALV_FULLSCREEN_ADAPTER =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = it_mara

  • EXCEPTIONS

  • PROGRAM_ERROR = 1

  • OTHERS = 2

.

IF sy-subrc <> 0.

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

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

ENDIF.

ENDFORM. " DISPLAY

&----


*& Form build_layout

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form build_layout .

alvly-no_input = 'X'.

alvly-no_colhead = 'X'.

alvly-zebra = 'X'.

alvly-colwidth_optimize = 'X'.

endform. " build_layout

Former Member
0 Kudos

hi,

u can use the FM GUI_DOWNLOAD.

here is the sample code.


*Internal table to hold the material details
DATA: it_details TYPE STANDARD TABLE OF x_details,
      wa_details TYPE x_details.
 
*Internal table for file
DATA: BEGIN OF  it_details_txt OCCURS 0,
        line(700),
      END OF  it_details_txt.
 
*Employee details for the file
  CLEAR wa_details.
  LOOP AT it_details INTO wa_details.
    CLEAR it_details_txt.
    CONCATENATE
        wa_details-var1
        wa_details-var2
        wa_details-var3
        wa_details-var4
      INTO it_details_txt-line SEPARATED BY ','.
 
    APPEND it_details_txt.
    CLEAR wa_details.
  ENDLOOP.
 
*Download file in .CSV format to local desktop
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                = 'data.csv'
      filetype                = 'ASC'
    TABLES
      data_tab                = it_details_txt
    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                  = 11.
  IF sy-subrc = 0.
    MESSAGE 'Data downloaded successfully' TYPE 'S'.
  ENDIF.

Former Member
0 Kudos

Hi,

In the FM GUI_DOWNLOAD

the parameter HAS_FIELD_SEPARATOR should be set as 'X'.

Regards,

Jeet K Bhatt