Examples
Definition
The following examples show how you work with the class CL_APPOINTMENTS. The associated reports are also available in the SAP System as of Web Application Server Release 6.10.
The reports in the system may be slightly different to those here because they are constantly being further developed.
Creating a simple appointment for yourself
A user reserves an hour for their lunch today.
REPORT rssc_demo_cl_appointment_SIMPL .
*** Create an appointment for me at noon for lunch
*** Let system determine my own time zone
DATA appointment TYPE REF TO cl_appointment.
*DATA participants TYPE standard table of scspart.
DATA participant TYPE scspart.
DATA title LIKE scsappt-txt_short.
DATA location LIKE scsappt-room.
CREATE OBJECT appointment.
* set actual user as participant of appointment
CLEAR participant.
MOVE sy-uname TO participant-participan.
CALL METHOD appointment->add_participant( participant = participant ).
* set title and location
Move 'Lunch'(001) to title.
CALL METHOD appointment->set_title( title ).
move 'Canteen'(002) to location.
CALL METHOD appointment->set_location( location ).
* set date and time using default settings
* date_to will be the same as date_from
* time zone will be the one from the user master records settings
CALL METHOD appointment->set_date( date_from = sy-date
time_from = '120000'
time_to = '130000' ).
* save appointment on data base using default values
* for all other properties
CALL METHOD appointment->save.
Periodic all-day appointments with external participants
This report shows how you can add external persons as participants for an appointment so that they are informed of an appointment request.
The use of appointment rules and appointment attributes is also demonstrated.
REPORT rssc_demo_cl_appointment_perio .
* schedule a periodical event with me and some users on the internet
* the event will take nearly the whole day but doesn't hinder other
* meeting necessarily, hence mark the time as "not busy"
* So it has to appear at top of the calendar entries
* one of the users is optional only and should not be informed by mail
INCLUDE <cntn01>.
Type-pools: SCCON.
DATA appointment TYPE REF TO cl_appointment.
DATA participant TYPE scspart.
DATA address TYPE swc_object.
DATA address_container LIKE swcont OCCURS 0 WITH HEADER LINE.
DATA text TYPE SO_TXTTAB.
DATA title LIKE scsappt-txt_short.
DATA location LIKE scsappt-room.
DATA rule TYPE REF TO cl_appointment_rule.
CREATE OBJECT appointment.
* set actual user as participants of appointment
CLEAR participant.
MOVE sy-uname TO participant-participan.
CALL METHOD appointment->add_participant( participant = participant ).
* set an internet address as a second participant of that appointment
CLEAR participant.
swc_create_object address 'ADDRESS' space.
swc_set_element address_container 'AddressString'
'testuser@nowhere.com'.
swc_set_element address_container 'TypeId' 'U'.
swc_set_element address_container 'NoAdradmi' 'X'.
swc_set_element address_container 'NoIntern' 'X'.
swc_call_method address 'Create' address_container.
CHECK sy-subrc = 0.
* * get key and type of object
swc_get_object_key address participant-objkey.
CHECK sy-subrc = 0.
swc_get_object_type address participant-objtype.
CHECK sy-subrc = 0.
move sccon_part_sndmail_with_ans to participant-send_mail.
CALL METHOD appointment->add_participant( participant = participant ).
* third user is an external business partner
* caution: the following values won't work in a real system and need
* to be replaced by correct application values
CLEAR participant.
* * set business object instance
move 'MyPartner' to participant-objtype.
move '1234567890' to participant-objtype.
* * set address of business object from ZAV
move '0000000001' to participant-addrnumber.
move '0000000002' to participant-persnumber.
move 'INT' to participant-comm_mode. "via Internet
move '001' to participant-consnumber. "first Internetaddress
* * this user is only optional and should not get a mail
move sccon_part_role_optional to participant-role.
move sccon_part_sndmail_no to participant-send_mail.
* set title and location
Move 'Hotline'(001) to title.
CALL METHOD appointment->set_title( title ).
move 'HL Room'(002) to location.
CALL METHOD appointment->set_location( location ).
* set date and time using default settings
* date_to will be the same as date_from
* time zone will be the one from the user master records settings
CALL METHOD appointment->set_date( date_from = sy-date
time_from = '080000'
time_to = '180000' ).
* set appointment on top of day entries as an all day event
CALL METHOD appointment->set_view_attributes
EXPORTING
SHOW_LOCAL = 'X'
SHOW_ON_TOP = 'X'.
* mark appointment time as not busy, so other appointments
* could be scheduled with free/busy analyzer
CALL METHOD appointment->set_busy_value( sccon_busy_free ).
* edit a rule and add it to an appointment
CREATE OBJECT rule.
CALL METHOD rule->edit( no_period = ' ' ).
CALL METHOD appointment->set_rule( rule = rule ).
* write appointment text
append 'Hey' to text.
append 'Let''s have Hotline.' to text.
append ' Please add your phone number below:' to text.
CALL METHOD appointment->set_text( text ).
* make text changeable by every participant (if internal)
CALL METHOD appointment->set_text_authority( '1' ).
* save appointment on data base using default values
* for all other properties
CALL METHOD appointment->save.
Working with appointments that belong to an application object
Two appointments are created for a business object identified by a GUID. The appointments are assigned to the business object using this application GUID.
The ways in which appointments created once can be reinstantiated are also shown: Using the appointment ID or using the application GUID.
These appointments are deleted again at the end.
REPORT rssc_demo_cl_appointment_appl .
*** this report shows how an application can handle appointments which
*** belongs to their business object. The operations are:
*** - creating two appointments for one business object
*** - changing some attributes of one of them
*** - Selecting both appointments with the help of the business object*** - deleting both appointments
INCLUDE <cntn01>.
TYPE-POOLS: sccon.
DATA appointmen TYPE REF TO cl_appointment.
DATA first_appointment TYPE REF TO cl_appointment.
DATA appointment_type TYPE sc_appttyp.
DATA participant_list TYPE STANDARD TABLE OF scspart.
DATA participant TYPE scspart.
DATA address TYPE swc_object.
DATA address_container LIKE swcont OCCURS 0 WITH HEADER LINE.
DATA text TYPE TABLE OF soli.
DATA title LIKE scsappt-txt_short.
DATA location LIKE scsappt-room.
DATA appointments TYPE TABLE OF REF TO cl_appointment.
DATA application_guid TYPE sc_appguid.
DATA appointment_id TYPE sc_aptguid.
DATA part_list TYPE scparttab.
*************************************************************
*** simulate data which normally is stored within application
*************************************************************
** get an application object GUID
PERFORM get_application_guid CHANGING application_guid.
*************************************************************
CREATE OBJECT appointment.
* * set the type of the appointment
* * this type normally belongs to exactly one application
* * there might be some exit functionalities behind that type
* * assume that in that case the appointment type is defined
* * as "PARTNERS"
* * See class documentation for details
appointment_type = 'PARTNERS'.
CALL METHOD appointment->set_type( appointment_type ).
* set actual user as participants of appointment
CLEAR participant.
MOVE sy-uname TO participant.
CALL METHOD appointment->add_participant( participant = participant ).
* set an internet address as a second participant of that appointment
CLEAR participant.
swc_create_object address 'ADDRESS' space.
swc_set_element address_container 'AddressString'
'testuser@nowhere.com'.
swc_set_element address_container 'TypeId' 'U'.
swc_set_element address_container 'NoAdradmi' 'X'.
swc_set_element address_container 'NoIntern' 'X'.
swc_call_method address 'Create' address_container.
CHECK sy-subrc = 0.
* * get key and type of object
swc_get_object_key address participant-objkey.
CHECK sy-subrc = 0.
swc_get_object_type address participant-objtype.
CHECK sy-subrc = 0.
MOVE 'X' TO participant-send_mail.
CALL METHOD appointment->add_participant( participant = participant ).
* set title and location
MOVE 'Business lunch'(001) TO title.
CALL METHOD appointment->set_title( title ).
MOVE 'Hotel Sun'(002) TO location.
CALL METHOD appointment->set_location( location ).
* set date and time using default settings
* date_to will be the same as date_from
* time zone will be the one from the user master records settings
CALL METHOD appointment->set_date( date_from = sy-date
time_from = '120000'
time_to = '130000' ).
* set application guid
CALL METHOD appointment->set_application_data(
application_guid = application_guid ).
* set it to a high priority meeting
CALL METHOD appointment->set_priority( sccon_prio_very_high ).
* this meeting is not yet confirmed
CALL METHOD appointment->set_status( sccon_status_planned ).
* save appointment on database using default values
* for all other properties
CALL METHOD appointment->save.
* get the appointment guid for later use
appointment_id = appointment->get_guid( ).
* * free all objects like it is if we have a new LUW
* * (except this appointment id)
FREE: appointment.
************************************************************************
*** Create a second meeting for the same business process. ***
*** So use the same application guid ***
*** Use the same participants as before ***
************************************************************************
CREATE OBJECT appointment.
* * set the type of the appointment
* * this time assume it's another: "FRIENDS"
appointment_type = 'FRIENDS'.
CALL METHOD appointment->set_type( appointment_type ).
* set title and location
MOVE 'Business Party'(001) TO title.
CALL METHOD appointment->set_title( title ).
MOVE 'Night Club Sunny'(002) TO location.
CALL METHOD appointment->set_location( location ).
* set date and time using default settings
* date_to will be the same as date_from
* time zone will be the one from the user master records settings
CALL METHOD appointment->set_date( date_from = '20011231'
time_from = '220000'
date_to = '20020101'
time_to = '060000' ).
* set the same application guid
CALL METHOD appointment->set_application_data(
application_guid = application_guid ).
* write invitation text
APPEND ' Partners are invited, too!' TO text.
CALL METHOD appointment->set_text( text ).
** get the participants from the first appointment
** and add them to the second appointment
CREATE OBJECT first_appointment EXPORTING guid = appointment_id.
CALL METHOD first_appointment->get_participants
IMPORTING participants = participant_list .
LOOP AT participant_list INTO participant.
CALL METHOD appointment->add_participant( participant ).
ENDLOOP.
* save appointment on database using default values
* for all other properties
CALL METHOD appointment->save.
* * free all objects like it is if we have a new LUW
* * (except first appointment id)
FREE: appointment, first_appointment.
***********************************************************************
* * change location of first appointment
***********************************************************************
CREATE OBJECT first_appointment EXPORTING guid = appointment_id.
CALL METHOD first_appointment->set_location( location = 'Mc Donald' ).
CALL METHOD first_appointment->save.
FREE: first_appointment.
***********************************************************************
*** delete now both appointments
*** the only identifier is the application guid, hence the link to the
*** corresponding business object
***********************************************************************
* * get both appointments by application guid (static method)appointments = cl_appointment=>select_by_application_guid(
application_guid = application_guid ).
LOOP AT appointments INTO appointment.
* * delete this appointment
CALL METHOD appointment->delete.
ENDLOOP.
WRITE: / 'Two appointments created, modified and again deleted.'.
*****************************************************************
*****************************************************************
FORM get_application_guid CHANGING application_guid.
CALL FUNCTION 'GUID_CREATE'
IMPORTING
ev_guid_16 = application_guid.
ENDFORM.