cancel
Showing results for 
Search instead for 
Did you mean: 

Convert alv output to excel

former_member213535
Participant
0 Kudos

Hi everyone,

Can any one tell me step by step procedure to convert alv report in to excel format using coding and send that to any email...

I read many blogs but I could not get the procedure.

Thanks and Regards,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

You can check this code as an example and try to understand how it is working:

REPORT  ZR_EXCEL_EMAIL1.

INCLUDE ole2incl.                       "include

used for providing classes used for using create

object for creating application and worksheets

data: p_email   type somlreci1-receiver

                      value 'abct@gmail.com'.

data: begin of it001 occurs 0,

      bukrs type t001-bukrs,

      butxt type t001-butxt,

      end of it001.

data:   imessage type standard table of solisti1

with header line,

        iattach type standard table of solisti1 with

header line,

        ipacking_list like sopcklsti1 occurs 0 with

header line,

        ireceivers like somlreci1 occurs 0 with

header line,

        iattachment like solisti1 occurs 0 with

header line.

****Excel file declarations

DATA: application TYPE ole2_object,

       workbook TYPE ole2_object,

       sheet TYPE ole2_object,

       cells TYPE ole2_object,

       COLUMN TYPE OLE2_OBJECT.

start-of-selection.

  select bukrs butxt into table it001 from t001.

*  Populate table with detaisl to be entered into

.xls file

  perform build_xls_data .

*Populate message body text

  clear imessage.   refresh imessage.

  imessage = 'Please find attached excel file'.

  append imessage.

*Send file by email as .xls speadsheet

  perform send_email_with_xls tables imessage

                                      iattach

                                using p_email

                                      'Example Excel

Attachment'

                                      'XLS'

                                      'TestFileName'

                                    

'CompanyCodes'.

****************************************************

********************

*     Form  BUILD_XLS_DATA

****************************************************

********************

form build_xls_data .

* constants: con_cret type x value '0D',  "OK for

non Unicode

*            con_tab type x value '09'.   "OK for

non Unicode

*If you have Unicode check active in program

attributes thnen you will

*need to declare constants as follows

*class cl_abap_char_utilities definition load.

constants:

    con_tab  type c value

cl_abap_char_utilities=>horizontal_tab,

    con_cret type c value

cl_abap_char_utilities=>cr_lf.

  DATA: a type c VALUE ' '.

  data year type char4.

  data month type char2.

  data day type char2.

  year = sy-datum+0(4).

  month = sy-datum+4(2).

  day = sy-datum+6(2).

  data date_string type char10.

  concatenate day '.' month '.' year into

date_string.

  iattach = 'Active Contracts Status Report'.

  concatenate a a iattach con_cret con_cret into

iattach SEPARATED BY con_tab.

  concatenate con_cret iattach  into iattach.

  append  iattach.

  iattach = 'Dept: MGS'.

  concatenate con_cret iattach  into iattach.

  append  iattach.

  iattach = 'Issue Date:'.

  concatenate con_cret iattach date_string con_cret

into iattach.

  append  iattach.

  concatenate 'BUKRS' 'BUTXT'

         into iattach separated by con_tab.

  concatenate con_cret iattach into iattach.

  append  iattach.

loop at it001 .

    concatenate it001-bukrs it001-butxt

           into iattach separated by con_tab.

    concatenate con_cret iattach  into iattach.

    append  iattach.

  endloop .

endform.

****************************************************

********************

*     Form  SEND_EMAIL_WITH_XLS

****************************************************

********************

form send_email_with_xls tables pit_message

                                          pit_attach

                                    using p_email

                                          p_mtitle

                                          p_format

                                          p_filename

                                        

p_attdescription.

  data: xdocdata like sodocchgi1,

        xcnt type i.

*Fill the document data.

  xdocdata-doc_size = 1.

*Populate the subject/generic message attributes

  xdocdata-obj_langu = sy-langu .

  xdocdata-obj_name  = 'SAPRPT' .

  xdocdata-obj_descr = p_mtitle .

*Fill the document data and get size of attachment

  clear xdocdata.

  read table iattach index xcnt.

  xdocdata-doc_size = ( xcnt - 1 ) * 255 + strlen(

iattach ).

  xdocdata-obj_langu  = sy-langu.

  xdocdata-obj_name   = 'SAPRPT'.

  xdocdata-obj_descr  = p_mtitle.

  clear iattachment.  refresh iattachment.

  iattachment[] = pit_attach[].

