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: 

Function Module SO_OBJECT_SEND

Former Member
0 Kudos

Hi Gurus,

Can we send the attachments using Function Module 'SO_OBJECT_SEND'. ?

If so please do let me know the code for filling the attachment and using this FM.

Promise to reward points.

Thanks & Regards

Mac

5 REPLIES 5

Former Member
0 Kudos

Hi Mohan,

This might help u out.

REPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING LINE-SIZE 200.

DATA : BEGIN OF ITAB OCCURS 0,

PERNR LIKE PA0001-PERNR,

ENAME LIKE PA0001-ENAME,

END OF ITAB.

DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,

receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,

packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,

listobject LIKE abaplist OCCURS 10,

compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,

w_object_hd_change LIKE sood1,

compressed_size LIKE sy-index.

START-OF-SELECTION.

SELECT PERNR ENAME

INTO CORRESPONDING FIELDS OF TABLE ITAB

FROM PA0001

WHERE PERNR < 50.

LOOP AT ITAB.

WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50

SY-VLINE.

ENDLOOP.

  • Receivers

receiver_list-recextnam = 'EXTERNAL-MAIL-ID@YAHOO.COM'. "-->

  • EMAIL ADDRESS

RECEIVER_list-RECESC = 'E'. "<-

RECEIVER_list-SNDART = 'INT'."<-

RECEIVER_list-SNDPRI = '1'."<-

APPEND receiver_list.

  • General data

w_object_hd_change-objla = sy-langu.

w_object_hd_change-objnam = 'Object name'.

w_object_hd_change-objsns = 'P'.

  • Mail subject

w_object_hd_change-objdes = 'Message subject'.

  • Mail body

APPEND 'Message content' TO message_content.

  • Attachment

CALL FUNCTION 'SAVE_LIST'

EXPORTING

list_index = '0'

TABLES

listobject = listobject.

CALL FUNCTION 'TABLE_COMPRESS'

IMPORTING

compressed_size = compressed_size

TABLES

in = listobject

out = compressed_attachment.

DESCRIBE TABLE compressed_attachment.

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 = compressed_size.

APPEND packing_list.

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

object_hd_change = w_object_hd_change

object_type = 'RAW'

owner = sy-uname

TABLES

objcont = message_content

receivers = receiver_list

packing_list = packing_list

att_cont = compressed_attachment.

Reward if helpful.

Thankyou,

Regards.

Former Member
0 Kudos

Hi,

Yes.check below code.....

REPORT ZTSAPMAIL.

DATA: X_OBJECT_TYPE LIKE SOOD-OBJTP.

DATA: BEGIN OF X_OBJECT_HD_CHANGE.

INCLUDE STRUCTURE SOOD1.

DATA: END OF X_OBJECT_HD_CHANGE.

DATA: BEGIN OF X_OBJCONT OCCURS 10.

INCLUDE STRUCTURE SOLI.

DATA: END OF X_OBJCONT.

DATA: BEGIN OF X_OBJHEAD OCCURS 0.

INCLUDE STRUCTURE SOLI.

DATA: END OF X_OBJHEAD.

DATA: BEGIN OF RAW_HEAD.

INCLUDE STRUCTURE SORH.

DATA: END OF RAW_HEAD.

DATA: BEGIN OF X_RECEIVERS OCCURS 0.

INCLUDE STRUCTURE SOOS1.

DATA: END OF X_RECEIVERS.

PARAMETERS: RECEIVER LIKE X_RECEIVERS-RECNAM. " Name

*BUILD MESSAGE HEADER

MOVE 'Sort field goes here' TO X_OBJECT_HD_CHANGE-OBJSRT. " Sort field

MOVE 'Name of the object goes here' TO X_OBJECT_HD_CHANGE-OBJNAM. " Name

MOVE 'Document title goes here' TO X_OBJECT_HD_CHANGE-OBJDES. " Title

MOVE 'F' TO X_OBJECT_HD_CHANGE-OBJSNS. " Functional OBJECT

MOVE 'E' TO X_OBJECT_HD_CHANGE-OBJLA. " Language

Object type of the new document

MOVE 'RAW' TO X_OBJECT_TYPE.

CLEAR X_OBJCONT.

