Vous êtes sur la page 1sur 12

4/4/2018 ABAPblog.

com - Create XLSX/MHTML file from internal table in background

Tweets by @abapblog
Łukasz Pęgiel
Retweeted

Lars Hvam Petersen


@LarsHvam
#abapGit in #ADT Proof of
concept, work in progress
#ABAPyoutube.com/watch? (https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fabapblog.com&t=) (https://twitter.com/intent/tweet?
v=-5_XRS…

source=http%3A%2F%2Fabapblog.com&text=:%20http%3A%2F%2Fabapblog.com&via=abapblog)
YouTube @YouTube (https://plus.google.com/share?

url=http%3A%2F%2Fabapblog.com) (http://pinterest.com/pin/create/button/?url=http%3A%2F%2Fabapblog.com&description=) (https://getpocket.com/save?

url=http%3A%2F%2Fabapblog.com&title=) (http://www.reddit.com/submit?url=http%3A%2F%2Fabapblog.com&title=) (http://www.linkedin.com/shareArticle?

mini=true&url=http%3A%2F%2Fabapblog.com&title=&summary=&source=http%3A%2F%2Fabapblog.com) (https://pinboard.in/popup_login/?

url=http%3A%2F%2Fabapblog.com&title=&description=)

30 Mar 2018
Home (/) / Articles (/articles) / Tricks (/articles/tricks)
/Łukasz
Create
PęgielXLSX/MHTML file from internal table in background (http://abapblog.com/articles/tricks/33-create-xlsx-mhtml-file-from-
Retweeted
internal-table-in-background)
Vitaliy Rudnytskiy
@Sygyzmundovych
List of #sitWRO sessions is

Embed View on Twitter

Create XLSX/MHTML file from internal table in


background (/articles/tricks/33-create-xlsx-mhtml-file-
from-internal-table-in-background)
Written by Łukasz Pęgiel Category: Tricks (/Articles/Tricks) Published: 12 May 2013 Hits: 75568

Rating 94% (13 Votes)

Attachments:

