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

creating text file from table

Former Member
0 Likes
580

Hi all

I have a table LFA1 with headers LIFNR, MANDT, NAME1, NAME2, ...., . That table contains data and I need to create text file that collects all headers with all data, where each field is separated by TAB.

thanks for your help.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
546

Here is program for KNA1.

*"Table declarations...................................................

tables:

kna1. " General Data in Customer Master

*"Selection screen elements............................................

select-options:

s_kunnr for kna1-kunnr. " Customer Number 1

*" Type declarations...................................................

"----


types:

begin of type_s_customer_details,

name like kna1-kunnr,

address like kna1-adrnr,

title like kna1-anred,

createdon like kna1-erdat,

createdby like kna1-ernam,

end of type_s_customer_details.

"----


  • Internal table to hold General Data in Customer Master data *

"----


data:

t_customer_details type table

of type_s_customer_details

with header line.

"----


  • START-OF-SELECTION EVENT *

"----


start-of-selection.

perform select.

&----


*& Form select

&----


  • This subroutine selects information from database and exports the *

  • data into presentation layer *

----


  • There are no interface parameters to be passed to this subroutine. *

----


form select .

select kunnr

adrnr

anred

erdat

ernam

into table t_customer_details

from kna1

where kunnr in s_kunnr.

if sy-subrc ne 0.

write : / 'DATABASE SELECTION FAILED'.

else.

call function 'GUI_DOWNLOAD'

exporting

  • BIN_FILESIZE =

filename = 'd:\customer_details.txt'

filetype = 'ASC'

  • APPEND = ' '

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

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • IMPORTING

  • FILELENGTH =

tables

data_tab = t_customer_details

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

write : / 'Upload Failed' , sy-subrc.

else.

write : / 'Upload Completed'.

endif.

endif.

endform. " SELECT

4 REPLIES 4
Read only

Former Member
0 Likes
547

Here is program for KNA1.

*"Table declarations...................................................

tables:

kna1. " General Data in Customer Master

*"Selection screen elements............................................

select-options:

s_kunnr for kna1-kunnr. " Customer Number 1

*" Type declarations...................................................

"----


types:

begin of type_s_customer_details,

name like kna1-kunnr,

address like kna1-adrnr,

title like kna1-anred,

createdon like kna1-erdat,

createdby like kna1-ernam,

end of type_s_customer_details.

"----


  • Internal table to hold General Data in Customer Master data *

"----


data:

t_customer_details type table

of type_s_customer_details

with header line.

"----


  • START-OF-SELECTION EVENT *

"----


start-of-selection.

perform select.

&----


*& Form select

&----


  • This subroutine selects information from database and exports the *

  • data into presentation layer *

----


  • There are no interface parameters to be passed to this subroutine. *

----


form select .

select kunnr

adrnr

anred

erdat

ernam

into table t_customer_details

from kna1

where kunnr in s_kunnr.

if sy-subrc ne 0.

write : / 'DATABASE SELECTION FAILED'.

else.

call function 'GUI_DOWNLOAD'

exporting

  • BIN_FILESIZE =

filename = 'd:\customer_details.txt'

filetype = 'ASC'

  • APPEND = ' '

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

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • IMPORTING

  • FILELENGTH =

tables

data_tab = t_customer_details

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

write : / 'Upload Failed' , sy-subrc.

else.

write : / 'Upload Completed'.

endif.

endif.

endform. " SELECT

Read only

amit_khare
Active Contributor
0 Likes
546

Basically you want to create a tab delimed file and download it.

Refer the links -

Regards,

Amit

Reward all helpful replies.

Read only

Former Member
0 Likes
546

select data into internal table and then...

data: ld_filename type string ;

ld_filename = 'c:\demo.txt'.

DATA: begin of it_datatab occurs 0,

row(500) type c,

end of it_datatab.

HII

call function 'GUI_DOWNLOAD'

exporting

filename = ld_filename

filetype = 'ASC'

tables

data_tab = it_datatab[]

exceptions

file_open_error = 1

file_write_error = 2

others = 3.

Regards

vasu

Read only

Former Member
0 Likes
546

Hi try using this fn module,

WS_DOWNLOAD

It saves table as File on the Presentation Server