Skip to end of metadata
Go to start of metadata

Back to Sending Mails - Home Page

Author: Martin Lang
Submitted: Aug 3rd 2009

Prerequisites: Check for these Notes and apply if required:

Sample Code:

*& Report  ZAG_CAL_ICAL

report  z_appointment_to_outlook.

include <cntn01>.
type-pools: sccon.
data: mail type text40.

* Provide select option to enter multiple attendees
select-options: email for mail no intervals default ''.

data lo_appointment type ref to cl_appointment.
data ls_participant type scspart.
data lv_address type swc_object.
data ls_address_container like swcont occurs 0 with header line.
data lt_text type so_txttab.
data ls_text like line of lt_text.
data lv_location like scsappt-room.
data lo_send_request type ref to cl_bcs.
data lv_sent_to_all type os_boolean.

create object lo_appointment.

* Add multiple attendees
loop at email.
clear ls_participant.
swc_create_object lv_address 'ADDRESS' space.
swc_set_element ls_address_container 'AddressString' email-low.
swc_set_element ls_address_container 'TypeId' 'U'.
swc_call_method lv_address 'Create' ls_address_container.
check sy-subrc = 0.

* * get key and type of object
swc_get_object_key lv_address ls_participant-objkey.
check sy-subrc = 0.
swc_get_object_type lv_address ls_participant-objtype.
check sy-subrc = 0.
move sccon_part_sndmail_with_ans to ls_participant-send_mail.
ls_participant-comm_mode = 'INT'.
lo_appointment->add_participant( participant = ls_participant ).


* Sample Apppointment for specific date/time
*lo_appointment->set_date( date_from = '20090801'
*                          time_from = '130000'
*                           date_to = '20090801'
*                           time_to = '140000'
*                           ).

* Sample Appointment for All-Day-Event
lo_appointment->set_date( date_from = '20090803'
                          date_to = '20090803'

* Make appointment appear "busy"
lo_appointment->set_busy_value( sccon_busy_busy   ).

* Set Location
lo_appointment->set_location_string( 'Location' ).

* Set Organizer
lo_appointment->set_organizer( sy-uname ).

* "Type of Meeting" (value picked from table SCAPPTTYPE)
lo_appointment->set_type( 'ABSENT' ).

* Make this an all day event
lo_appointment->SET_VIEW_ATTRIBUTES( SHOW_ON_TOP  = 'X').

* Set Meeting body text
ls_text = 'This is the Body Text of the Appointment'.
append ls_text to lt_text.
lo_appointment->set_text( lt_text ).

* Set Meeting Subject
lo_appointment->set_title( 'This is the Appointment Subject' ).

* Important to set this one to space. Otherwise SAP will send a not user-friendly e-mail
lo_appointment->save( send_invitation = space ).

* Now that we have the appointment, we can send a good one for outlook by switching to BCS
lo_send_request = lo_appointment->create_send_request( ).

* don't request read/delivery receipts
lo_send_request->set_status_attributes( i_requested_status   = 'N'
                                        i_status_mail        = 'N'

* Send it to the world
lv_sent_to_all = lo_send_request->send( i_with_error_screen = 'X' ).

commit work and wait.


  1. Unknown User (jol6b4e)

    Thanks! Great code (wink)

  2. Unknown User (n1bc4sg)

    -Needs Note  1353329.  Thanks, should have found this before starting to write ugly code...