ZAB_MHTML_XLS.nugg (http://abapblog.com/files/nugg/ZAB_MHTML_XLS.nugg)
(http://abapblog.com/files/nugg/ZAB_MHTML_XLS.nugg)
ZCL_ABAPBLOG_COM.nugg (http://abapblog.com/files/nugg/ZCL_ABAPBLOG_COM.nugg)
(http://abapblog.com/files/nugg/ZCL_ABAPBLOG_COM.nugg)

Tags: CL_SALV_COLUMNS_TABLE (/component/search/?searchword=CL_SALV_COLUMNS_TABLE&ordering=&searchphrase=all) , CL_SALV_AGGREGATIONS

(/component/search/?searchword=CL_SALV_AGGREGATIONS&ordering=&searchphrase=all) , CL_SALV_TABLE (/component/search/?

searchword=CL_SALV_TABLE&ordering=&searchphrase=all) , CL_SALV_CONTROLLER_METADATA=>GET_LVC_FIELDCATALOG (/component/search/?

searchword=CL_SALV_CONTROLLER_METADATA=&GTGET_LVC_FIELDCATALOG=&ordering=&searchphrase=all) , CL_SALV_EX_UTIL (/component/search/?

searchword=CL_SALV_EX_UTIL&ordering=&searchphrase=all) , CL_SALV_BS_TT_UTIL (/component/search/?

searchword=CL_SALV_BS_TT_UTIL&ordering=&searchphrase=all) , SCMS_XSTRING_TO_BINARY (/component/search/?

searchword=SCMS_XSTRING_TO_BINARY&ordering=&searchphrase=all)

http://abapblog.com/articles/tricks/33-create-xlsx-mhtml-file-from-internal-table-in-background 1/12
4/4/2018 ABAPblog.com - Create XLSX/MHTML file from internal table in background

109 Comments

I think that any of us had meet the situation when we needed to create an Excel output from internal table in background. There is a really nice project called
ABAP2XLSX which gives you to possibility to do all you need but in some case you won't be allowed to install ABAP2XLSX at you SAP instance. Don't worry there is a
way to do it, but in older SAP version we will be allowed only to save the file as MHTML excel (like in ALV->Export to Spreadsheet). In newest version we're able save
the file directly to XLSX also. In a method shown bellow you can see that to create Excel file you need to only pass internal table, the rest of the parameters are option
which gives you opurtinity to pass the settings you've made in your program to the output file.

So what am I doing here.... firstly I check if the fieldcatalog was passed. If not then I create it on a base of internal table with usage of cl_salv_table and
cl_salv_controller_metadata=>get_lvc_fieldcatalog. After I finally have the fieldcatalog I create result table with sort and filter criteria if they were passed. To
do that I use class cl_salv_ex_util. At the end result table is transformed to xstring with method cl_salv_bs_tt_util=>if_salv_bs_tt_util~transform. So
you're receiving at the end of the method an xstring file so you can do what you want with it, for example send via mail to the user, or save it on local PC (like in the
example found at the end). The most important is that you can use this method in a background so you can prepare some jobs for your programs and send
results of them to the users!

Importing:

it_fieldcat type lvc_t_fcat optional -> field catalog for list viewer control
it_sort type lvc_t_sort optional -> alv control: table of sort criteria
it_filt type lvc_t_filt optional -> alv control: table of filter conditions
is_layout type lvc_s_layo optional -> alv control: layout structure
i_xlsx type flag optional -> create xlsx file?

Changing:

ct_data type standard table -> our internal table

Exporting:

e_xstring type xstring -> xstring with our excel file

Implementation:

method create_xls_from_itab.

data: mt_fcat type lvc_t_fcat.


data: mt_data type ref to data.
data: m_flavour type string.
data: m_version type string.
data: mo_result_data type ref to cl_salv_ex_result_data_table.
data: mo_columns type ref to cl_salv_columns_table.
data: mo_aggreg type ref to cl_salv_aggregations.
data: mo_salv_table type ref to cl_salv_table.
data: m_file_type type salv_bs_constant.
field-symbols <tab> type any table.

get reference of ct_data into mt_data.

*if we didn't pass fieldcatalog we need to create it


if it_fieldcat[] is initial.
assign mt_data->* to <tab>.
try .
cl_salv_table=>factory(
exporting
list_display = abap_false
importing
r_salv_table = mo_salv_table
changing
t_table = <tab> ).
catch cx_salv_msg.

endtry.
"get colums & aggregation infor to create fieldcat
mo_columns = mo_salv_table->get_columns( ).
mo_aggreg = mo_salv_table->get_aggregations( ).
mt_fcat = cl_salv_controller_metadata=>get_lvc_fieldcatalog(
r_columns = mo_columns
r_aggregations = mo_aggreg ).
else.
*else we take the one we passed
mt_fcat[] = it_fieldcat[].
endif.

if cl_salv_bs_a_xml_base=>get_version( ) eq if_salv_bs_xml=>version_25 or
cl_salv_bs_a_xml_base=>get_version( ) eq if_salv_bs_xml=>version_26.

mo_result_data = cl_salv_ex_util=>factory_result_data_table(
r_data = mt_data
s_layout = is_layout
t_fieldcatalog = mt_fcat
t_sort = it_sort
t_filter = it_filt
).

case cl_salv_bs_a_xml_base=>get_version( ).
when if_salv_bs_xml=>version_25.
m_version = if_salv_bs_xml=>version_25.
when if_salv_bs_xml=>version_26.
m_version = if_salv_bs_xml=>version_26.

http://abapblog.com/articles/tricks/33-create-xlsx-mhtml-file-from-internal-table-in-background 2/12
4/4/2018 ABAPblog.com - Create XLSX/MHTML file from internal table in background
endcase.

"if we flag i_XLSX then we'll create XLSX if not then MHTML excel file
if i_xlsx is not initial.
m_file_type = if_salv_bs_xml=>c_type_xlsx.
else.
m_file_type = if_salv_bs_xml=>c_type_mhtml.
endif.

m_flavour = if_salv_bs_c_tt=>c_tt_xml_flavour_export.
"transformation of data to excel
call method cl_salv_bs_tt_util=>if_salv_bs_tt_util~transform
exporting
xml_type = m_file_type
xml_version = m_version
r_result_data = mo_result_data
xml_flavour = m_flavour
gui_type = if_salv_bs_xml=>c_gui_type_gui
importing
xml = e_xstring.
endif.
endmethod.

Example of use:

report zab_mhtml_xls.

data: gt_file type filetable with header line.


data: g_rc type i.
data: gt_spfli type standard table of spfli.
data: g_xstring type xstring.
data: g_size type i.
data: gt_bintab type solix_tab.
data: g_filename type string.
data: g_path type string.
"get path
parameters: p_path type string obligatory.

at selection-screen on value-request for p_path.

cl_gui_frontend_services=>file_save_dialog(
exporting
* window_title = window_title
default_extension = 'XLS'
* default_file_name = default_file_name
* with_encoding = with_encoding
* file_filter = file_filter
* initial_directory = initial_directory
* prompt_on_overwrite = 'X'
changing
filename = g_filename
path = g_path
fullpath = p_path
* user_action = user_action
* file_encoding = file_encoding
exceptions
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
others = 4
).
if sy-subrc <> 0.
* Implement suitable error handling here
endif.

start-of-selection.
"fill table with data
select * from spfli into corresponding fields of table gt_spfli.

"call creation of xls


zcl_abapblog_com=>create_xls_from_itab(
* exporting
* it_fieldcat = it_fieldcat
* it_sort = it_sort
* it_filt = it_filt
* is_layout = is_layout
* i_xlsx = 'X'
importing
e_xstring = g_xstring
changing
ct_data = gt_spfli
).

if g_xstring is not initial.


"save file
call function 'SCMS_XSTRING_TO_BINARY'
exporting
buffer = g_xstring
* APPEND_TO_TABLE = ' '
importing
output_length = g_size
tables
binary_tab = gt_bintab.

cl_gui_frontend_services=>gui_download(
exporting
bin_filesize = g_size
filename = p_path
filetype = 'BIN'
changing

http://abapblog.com/articles/tricks/33-create-xlsx-mhtml-file-from-internal-table-in-background 3/12
4/4/2018 ABAPblog.com - Create XLSX/MHTML file from internal table in background
data_tab = gt_bintab
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.
* Implement suitable error handling here
endif.

endif.

Enjoy!

109 Comments ABAPblog.com 


1 Login

Sort by Newest
 Recommend 9 ⤤ Share

Join the discussion…

LOG IN WITH
OR SIGN UP WITH DISQUS ?

Name

Petr Bureš • 22 days ago


Hello Lukasz,

thank you for your article.

I have one qustion, do you think the excel file can be created as "read only" file?
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > Petr Bureš • 22 days ago


Hello Petr,
Unfortunately not. I think you can achieve this only with abap2xlsx.

Cheers
Łukasz
△ ▽ • Reply • Share ›

Suresh Kumar • 3 months ago


Hi Lukasz,

Fantastic Blog, is this solution suitable for reading XLS/XLSX files from Application server ?
That would be great if its possible?any workarounds?, because I have requirement to read password protected workbooks from AL11 directly,
which is not possible even through ABAP2XLSX library too.

Cheers,
Suresh Kumar
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > Suresh Kumar • 3 months ago


Hi @Suresh Kumar ,
you cannot read xlsx with this functionality. It's only to write.
Cheers
Łukasz
△ ▽ • Reply • Share ›

eley2077 • 4 months ago


Hallo, Ich bekomme immer wieder folgende Excel Reparaturen Meldung bevor Excel sich öffnet.

Excel hat die Überprüfung und Reparatur auf Dateiebene abgeschlossen. Einige Teile dieser Arbeitsmappe wurden repariert oder verworfen.
http://abapblog.com/articles/tricks/33-create-xlsx-mhtml-file-from-internal-table-in-background 4/12
4/4/2018 ABAPblog.com - Create XLSX/MHTML file from internal table in background
ce at d e Übe p ü u g u d epa atu au ate ebe e abgesc osse ge e e d ese be ts appe u de epa e t ode e o e

woran liegt das? Version? ich benutze Excel Professional 2013 und 2016. Vielen Dank
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > eley2077 • 4 months ago


Usually the problem is the way of converting the xstring to binary, but as I don't have Excel 2013 & 2016 I cannot confirm it. Maybe you
can also check in your system if you have other if_salv_bs_xml versions?
case cl_salv_bs_a_xml_base=>get_version( ).
when if_salv_bs_xml=>version_25.
m_version = if_salv_bs_xml=>version_25.
when if_salv_bs_xml=>version_26.
m_version = if_salv_bs_xml=>version_26.
endcase.
△ ▽ • Reply • Share ›

eley2077 > Łukasz Pęgiel • 4 months ago


thank you 4 ur answer.
I got here the value m_version = 2.6 . also Version 26. I am thinking to Change it to 2.7.
What do u think?
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > eley2077 • 4 months ago


If you have 2.7 in IF_SALV_BS_XML then I would try :)
△ ▽ • Reply • Share ›

eley2077 > Łukasz Pęgiel • 4 months ago


Schlechter geworden. Excel hat die Datei nicht mal geöffnet.

The get_Version method result is 2.6. I chanded it to 2.7. after then Excel could not open the file.

I used fot Converting to binary this Function modul:

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = i_file

TABLES

binary_tab = lt_binary_file.
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > eley2077 • 4 months ago


Oh, here you can have problem - > the lenght. Add importing output_length = xstrlen( i_file ) to your FM or calculate the
lenght earlier if FM will not allow to use xstrlen directly.
△ ▽ • Reply • Share ›

eley2077 > Łukasz Pęgiel • 4 months ago


hmm, what should i do with the Output_length?
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > eley2077 • 4 months ago


calculate the lenght of xstring and pass it there.
△ ▽ • Reply • Share ›

eley2077 > Łukasz Pęgiel • 4 months ago


thank you. it works now.
I made the Calculation bevor I pass the Output_length to the FM alone like this
------------
DESCRIBE TABLE lt_binary_file LINES l_length_of_binary
l_length_of_binary = l_length_of_binary * 255.
--------------
Now I Pass dirctly the Output_length to the FM and it works.
It war my fault.
△ ▽ • Reply • Share ›

Manoj Sahu • 4 months ago


Hello Lukasz,
Thanks a lot for your article.
It fulfill my requirement.

Now my concern is how to send 'xlsx' file as a attachment.


I would be very thankful if you could give me any idea on it.

Warm Regards
http://abapblog.com/articles/tricks/33-create-xlsx-mhtml-file-from-internal-table-in-background 5/12
4/4/2018 ABAPblog.com - Create XLSX/MHTML file from internal table in background
Warm Regards,
Manoj Sahu.
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > Manoj Sahu • 4 months ago


Hi Manoj,
please search for CL_BCS class usage example or use this class http://abapblog.com/article....

Cheers
Łukasz
△ ▽ • Reply • Share ›

Manoj Sahu > Łukasz Pęgiel • 4 months ago


Hello Lukasz,
Thank you so much again for your guidance and quick reply.

Manoj.
△ ▽ • Reply • Share ›

ABAP_JUNIOR • 5 months ago


Hi Lukasz,
thanks for the article.
I have a question from you .

I should create Excel with more sheet . I have three internal Tables and for everyone i have create xls File.
Now Before downloading, i would create one file excel with 3 Sheets (because i have three internal tables) .
How can i concatenate the different xstring in my different Sheet ??
Can u help me???
Thanks man
ABAP Junior
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > ABAP_JUNIOR • 5 months ago


Hello,
it's not possible to concatenate the xstring in order to get 3 worksheets instead of 3 workbooks. Having more then one worksheet is only
possible when you use OLE or ABAP2XLSX, not with this methodology.
Cheers
Łukasz
△ ▽ • Reply • Share ›

Dheeru • 7 months ago


Hi Lukasz,

It's was really a very good article. Thanks for sharing this to everyone.

I had a question on email attachment, Prasad helped me on that part. I am facing a issue now. I ran for two sets of data
1) which has 10K records - result was successful(able to open attachment).
2) which has 30K records - can see the attachment but unable to open it. I get the error as 'Database error for <get data="" from="" kpro=""> <>'. I
am assuming this might be due to large file size. I tried to implement the file ZIP logic, but something went wrong. Can you please suggest me
with the logic or any logic I can implement.

Thanks,
Dheeru.
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > Dheeru • 7 months ago


Hello Dheru,
It may be that you have some problematic content in one of the cells, so it makes the workbook not readable. It could be also there
limitation of this method. To be honest I was using it always in smaller sets < 5000 entries, so it was working for me correctly.

I doubt that its because the number of entries.

Cheers
Łukasz
△ ▽ • Reply • Share ›

Dheeru > Łukasz Pęgiel • 7 months ago


Hi Lukasz,

Yeah, the size was the reason why I was unable to open the file. As I cant send 1 large file, I am splitting up the file into multiple
files and sent them. Thank you very much once again for the useful article.
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > Dheeru • 7 months ago


Good to know in case of future usage :) Tnx
△ ▽ • Reply • Share ›
http://abapblog.com/articles/tricks/33-create-xlsx-mhtml-file-from-internal-table-in-background 6/12
4/4/2018 ABAPblog.com - Create XLSX/MHTML file from internal table in background

