Application Development and Automation 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: 
Read only

Problem when emailing report output

Former Member
0 Likes
388

Hi friends,

I have created a program for sending output of report through email. Problem is, after execution, mail is not found in specified email-id.

Do it require any (basis or other) setting required.

Pl. guid me, I have given my code below . Points will be rewareded.

DATA:listobject LIKE abaplist OCCURS 0,

comsize LIKE sy-index,

comattach LIKE soli OCCURS 0 WITH HEADER LINE,

rec_list LIKE soos1 OCCURS 5 WITH HEADER LINE,

packing_list LIKE soxpl OCCURS 0 WITH HEADER LINE,

mess_con LIKE soli OCCURS 0 WITH HEADER LINE,

w_object LIKE sood1.

rec_list-recextnam = my gmail id " tried using cpital letter and small letters

rec_list-recesc = 'E'.

rec_list-sndart = 'INT'.

rec_list-sndpri = '1'.

APPEND rec_list.

w_object = sy-langu.

w_object = 'Object name'.

w_object = 'P'.

w_object = 'Message subject'.

APPEND 'Message content' TO mess_con.

CALL FUNCTION 'SAVE_LIST'

EXPORTING

LIST_INDEX = '0'

TABLES

listobject = listobject

  • EXCEPTIONS

  • LIST_INDEX_INVALID = 1

  • OTHERS = 2

.

IF sy-subrc <> 0.

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

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

ENDIF.

CALL FUNCTION 'TABLE_COMPRESS'

IMPORTING

COMPRESSED_SIZE = comsize

TABLES

in = listobject

out = comattach

  • EXCEPTIONS

  • COMPRESS_ERROR = 1

  • OTHERS = 2

.

IF sy-subrc <> 0.

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

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

ENDIF.

DESCRIBE TABLE comattach.

CLEAR packing_list.

packing_list-transf_bin = 'X'.

packing_list-head_start = 0.

packing_list-head_num = 0.

packing_list-body_start = 1.

packing_list-body_num = sy-tfill.

packing_list-objtp = 'ALI'.

packing_list-objnam = 'Object name'.

packing_list-objdes = 'Attachment description'.

packing_list-objlen = comsize.

APPEND packing_list.

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

OBJECT_HD_CHANGE = w_object

OBJECT_TYPE = 'RAW'

OWNER = SY-UNAME

TABLES

OBJCONT = mess_con

RECEIVERS = rec_list

PACKING_LIST = packing_list

ATT_CONT = comattach

.

IF sy-subrc <> 0.

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

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

ENDIF.

IF sy-subrc = 0.

MESSAGE 'Mail Sent' TYPE 'I'.

ENDIF.

Thanks in advance.

Regards,

s.senthilkumar

2 REPLIES 2
Read only

Former Member
0 Likes
351

check with transaction SOST if it is found there ..

Read only

Former Member
0 Likes
351

Hi,

data: p_email type somlreci1-receiver

value mail-id.

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.

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.

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_error = 7

others = 8.

endform.

Try this Code

Reward if useful.....

Thanks,

Durai.V