MOVE 'Contents of mail' TO X_OBJCONT-LINE.

APPEND X_OBJCONT.

CLEAR X_OBJCONT-LINE. APPEND X_OBJCONT.

MOVE 'More contents' TO X_OBJCONT-LINE.

APPEND X_OBJCONT.

MOVE 'Still more contents'

to x_objcont-line.

APPEND X_OBJCONT.

MOVE ' ' TO X_OBJCONT-LINE.

APPEND X_OBJCONT.

Specific header (Dependent on the object type, here RAW)

REFRESH X_OBJHEAD.

DESCRIBE TABLE X_OBJCONT LINES RAW_HEAD-RAWSIZ.

MOVE RAW_HEAD TO X_OBJHEAD.

APPEND X_OBJHEAD.

*RECEIVERS table

CLEAR X_RECEIVERS.

REFRESH X_RECEIVERS.

MOVE RECEIVER TO X_RECEIVERS-RECNAM. " Name

MOVE 'B' TO X_RECEIVERS-RECESC. " Receiver type

MOVE 'X' TO X_RECEIVERS-SNDCP. " Send as a copy

MOVE 'X' TO X_RECEIVERS-SNDEX. " EXPRESS DOCUMENT

APPEND X_RECEIVERS.

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

folder_id = 'OUTBOX'

forwarder = x_forwarder

object_fl_change = x_object_fl_change

OBJECT_HD_CHANGE = X_OBJECT_HD_CHANGE

object_id = x_object_id

OBJECT_TYPE = X_OBJECT_TYPE

OUTBOX_FLAG = 'X'

OWNER = SY-UNAME

store_flag = x_store_flag

importing

object_id_new = x_object_id_new

sent_to_all = x_sent_to_all "May need to use

TABLES

OBJCONT = X_OBJCONT

OBJHEAD = X_OBJHEAD

objpara = x_objpara

objparb = x_objparb

RECEIVERS = X_RECEIVERS.

Don't forget to reward if useful..

Former Member
0 Kudos

Hi,

Use FM SO_NEW_DOCUMENT_SEND_API1, Search in the SDN forum with same FM you will get example code.

Regards,

Satish

Former Member
0 Kudos

Hai ,

SAP supplies a function module 'SO_OBJECT_SEND' to allow you send SAPOffice mails from within your ABAP programs.

Just try this.

Author: Kevin Wilson

FUNCTION z_send_email_itab_uname.

*"----


""Local interface:

*" IMPORTING

*" VALUE(APPLICATION) LIKE SOOD1-OBJNAM

*" VALUE(EMAILTITLE) LIKE SOOD1-OBJDES

*" VALUE(RECEXTNAM) LIKE SOOS1-RECEXTNAM OPTIONAL

*" VALUE(SENDER) LIKE SOUD-USRNAM DEFAULT SY-UNAME

*" VALUE(UNAME) LIKE SOOS1-RECEXTNAM OPTIONAL

*" EXPORTING

*" VALUE(RETURN_CODE) LIKE SY-SUBRC

*" TABLES

*" TEXTTAB STRUCTURE SOLI

*"----


  • tables

TABLES: pa0105, "Employee detail for username and email address

usr21, "Login addition address data

adr6. "Address table for email addresses

*- local data declaration

DATA: ohd LIKE sood1,

oid LIKE soodk,

to_all LIKE sonv-flag,

t_uname LIKE sy-uname,

okey LIKE swotobjid-objkey.

DATA: BEGIN OF receivers OCCURS 0.

INCLUDE STRUCTURE soos1.

DATA: END OF receivers.

*- fill odh

CLEAR ohd.

ohd-objla = sy-langu.

ohd-objnam = application.

ohd-objdes = emailtitle.

ohd-objpri = 3.

ohd-objsns = 'F'.

ohd-ownnam = sy-uname.

IF NOT uname IS INITIAL.

  • Find personnel number of username

CONDENSE uname NO-GAPS.

WHILE uname CS ','.

t_uname = uname+0(sy-fdpos).

ADD 1 TO sy-fdpos.

SHIFT uname LEFT BY sy-fdpos PLACES.

PERFORM find_email_address USING t_uname

CHANGING recextnam.