Prasad Patil • 7 months ago


Very nicely explained and very useful. I was facing a problem while opening xlsx sent through an attachment. Tried your approach of converting
the internal table data to xlsx format and it worked! Thanks a ton for sharing this..
1△ ▽ • Reply • Share ›

Dheeru > Prasad Patil • 7 months ago


Hi Prasad,

Can you please share me the code, how to send the xlsx as attachement.
△ ▽ • Reply • Share ›

Prasad Patil > Dheeru • 7 months ago


Hello Dheeru,

You can refer Łukasz code upto FM SCMS_XSTRING_TO_BINARY which will give you a binary table. After that use the following
code :

data send_request type ref to cl_bcs.


data document type ref to cl_document_bcs.
data l_document type ref to cl_document_bcs.

data recipient type ref to if_recipient_bcs.


data sender type ref to if_sender_bcs.
data bcs_exception type ref to cx_bcs.
data sent_to_all type os_boolean.

data : mailto type ad_smtpadr,


mailfrom type ad_smtpadr value 'abc@def.com',
gd_spool_nr like tsp01-rqident,
l_attcdoctype type soodk-objtp,
l_atttitle type sood-objdes.
see more

△ ▽ • Reply • Share ›

Dheeru > Prasad Patil • 7 months ago


Thank you very much Prasad for your time on posting the code. It fixed my issue. Thank you very much.
△ ▽ • Reply • Share ›

