cancel
Showing results for 
Search instead for 
Did you mean: 

send mail with business object link

Former Member
0 Kudos

Hi,

can anyone please tell me, how can i send a mail with an business object as an attachement. when i clik on attachment, it should execute the method of business object which will display the document.

it will be a great help,if any one can send the code.

Thanks,

naresh.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

You need classes CA_SAPUSER_BCS and CL_CAM_ADDRESS_BCS .

CLASS ca_sapuser_bcs DEFINITION LOAD.

CLASS cl_cam_address_bcs DEFINITION LOAD.

You require the following local variables:

DATA: send_request TYPE REF TO cl_bcs.

DATA: document TYPE REF TO cl_document_bcs.

DATA: sender TYPE REF TO cl_sapuser_bcs.

DATA: recipient TYPE REF TO if_recipient_bcs.

DATA: exception_info TYPE REF TO if_os_exception_info,

bcs_exception type ref to cx_bcs.

DATA: num_rows type i.

DATA: textlength type SO_OBJ_LEN.

First create a mail request:

send_request = cl_bcs=>create_persistent( ).

Create the mail sender:

  • Get sender object

sender = cl_sapuser_bcs=>create( sy-uname ).

  • Add sender

CALL METHOD send_request->set_sender

EXPORTING i_sender = sender.

You can define your mail address in this Web Application Server in the user maintenance.

The mail can be sent to one or more addresses:

  • Create recipient

data: c_address TYPE ADR6-SMTP_ADDR.

move mail_address to c_address.

recipient = cl_cam_address_bcs=>create_internet_address(

c_address ).

  • Add recipient with its respective attributes to send request

CALL METHOD send_request->add_recipient

EXPORTING

i_recipient = recipient

i_express = ' '

i_copy = ' '

i_blind_copy = ' '.

You receive the mail address as a string and you have to convert in into the required data type.

The mail is sent to one address only without any additional attributes.

You can now send the mail and write everything to the database.

  • Send document

CALL METHOD send_request->send( ).

COMMIT WORK.

You still have not taken any precautions against error situations.

You can take care of this by embedding the following code in a TRY – CATCH block:

try.

... Now the code comes after the creation of send_request up to the COMMIT WORK:

catch cx_bcs into bcs_exception.

if messages is not initial.

messages->add_message( condition = 'mail'

message =

'Error occurred while sending the mail' )."#EC NOTEXT

endif.

exit

endtry.

Reward if it is helpful.

Regards,

Rajesh

Former Member
0 Kudos

Hi,

Have a look at SAP standard program <b>RSWUWFML2</b>.

It sends the workitems in the workflow as attachments and the user is able to execute these work items directly from the inbox.

Hope it helps.

Regards,

Shashank