ENDWHILE.

*Do the last record

IF uname <> space.

t_uname = uname.

PERFORM find_email_address USING t_uname

CHANGING recextnam.

ENDIF.

ENDIF.

*- send Email

IF NOT recextnam IS INITIAL.

CONDENSE recextnam NO-GAPS.

CHECK recextnam CS '@'.

ENDIF.

*- for every individual recipient send an Email

  • (see OSS message 0120050409/0000362105/1999)

WHILE recextnam CS ','.

PERFORM init_rec TABLES receivers.

READ TABLE receivers INDEX 1.

receivers-recextnam = recextnam+0(sy-fdpos).

ADD 1 TO sy-fdpos.

SHIFT recextnam LEFT BY sy-fdpos PLACES.

MODIFY receivers INDEX 1.

PERFORM so_object_send_rec

TABLES texttab receivers

USING ohd

sender.

ENDWHILE.

*- check last recipient in recipient list

IF recextnam <> space.

PERFORM init_rec TABLES receivers.

READ TABLE receivers INDEX 1.

receivers-recextnam = recextnam.

MODIFY receivers INDEX 1.

PERFORM so_object_send_rec

TABLES texttab receivers

USING ohd

sender.

ENDIF.

ENDFUNCTION.

----


  • FORM SO_OBJECT_SEND_REC *

----


FORM so_object_send_rec

TABLES objcont STRUCTURE soli

receivers STRUCTURE soos1

USING object_hd STRUCTURE sood1

sender LIKE soud-usrnam.

DATA: oid LIKE soodk,

to_all LIKE sonv-flag,

okey LIKE swotobjid-objkey.

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

extern_address = 'X'

object_hd_change = object_hd

object_type = 'RAW'

outbox_flag = 'X'

sender = sender

IMPORTING

object_id_new = oid

sent_to_all = to_all

office_object_key = okey

TABLES

objcont = objcont

receivers = receivers

EXCEPTIONS

active_user_not_exist = 1

communication_failure = 2

component_not_available = 3

folder_not_exist = 4

folder_no_authorization = 5

forwarder_not_exist = 6

note_not_exist = 7

object_not_exist = 8

object_not_sent = 9

object_no_authorization = 10

object_type_not_exist = 11

operation_no_authorization = 12

owner_not_exist = 13

parameter_error = 14

substitute_not_active = 15

substitute_not_defined = 16

system_failure = 17

too_much_receivers = 18

user_not_exist = 19

x_error = 20

OTHERS = 21.

IF sy-subrc <> 0.

CASE sy-subrc.

WHEN 1.

MESSAGE i999(b1) WITH 'Activer user does not exist.'

'Send Mail failed!'.

WHEN 2.

MESSAGE i999(b1) WITH 'Communication Failure.'

'Send Mail failed!'.

WHEN 3.

MESSAGE i999(b1) WITH 'Component not available.'

'Send Mail failed!'.

WHEN 4.

MESSAGE i999(b1) WITH 'Folder does not exist..'

'Send Mail failed!'.

WHEN 5.

MESSAGE i999(b1) WITH 'No authorization for folder.'

'Send Mail failed!'.

WHEN 6.

MESSAGE i999(b1) WITH 'Forwarder does not exist.'

'Send Mail failed!'.

WHEN 7.

MESSAGE i999(b1) WITH 'Note does not exist.'

'Send Mail failed!'.

WHEN 8.

MESSAGE i999(b1) WITH 'Object does not exist.'

'Send Mail failed!'.

WHEN 9.

MESSAGE i999(b1) WITH 'Object not sent.'

'Send Mail failed!'.

WHEN 10.

MESSAGE i999(b1) WITH 'No authorization for object.'

'Send Mail failed!'.

WHEN 11.

MESSAGE i999(b1) WITH 'Object type does not exist.'

'Send Mail failed!'.

WHEN 12.

MESSAGE i999(b1) WITH 'No authorization for operation.'

'Send Mail failed!'.

WHEN 13.

MESSAGE i999(b1) WITH 'Owner does not exist.'

'Send Mail failed!'.

WHEN 14.

MESSAGE i999(b1) WITH 'Parameter Error.'

'Send Mail failed!'.

WHEN 15.