Prasad Patil > Dheeru • 7 months ago


Happy to be of some help to you!
You are most welcome.. :)
△ ▽ • Reply • Share ›

Lorenzo • 7 months ago


Many thanks! I have found your code very useful.
1△ ▽ • Reply • Share ›

Venumadhavan Boppudi • 8 months ago


Hello Łukasz Pęgiel
I have requirement where I need to change TAB name on excel created using this method.
Can you please suggest, whether we can achieve using this method ?
Venu M B
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > Venumadhavan Boppudi • 8 months ago


No, I don't think it's possible using this method. Sorry.
△ ▽ • Reply • Share ›

ANDRE EBONGUE • 9 months ago


hy Lukasz really gr8 job, but how can i manage if i don't want to have the headers in my file?
Thanx in advance
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > ANDRE EBONGUE • 9 months ago


Hi Andre,
To be honest I don't think it's possible with this functions although I'm not 100% sure as I never tried to do it this way.

Cheers
△ ▽ • Reply • Share ›

ANDRE EBONGUE > Łukasz Pęgiel • 9 months ago


Ok i'll try and let u know!

http://abapblog.com/articles/tricks/33-create-xlsx-mhtml-file-from-internal-table-in-background 7/12
4/4/2018 ABAPblog.com - Create XLSX/MHTML file from internal table in background
Le 15 juil. 2017 10:02, "Disqus" <notifications@disqus.net> a écrit :
△ ▽ • Reply • Share ›