*Describe the body of the message

  clear ipacking_list.  refresh ipacking_list.

  ipacking_list-transf_bin = space.

  ipacking_list-head_start = 1.

  ipacking_list-head_num = 0.

  ipacking_list-body_start = 1.

  describe table imessage lines ipacking_list-

body_num.

  ipacking_list-doc_type = 'RAW'.

  append ipacking_list.

*Create attachment notification

  ipacking_list-transf_bin = 'X'.

  ipacking_list-head_start = 1.

  ipacking_list-head_num   = 1.

  ipacking_list-body_start = 1.

  describe table iattachment lines ipacking_list-

body_num.

  ipacking_list-doc_type   =  p_format.

  ipacking_list-obj_descr  =  p_attdescription.

  ipacking_list-obj_name   =  p_filename.

  ipacking_list-doc_size   =  ipacking_list-body_num

* 255.

  append ipacking_list.

*Add the recipients email address

  clear ireceivers.  refresh ireceivers.

  ireceivers-receiver = p_email.

  ireceivers-rec_type = 'U'.

  ireceivers-com_type = 'INT'.

  ireceivers-notif_del = 'X'.

  ireceivers-notif_ndel = 'X'.

  append ireceivers.

  call function 'SO_DOCUMENT_SEND_API1'

       exporting

            document_data              = xdocdata

            put_in_outbox              = 'X'

            commit_work                = 'X'

       tables

            packing_list               =

ipacking_list

            contents_bin               = iattachment

            contents_txt               = imessage

            receivers                  = ireceivers

       exceptions

            too_many_receivers         = 1

            document_not_sent          = 2

            document_type_not_exist    = 3

            operation_no_authorization = 4

            parameter_error            = 5

            x_error                    = 6

            enqueue_er

former_member213535
Participant
0 Kudos

Hi,

Can you please elaborate on

1.   perform build_xls_data

2.    *Send file by email as .xls speadsheet

  perform send_email_with_xls tables imessage

                                      iattach

                                using p_email

                                      'Example Excel Attachment'

                                      'XLS'

                                      'TestFileName'

                                      'CompanyCodes'.

these parts of the program.

My requirement is "I have an alv output and I converted it to excel by using ALV_XXL_CALL. Now i want to send it to any mails.

Thaks and regards.

Former Member
0 Kudos

perform build_xls_data.  with this subroutine i am making excel data which is stored in the

iattach type standard table of solisti1 with header line

perform send_email_with_xls tables imessage

                                      iattach

                                using p_email

                                      'Example Excel Attachment'

                                      'XLS'

                                      'TestFileName'

                                      'CompanyCodes'.   with this subroutine i am sending email

in case you are using fm ALV_XXL_CALL then you are getting internal table which if downloaded then you'll get excel file. you have to download to user system and upload to server and then send email as attachment.

Therefore instead of using ALV_XXL_CALL follow this above mentioned method.

former_member213535
Participant
0 Kudos

Hi,

Shall i need to do any background job for this?

I did not get output.

Thank you,

SGeetha

Former Member
0 Kudos

Hi,

go to tcode sost and check email attachment.

jude_bradley
Advisor
Advisor
0 Kudos

Hello Singanamala,

This query is opened in FES-GUI,but does not belong there.

Please note that Function Module  ALV_XXL_CALL is not released for customer use,therefore, no support can be given from SAP if you use this.It's entirely at your own risk.

Regards,

Jude

former_member213535
Participant
0 Kudos

Hi,

Thank you for your answer.I got the output in SOST transaction. But I need to send that excel file to other emails with out going to other transactions.

Please help me in  this.

Thankk you.

Former Member
0 Kudos

Singanamala Geetha,

after fm 'SO_DOCUMENT_SEND_API1'

write this command

SUBMIT rsconn01 WITH mode = 'INT' WITH output = 'X' AND RETURN.

so that email goes out to the recepient from SAP system.

former_member213535
Participant
0 Kudos

Hi,

I tried that one but i did not get. Shall I need to do any settings for this one? If yes please let me know about that.

Thanks and Regards,

S.Geetha.

Former Member
0 Kudos

you have give to configure email server ip address in sap system so that it uses email server and sends it.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Singanamala,

         Please refer the below link :

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

Hope this will help you out.

Thanks & Regards,

Priya