This sample code demonstrates how to send Appointments or Meetings Requests to Microsoft Outlook directly from Sap. There are many possible ways to use this, one very logical and helpful use is to automatically send “vacation”/Leave of absence appointments back to a respective employee and his manager after vacation/leave request approval in SAP HCM.
Sending eMails is a very basic Standard functionality. Sending appointments/meeting requests however, also directly from SAP is something more unique, but it’s supported nonetheless and can be very useful e.g. for Automatically Sending “vacation”/Leave of absence appointments back to the employee and his manager after vacation/leave request approval Automatically sending resubmission/follow-up appointments e.g. x days before contract expiration…
Sending out Appointments to e.g. Microsoft Outlook essentially makes use of the ABAP Class CL_APPOINTMENT.
The Class should exist and work on systems SAP NetWeaver 6.20 and higher.
Short Text of Note
Incorrect display of ICS documents
iCalendar document that is sent is processed incorrectly
Title of sent appointment is incorrect
All‐Day Appointment doesn’t appear correctly in Outlook
Note: Implement these notes with transaction SNOTE, which automatically checks for the applicability basedm on your current versions/patchlevels
Overview and Result
The program below is a sample to demonstrate how appointments can be sent touching on many of the available options like:
Define Appointment Subject, Location & Body Long Text
Specify Start/End Date/Time
Define “Show as”: Free, Busy etc.
This screenshot represents an appointment sent through the sample code below and received with Microsoft Outlook 2007:
Sample code for demonstration purposes:
*& Report z_appointment_to_outlook. *&
* Version for R/3 4.7 developed by Pedrocchi Dario
REPORT z_appointment_to_outlook. INCLUDE <cntn01>.
DATA: mail TYPE text40.
* Provide select option to enter multiple attendees
SELECTION-SCREEN: BEGIN OF BLOCK org.
SELECT-OPTIONS: email FOR mail NO INTERVALS
SELECTION-SCREEN: END OF BLOCK org.
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.
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 ).
ENDLOOP. ** 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’ ).
lo_appointment->set_location( ‘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.