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: 

Hi can any oen having ths smaple code to download csv file?

former_member184119
Active Contributor
0 Kudos

Hi friends

can any one having the code to download .csv file

seperated by “;” ..its very urguent please kindly send me the

reply as soon as possible...all answers are rewarded...

Regards

sas

1 ACCEPTED SOLUTION

p291102
Active Contributor
0 Kudos

Hi,

DATA:RAW(4096) TYPE C OCCURS 0.

DATA:BEGIN OF ITAB OCCURS 0,
     DATE1 TYPE SY-DATUM,
     DATE2 TYPE SY-DATUM,
     END OF ITAB.

CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
  EXPORTING
*   I_FIELD_SEPERATOR          = ';'
*   I_LINE_HEADER              =
    I_TAB_RAW_DATA             = RAW
   I_FILENAME                 = C:\Documents and Settings\itfactory\Desktop\sss.xls'

  TABLES
    I_TAB_CONVERTED_DATA       = ITAB
* 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.

LOOP AT ITAB.

  WRITE:/ ITAB-DATE1, ITAB-DATE2.

ENDLOOP.

Thanks,

Sankar M

10 REPLIES 10

Former Member
0 Kudos

0 Kudos

Hi Gayatri..?

u have sent me u r profile link..?

what exactly u r poitning out i didnt get that..?

please check your answer once..

p291102
Active Contributor
0 Kudos

Hi,

DATA:RAW(4096) TYPE C OCCURS 0.

DATA:BEGIN OF ITAB OCCURS 0,
     DATE1 TYPE SY-DATUM,
     DATE2 TYPE SY-DATUM,
     END OF ITAB.

CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
  EXPORTING
*   I_FIELD_SEPERATOR          = ';'
*   I_LINE_HEADER              =
    I_TAB_RAW_DATA             = RAW
   I_FILENAME                 = C:\Documents and Settings\itfactory\Desktop\sss.xls'

  TABLES
    I_TAB_CONVERTED_DATA       = ITAB
* 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.

LOOP AT ITAB.

  WRITE:/ ITAB-DATE1, ITAB-DATE2.

ENDLOOP.

Thanks,

Sankar M

Former Member
0 Kudos

Hi,

We can download the flat file data either from operating system level and Application server.

1.Download from operating system level.

data: itab like t001 occurs 0 with header line.

select * from t001 into table itab.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE = ' '

  • CODEPAGE = ' '

FILENAME = 'D:\ABAP EVE\fiel3.txt'

FILETYPE = 'ASC'

  • 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 =

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.

write:/ 'not created'.

else.

write:/ 'created in os'.

ENDIF.

2.Download from Application server into flat file.

DATA: fname(25) VALUE 'D:\ABAP EVE\file2.txt'.

DATA: str(100).

DATA: BEGIN OF itab OCCURS 0,

bukrs LIKE t001-bukrs,

butxt LIKE t001-butxt,

END OF itab.

OPEN DATASET fname FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

SELECT bukrs butxt FROM t001 INTO TABLE itab UP TO 10 ROWS.

LOOP AT itab.

CONCATENATE itab-bukrs itab-butxt INTO str SEPARATED BY ','.

TRANSFER str TO fname.

ENDLOOP.

ELSE.

WRITE:/ 'sorry'.

ENDIF.

CLOSE DATASET fname.

Regards,

Chandu

former_member184119
Active Contributor
0 Kudos

OK FRIENDS MIGHT BE MY QUESTION IS CONFUSIN YOU..

ok text file seperated by comma any one having the code..reply please..?

ok piece of sample code i am writng please sujjest the necesary cahnge i need to make.?

data: begin of itab occurs 1,

a(2) ,

end of itab.

do 10 times.

itba- a = sy-index.

append itab.

enddo.

now when i call gui download..it will download into text file

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'd:\sas.txt'

FILETYPE = 'ASC'

WRITE_FIELD_SEPARATOR = 'X'

tables

data_tab = itab

with /n format..i.e. it is downloaded in one column only..

ie.

1

2

3

4

this format but i want

1;2;3;4;

i want it just seperated by ':' can any help in this..?

Edited by: saslove sap on Apr 1, 2008 8:23 AM

