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: 

Heading line in excel sheet.

Former Member
0 Kudos

Hi Experts,

I am working in R/3 4.7 system. I am populating an excel sheet with values from an internal table. Now I want to include a row for heading in the beginning of the excel

sheet. In ECC 6.0 there is a parameter in GUI_DOWNLOAD for heading. But it is not available

in 4.7 system. How should i proceed?

Thanks in advance.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

For heading you have to call gui_download two times first time u pass the heading details and in second pass the table and in parameter APPEND = 'X'.

4 REPLIES 4

former_member386202
Active Contributor
0 Kudos

Hi,

Refer Below code

&----


*& Form down_desktop_file

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM down_desktop_file .

*--Local Variables

DATA : l_file TYPE string.

SELECT * FROM zsd_ra

INTO TABLE it_sd_ra.

*-- for Heading in excel sheet

st_head-name = text-031.

APPEND st_head TO it_head.

st_head-name = text-032.

APPEND st_head TO it_head.

st_head-name = text-033.

APPEND st_head TO it_head.

st_head-name = text-034.

APPEND st_head TO it_head.

st_head-name = text-035.

APPEND st_head TO it_head.

st_head-name = text-036.

APPEND st_head TO it_head.

st_head-name = text-037.

APPEND st_head TO it_head.

st_head-name = text-038.

APPEND st_head TO it_head.

LOOP AT it_sd_ra INTO st_ra1.

st_data-gjahr = st_ra1-gjahr.

MOVE st_ra1-monat TO st_data-monat.

st_data-zzprojectid = st_ra1-zzprojectid.

st_data-zwbs = st_ra1-zwbs.

st_data-zeac_amount = st_ra1-zeac_amount.

st_data-zlabor = st_ra1-zlabor.

st_data-zmaterial = st_ra1-zmaterial.

st_data-zohead = st_ra1-zohead.

APPEND st_data TO it_data.

CLEAR: st_ra1,

st_data.

ENDLOOP.

    • Down load TAB delimited file

l_file = p_filep.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = l_file

filetype = 'ASC'

write_field_separator = c_chk

TABLES

data_tab = it_data

fieldnames = it_head

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.

MESSAGE i368(00) WITH 'Error writing file'(m03) l_file.

ELSE.

WRITE:/ 'file downloaded', l_file.

ENDIF.

ENDFORM. " down_desktop_file

Regards,

Prashant

Former Member
0 Kudos

Hi,

For heading you have to call gui_download two times first time u pass the heading details and in second pass the table and in parameter APPEND = 'X'.

former_member181995
Active Contributor
0 Kudos

Mhmd,

steps are:

A.First populate the data into your internal table.

B. Now insert the Text in the header of the Internal Table( Sy-tabix = 1) index =1

C. Append the data.

You would see the header is populted into the internal table.

D. Now Download the Internalt table into the EXCEL.

Amit.

former_member705122
Active Contributor
0 Kudos

Hi Aslam,

Run this sample code in 4.7 and check.

TYPES:
  BEGIN OF type_itab1,
    string TYPE string,
  END OF type_itab1.
 
DATA:
  BEGIN OF itab OCCURS 0,
    vbeln  LIKE vbap-vbeln,
    posnr  LIKE vbap-posnr,
  END OF itab.
 
DATA:
   wa_itab TYPE type_itab1,
   itab1   TYPE STANDARD TABLE OF type_itab1.
 
SELECT vbeln
       posnr
    UP TO 5 ROWS
  FROM vbap
  INTO TABLE itab.
 
SORT itab.
 
DELETE ADJACENT DUPLICATES FROM itab COMPARING ALL FIELDS.
 
LOOP AT itab.
  CONCATENATE itab-vbeln
              itab-posnr
         INTO wa_itab-string
         SEPARATED BY ','.
  APPEND wa_itab TO itab1.
ENDLOOP.
 
CONCATENATE 'vbeln'
            'posnr'
       INTO wa_itab-string
       SEPARATED BY ','.
INSERT wa_itab
INTO itab1 INDEX 1.
 
CHECK sy-subrc EQ 0.
 
CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename = 'C:Documents and Settings	estDesktop	est2.csv'
    filetype = 'ASC'
  TABLES
    data_tab = itab1
  EXCEPTIONS
    OTHERS   = 1.

for more info refer this link:

This will work, check once.

Regards

Adil