Abaper Sap • a year ago


Hi Łukasz,

There isn't the attribute if_salv_bs_xml=>c_type_xlsx (old release).


Instead save XLSX, I have opted for HTML, but besides the table (OK), is exhibited the text: "MIME-Version: 1.0 X-Document-Type: Worksheet
Content-Type: multipart/related; ..."

How can I fix it? Thanks.

Is there another way to sent a XLSX by e-mail?


△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > Abaper Sap • a year ago


If you don't have abap2xlsx installed then you probably can't. But with MHTML I never had problems. It was always displayed correctly, but
you have to give it MHTM, MHTML or XLS extension, and then Excel will open it correctly.
△ ▽ • Reply • Share ›

Abaper Sap > Łukasz Pęgiel • a year ago


Hi, Łukasz.
So, just to be clear, is it necessary install abap2xlsx to use the attribute if_salv_bs_xml=>c_type_xlsx? Abap2xls installation,
change standard objects? Or, which SAP release does the c_type_xlsx exist?
I've thought this solution was applicable in the "case you won't be allowed to install ABAP2XLSX at you SAP instance" ..
△ ▽ • Reply • Share ›

eley2077 > Abaper Sap • a year ago


The Attribute (if_salv_bs_xml=>c_type_xlsx) is a constant . the value is '10'. I think, you can intiate/declare it alone.
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > eley2077 • a year ago


