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: 

How to download data from an internal table to a text

Former Member
0 Kudos

Hi All,

I want to download data from an internal table to a text file.

The fields should be pipe(|) separated. I have tried GUI_DOWNLOAD but it is not taking the field separator.

The sample of the desired data that i require should be this way:-

13456TR|M|COUP|MATERIAL|KGS

Thanks in advance.

Regards

Satish.

4 REPLIES 4

Former Member
0 Kudos

You can try to concatenate all the fields of your structure (used to define record-set file) into new char variable as this:

concatenate file-field1 file-field2 .... into newchar separated by '|'.

after this you can transfer the new data into a internal table before to call GUI_DOWNLOAD.

Gianluca

Former Member
0 Kudos

I had this problem once. I had to resort to creating a second internal table with every other record seperated by element 'pipe1 ... pipe2 ... pipe3...etc'. I then just looped through the original internal table and filled in the other content before exporting the text file.

It's crude, and an extra step, but it works.

andreas_mann3
Active Contributor
0 Kudos

Hi ,

look here:

and posting from Raja

regards Andreas

Former Member
0 Kudos

Hi,

Try this..

REPORT zc1download message-id zc1dwnmsg.

&----


*& Declaration Section for the Tables *

&----


TABLES: makt.

&----


*& Declaration Section for the Internal Tables

&----


DATA: intab TYPE TABLE OF makt,

wa_intab LIKE LINE OF intab,

no_of_rec TYPE i,

count TYPE i.

DATA: BEGIN OF f_intab,

str(255) TYPE c,

END OF f_intab.

DATA: t_intab LIKE TABLE OF f_intab,

w_intab LIKE LINE OF t_intab,

temp(255) TYPE c.

FIELD-SYMBOLS: <f> TYPE ANY.

&----


*& Selection ScreenSection for the file download

&----


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

PARAMETERS: file TYPE rlgrap-filename MEMORY ID file,

tab RADIOBUTTON GROUP rad1 DEFAULT 'X',

others RADIOBUTTON GROUP rad1,

delimit TYPE c.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

IF file IS INITIAL. " check to ensure file.

MESSAGE i001.

EXIT.

ENDIF.

IF others = 'X'. " check to ensure delimiter.

IF delimit = ' '.

MESSAGE i002.

EXIT.

ENDIF.

ENDIF.

SELECT * FROM makt INTO TABLE intab.

IF tab = 'X'. " default delimiter tab is used

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

filename = file

filetype = 'DAT'

mode = 'A'

TABLES

data_tab = intab

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 ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ELSE. " If user defind delimiter is to be used

  • Counts the number of fields *

DO.

ASSIGN COMPONENT sy-index OF STRUCTURE wa_intab TO <f>.

IF sy-subrc <> 0.

EXIT.

ELSE.

count = count + 1.

ENDIF.

ENDDO.

LOOP AT intab INTO wa_intab.

DO count TIMES. " Adding the delimiter in required places

ASSIGN COMPONENT sy-index OF STRUCTURE wa_intab TO <f>.

CONCATENATE temp delimit <f> INTO temp.

ENDDO.

SHIFT temp.

APPEND temp TO t_intab.

CLEAR temp.

ENDLOOP.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

filename = file

filetype = 'ASC'

mode = 'A'

TABLES

data_tab = t_intab

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 ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDIF.

WRITE:/ 'The Data has been tranfered to :', file.

Cheers

Kathir!~