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: 

Add header line to excel sheet when using FM RH_START_EXCEL_WITH_DATA

morten_nielsen
Active Contributor
0 Kudos

Hi

I'm using FM RH_START_EXCEL_WITH_DATA to download an internal table to EXCEL. But when excel is started it's without a header line.

What I would like to do, is to take the field-names/field-text from the abap dictionary, and use them as the header line. How do I achieve this ?

Regards

Morten Nielsen

1 ACCEPTED SOLUTION

tarangini_katta
Active Contributor

Hi Morten,

As i said u need to get fieldnames from table or hard code.

I think these 2 only are the ways.

Thanks

10 REPLIES 10

tarangini_katta
Active Contributor
0 Kudos

Hi,

This function module doesn'have any exporting parameters.

Y can't use GUI_DOUWNLAOD or cl_gui_frontend_services->gui_download.

Thanks

0 Kudos

Hi,

You can try using XXL_FULL_API function module. Otherwise you can use WS_EXCEL or WS_DOWNLOAD function module where you can enter the header into separate internal table and download the data along with them.

Sample Code

DATA: BEGIN OF it_header OCCURS 0,

text(50) TYPE c,

END OF it_header.

*Header Text for Excel File

it_header-text = 'Doc Num'. APPEND it_header.

it_header-text = 'Doc Type'. APPEND it_header.

it_header-text = 'Created On'. APPEND it_header.

it_header-text = 'Vendor Name'. APPEND it_header.

*Downloading to Excel

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

filename = pfile

filetype = 'DAT'

TABLES

data_tab = it_download

fieldnames = it_header

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

OTHERS = 10.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

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

ENDIF.

Regards

Khanna

0 Kudos

Hi

It seems that WS_EXCEL and WS_DOWNLOAD is obsolete, so I guess i need to use cl_gui_front_end_services=>gui_download, but this method does not support header like the WS_DOWNLOAD FM.

Is the only option here to hardcode the fieldnames in the first line of the internal table or... ?

Regards

Morten

tarangini_katta
Active Contributor
0 Kudos

HI,

Take the dictionary feildnames and insert into itab.Then it will display the excel with the header line.

0 Kudos

Thanks Tarangini

Do you have any neat tricks for doing this, i would like to avoid hard coding the fieldnames

Regards

Morten

tarangini_katta
Active Contributor
0 Kudos

Hi,

For which table ur downloading the data.

We will have the FM'S to get the fieldnames of the tables.

So based the table u will get the fieldname and pass to into itab.

Thanks

tarangini_katta
Active Contributor

Hi Morten,

As i said u need to get fieldnames from table or hard code.

I think these 2 only are the ways.

Thanks

0 Kudos

ok thanks Tarangini

is there a FM I can use for this ?

Regards

Morten

0 Kudos

Hi ,

See this sample code.

Tables : zacg_cca,zacg_exsh.

data: P_file like RLGRAP-FILENAME.

Data: Begin of it_header occurs 0,

Header(15) ,

end of it_header.

Data : begin of it_final occurs 0,

ccode type zacg_cca-ccode,

mat_cd type zacg_cca-mat_cd,

ingr_desc type zacg_cca-ingr_desc,

conc type zacg_cca-conc,

quantity type zacg_cca-quantity,

percqty type zacg_cca-percqty,

flag ,

APP_DATE type zacg_cca-app_date,

rsamnos type zacg_cca-rsamnos,

end of it_final.

SELECTION-SCREEN : BEGIN OF BLOCK blk WITH FRAME TITLE text-000.

select-options : s_Date for zacg_cca-app_date.

SELECTION-SCREEN : END OF BLOCK blk.

it_header-Header = 'Samp_code'.

Append it_header.

it_header-Header = 'Mat_code'.

Append it_header.

it_header-Header = 'Ingr_Desc'.

Append it_header.

it_header-Header = 'Conc'.

Append it_header.

it_header-Header = 'Quan'.

Append it_header.

it_header-Header = 'Perc'.

Append it_header.

it_header-Header = 'Flag'.

Append it_header.

it_header-Header = 'Date'.

Append it_header.

it_header-Header = 'Rsamnos'.

Append it_header.

it_header-Header = 'Mat_code'.

Append it_header.

select ccode

mat_cd

ingr_desc

conc

quantity

percqty

app_date

rsamnos

from zacg_cca into corresponding

fields of table

it_final where zacg_cca~app_date in s_date.

loop at it_final.

it_final-flag = 'T'.

modify it_final.

it_final-quantity = it_final-quantity * 2 .

Modify it_final.

endloop.

CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'

EXPORTING

FILE_NAME = 'E:\IT\P_FILE'

  • CREATE_PIVOT = 0

  • DATA_SHEET_NAME = ' '

  • PIVOT_SHEET_NAME = ' '

  • PASSWORD = ' '

  • PASSWORD_OPTION = 0

TABLES

  • PIVOT_FIELD_TAB =

DATA_TAB = it_final[]

FIELDNAMES = it_header[]

EXCEPTIONS

FILE_NOT_EXIST = 1

FILENAME_EXPECTED = 2

COMMUNICATION_ERROR = 3

OLE_OBJECT_METHOD_ERROR = 4

OLE_OBJECT_PROPERTY_ERROR = 5

INVALID_PIVOT_FIELDS = 6

DOWNLOAD_PROBLEM = 7

OTHERS = 8

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

Regards

ABG

0 Kudos

Hi,

This FM

DDIF_FIELDINFO_GET

to get the fieldnames from the table .

Just pass u r strucu´ture to this FM u will get all the fields used in this Fm.