0 Kudos

LOOP AT t_ban INTO wa_ban.

*replacing comma and double quotes to get proper output in *CSV format

FIND c_comma IN wa_ban.

IF sy-subrc = 0.

REPLACE ALL OCCURRENCES OF c_comma IN wa_ban WITH c_semi.

ENDIF.

FIND c_quot IN wa_ban.

IF sy-subrc = 0.

REPLACE ALL OCCURRENCES OF c_quot IN wa_ban WITH c_semi.

ENDIF.

CONCATENATE wa_ban-oaekgrp "OA Pur GRP

wa_ban-eknam "Buyer

wa_ban-ekorg "Pur.Org.

wa_ban-flief "Vendor No.

wa_ban-konnr "Contract

wa_ban-ktpnr "Contract Line Item

wa_ban-zugba "Assigned

wa_ban-werks "Plant

wa_ban-banfn "Requisition #

wa_ban-bnfpo "Req. Item #

wa_ban-lfdat "Req delivery date

wa_ban-ekgrp "Req. Pur Grp

wa_ban-ernam "User

wa_ban-error "Error descp

INTO lt_objbin SEPARATED BY c_comma.

APPEND lt_objbin.

CLEAR lt_objbin.

ENDLOOP.

Before concatenating all the fields we need to replace , by ; and " by ;

Now the table lt_objbin will contain the content of the internal table t_ban separated by (,) comma character

And after populating lt_objbin u can use GUI_DOWNLOAD to download the file

Try it

0 Kudos

i didnt get your code gayatri..please..see my code and suggest the necessarty changes..because i yoour code i didnt get what is data type what is data length..?

Please..make some time to reply friends

0 Kudos

Hi,

Actually ur internal table is not clear

u want ur output in 1;2;3;4 this format right

But the CSV file format is like it will have some records. and in every record the fields are separeted by comma

eg:

name,dept,branch,city

In ur case u want to separate ur records with ; by cocatenating all the records into a single line. isn't it

so give some more details like what u exactly want to download

0 Kudos

hi gayatri forget about the csvfile....

just tell me if i want to download a file into txt file which should have the data in the format 1;2;3;4....

plz sendd me the sample code..so that i can do the rest of the things by r&d if i get it...

any one reply plz..?

Former Member
0 Kudos

Hi,

Check this.i hope it is very helpfull to u.

DATA:BEGIN OF ITAB3 OCCURS 0,

MATNR1 LIKE MARA-MATNR,

MATNR2 LIKE MARA-MATNR,

end of itab3.

DATA:BEGIN OF ITAB OCCURS 0,

MATNR LIKE MARA-MATNR,

ERSDA LIKE MARA-ERSDA,

ERNAM LIKE MARA-AENAM,

MTART LIKE MARA-MTART,

MBRSH LIKE MARA-MBRSH,

MATKL LIKE MARA-MATKL,

MEINS LIKE MARA-MEINS,

END OF ITAB.

data : begin of itab1 occurs 0,

filename type string,

end of itab1.

DATA:FILENAME TYPE STRING.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'c:\technoSoft\input.txt'

FILETYPE = 'ASC'

TABLES

DATA_TAB = itab3.

data c(4) type N.

LOOP AT ITAB3.

c = SY-TABIX.

refresh ITAB.

refresh ITAB1.

FILENAME = ' '.

SELECT MATNR ERSDA ERNAM MTART MBRSH MATKL MEINS FROM MARA INTO TABLE ITAB WHERE MATNR BETWEEN ITAB3-MATNR1 AND ITAB3-MATNR2 .

CONCATENATE 'C:\technosoft\processfile\mara' SY-DATUM '-' SY-UZEIT '-' c '.TXT' INTO FILENAME.

loop at itab.

concatenate itab-MATNR ';' itab-ERSDA ';' itab-ERNAM ';' itab-MTART ';'

itab-MBRSH ';' itab-MATKL ';' itab-MEINS into itab1-filename.

append itab1.

endloop.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = FILENAME

FILETYPE = 'ASC'

WRITE_FIELD_SEPARATOR = ';'

WK1_T_FORMAT = ','

TABLES

DATA_TAB = ITAB1

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.