Even if you declare it alone, it will not create a XLSX for you and it will throw an error, because in older releases it's not
handled. I can't remember exatcly on which release it was added but definitelly in 7.40 it's there.

And yes this solution is applicable if you can't install abap2xlsx. Anyway you can always create mhtml version in older
releases and excel will read it correctly.
△ ▽ • Reply • Share ›

Abaper Sap > Łukasz Pęgiel • a year ago


Thanks, Łukasz, for your help.
I've solved the problem, it wasn't the best way, but ... I've saved a .XLSX using OLE2 and after open/read the binary file and
finally send it by BCS class. This way, the customer can read the .XLSX file on iphone (my initial problem).
Anyway, I will try to convince the customer to install abap2xls.
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > Abaper Sap • a year ago


That's really good idea. A perfect tool for such stuff!
△ ▽ • Reply • Share ›

eley2077 • a year ago


Hallo,

kann ich eine gespeicherte Layout Variante vom Typ SLIS_VARI übergeben?

Wie soll ich das machen, wenn das gehen würde.

Danke
------------
can i pass diyplay variant type SLIS_VARI ?
If it is possible, how can I do it?
Thank you
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > eley2077 • a year ago


You can use FM LVC_TRANSFER_FROM_SLIS to convert SLIS fiedlcatalog to LVC one :)
△ ▽ • Reply • Share ›

eley2077 > Łukasz Pęgiel • a year ago


Thank you for your answer.

http://abapblog.com/articles/tricks/33-create-xlsx-mhtml-file-from-internal-table-in-background 8/12
4/4/2018 ABAPblog.com - Create XLSX/MHTML file from internal table in background

To display the output table I use first:

1-factory method cl_salv_table=>factory(…)

2- then I use the get layout method

Data lo_table TYPE REF TO cl_salv_table.

Data lo_layout TYPE REF TO cl_salv_layout.

Lo_layout = lo_table-> get_layout ().

3- then I set the initial layout variant here

Lo_layout-> set_initial_layout (p_vari).

4- then I use the display method

Lo_table-> display ().

Now I dont want to use the display method, BUT the method

Zcl_abapblog_com => create_xls_from_itab

To generate Excel.

This works well BUT I can not pass the variant p_vari from type SLIS_VARI (disvariant-variant) to the
method create_xls_from_itab.
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > eley2077 • a year ago


