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: 

abap2xlsx output as mail attachment

former_member576008
Active Participant
0 Kudos
1,041

Hi,

My requirement is to send the ALV output as such (totals,sub totals,color..etc) as an excel file, using the great abap2xlsx code I am able to download the data to local system. I have used CL_BCS class to send email.

Could please help me how to send the output as email attachment.

Thanks.

Regards,

Nandha

6 REPLIES 6

Former Member
0 Kudos
245

hello,

You need to write the output required by the report. When you run your report as a background job a spool will be created for the output. Read this spool and convert the spool to a pdf document in your program and then send it as an attachment in the mail.

Following links for converting spool to pdf

https://scn.sap.com/thread/1339865

http://scn.sap.com/thread/1575251

http://scn.sap.com/thread/1615921

There is a program out there to convert spool to pdf and then mail it.

http://wiki.sdn.sap.com/wiki/display/Snippets/Convert+Spool+request+to+PDF+and+send+as+e-mail

best regards,

swanand

0 Kudos
245

Hi Swanand,

Thanks for your quick reply.

I need to send my output as XLS or XLSX attachment. Thats why i used the free code abap2xlsx to get totals and subtotals in excel file.

Is it possible ?

Regards,

Nandha

0 Kudos
245

CL_DOCUMENT_BCS has a method (ADD_ATTACHMENT) that can be used to add an attachment.

In my usage, I used GUI_UPLOAD to get the binary from the file, then added the binary as an attachment to the cl_document_bcs object I instanced.

Former Member
0 Kudos
245

Hi Nanda,

     you can use method add_attachment of class cl_document_bcs to add excel attachment to the mail. The attachment content should be in binary format (type solix_tab). Below code snippet should give you some idea.

     document->add_attachment (

          i_attachment_type     = 'xls'

          i_attachment_subject = 'TEST'

          i_attachment_size     = lsize

          i_attachment_content = xls_content ).

     Attachment content and the size can be obtained using method string_to_solix of class cl_bcs_convert. The below code shows the same.

     cl_bcs_convert->string_to_solix ( 

          EXPORTING

               iv_string       =  xls_content

               iv_codepage = '4103'

               iv_add_bom  = 'X'

          IMPORTING

               et_solix       = xls_content

               ev_size       = lsize ).

Hope this helps.

~Athreya

0 Kudos
245

Hi Athreya and Steve,

My issue is not sending an attachment using CL_BCS class.

ABAP2XLSX is generating the formatted excel and allowing us to save in local system, i want that document to be sent. That means how to get the binary content of it.

Please let me know if its not clear.

Regards,

Nandha

0 Kudos
245

For files from the client machine, I use this:

CALL FUNCTION 'GUI_UPLOAD'

         EXPORTING

           FILENAME                      = FILE_NAME

           FILETYPE                      = 'BIN'

         IMPORTING

           FILELENGTH                    = iLen

         TABLES

           DATA_TAB                      = BIN

         EXCEPTIONS

           FILE_OPEN_ERROR               = 1

           FILE_READ_ERROR               = 2

           NO_BATCH                      = 3

           GUI_REFUSE_FILETRANSFER       = 4

           INVALID_TYPE                  = 5

           NO_AUTHORITY                  = 6

           UNKNOWN_ERROR                 = 7

           BAD_DATA_FORMAT               = 8

           HEADER_NOT_ALLOWED            = 9

           SEPARATOR_NOT_ALLOWED         = 10

           HEADER_TOO_LONG               = 11

           UNKNOWN_DP_ERROR              = 12

           ACCESS_DENIED                 = 13

           DP_OUT_OF_MEMORY              = 14

           DISK_FULL                     = 15

           DP_TIMEOUT                    = 16

           OTHERS                        = 17

           .

For files on the application server I use the following (this is extracted from a method I wrote, so some variables are members of the class, not local). For the below method, I did test using excel files stored on the application server, however, they were uploaded through CG3Z, not built the same way as yours:

   DATA:

     SOLIX  TYPE SOLIX,

     BIN    TYPE SOLIX_TAB,

     iLen   TYPE I VALUE 0,

     iExt   TYPE I VALUE 0,

     iFil   TYPE I VALUE 0,

     iTmp   TYPE I VALUE 0

     .

       OPEN DATASET FILE_NAME

         FOR INPUT

         IN BINARY MODE .

     IF sy-subrc <> 0 .

          " Handle exception

     ENDIF .

     DO .

       READ DATASET FILE_NAME INTO SOLIX LENGTH iLen .

       SUBRC = SY-SUBRC .

       M_SIZE = M_SIZE + iLen .               " Aggregate Length to get total length for file

       APPEND SOLIX TO BIN .                    " This is your file contents in Binary

       IF SUBRC <> 0 .

         EXIT .

       ENDIF .

     ENDDO .

       CLOSE DATASET FILE_NAME .

         IF sy-subrc <> 0 .

               " Handle Exception

          ENDIF .



I'm afraid if these methods don't work, I do not have any further ideas. Good Luck!