Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

creating text file from table

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.

Tags:
Former Member replied

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

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question