Now I get it sorry.
It looks simple then, on 4th step please do:

data: lt_fcat type lvc_t_fcat.

lt_fcat = cl_salv_controller_metadata=>get_lvc_fieldcatalog(
r_columns = lo_table->get_columns( )
r_aggregations = lo_table->>get_aggregations( )
).
and now call of create_xls_from_itab.

It will then get currently set layout of SALV.


△ ▽ • Reply • Share ›

eley2077 > Łukasz Pęgiel • a year ago

△ ▽ • Reply • Share ›

eley2077 > eley2077 • a year ago


the Answer is:
I should use the FM: LVC_VARIANT_SELECT.
1△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > eley2077 • a year ago


Super, thanks for sharing !
△ ▽ • Reply • Share ›

eley2077 > Łukasz Pęgiel • a year ago


your welcome ;)
△ ▽ • Reply • Share ›

Berk Batur • a year ago


Hi Lukasz,
I used your code , it worked very well.. Thanks for helping..
△ ▽ • Reply • Share ›

Łukasz Pęgiel abapblog.com > Berk Batur • a year ago


I'm glad I could help :)
△ ▽ • Reply • Share ›

Load more comments

ALSO ON ABAPBLOG.COM

CMD_EI_API deletes contact persons? Battleships game (two players)


1 comment • 8 months ago 6 comments • 3 years ago
http://abapblog.com/articles/tricks/33-create-xlsx-mhtml-file-from-internal-table-in-background 9/12
4/4/2018 ABAPblog.com - Create XLSX/MHTML file from internal table in background
1 comment • 8 months ago 6 comments • 3 years ago
Randy Bach — Thank God I found this blog! And thank you too. I have Walid — Ok thanks Lukasz !!
Avatarsame issue and after much searching possibly now have the solution. Avatar

ABAP Favorites Eclipse plugin Speed up your coding with ABAP in Eclipse (SITWRO 2017
14 comments • 9 months ago session)
Łukasz Pęgiel — Hello Timo,Technically I think it should not be a 2 comments • 10 months ago
Avatarproblem. I'll check if I can add it easily just as line number or as full adt Łukasz Pęgiel — Probably yes, additionally SAP has based lot's of it's
link.Cheers Łukasz Avatartools on Eclipse, like for example Design studio. The most important it's
better than SAP GUI :-)

✉ Subscribe d Add Disqus to your siteAdd DisqusAdd 🔒 Privacy

back to top
Like 2 Tweet Share

Prev (/articles/tricks/38-copy-routing-create-on-a-base-of-existing-one) Next (/articles/tricks/27-subtotal-lines-of-alv-grid-oo-as-content-separator)

http://abapblog.com/articles/tricks/33-create-xlsx-mhtml-file-from-internal-table-in-background 10/12
4/4/2018 ABAPblog.com - Create XLSX/MHTML file from internal table in background