MESSAGE i999(b1) WITH 'Substitute not active.'

'Send Mail failed!'.

WHEN 16.

MESSAGE i999(b1) WITH 'Substitute not defined.'

'Send Mail failed!'.

WHEN 17.

MESSAGE i999(b1) WITH 'System failure.'

'Send Mail failed!'.

WHEN 18.

MESSAGE i999(b1) WITH 'Too many receivers.'

'Send Mail failed!'.

WHEN 19.

MESSAGE i999(b1) WITH 'User does not exist.'

'Send Mail failed!'.

WHEN 20.

MESSAGE i999(b1) WITH 'Unknown error ocurred.'

'Send Mail failed!'.

WHEN 21.

MESSAGE i999(b1) WITH 'Unknown error ocurred.'

'Send Mail failed!'.

ENDCASE.

ENDIF.

ENDFORM.

*

*

*

*----


    • FORM INIT_REC *

*----


FORM init_rec TABLES receivers STRUCTURE soos1.

CLEAR receivers.

REFRESH receivers.

MOVE sy-datum TO receivers-rcdat .

MOVE sy-uzeit TO receivers-rctim.

MOVE '1' TO receivers-sndpri.

MOVE 'X' TO receivers-sndex.

MOVE 'U-' TO receivers-recnam.

MOVE 'U' TO receivers-recesc.

MOVE 'INT' TO receivers-sndart.

MOVE '5' TO receivers-sortclass.

APPEND receivers.

ENDFORM.

&----


*& Form find_email_address

&----


  • Returns the email address for a USERID whether they are an

  • employee or just a user.

----


  • <--P_RECEXTNAM Email address

  • -->P_UNAME USERID

----


FORM find_email_address USING p_uname

CHANGING p_recextnam LIKE soos1-recextnam.

DATA: t_pernr LIKE pa0105-pernr,

t_email LIKE pa0105-usrid_long.

  • STEP 1 - Find personnel number for UNAME

SELECT SINGLE pernr INTO t_pernr

FROM pa0105

WHERE subty = '0001' AND

endda >= sy-datum AND

begda <= sy-datum AND

usrid = p_uname.

  • Employee record found

IF sy-subrc = 0.

  • STEP 2 - Find email address for personnel number

SELECT SINGLE usrid_long INTO t_email

FROM pa0105

WHERE pernr = t_pernr AND

subty = '0022' AND

endda >= sy-datum AND

begda <= sy-datum.

IF sy-subrc = 0.

IF NOT p_recextnam IS INITIAL.

CONCATENATE p_recextnam t_email

INTO p_recextnam SEPARATED BY ','.

ELSE.

p_recextnam = t_email.

ENDIF.

ELSE. "Never found an email address for employee

      • WHO SHOULD WE SEND TO HERE??? ***

ENDIF.

  • Employee number not found. Search in ADR6 table

ELSE.

  • See if user name is in the username table.

  • i.e. The user is not an employee

SELECT SINGLE addrnumber persnumber

INTO (usr21-addrnumber, usr21-persnumber)

FROM usr21

WHERE bname = p_uname.

IF sy-subrc = 0.

  • Found user name now let's get the email address

SELECT SINGLE smtp_addr INTO t_email

FROM adr6

WHERE addrnumber = usr21-addrnumber AND

persnumber = usr21-persnumber.

IF sy-subrc <> 0 OR t_email IS INITIAL.

      • WHO SHOULD WE SEND TO HERE??? ***

ELSE. "Found email

IF NOT p_recextnam IS INITIAL.

CONCATENATE p_recextnam t_email

INTO p_recextnam SEPARATED BY ','.

ELSE.

p_recextnam = t_email.

ENDIF.

ENDIF.

ELSE. "UNAME just does not have an email address addigned at all

      • WHO SHOULD WE SEND TO HERE??? ***

ENDIF.

ENDIF.

ENDFORM. " find_email_address

Regards.

Sowjanya.B.

Former Member
0 Kudos

hi

good

go through these links,which will give you clear idea about

'SO_OBJECT_SEND'

http://www.thespot4sap.com/Articles/SAP_Mail_SO_Object_Send.asp

http://www.sap-img.com/fu016.htm

thanks

mrutyun^