Skip to Content

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

Inserting Field Names as Header while downloading the file

Hi,

I am downloading one file using CALL METHOD cl_gui_frontend_services=>gui_download and wanted to add field names as header while downloading.I have the filed names in one internal table and have written the code as follows:

LOOP AT gt_import INTO gw_import.

gw_fldname-field_name = gw_import-field_name.

APPEND gw_fldname TO gt_fldname.

ENDLOOP.

Here gt_fldname has the field names.

l_descr_ref ?= cl_abap_typedescr=>describe_by_data( gt_fldname ).

CLEAR : l_counter.

LOOP AT l_descr_ref->components[] ASSIGNING <lfs_comp_wa>.

l_counter = l_counter + 1.

ASSIGN COMPONENT sy-index OF STRUCTURE gt_fldname TO <lfs_comp>.

IF sy-subrc = 0.

<lfs_comp> = <lfs_comp_wa>-name.

ENDIF.

ENDLOOP.

CALL METHOD cl_gui_frontend_services=>gui_download

EXPORTING

filename = pdir1

filetype = text-038

append = ''

write_field_separator = 'X'

CHANGING

data_tab = <lfs_comp>

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

not_supported_by_gui = 22

error_no_gui = 23

OTHERS = 24.

IF sy-subrc <> 0.

EXIT.

ENDIF.

CALL METHOD cl_gui_frontend_services=>gui_download

EXPORTING

filename = pdir1

filetype = text-038

append = 'X'

write_field_separator = 'X'

CHANGING

data_tab = <gfs_table1>

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

not_supported_by_gui = 22

error_no_gui = 23

OTHERS = 24.

IF sy-subrc <> 0.

EXIT.

ENDIF.

But it goes to dump at l_descr_ref ?= cl_abap_typedescr=>describe_by_data( gt_fldname ) where I am trying to make the filed names horizontal.

Can anyone help on this?

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