SAVE (http://abapblog.com/search/?searchword=SAVE&ordering=&searchphrase=exact&Itemid=102&option=com_search) READ


(http://abapblog.com/search/?searchword=READ&ordering=&searchphrase=exact&Itemid=102&option=com_search)

USER (http://abapblog.com/search/?
searchword=USER&ordering=&searchphrase=exact&Itemid=102&option=com_s
SETTINGS (http://abapblog.com/search/?
searchword=SETTINGS&ordering=&searchphrase=exact&Itemid=102&option=com_search) FALV

(http://abapblog.com/search/?
searchword=FALV&ordering=&searchphrase=exact&Itemid=102&option=com_sear
INFO (http://abapblog.com/search/?searchword=INFO&ordering=&searchphrase=exact&Itemid=102&option=com_search) ESRUO (http://abapblog.com/search/?
searchword=ESRUO&ordering=&searchphrase=exact&Itemid=102&option=com_search) COC1 (http://abapblog.com/search/?
searchword=COC1&ordering=&searchphrase=exact&Itemid=102&option=com_search) FEATURE (http://abapblog.com/search/?
searchword=FEATURE&ordering=&searchphrase=exact&Itemid=102&option=com_search) CHECK (http://abapblog.com/search/?
searchword=CHECK&ordering=&searchphrase=exact&Itemid=102&option=com_search) ABAP HTML (http://abapblog.com/search/?searchword=ABAP
HTML&ordering=&searchphrase=exact&Itemid=102&option=com_search) DESCRIBE (http://abapblog.com/search/?
searchword=DESCRIBE&ordering=&searchphrase=exact&Itemid=102&option=com_search) NAME (http://abapblog.com/search/?

ZDEMO (http://abapblog.com/search/?
searchword=NAME&ordering=&searchphrase=exact&Itemid=102&option=com_search)

searchword=ZDEMO&ordering=&searchphrase=exact&Itemid=102&option=com_search) FILL
(http://abapblog.com/search/?searchword=FILL&ordering=&searchphrase=exact&Itemid=102&option=com_search) MDPA (http://abapblog.com/search/?
FROM (http://abapblog.com/search/?
searchword=MDPA&ordering=&searchphrase=exact&Itemid=102&option=com_search)

searchword=FROM&ordering=&searchphrase=exact&Itemid=102&option=com_search) EBAN (http://abapblog.com/search/?


searchword=EBAN&ordering=&searchphrase=exact&Itemid=102&option=com_search) BAPI (http://abapblog.com/search/?
searchword=BAPI&ordering=&searchphrase=exact&Itemid=102&option=com_search) ROUTING (http://abapblog.com/search/?
DELETE (http://abapblog.com/search/?
searchword=ROUTING&ordering=&searchphrase=exact&Itemid=102&option=com_search)

searchword=DELETE&ordering=&searchphrase=exact&Itemid=102&option=com_search) MTK (http://abapblog.com/search/?


searchword=MTK&ordering=&searchphrase=exact&Itemid=102&option=com_search) DARKEST DARK THEME (http://abapblog.com/search/?searchword=DARKEST DARK
THEME&ordering=&searchphrase=exact&Itemid=102&option=com_search) RM07DOCS (http://abapblog.com/search/?
searchword=RM07DOCS&ordering=&searchphrase=exact&Itemid=102&option=com_search) SALV
(http://abapblog.com/search/?
searchword=SALV&ordering=&searchphrase=exact&Itemid=102&option=com_search)

Follow @abapblog

abapblog

Follow

abapblog.com
91 polubienia

Polub tę stronę Wyślij wiadomość

Bądź pierwszą osobą wśród znajomych, która to polubi

Laserowe usuwanie blizn Tychy (http://zofia.pegiel.pl/twarz/emerge)


Laserowe usuwanie zmarszczek Tychy (http://zofia.pegiel.pl/twarz/emerge)
Paznokcie hybrydowe Tychy (http://zofia.pegiel.pl/dlonie/paznokcie-hybrydowe)
Paznokcie tytanowe Tychy (http://zofia.pegiel.pl/dlonie/manicure-tytanowy)
Salon Kosmetyczny Tychy (http://zofia.pegiel.pl)
Trycholog Tychy (http://trycholog.tychy.pl)
Wypadanie włosów Tychy (http://trycholog.tychy.pl)

ABAP Favorites Eclipse plugin

(http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=3522403)

http://abapblog.com/articles/tricks/33-create-xlsx-mhtml-file-from-internal-table-in-background 11/12
4/4/2018 ABAPblog.com - Create XLSX/MHTML file from internal table in background

-38%

ABAP code and articles provided on http://abapblog.com (http://abapblog.com), if it is not statet otherwise, were created by Łukasz Pęgiel. You can use the code in your SAP instance for commercial and non-commercial use without any warranty from side of the
author. You cannot sell the code as a full program or a part of it.
Replicating of the articles and code is prohibited unless the agreement of the author is given to you.

Ads by Google Ads by Google Ads by Google

How to Export Download Converter And File

A Download A Background Check New Email Account Open

http://abapblog.com/articles/tricks/33-create-xlsx-mhtml-file-from-internal-table-in-background 12/12

Vous aimerez peut-être aussi