Skip to Content
0

Infoset Query report output as excel attached mail(in background - more than 255 char)

Jun 06, 2017 at 10:57 AM

140

avatar image

I am trying to send email with excel attachment for the output of a Query report program, which is run in background. I am able to achieve this for a line width less than or equal to 255 chars, but not more than that. As we will be running Infoset Queries with dynamic variant, wide lists, need a solution for this.

I have tried the below 2 approaches:

1. Writing the query output to the spool and sending this as excel attachments using FMs:

a. RSPO_RETURN_ABAP_SPOOLJOB

b. SO_RAW_TO_RTF

c. SCMS_STRING_TO_XSTRING

d. SCMS_XSTRING_TO_BINARY

e. SO_NEW_DOCUMENT_ATT_SEND_API1

But, the excel file is getting truncated with limited width of 255 char.

2. Getting runtime ALV object using:

cl_salv_bs_runtime_info=>get_data(
IMPORTING
t_data = <lt_data>.

But, the datatype of the alv report(field catalog) is unknown/dynamic. So I am not getting the way to fetch the obtained data, convert into excel for sending email.

Please suggest a way to achieve this, if anybody has encountered such a situation.

Thank you,

Namrata

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Raymond Giuseppi
Jun 06, 2017 at 02:02 PM
1

cl_salv_bs_runtime_info is also able to retrieve the field catalog and more informations (cl_salv_bs_runtime_info=>get_metadata) to analyze the returned dynamic internal table (cl_salv_bs_runtime_info=>get_data[_ref]). You could then use class like cl_salv_ex_util, cl_salv_bs_tt_util to generate dynamically an xml (type mhtml) attachment.

* Get ref to data
lr_data = cl_salv_bs_runtime_info=>get_data_ref( ).
* Get metadata (layout)
ls_metadata = cl_salv_bs_runtime_info=>get_metadata( ).
* Rebuild the ALV
lr_result_data = cl_salv_ex_util=>factory_result_data_table(
  r_data                 = lr_data
  s_layout               = ls_metadata-s_layout
  t_fieldcatalog         = ls_metadata-t_fcat
  t_sort                 = ls_metadata-t_sort
  t_filter               = ls_metadata-t_filter ).
* Convert to mhtml/xml
cl_salv_bs_tt_util=>if_salv_bs_tt_util~transform(
  EXPORTING
    xml_version   = if_salv_bs_xml=>version
    r_result_data = lr_result_data
    xml_type      = if_salv_bs_xml=>c_type_mhtml
    xml_flavour   = if_salv_bs_c_tt=>c_tt_xml_flavour_export
    gui_type      = if_salv_bs_xml=>c_gui_type_gui
  IMPORTING
    xml           = lv_xml ).

You should be able to adapt for your requirements just by setting some break-points and debug an export to mhtml from any standard ALV grid program of your system.

Show 5 Share
10 |10000 characters needed characters left characters exceeded

Thank you for your suggestion Raymond.

I am looking for excel attachment to be sent via email. Is there any way/class to generate excel attachment in the similar way?

0

Sure, you can use community tools like Abap2xlsx or in recent versions a class like CL_XLSX_DOCUMENT. Or use the same tools that you used in 'I am able to achieve this for a line width less than or equal to 255 chars'?

0

I tried the logic accessing the result in the internal table. But, lr_result_data does not hold the values from the ALV output(snapshot below). How can the dynamic data from lr_data be converted to internal table for sending email? The format of the internal table is unknown and dynamic. It depends on the infoset query variant.

I was able to achieve it , converting data to string which was written in spool, then to ascii and sent excel via email which had limitation of 255 char(approach no. 1 explained in the question)

itab.png (24.0 kB)
0

You could convert the xml to Excel or use method get_data and not get_data_ref, or use a dummy printer that allows a report width of 1023...


1

Hi Raymond,

I have used the method get_data() and I can see the data in a reference variable <lt_data> using the following code in debugging mode.

But I am not getting how to obtain the data in a suitable internal table, as this will dynamic, based on the query variants.

Also, I did not find any class like CL_XLSX_DOCUMENT.

cl_salv_bs_runtime_info=>get_data(IMPORTINGt_data = <lt_data>.
0
Sandra Rossi Jun 08, 2017 at 06:17 AM
0

As Raymond said: "use a dummy printer that allows a report width of 1023..." (1023 is the max width of an ABAP list spool)

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Sandra,

Thanks for your reply! Please would you elaborate on how to use the dummy printer with 1023 report width?

0

There is a "format type" available in the print dialog (this print dialog may be displayed when you run the query in background). You may create a format type using transaction SPAD, define it as being a list format, with width 1023.

0