sending notifications for work items

74
Workflow Program Added by Aveek Ghose , last edited by Aveek Ghose on Dec 17, 2011 Author: Aveek Ghose Submitted: 17/12/2011 Related Links: <link> <Sending notifications for work items> < --- & ------------------------------------------------------------- ------- *& Report RSWUWFML2 *& *& Enhanced version of RSWUWFML &------------------------------------------------------------- -------- REPORT ZDMSWF_RSWUWFML2. DEFINE swu_trace_write. swu_trace_write_formsmsg &2 &1 &4 &3 &5 &6 &7 &8 &9. END-OF-DEFINITION. TABLES: swwwihead, swu_wlscan, rs38l. ************************************************************** ******

Upload: sriyash-live

Post on 06-Sep-2014

371 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Sending Notifications for Work Items

Workflow Program Added by Aveek Ghose, last edited by Aveek Ghose on Dec 17, 2011

Author: Aveek Ghose

Submitted: 17/12/2011Related Links:

<link>

<Sending notifications for work items>

<---&--------------------------------------------------------------------*& Report RSWUWFML2*&*& Enhanced version of RSWUWFML&---------------------------------------------------------------------

REPORT ZDMSWF_RSWUWFML2.

DEFINE swu_trace_write.swu_trace_write_formsmsg &2&1&4 &3 &5 &6 &7 &8 &9.END-OF-DEFINITION.

TABLES: swwwihead,swu_wlscan,rs38l.

********************************************************************

Parameters *********************************************************************

Instance dataSELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t06.PARAMETERS: p_jobsuf LIKE swu_wlscan-curr_numb DEFAULT '2'.

'1' is the suffix for SAPforms, so here we choose '2' as default.SELECT-OPTIONS: p_tasks FOR swwwihead-wi_rh_task.PARAMETERS: p_new TYPE char1 AS CHECKBOX DEFAULT 'X'.

Page 2: Sending Notifications for Work Items

PARAMETERS: p_psubst TYPE char1 AS CHECKBOX.SELECTION-SCREEN END OF BLOCK b1.

How many messages should be sent?SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t01.

PARAMETERS: x_n14all RADIOBUTTON GROUP g1 USER-COMMAND chck DEFAULT 'X'," For each work item one message is sentx_14all RADIOBUTTON GROUP g1." One message per work itemSELECTION-SCREEN END OF BLOCK b2.

With executable attachment (Shortcut)SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-t02.PARAMETERS: x_sc_inb AS CHECKBOX USER-COMMAND chck default 'X'," shortcut for inboxx_sc_dis AS CHECKBOX USER-COMMAND chck," shortcut for displayx_sc_exe AS CHECKBOX USER-COMMAND chck default 'X'." shortcut for executeSELECTION-SCREEN END OF BLOCK b3.

Textlines for standard notification textSELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-t03.PARAMETERS: p_s_nac LIKE sy-msgid DEFAULT 'SWU_NOTIF'.PARAMETERS: p_s_nan LIKE sy-msgno DEFAULT '001'.PARAMETERS: p_prol LIKE dokhl-object DEFAULT 'SWU_NOTIF_PROLOG1'.PARAMETERS: p_epil LIKE dokhl-object DEFAULT 'SWU_NOTIF_EPILOG1'.SELECTION-SCREEN END OF BLOCK b4.

shortcut parametersSELECTION-SCREEN BEGIN OF BLOCK b5 WITH FRAME TITLE text-t07.PARAMETERS: p_logon TYPE text40.SELECTION-SCREEN END OF BLOCK b5.

user exitsSELECTION-SCREEN BEGIN OF BLOCK b8 WITH FRAME TITLE text-t08.SELECT-OPTIONS: p_expre FOR rs38l-name.SELECT-OPTIONS: p_exadr FOR rs38l-name.SELECTION-SCREEN END OF BLOCK b8.

Parameters for a single runSELECTION-SCREEN BEGIN OF BLOCK b6 WITH FRAME TITLE text-t04.PARAMETERS: p_fromd LIKE sy-datum,p_fromt LIKE sy-uzeit," only work items created after this date/time" are considered" these parameters overrule the table settingsp_user LIKE sy-uname.

Page 3: Sending Notifications for Work Items

" only messages for work items in this user's inbox" are forwardedSELECTION-SCREEN END OF BLOCK b6.

ProtocolSELECTION-SCREEN BEGIN OF BLOCK b7 WITH FRAME TITLE text-t05.PARAMETERS: x_err_tr RADIOBUTTON GROUP g2 DEFAULT 'X',"trace errors onlyx_alw_tr RADIOBUTTON GROUP g2."trace everythingSELECTION-SCREEN END OF BLOCK b7.

********************************************************************

Declarations *********************************************************************

INCLUDE: rswuincl. " workflow constantsINCLUDE: rswugdat. " for trace writing %GT 3.1

TYPES: t_solisti1_tab TYPE TABLE OF solisti1.

TYPES: BEGIN OF t_user_data,uname TYPE syuname,langu TYPE sylangu,email TYPE string,logon_langu TYPE sylangu, " note 849251sent TYPE xfeld,END OF t_user_data.

TYPES: BEGIN OF t_substitution,user TYPE syuname,substitute TYPE syuname,profile TYPE hr_rep_prf,END OF t_substitution.

TYPES: BEGIN OF t_wi_data,wi_id LIKE swwwihead-wi_id,tclass TYPE hr_task_cl,END OF t_wi_data.

TYPES: t_user_data_tab TYPE TABLE OF t_user_data.TYPES: t_substitution_tab TYPE TABLE OF t_substitution.TYPES: sopcklsti1_tab TYPE TABLE OF sopcklsti1.

CONSTANTS:c_docu_id_dialog_text LIKE dokhl-id VALUE 'DT',c_docu_typ_e LIKE dokil-typ VALUE 'E',c_action_display TYPE char40 VALUE 'DISPLAY',c_action_execute TYPE char40 VALUE 'EXECUTE',

Page 4: Sending Notifications for Work Items

c_esc_unix TYPE c VALUE 'U',c_com_type_int TYPE so_snd_art VALUE 'INT',c_pd_otype_usr LIKE swhactor-otype VALUE 'US'.

miscellaneousDATA: l_crlf(2) TYPE c.DATA: BEGIN OF crlf,x(1) TYPE x VALUE '0D',y(1) TYPE x VALUE '0A',END OF crlf.DATA l_dynp_valu TYPE doku_obj. "dynfieldvalue.

Send optionsDATA: BEGIN OF s_opt,one4all, " one message for all work itemsshortcut_inbox, " shortcut for opening the inboxshortcut_display, " shortcut for WI displayshortcut_execute, " shortcut for WI executeno_shortcuts, " no shortcuts at allEND OF s_opt.

Scheduling dataDATA: l_from_date LIKE sy-datum,l_from_time LIKE sy-uzeit,l_to_date LIKE sy-datum,l_to_time LIKE sy-uzeit,l_set_lastrun LIKE sy-binpt, " Whether or not to treat this" as a full run and set the last-run timestamp.l_system_timezone TYPE sy-zonlo.

Work item dataRANGES task_sel FOR swwwihead-wi_rh_task.

DATA: lt_users LIKE swhactor OCCURS 0 WITH HEADER LINE,lt_wi_data TYPE t_wi_data OCCURS 0 WITH HEADER LINE,lt_task_tab LIKE swhactor OCCURS 0 WITH HEADER LINE,l_uname LIKE soud-usrnam,l_send_wi_id LIKE swwwihead-wi_id.

Mail dataDATA: ls_address TYPE t_user_data,lt_user_addresses LIKE sousradri1 OCCURS 0 WITH HEADER LINE,l_items_sent,l_proxy_email TYPE swu_prxadr.

text handlingDATA: l_text_prolog TYPE string,l_text_epilog TYPE string,l_body TYPE string.

Page 5: Sending Notifications for Work Items

user dataDATA: lt_user_data TYPE TABLE OF t_user_data,wa_user_data TYPE t_user_data.

Error and trace handling dataDATA: l_msg_v1 LIKE balm-msgv1,lo_log TYPE REF TO cl_swn_log,l_msg_text(100) TYPE c.

user exit dataRANGES rt_exit_prep FOR rs38l-name.RANGES rt_exit_addr FOR rs38l-name.

General purpose dataDATA: l_count LIKE sy-index,l_tabix LIKE sy-tabix.

Table for substitutionDATA: BEGIN OF g_substitutions OCCURS 0, " global variableuser LIKE sy-uname,substitute LIKE sy-uname,profile TYPE hr_rep_prf,END OF g_substitutions.DATA: l_subrc TYPE sysubrc.DATA: l_noclass TYPE hr_task_cl.DATA: lt_77ro TYPE TABLE OF t77ro.DATA: wa_77ro TYPE t77ro.

Header definitionDATA: h_wi_header LIKE swwwihead, "#EC NEEDEDls_wi_header LIKE swwwihead.

**************************************************************

Initialize send options ***************************************************************

AT SELECTION-SCREEN OUTPUT.

check the combination 14all/collection mailIF NOT x_14all IS INITIAL.CLEAR x_sc_dis. CLEAR x_sc_exe.

x_sc_inb = 'X'.

deactivate the radio-buttonsLOOP AT SCREEN.IF screen-name = 'X_SC_DIS' ORscreen-name = 'X_SC_EXE' ORscreen-name = 'P_EPIL'.screen-input = 0.MODIFY SCREEN.

Page 6: Sending Notifications for Work Items

ENDIF.ENDLOOP.ELSE.

re-activate the radio-buttonsLOOP AT SCREEN.IF screen-name = 'X_SC_DIS' ORscreen-name = 'X_SC_EXE' ORscreen-name = 'P_EPIL'.screen-input = 1.MODIFY SCREEN.ENDIF.ENDLOOP.ENDIF.

do not alter fields if at least one field

has been changedIF p_prol NP 'SWU_NOTIF*' ORp_s_nac NP 'SWU_NOTIF*' ORp_epil NE space ANDp_epil NP 'SWU_NOTIF*'.

customer has modifiedELSE.

switch the default valuesIF x_14all = 'X'.IF p_s_nac CP 'SWU_NOTIF*'.p_s_nan = '001'.ENDIF.IF x_sc_inb IS INITIAL.p_prol = 'SWU_NOTIF_INBOX'.ELSE.p_prol = 'SWU_NOTIF_INBOX2'.ENDIF.p_epil = space.ELSE.p_s_nan = '002'.p_prol = 'SWU_NOTIF_PROLOG1'.IF x_sc_inb = 'X' OR x_sc_dis = 'X' OR x_sc_exe = 'X' .p_epil = 'SWU_NOTIF_EPILOG2'.ELSE.p_epil = 'SWU_NOTIF_EPILOG1'.ENDIF.ENDIF.ENDIF.

AT SELECTION-SCREEN ON p_prol.

Page 7: Sending Notifications for Work Items

IF NOT p_prol IS INITIAL.CALL FUNCTION 'SWF_DOCUMENTATION_CHECK'EXPORTINGdocu_object = p_prolEXCEPTIONSdocumentation_not_found = 1OTHERS = 2.IF sy-subrc %LT%GT 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.ENDIF.

AT SELECTION-SCREEN ON p_epil.

IF NOT p_epil IS INITIAL.CALL FUNCTION 'SWF_DOCUMENTATION_CHECK'EXPORTINGdocu_object = p_epilEXCEPTIONSdocumentation_not_found = 1OTHERS = 2.IF sy-subrc %LT%GT 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_prol.

PERFORM get_dynpro_value USING 'P_PROL' CHANGING l_dynp_valu.

CALL FUNCTION 'DOCU_VALUE_REQUEST'EXPORTINGid = c_docu_id_dialog_textobject = l_dynp_valu

LANGU = SY-LANGUtyp = c_docu_typ_e

FOR_MAINTAIN = 'X'for_display = 'X'

WINDOW_TITLE =IMPORTINGvalue_object = p_prol.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_epil.

PERFORM get_dynpro_value USING 'P_EPIL' CHANGING l_dynp_valu.

Page 8: Sending Notifications for Work Items

CALL FUNCTION 'DOCU_VALUE_REQUEST'EXPORTINGid = c_docu_id_dialog_textobject = l_dynp_valu

LANGU = SY-LANGUtyp = c_docu_typ_e

FOR_MAINTAIN = 'X'for_display = 'X'

WINDOW_TITLE =IMPORTINGvalue_object = p_epil.

START-OF-SELECTION.

NEW PLM ROADSHOW

P_TASKS-LOW = 'TS84000033'.p_tasks-SIGN = 'I'.p_tasks-option = 'EQ'.append p_tasks.P_TASKS-LOW = 'TS96000134'.p_tasks-SIGN = 'I'.p_tasks-option = 'EQ'.append p_tasks.P_TASKS-LOW = 'TS98000131'.p_tasks-SIGN = 'I'.p_tasks-option = 'EQ'.append p_tasks.

assign crlf. Unfortunately this is different in 4.6

and unicode systems

l_crlf = crlf.l_crlf = cl_abap_char_utilities=%GTcr_lf.

Use the task list as a selection criterion if necessary.IF task_sel[] IS INITIAL.task_sel[] = p_tasks[].ENDIF.

Set the send options.IF NOT x_14all IS INITIAL.s_opt-one4all = 'X'.ENDIF.IF x_sc_inb IS INITIAL.

Page 9: Sending Notifications for Work Items

s_opt-shortcut_inbox = 'X'.ENDIF.IF x_sc_dis IS INITIAL.s_opt-shortcut_display = 'X'.ENDIF.IF x_sc_exe IS INITIAL.s_opt-shortcut_execute = 'X'.ENDIF.IF x_sc_inb IS INITIAL ANDx_sc_dis IS INITIAL ANDx_sc_exe IS INITIAL.s_opt-no_shortcuts = 'X'.ENDIF.

user exitsIF rt_exit_prep[] IS INITIAL.rt_exit_prep[] = p_expre[].ENDIF.IF rt_exit_addr[] IS INITIAL.rt_exit_addr[] = p_exadr[].ENDIF.

establish tracelo_log = cl_swn_log=%GTget_instance( ).lo_log-%GTcreate_log( i_subobject = 'NOTIFICATIONS' ).

trace the selection optionsMESSAGE s015(swu_notif)WITH 'p_jobsuf' p_jobsuf "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).LOOP AT task_sel.MESSAGE s015(swu_notif)WITH 'p_tasks' task_sel-low "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).ENDLOOP.LOOP AT rt_exit_prep.MESSAGE s015(swu_notif)WITH 'p_expre' rt_exit_prep-low "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).ENDLOOP.LOOP AT rt_exit_addr.MESSAGE s015(swu_notif)WITH 'p_expre' rt_exit_addr-low "#EC NOTEXTINTO l_msg_text.

Page 10: Sending Notifications for Work Items

lo_log-%GTadd_message( ).ENDLOOP.MESSAGE s015(swu_notif)WITH 'x_sc_inb' x_sc_inb "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).MESSAGE s015(swu_notif)WITH 'x_sc_dis' x_sc_dis "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).MESSAGE s015(swu_notif)WITH 'x_sc_exe' x_sc_exe "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).MESSAGE s015(swu_notif)WITH 'p_s_nac' p_s_nac "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).MESSAGE s015(swu_notif)WITH 'p_s_nan' p_s_nan "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).MESSAGE s015(swu_notif)WITH 'p_prol' p_prol "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).MESSAGE s015(swu_notif)WITH 'p_epil' p_epil "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).MESSAGE s015(swu_notif)WITH 'p_logon' p_logon "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).MESSAGE s015(swu_notif)WITH 'p_fromd' p_fromd "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).MESSAGE s015(swu_notif)WITH 'p_fromt' p_fromt "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).MESSAGE s015(swu_notif)WITH 'p_user' p_user "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).MESSAGE s015(swu_notif)WITH 'x_err_tr' x_err_tr "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).

Page 11: Sending Notifications for Work Items

MESSAGE s015(swu_notif)WITH 'x_alw_tr' x_alw_tr "#EC NOTEXTINTO l_msg_text.lo_log-%GTadd_message( ).

*********************************************************

check the sender address**********************************************************

SAPoffice cannot send SMTP e-mail when the current user has

no home SMTP address assigned.

PERFORM get_email_address_camUSING sy-unameCHANGING ls_address.

report errorIF ls_address-email IS INITIAL.MESSAGE e019(swu_notif)WITH sy-unameINTO l_msg_text.lo_log-%GTadd_message( i_probclass = lo_log-%GTprio_top ).WRITE: / l_msg_text.

save the tracelo_log-%GTsave_log( ).lo_log-%GTrefresh_log( ).EXIT.ENDIF.

*********************************************************

Get the system time zone **********************************************************

The system time zone is used to convert the scheduling

information of the report into a time stamp.

CALL FUNCTION 'GET_SYSTEM_TIMEZONE'IMPORTINGtimezone = l_system_timezoneEXCEPTIONScustomizing_missing = 1OTHERS = 2.IF sy-subrc %LT%GT 0.

report errorMESSAGE e020(swu_notif)

Page 12: Sending Notifications for Work Items

WITH sy-unameINTO l_msg_text.lo_log-%GTadd_message( i_probclass = lo_log-%GTprio_top ).WRITE: / l_msg_text.

save the tracelo_log-%GTsave_log( ).lo_log-%GTrefresh_log( ).EXIT.ENDIF.

**************************************************************

Read the scheduling information ***************************************************************

Read the last date and time the report was run successfully

for this job suffix.

If the corresponding report parameters are not set and

we have not found an entry, swu_wlscan-l_last_date and

swu_wlscan-l_last_time will be initial, which does not cause any harm.

IF p_fromd IS INITIAL ANDp_fromt IS INITIAL ANDp_user IS INITIAL.SELECT SINGLE * FROM swu_wlscan WHERE curr_numb = p_jobsuf.l_from_date = swu_wlscan-last_date.l_from_time = swu_wlscan-last_time.l_set_lastrun = 'X'.ELSE.l_from_date = p_fromd.l_from_time = p_fromt.ENDIF.

l_to_date = sy-datum.

make sure we catch work items created this second note 865149: avoide time gap

l_to_time = sy-uzeit.l_to_time = l_to_time - 5.IF l_to_time %GT= '235955'.l_to_date = l_to_date - 1.ENDIF.

*****************************************************

prepare substitution stuff ******************************************************

Page 13: Sending Notifications for Work Items

determine substitution profile which means no restrictionPERFORM re77s0 IN PROGRAM mstt77s0USING 'WORKF' 'DEFCL' l_noclass l_subrc. "#EC NOTEXT

read the correlation between profile and tclassSELECT * FROM t77ro INTO TABLE lt_77ro. "#EC CI_GENBUFF

replace NO_CLASS by spaceCLEAR wa_77ro-tclass.MODIFY lt_77ro FROM wa_77roTRANSPORTING tclassWHERE tclass = l_noclass.

**************************************************************

call user exit which may change environment data ***************************************************************

IF NOT rt_exit_prep[] IS INITIAL.LOOP AT rt_exit_prep.IF NOT rt_exit_prep-low IS INITIAL.CALL FUNCTION rt_exit_prep-low.ENDIF.ENDLOOP.ENDIF.

*****************************************************

Set the notification text ******************************************************

PERFORM get_document USING c_docu_id_dialog_textp_prolsy-languCHANGING l_text_prolog.

PERFORM get_document USING c_docu_id_dialog_textp_epilsy-languCHANGING l_text_epilog.

**************************************************************

read the proxy table ***************************************************************

check whether the proxy table contains a matching entry

if yes, the email is sent to the proxy address rather than

Page 14: Sending Notifications for Work Items

to the end user's emailSELECT proxy_addr INTO l_proxy_email FROM swutyp2adrWHERE form_type = space.ENDSELECT.

**************************************************************

Select the work items ***************************************************************

PERFORM select_workitems.IF p_new is initial.PERFORM select_modified_workitems.ENDIF.

***************************************************************

Send the notifications for these work items ****************************************************************

PERFORM send_wi_mails.

*****************************************************************

Update the scheduling information ******************************************************************

*AR Update table swu_wlscan only when the default is used.IF l_set_lastrun = 'X'.swu_wlscan-curr_numb = p_jobsuf.swu_wlscan-last_date = l_to_date.swu_wlscan-last_time = l_to_time.MODIFY swu_wlscan.ENDIF.

save the trace

lo_log-%GTsave_log( ).lo_log-%GTrefresh_log( ).

********************************************************************

End of the report *********************************************************************

*********************************************************************

Form routines **********************************************************************

Page 15: Sending Notifications for Work Items

---------------------------------------------------------------------

FORM SEND_WI_MAILS *---------------------------------------------------------------------

Send notifications for the work items in table lt_wi_id *---------------------------------------------------------------------FORM send_wi_mails.

DATA: l_subrc LIKE sy-subrc.DATA: wi_recipients TYPE t_user_data OCCURS 0 WITH HEADER LINE.DATA: ls_address TYPE t_user_data.DATA: l_user_found TYPE xfeld.

FIELD-SYMBOLS: %LTuser_data%GT TYPE t_user_data.

********************************************************************

Read the selected agents (users) *********************************************************************

Loop thru all workitems.LOOP AT lt_wi_data.

CLEAR lt_users. REFRESH lt_users.CLEAR wi_recipients.

write to logMESSAGE s014(swu_notif) WITH lt_wi_data-wi_idINTO l_msg_text.lo_log-%GTadd_message( ).

Determine the recipients.CALL FUNCTION 'RH_WI_AGENTS_GET'EXPORTINGact_wi_id = lt_wi_data-wi_id

SEARCH_DATE = SY-DATUM

ONLY_USER = 'X'TABLES

ACT_ORG_TASK =

EXCLUDED_AGENTS =wi_agent_list = lt_usersEXCEPTIONSno_active_plvar = 1no_agent_found = 2general_task = 3background_task = 4OTHERS = 5.

Page 16: Sending Notifications for Work Items

l_subrc = sy-subrc.

in contrary to version 1 we don't send to all users

*****************************************************************

Determine the recipients of the messages to be sent ******************************************************************

handle general tasksIF l_subrc = 3.MESSAGE s004(swu_notif) WITH lt_wi_data-wi_idINTO l_msg_text.lo_log-%GTadd_message( ).CONTINUE.ENDIF.

Do users exist?CHECK l_subrc = 0.

Consider substitution. Maybe it's class-specificPERFORM add_substitutesTABLES lt_usersUSING lt_wi_dataCHANGING l_subrc.

LOOP AT lt_users.

l_uname = lt_users-objid.

consider user restrictionIF NOT p_user IS INITIAL AND p_user NE l_uname.

no, it's not the user in the selection option -%GT skipCONTINUE.ENDIF.

did we already send to the user?CLEAR: wa_user_data, l_user_found, l_tabix.READ TABLE lt_user_dataWITH KEY uname = lt_users-objid BINARY SEARCHASSIGNING %LTuser_data%GT.l_tabix = sy-tabix. " note 739988IF sy-subrc = 0.l_user_found = 'X'.ENDIF.

If sending only one message for all work items...IF s_opt-one4all = 'X' AND l_user_found = 'X'.

Page 17: Sending Notifications for Work Items

Message to this user has already been sent.CONTINUE. " goto loop startENDIF.

IF l_user_found IS INITIAL.

New userwa_user_data-uname = l_uname.IF l_tabix %LT= 0.l_tabix = 1.ENDIF.INSERT wa_user_data INTO lt_user_dataINDEX l_tabix.READ TABLE lt_user_data INDEX l_tabix ASSIGNING %LTuser_data%GT.

read address dataCLEAR ls_address.PERFORM get_email_addressUSING l_unameCHANGING ls_address.

IF NOT ls_address-email IS INITIAL.

Only in this case we rely on recipient_address and comm_type to be set correctly.

%LTuser_data%GT-email = ls_address-email.%LTuser_data%GT-langu = ls_address-langu.%LTuser_data%GT-logon_langu = ls_address-logon_langu. " note 849251ELSE.

Clear.MESSAGE w013(swu_notif) WITH l_unameINTO l_msg_text.lo_log-%GTadd_message( ).CLEAR: %LTuser_data%GT-email.ENDIF.

If remote address is found then send to the SAPoffice user.%LTuser_data%GT-uname = l_uname.

ENDIF. "user found?

IF NOT %LTuser_data%GT-email IS INITIAL.

Convert (e.g. INT -%GT U).APPEND %LTuser_data%GT TO wi_recipients.ENDIF.ENDLOOP.

********************************************************************

Page 18: Sending Notifications for Work Items

Send the message *********************************************************************

Don't send to nobody!CHECK NOT wi_recipients[] IS INITIAL.

IF s_opt-one4all IS INITIAL.

Set the work item ID for sending. It is not needed if only one message for all work items is sent.

l_send_wi_id = lt_wi_data-wi_id.PERFORM send_messagesTABLES lt_task_tabwi_recipientsUSING l_send_wi_ids_optCHANGING l_subrc.ENDIF.

ENDLOOP.

handle the one-for-all case

IF NOT s_opt-one4all IS INITIAL ANDNOT wi_recipients[] IS INITIAL.

no message has been sent so far -%GT do it nowCLEAR l_send_wi_id. " only one message for all work itemsPERFORM send_messagesTABLES lt_task_tabwi_recipientsUSING l_send_wi_ids_optCHANGING l_subrc.ENDIF.

If the flag has not been set, output that nothing has been sent.IF l_items_sent IS INITIAL.PERFORM write_nothing_sent.ENDIF.

ENDFORM. "send_wi_mails

&---------------------------------------------------------------------*& Form SEND_MESSAGES&---------------------------------------------------------------------

send mails for a particular work items----------------------------------------------------------------------FORM send_messages TABLES pt_tasks STRUCTURE swhactor

Page 19: Sending Notifications for Work Items

pt_recipients TYPE t_user_data_tabUSING p_wi_id LIKE swwwihead-wi_idp_opt LIKE s_optCHANGING p_return_code LIKE sy-subrc.

PRECONDITION: We assume that RECIPIENTS contains

mail recipients.

INCLUDE %LTcntain%GT.

Build Document content. Three packages of data are declard: one for the lt_content of

the whole message, one for the text part of the message,

one for the attachment part of the message.DATA: lt_content LIKE solisti1 OCCURS 0 WITH HEADER LINE,lt_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,lt_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,lt_content_txt LIKE solisti1 OCCURS 0 WITH HEADER LINE,lt_packing_list_txt LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,lt_document_data LIKE sodocchgi1.

Mail sending information.DATA: l_express LIKE sos04-l_sex,lt_real_recipients LIKE somlreci1 OCCURS 0 WITH HEADER LINE,l_sent_to_all LIKE sonv-flag,l_mail_subject LIKE sopcklsti1-obj_descr,l_mail_language LIKE sopcklsti1-obj_langu.

Text information.

DATA BEGIN OF lt_text_lines OCCURS 0.

INCLUDE STRUCTURE tline.

DATA END OF lt_text_lines.DATA lt_text_lines LIKE tline OCCURS 0.DATA lt_stream_lines TYPE swr_txtlin OCCURS 0.

Workitem information.DATA: l_task LIKE swwwihead-wi_rh_task.DATA: l_wi_header LIKE swwwihead.DATA: l_wi_type LIKE swwwihead-wi_type.

General purpose information.DATA: l_line_no TYPE i,l_count TYPE i.

**********************************************************

Page 20: Sending Notifications for Work Items

Get the info needed to assemble the message ***********************************************************CLEAR lt_text_lines. REFRESH lt_text_lines.CLEAR l_body. "%LT%LT%LT insert note 720290

**********************************************************

Create text. ***********************************************************IF s_opt-one4all IS INITIAL.

For each individual work item a message is sent.

Get workitem information.CALL FUNCTION 'SWW_WI_HEADER_READ'EXPORTINGwi_id = p_wi_id

READ_FOR_UPDATE = ' 'IMPORTINGwi_header = l_wi_headerEXCEPTIONSread_failed = 1OTHERS = 2.

IF sy-subrc NE 0.l_msg_v1 = p_wi_id.PERFORM write_error_msg USING lt_wi_data-wi_id '312' l_msg_v1space.p_return_code = 1.EXIT.ENDIF.

****************************************************************

Build the mail text, mail subject and mail language *****************************************************************

for deadline items get the text from the original item

note 762089 V3: make sure variable replacement works

leave container read up to SWU_GET_TASK_TEXTLINES

IF l_wi_header-wi_type = 'D'.CALL FUNCTION 'SWW_WI_HEADER_READ'EXPORTINGwi_id = l_wi_header-wi_chckwiIMPORTINGwi_header = h_wi_headerEXCEPTIONS

Page 21: Sending Notifications for Work Items

read_failed = 1OTHERS = 2.

force the deadline text to be takenl_wi_type = 'D'. "#EC NOTEXTl_task = h_wi_header-wi_rh_task.ELSE.

take the normal work item textl_wi_type = 'W'. "#EC NOTEXTl_task = l_wi_header-wi_rh_task.ENDIF.

perform variable substitution for task description.TRY.CALL FUNCTION 'SWU_GET_TASK_TEXTLINES'EXPORTINGtask = l_taskusage = l_wi_typelanguage = l_wi_header-wi_langwiheader = l_wi_headerTABLESstream_text_lines = lt_stream_linesEXCEPTIONSwrong_usage = 01text_not_found = 02text_system_error = 03.

convert table to string for easier handlingPERFORM table_to_string USING lt_stream_lines[] CHANGING l_body.

CATCH cx_sy_dyn_call_param_not_found.CALL FUNCTION 'SWU_GET_TASK_TEXTLINES'EXPORTINGtask = l_taskusage = l_wi_typelanguage = l_wi_header-wi_langwiheader = l_wi_headerTABLESascii_text_lines = lt_text_linesEXCEPTIONSwrong_usage = 01text_not_found = 02text_system_error = 03.

convert table to string for easier handlingPERFORM tline_to_string TABLES lt_text_lines[] CHANGING l_body.

ENDTRY.

IF l_body IS INITIAL.

Page 22: Sending Notifications for Work Items

If there is no text, we create a default text.l_body = 'This work item has no description.'(m06).ENDIF.

assemble mail body: prolog ... wi text ... epilogCONCATENATE l_text_prologl_bodyl_text_epilogINTO l_body.

Set subject and language of the mail message.IF p_s_nac IS INITIAL OR p_s_nan IS INITIAL.l_mail_subject = l_wi_header-wi_text.ELSE.MESSAGE ID p_s_nac TYPE 'S' NUMBER p_s_nanWITH sy-sysid l_wi_header-wi_textINTO l_mail_subject.ENDIF.l_mail_language = l_wi_header-wi_lang.

ELSE. "s_opt-one4all

There is only one message for all work items. subject...

IF p_s_nac IS INITIAL OR p_s_nan IS INITIAL.l_mail_subject = '&: You have received new work items.'(s02).REPLACE '&' WITH sy-sysid INTO l_mail_subject.CONDENSE l_mail_subject.ELSE.MESSAGE ID p_s_nac TYPE 'S' NUMBER p_s_nanWITH sy-sysidINTO l_mail_subject.ENDIF.

body...l_body = l_text_prolog.

set language of the mail message.l_mail_language = sy-langu.ENDIF.

**********************************************************

Create the text body part ***********************************************************

Fill the document lt_content with the text built so far, e.g.

workitem long text.PERFORM string_to_table USING l_body CHANGING lt_content_txt[].DESCRIBE TABLE lt_content_txt LINES l_count.

Page 23: Sending Notifications for Work Items

Update the packing list.CLEAR lt_packing_list_txt.lt_packing_list_txt-head_start = 1.lt_packing_list_txt-head_num = 0.lt_packing_list_txt-body_start = 1.lt_packing_list_txt-body_num = l_count.lt_packing_list_txt-doc_type = 'TXT'.lt_packing_list_txt-obj_name = 'Message'(003).lt_packing_list_txt-obj_descr = l_mail_subject.lt_packing_list_txt-obj_langu = l_mail_language.APPEND lt_packing_list_txt.

Update the current line number.l_line_no = l_count.

Fill the document data.READ TABLE lt_content_txt INDEX l_count.lt_document_data-doc_size =( l_count - 1 ) * 255 + STRLEN( lt_content_txt ).lt_document_data-obj_name = 'SAPoffice'(002).lt_document_data-obj_descr = l_mail_subject.lt_document_data-obj_prio = l_wi_header-wi_prio.lt_document_data-priority = l_wi_header-wi_prio.

***************************************************************

Set l_express flag. ****************************************************************IF l_wi_header-wi_prio = 1.l_express = 'X'.ENDIF.

Note: In the case when only one message is sent for the whole

worklist, we do not calculate whether any high-priority

work items are among then.

****************************************************************

Create the message to be sent. *****************************************************************APPEND LINES OF lt_content_txt TO lt_content.APPEND LINES OF lt_packing_list_txt TO lt_packing_list.

****************************************************************

Send the message *****************************************************************IF s_opt-no_shortcuts = 'X'.

No shortcut attachment involved -%GT

Page 24: Sending Notifications for Work Items

Send one message to several recipients at once.

transform recipient listlt_real_recipients-rec_type = c_esc_unix.LOOP AT pt_recipients.lt_real_recipients-receiver = pt_recipients-email.APPEND lt_real_recipients.ENDLOOP.

now sendPERFORM so_sendTABLES lt_contentlt_object_headerlt_packing_listlt_real_recipientsUSING p_wi_idlt_document_datal_expressCHANGING l_sent_to_all.ELSE.

Shortcuts involved -%GT Send to each recipient individually.

The attachment contains the (one) recipient's Internet mail

address. We send directly to the Internet mail address.PERFORM send_individualTABLES lt_contentlt_object_headerlt_packing_listpt_recipientsUSING lt_document_datal_expressl_line_nol_wi_headerCHANGING l_sent_to_all.ENDIF.

REFRESH pt_recipients.

ENDFORM. " SEND_MESSAGES

---------------------------------------------------------------------

FORM SEND_INDIVIDUAL *---------------------------------------------------------------------

send to an individual user *---------------------------------------------------------------------FORM send_individual TABLES pt_content STRUCTURE solisti1pt_object_header STRUCTURE solisti1pt_packing_list STRUCTURE sopcklsti1

Page 25: Sending Notifications for Work Items

pt_recipients TYPE t_user_data_tabUSING p_document_data LIKE sodocchgi1p_express LIKE sos04-l_sexp_line_no TYPE ip_wi_header LIKE swwwiheadCHANGING p_sent_to_all LIKE sy-binpt.

DATA: l_failed,l_success,lt_real_recipients LIKE somlreci1 OCCURS 0 WITH HEADER LINE,lt_content LIKE solisti1 OCCURS 0,lt_object_header LIKE solisti1 OCCURS 0,lt_packing_list TYPE sopcklsti1_tab,l_line_no TYPE i,ls_wi_hdr TYPE SWR_WIHDR.

LOOP AT pt_recipients.l_line_no = p_line_no.

REFRESH: lt_real_recipients.

initialize with the values passed in

lt_content[] = pt_content[].lt_object_header[] = pt_object_header[].lt_packing_list[] = pt_packing_list[].

add SAP shortcut attachments

IF x_sc_inb = 'X'.

shortcut launching the Inbox

PERFORM add_shortcut_inboxUSINGpt_recipients-unamept_recipients-logon_langu " note: 849251pt_recipients-emailp_wi_headerCHANGINGl_line_nolt_content[]lt_object_header[]lt_packing_list[].ENDIF.

IF x_sc_dis = 'X'.

Page 26: Sending Notifications for Work Items

shortcut launching the Inbox

PERFORM add_shortcut_actionUSINGpt_recipients-unamept_recipients-logon_langu " note: 849251pt_recipients-emailp_wi_headerc_action_displayCHANGINGl_line_nolt_content[]lt_object_header[]lt_packing_list.ENDIF.

IF x_sc_exe = 'X'.

shortcut launching the Inbox

PERFORM add_shortcut_actionUSINGpt_recipients-unamept_recipients-logon_langu " note: 849251pt_recipients-emailp_wi_headerc_action_executeCHANGINGl_line_nolt_content[]lt_object_header[]lt_packing_list[].ENDIF.

let the user exit modify the address

IF NOT rt_exit_addr[] IS INITIAL.PERFORM convert_headerUSING p_wi_headerCHANGING ls_wi_hdr.LOOP AT rt_exit_addr.IF NOT rt_exit_addr-low IS INITIAL.CALL FUNCTION rt_exit_addr-lowEXPORTING i_uname = pt_recipients-unamei_wi_hdr = ls_wi_hdrCHANGING c_email = pt_recipients-email.ENDIF.

Page 27: Sending Notifications for Work Items

ENDLOOP.ENDIF.IF pt_recipients-email IS INITIAL.CONTINUE.ENDIF.

compute the SAPoffice recipientIF l_proxy_email IS INITIAL.

use the current recipientCLEAR lt_real_recipients.lt_real_recipients-receiver = pt_recipients-email.lt_real_recipients-rec_type = c_esc_unix.APPEND lt_real_recipients.ELSE.

send via proxy

This currently only works via Internet maillt_real_recipients-receiver = l_proxy_email.lt_real_recipients-rec_type = c_esc_unix.APPEND lt_real_recipients.ENDIF.

PERFORM so_sendTABLES lt_contentlt_object_headerlt_packing_listlt_real_recipientsUSING p_wi_header-wi_idp_document_datap_expressCHANGING l_success.IF l_success IS INITIAL.l_failed = 'X'.ENDIF.

ENDLOOP.

IF l_failed IS INITIAL.p_sent_to_all = 'X'.ENDIF.

ENDFORM. "send_individual

---------------------------------------------------------------------

FORM SO_SEND *---------------------------------------------------------------------

Page 28: Sending Notifications for Work Items

send SAPoffice message *---------------------------------------------------------------------FORM so_send TABLES pt_content STRUCTURE solisti1pt_object_header STRUCTURE solisti1pt_packing_list STRUCTURE sopcklsti1pt_real_recipients STRUCTURE somlreci1USING p_wi_id LIKE swwwihead-wi_idp_document_data LIKE sodocchgi1p_express LIKE sos04-l_sexCHANGING p_sent_to_all LIKE sy-binpt.

DATA: l_new_object_id LIKE sofolenti1-object_id.

CLEAR l_new_object_id.l_items_sent = 'X'.

Send back a delivery and a non-delivery report.LOOP AT pt_real_recipients.pt_real_recipients-notif_del = 'X'.pt_real_recipients-notif_ndel = 'X'.IF NOT s_opt-one4all IS INITIAL.pt_real_recipients-blind_copy = 'X'.ENDIF.pt_real_recipients-express = p_express.MODIFY pt_real_recipients.ENDLOOP.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'EXPORTINGdocument_data = p_document_data

put_in_outbox = ' 'IMPORTINGsent_to_all = p_sent_to_allnew_object_id = l_new_object_idTABLESpacking_list = pt_packing_listobject_header = pt_object_headercontents_txt = pt_contentreceivers = pt_real_recipientsEXCEPTIONStoo_many_receivers = 1document_not_sent = 2document_type_not_exist = 3operation_no_authorization = 4parameter_error = 5x_error = 6enqueue_error = 7OTHERS = 8.

Page 29: Sending Notifications for Work Items

COMMIT WORK.

Write trace.MESSAGE s003(swu_notif) WITH l_new_object_idINTO l_msg_text.lo_log-%GTadd_message( ).

List the addressess.IF NOT x_alw_tr IS INITIAL.LOOP AT pt_real_recipients WHERE NOT proxy_id IS INITIAL.PERFORM write_send_addresseeUSING p_wi_idpt_real_recipients.ENDLOOP.ENDIF.

IF NOT p_sent_to_all IS INITIAL.PERFORM write_send_success_all USING p_wi_id .ELSE.PERFORM write_send_failed_all USING p_wi_id .ENDIF.

Delete the original entries. The error code is misleading.DELETE pt_real_recipients WHERE NOT proxy_id IS INITIAL.

IF NOT x_alw_tr IS INITIAL.LOOP AT pt_real_recipients WHERE retrn_code = 0.PERFORM write_send_successUSING p_wi_idpt_real_recipients.ENDLOOP.ENDIF.

LOOP AT pt_real_recipients WHERE retrn_code %LT%GT 0.PERFORM write_send_failedUSING p_wi_idpt_real_recipients.ENDLOOP.

ENDFORM. "so_send

---------------------------------------------------------------------

FORM write_send_failed *---------------------------------------------------------------------

........ *---------------------------------------------------------------------FORM write_send_failed USING value(wi_id) LIKE swwwihead-wi_idlt_real_recipients STRUCTURE somlreci1.

Page 30: Sending Notifications for Work Items

DATA: readable_recipients LIKE soudnamei1OCCURS 0 WITH HEADER LINE,text_buf(200).

CLEAR readable_recipients.

readable_recipients-userid = lt_real_recipients-rec_id.CALL FUNCTION 'SO_NAME_CONVERT_API1'EXPORTINGname = readable_recipientsTABLESnames = readable_recipientsEXCEPTIONSuser_not_exist = 1parameter_error = 2x_error = 3OTHERS = 4.

report errorMESSAGE s005(swu_notif)WITH wi_id readable_recipients-fullnameINTO l_msg_text.lo_log-%GTadd_message( ).

CASE lt_real_recipients-retrn_code.WHEN 0. " successfulMESSAGE s373(wz) WITH wi_idINTO l_msg_text.WHEN 34.MESSAGE e376(wz) WITH wi_idINTO l_msg_text.WHEN 69.MESSAGE e374(wz) WITH wi_idINTO l_msg_text.WHEN 75.MESSAGE e375(wz) WITH wi_idINTO l_msg_text.WHEN 80.MESSAGE e377(wz) WITH wi_idINTO l_msg_text.WHEN 89.MESSAGE e378(wz) WITH wi_idINTO l_msg_text.WHEN 90.MESSAGE e379(wz) WITH wi_idINTO l_msg_text.WHEN 91.MESSAGE e380(wz) WITH wi_idINTO l_msg_text.WHEN 92.

Page 31: Sending Notifications for Work Items

MESSAGE e381(wz) WITH wi_idINTO l_msg_text.WHEN OTHERS.MESSAGE e371(wz) WITH wi_idINTO l_msg_text.ENDCASE.lo_log-%GTadd_message( ).WRITE: / l_msg_text.

ENDFORM. "write_send_failed

---------------------------------------------------------------------

FORM write_send_addressee *---------------------------------------------------------------------FORM write_send_addressee USING value(wi_id) LIKE swwwihead-wi_idlt_real_recipients STRUCTURE somlreci1.

IF NOT x_alw_tr IS INITIAL.MESSAGE s011(swu_notif) WITH wi_id lt_real_recipients-receiverINTO l_msg_text.lo_log-%GTadd_message( ).WRITE: / l_msg_text.ENDIF.

ENDFORM. "write_send_addressee

---------------------------------------------------------------------

FORM write_send_success *---------------------------------------------------------------------FORM write_send_successUSING value(wi_id) LIKE swwwihead-wi_idlt_real_recipients STRUCTURE somlreci1.

DATA: readable_recipients LIKE soudnamei1OCCURS 0 WITH HEADER LINE.

CLEAR readable_recipients.readable_recipients-userid = lt_real_recipients-rec_id.CALL FUNCTION 'SO_NAME_CONVERT_API1'EXPORTINGname = readable_recipientsTABLESnames = readable_recipientsEXCEPTIONSuser_not_exist = 1parameter_error = 2x_error = 3OTHERS = 4.

Page 32: Sending Notifications for Work Items

IF NOT x_alw_tr IS INITIAL.IF wi_id IS INITIAL.MESSAGE s012(swu_notif)WITH readable_recipients-fullnameINTO l_msg_text.ELSE.MESSAGE s011(swu_notif)WITH wi_id readable_recipients-fullnameINTO l_msg_text.ENDIF.lo_log-%GTadd_message( ).WRITE: / l_msg_text.ENDIF.

ENDFORM. "write_send_success

&---------------------------------------------------------------------*& Form WRITE_ERROR_MSG&---------------------------------------------------------------------FORM write_error_msg USING p_wi_id LIKE swwwihead-wi_idp_msgno LIKE t100-msgnrp_msgv1 LIKE balm-msgv1p_recipient .

Write that some error has occured.IF NOT p_wi_id IS INITIAL ANDx_14all IS INITIAL.IF NOT p_wi_id IS INITIAL.SKIP.MESSAGE s009(swu_notif) WITH p_wi_idINTO l_msg_text.ELSE.MESSAGE s010(swu_notif) WITH p_wi_idINTO l_msg_text.ENDIF.WRITE: / l_msg_text.lo_log-%GTadd_message( ).ENDIF.

IF NOT p_recipient IS INITIAL.WRITE: / 'Addressee:'(m09), 20 p_recipient.ENDIF.

Write the concrete reason.MESSAGE ID p_msgno TYPE 'E' NUMBER p_msgno WITH p_msgv1INTO l_msg_text.lo_log-%GTadd_message( ).WRITE: / l_msg_text.WRITE: /.

Page 33: Sending Notifications for Work Items

ENDFORM. " WRITE_ERROR_MSG

&---------------------------------------------------------------------*& Form WRITE_SEND_FAILED_ALL&---------------------------------------------------------------------FORM write_send_failed_all USING p_wi_id LIKE swwwihead-wi_id.

IF NOT p_wi_id IS INITIAL.SKIP.MESSAGE s009(swu_notif) WITH p_wi_idINTO l_msg_text.ELSE.MESSAGE s010(swu_notif) WITH p_wi_idINTO l_msg_text.ENDIF.WRITE: / l_msg_text.lo_log-%GTadd_message( ).

ENDFORM. " WRITE_SEND_FAILED_ALL

&---------------------------------------------------------------------*& Form WRITE_SEND_SUCCESS_ALL&---------------------------------------------------------------------FORM write_send_success_all USING p_wi_id LIKE swwwihead-wi_id.

IF NOT x_alw_tr IS INITIAL. " traceIF NOT p_wi_id IS INITIAL.SKIP.MESSAGE s007(swu_notif) WITH p_wi_idINTO l_msg_text.lo_log-%GTadd_message( ).ELSE.MESSAGE s008(swu_notif) WITH p_wi_idINTO l_msg_text.lo_log-%GTadd_message( ).ENDIF.ENDIF.

ENDFORM. " WRITE_SEND_SUCCESS_ALL

&---------------------------------------------------------------------*& Form WRITE_NOTHING_SENT&---------------------------------------------------------------------FORM write_nothing_sent.

IF NOT x_alw_tr IS INITIAL.DESCRIBE TABLE lt_wi_data.MESSAGE s006(swu_notif) WITH sy-tfillINTO l_msg_text.WRITE: / l_msg_text.

Page 34: Sending Notifications for Work Items

lo_log-%GTadd_message( ).ENDIF.

ENDFORM. " WRITE_NOTHING_SENT

---------------------------------------------------------------------

FORM SELECT_WORKITEMS *---------------------------------------------------------------------

select work items from the database *---------------------------------------------------------------------FORM select_workitems.

Select those workitems with the correct task, state and creation

date and time.

************************************************************************

The select statement encourages one of the database indices * to be used. Either the task index or the status/type index. *

Tests show that this really does influence the database access *

positively. *

This algorithm will be inefficient when tasks are excluded rather *

than included. *

The combination 'Waiting' and Notification/deadline type *

cannot occur. *************************************************************************IF task_sel[] IS INITIAL. "No tasks

Use the type/status index.

SELECT wi_id tclassINTO CORRESPONDING FIELDS OF TABLE lt_wi_dataFROM swwwiheadWHEREwi_type = wi_normal ANDwi_stat = wi_status_ready ANDretry_cnt = '0' AND( wi_cd %GT l_from_date OR " l_from_date/time %LT creation_date/time( wi_cd = l_from_date ANDwi_ct %GT l_from_time ) )AND " creation_date/time %LT= l_to_date/time( wi_cd %LT l_to_date OR

Page 35: Sending Notifications for Work Items

( wi_cd = l_to_date ANDwi_ct %LT= l_to_time ) ).

SELECT wi_id tclassAPPENDING CORRESPONDING FIELDS OF TABLE lt_wi_dataFROM swwwiheadWHEREwi_type = wi_deadline ANDwi_stat = wi_status_ready ANDretry_cnt = '0' AND( wi_cd %GT l_from_date OR " l_from_date/time %LT creation_date/time( wi_cd = l_from_date ANDwi_ct %GT l_from_time ) )AND " creation_date/time %LT= l_to_date/time( wi_cd %LT l_to_date OR( wi_cd = l_to_date ANDwi_ct %LT= l_to_time ) )

note 0000790920%_hintsoracle 'INDEX("&TABLE&" "SWWWIHEAD~C" "SWWWIHEAD^C" "SWWWIHEAD_C" "SWWWIHEAD_C__X")'DB2 'USE VALUES FOR OPTIMIZATION'DB2 '&SUBSTITUTE VALUES&'. "#EC CI_HINTS

no longer select waiting work items

ELSE.

Use the task index.SELECT wi_id tclassINTO CORRESPONDING FIELDS OF TABLE lt_wi_dataFROM swwwiheadWHEREwi_rh_task IN task_sel ANDwi_stat = wi_status_ready ANDwi_type = wi_normal AND( wi_cd %GT l_from_date OR " l_from_date/time %LT creation_date/time( wi_cd = l_from_date ANDwi_ct %GT l_from_time ) )AND " creation_date/time %LT= l_to_date/time( wi_cd %LT l_to_date OR( wi_cd = l_to_date ANDwi_ct %LT= l_to_time ) ).

Add all the deadline items.SELECT wi_id tclassAPPENDING CORRESPONDING FIELDS OF TABLE lt_wi_dataFROM swwwiheadWHERE

Page 36: Sending Notifications for Work Items

wi_stat = wi_status_ready ANDwi_type = wi_deadline AND( wi_cd %GT l_from_date OR " l_from_date/time %LT creation_date/time( wi_cd = l_from_date ANDwi_ct %GT l_from_time ) )AND " creation_date/time %LT= l_to_date/time( wi_cd %LT l_to_date OR( wi_cd = l_to_date ANDwi_ct %LT= l_to_time ) )

note 0000790920%_hintsoracle 'INDEX("&TABLE&" "SWWWIHEAD~C" "SWWWIHEAD^C" "SWWWIHEAD_C" "SWWWIHEAD_C__X")'DB2 'USE VALUES FOR OPTIMIZATION'DB2 '&SUBSTITUTE VALUES&'. "#EC CI_HINTS

Filter out the deadline items with wrong taskDATA: l_wi_header LIKE swwwihead.

LOOP AT lt_wi_data.

CLEAR l_wi_header.CALL FUNCTION 'SWW_WI_HEADER_READ'EXPORTINGwi_id = lt_wi_data-wi_idIMPORTINGwi_header = l_wi_headerEXCEPTIONSOTHERS = 1.

CHECK l_wi_header-wi_type = wi_deadline.

CLEAR swwwihead.SELECT SINGLE * FROM swwwiheadWHERE wi_id = l_wi_header-wi_chckwi.

IF NOT swwwihead-wi_rh_task IN task_sel.DELETE lt_wi_data.ENDIF.ENDLOOP.

ENDIF.

ENDFORM. "select_workitems

&---------------------------------------------------------------------*& Form add_substitutes&---------------------------------------------------------------------

Page 37: Sending Notifications for Work Items

add substitutes to the list of agents match task classification against susbstitution profile

----------------------------------------------------------------------FORM add_substitutes TABLES pt_users STRUCTURE swhactorUSING p_wi_data TYPE t_wi_dataCHANGING p_rc LIKE sy-subrc.

DATA: l_subst_found,l_rc LIKE sy-subrc,

lt_user_subst TYPE t_substitution OCCURS 0 WITH HEADER LINE,lt_add_users TYPE t_substitution OCCURS 0 WITH HEADER LINE,l_tclass LIKE p_wi_data-tclass.

LOOP AT pt_users.

note 768698: consider all substitutesCLEAR l_subst_found.

check whether a substitution has already been detected

for that userLOOP AT g_substitutions.IF pt_users-objid = g_substitutions-user.l_subst_found = 'X'. " but continue for other substitutesIF NOT g_substitutions-substitute IS INITIAL.

take this oneAPPEND g_substitutions TO lt_add_users.ENDIF.ENDIF.ENDLOOP.IF l_subst_found IS INITIAL.

check for new substitutionsPERFORM update_substitutionsTABLES lt_add_usersUSING pt_usersCHANGING l_rc.ENDIF.

add the substitutes with matching tclass/profileLOOP AT lt_add_users.IF lt_add_users-profile IS INITIAL.

applies to all tclassesCONTINUE.ELSE.l_tclass = p_wi_data-tclass.IF l_tclass = l_noclass.CLEAR l_tclass.ENDIF.

Page 38: Sending Notifications for Work Items

READ TABLE lt_77roWITH KEY reppr = lt_add_users-profiletclass = l_tclassTRANSPORTING NO FIELDS.IF sy-subrc NE 0.

no match -%GT deleteDELETE lt_add_users.ENDIF.ENDIF.ENDLOOP.ENDLOOP.

update the user tableLOOP AT lt_add_users.pt_users-otype = c_pd_otype_usr.pt_users-objid = lt_add_users-substitute.APPEND pt_users.ENDLOOP.SORT pt_users BY otype objid.DELETE ADJACENT DUPLICATES FROM pt_users.

ENDFORM. " add_substitutes

&---------------------------------------------------------------------*& Form update_substitutions&---------------------------------------------------------------------

determine all substitutes of a given agent regardless of the profile/tclass

----------------------------------------------------------------------FORM update_substitutions TABLES p_user_subst TYPE t_substitution_tabUSING p_user_tab STRUCTURE swhactorCHANGING p_rc LIKE sy-subrc.

DATA: lt_agents LIKE swhactor OCCURS 0 WITH HEADER LINE,lt_subst TYPE t_substitution OCCURS 0 WITH HEADER LINE,subst_str LIKE struc OCCURS 0 WITH HEADER LINE,subst_settings LIKE padd2.

DATA: lt_inbox_view_pass TYPE TABLE OF hrwfuser_v.DATA: ls_substitute TYPE swragent.

check for substitutionCALL FUNCTION 'RH_SUBSTITUTES_GET'EXPORTINGact_plvar = spaceact_otype = p_user_tab-otypeact_objid = p_user_tab-objid

Page 39: Sending Notifications for Work Items

ACT_BEGDA = SY-DATUMact_endda = sy-datum

SHOW_HOLDER_FLAG = 'X'

AUTHORITY_CHECK = 'X'TABLES

SUBST_OBJ =subst_str = subst_strEXCEPTIONSno_substitute_found = 1OTHERS = 2.IF sy-subrc NE 0.EXIT. " no substitutesENDIF.

LOOP AT subst_str.subst_settings = subst_str-vadata.

check if substitute has adopted the substitution at the momentIF ( NOT p_psubst IS INITIAL ) AND( subst_settings-active IS INITIAL ).ls_substitute-otype = subst_str-otype.ls_substitute-objid = subst_str-objid.CALL METHOD cl_swl_substitution=%GTget_adopted_substitutionsEXPORTINGi_substitute = ls_substituteIMPORTINGet_inbox_view = lt_inbox_view_pass.READ TABLE lt_inbox_view_passWITH KEY otype = p_user_tab-otypeobjid = p_user_tab-objidTRANSPORTING NO FIELDS.IF sy-subrc %LT%GT 0.CONTINUE.ENDIF.ELSE.IF subst_settings-active IS INITIAL.CONTINUE.ENDIF.ENDIF.

IF NOT subst_settings-active IS INITIAL.IF subst_str-otype = c_pd_otype_usr.

add the entry directlylt_subst-user = p_user_tab-objid.lt_subst-substitute = subst_str-objid.lt_subst-profile = subst_settings-reppr.

Page 40: Sending Notifications for Work Items

APPEND lt_subst.ELSE.

result is org unit -%GT compute associated usersCALL FUNCTION 'RH_STRUC_GET'EXPORTINGact_otype = subst_str-otypeact_objid = subst_str-objidact_wegid = 'SAP_TAGT'TABLESresult_tab = lt_agentsEXCEPTIONSno_plvar_found = 1no_entry_found = 2OTHERS = 3.LOOP AT lt_agents.IF lt_agents-otype = c_pd_otype_usr.

add the entry directlylt_subst-user = subst_str-objid.lt_subst-substitute = lt_agents-objid.lt_subst-profile = subst_settings-reppr.APPEND lt_subst.ENDIF.ENDLOOP.ENDIF.

ENDIF.ENDLOOP.

append new substitutions to global substitutions and to parameterAPPEND LINES OF lt_subst TO g_substitutions.APPEND LINES OF lt_subst TO p_user_subst.

ENDFORM. "update_substitutions

&---------------------------------------------------------------------*& Form add_shortcut_inbox&---------------------------------------------------------------------

Add shortcut attachment launching TX SO01----------------------------------------------------------------------FORM add_shortcut_inbox USING p_user TYPE syunamep_langu TYPE sylangup_email TYPE stringp_wi_header TYPE swwwiheadCHANGING p_line_no TYPE ipt_content TYPE t_solisti1_tabpt_header TYPE t_solisti1_tabpt_packing TYPE sopcklsti1_tab.

Page 41: Sending Notifications for Work Items

Add the attachment to the document content.

DATA: lt_attach LIKE solisti1 OCCURS 0.DATA: lt_content LIKE solisti1 OCCURS 0.DATA: lt_header LIKE solisti1 OCCURS 0 WITH HEADER LINE.DATA: lt_packing LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.

take over existing lineslt_header[] = pt_header[].lt_content[] = pt_content[].lt_packing[] = pt_packing[].

assemble shortcutPERFORM create_shortcut_inboxUSING p_user p_langu p_email p_logonCHANGING lt_attach[].

DESCRIBE TABLE lt_attach LINES l_count.APPEND LINES OF lt_attach TO lt_content.

attachment header

CLEAR lt_header. REFRESH lt_header.

lt_header = 'Go to Inbox'(005). "File name

APPEND lt_header.

CLEAR lt_header.lt_header = '&SO_FORMAT=ASC'." This indicates that it is ASCII.APPEND lt_header.

Update the packing list.CLEAR lt_packing.lt_packing-head_start = 1.lt_packing-head_num = 2.lt_packing-body_start = p_line_no + 1.lt_packing-body_num = l_count.lt_packing-doc_type = 'SAP'.lt_packing-doc_size = 255 * l_count.lt_packing-obj_name = 'INBOX'.lt_packing-obj_descr = 'Go to Inbox'(005).lt_packing-obj_langu = p_wi_header-wi_lang.APPEND lt_packing.

Page 42: Sending Notifications for Work Items

pass parameters backADD l_count TO p_line_no.pt_header[] = lt_header[].pt_content[] = lt_content[].pt_packing[] = lt_packing[].

ENDFORM. " add_shortcut_inbox

&--------------------------------------------------------------------*& Form create_shortcut_inbox&--------------------------------------------------------------------

create shortcut launching transaction SO01 (SAPoffice Inbox)---------------------------------------------------------------------FORM create_shortcut_inboxUSING p_user TYPE syunamep_langu TYPE sylangup_email TYPE stringp_logon_id TYPE text40CHANGING pt_attach TYPE soli_tab.

create sap shortcut attachment

entered( 'create_inbox_attachment' ).

DATA: l_logon_id TYPE text40.DATA: l_scrap TYPE text255.

assemble piece for email address

is required when sending to proxyIF NOT p_email IS INITIAL.CONCATENATE 'Workflow' l_crlf "#EC NOTEXT'Email=' p_email "#EC NOTEXTINTO l_scrap. "#EC NOTEXTENDIF.

parameter conversionsl_logon_id = p_logon_id.

create the shortcut as tableCALL FUNCTION 'SWN_CREATE_SHORTCUT'EXPORTINGi_transaction = 'SO01' "#EC NOTEXT

Page 43: Sending Notifications for Work Items

I_REPORT =

I_SYSTEM_COMMAND =

i_parameter =i_saplogon_id = l_logon_idi_sysid = sy-sysid

I_GUIPARM =i_user = p_useri_language = p_langui_windowsize = 'Normal window' "#EC NOTEXT

I_TITLE =i_custom = l_scrapIMPORTINGshortcut_table = pt_attach

SHORTCUT_STRING =EXCEPTIONS

INCONSISTENT_PARAMETERS = 1OTHERS = 1.

IF sy-subrc %LT%GT 0.REFRESH pt_attach.ENDIF.

leaving( 'create_inbox_attachment' ).ENDFORM. "CREATE_SHORTCUT_INBOX

&---------------------------------------------------------------------*& Form add_shortcut_action&---------------------------------------------------------------------

Add shortcut attachment launching TX SWNWIEX----------------------------------------------------------------------FORM add_shortcut_action USING p_user TYPE syunamep_langu TYPE sylangup_email TYPE stringp_wi_header TYPE swwwiheadp_action TYPE char40CHANGING p_line_no TYPE ipt_content TYPE t_solisti1_tabpt_header TYPE t_solisti1_tabpt_packing TYPE sopcklsti1_tab.

Add the attachment to the document content.

Page 44: Sending Notifications for Work Items

DATA: lt_attach LIKE solisti1 OCCURS 0.DATA: lt_header LIKE solisti1 OCCURS 0 WITH HEADER LINE.DATA: lt_content LIKE solisti1 OCCURS 0.DATA: lt_packing LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.DATA: l_caption TYPE string.DATA: l_action_param TYPE text255.

take over existing lines

lt_header[] = pt_header[].lt_content[] = pt_content[].lt_packing[] = pt_packing[].

assign the appropriate captionCASE p_action.WHEN c_action_display.l_caption = 'Workitem anzeigen'(s06).WHEN c_action_execute.l_caption = 'Workitem ausführen'(s04).WHEN OTHERS.l_caption = 'Unbekannte Aktion'(s03).ENDCASE.

assemble shortcutl_action_param = p_wi_header-wi_id.PERFORM create_shortcut_actionUSING p_action l_action_param p_user p_langu p_email p_logonCHANGING lt_attach[].

DESCRIBE TABLE lt_attach LINES l_count.APPEND LINES OF lt_attach TO lt_content.

attachment header

CLEAR lt_header. REFRESH lt_header.

lt_header = 'workitem.sap'." File name

APPEND lt_header.

CLEAR lt_header.lt_header = '&SO_FORMAT=ASC'." This indicates that it is ASCII.APPEND lt_header.

Page 45: Sending Notifications for Work Items

Update the packing list.CLEAR lt_packing.lt_packing-head_start = 1.lt_packing-head_num = 2.lt_packing-body_start = p_line_no + 1.lt_packing-body_num = l_count.lt_packing-doc_type = 'SAP'.lt_packing-doc_size = 255 * l_count.lt_packing-obj_name = 'WORKITEM'.lt_packing-obj_descr = l_caption.lt_packing-obj_langu = p_wi_header-wi_lang.APPEND lt_packing.

pass parameters backADD l_count TO p_line_no.pt_header[] = lt_header[].pt_content[] = lt_content[].pt_packing[] = lt_packing[].

ENDFORM. " add_shortcut_action

&--------------------------------------------------------------------*& Form create_shortcut_action&--------------------------------------------------------------------

create a shortcut for workitem display or execute---------------------------------------------------------------------FORM create_shortcut_actionUSING p_action TYPE char40p_action_param TYPE text255p_user TYPE syunamep_langu TYPE sylangup_email TYPE stringp_logon_id TYPE text40CHANGING pt_attach TYPE soli_tab.

create sap shortcut attachment

entered( 'create_action_wa_attach' ).

DATA: l_param TYPE text255.DATA: l_logon_id TYPE text40.DATA: l_scrap TYPE text255.

assemble piece for email address

Page 46: Sending Notifications for Work Items

is required when sending to proxyIF NOT p_email IS INITIAL.CONCATENATE 'Workflow' l_crlf "#EC NOTEXT'Email=' p_email "#EC NOTEXTINTO l_scrap.ENDIF.

assemble the parameter stringCONCATENATE'p_action=' p_action "#EC NOTEXT'; p_wi_id=' p_action_param "#EC NOTEXT'; DYNP_OKCODE=ONLI' "#EC NOTEXTINTO l_param.

parameter conversionsl_logon_id = p_logon_id.

create the shortcut as tableCALL FUNCTION 'SWN_CREATE_SHORTCUT'EXPORTINGi_transaction = '*swnwiex' "#EC NOTEXT

I_REPORT =

I_SYSTEM_COMMAND =i_parameter = l_parami_saplogon_id = l_logon_idi_sysid = sy-sysid

I_GUIPARM =i_user = p_useri_language = p_langui_windowsize = 'Normal window' "#EC NOTEXT

I_TITLE =i_custom = l_scrapIMPORTINGshortcut_table = pt_attach

SHORTCUT_STRING =EXCEPTIONS

INCONSISTENT_PARAMETERS = 1OTHERS = 1.

Page 47: Sending Notifications for Work Items

IF sy-subrc %LT%GT 0.REFRESH pt_attach.EXIT.ENDIF.

leaving( 'create_action_wa_attach' ).ENDFORM. "CREATE_SHORTCUT_ACTION

&--------------------------------------------------------------------*& Form get_email_address&--------------------------------------------------------------------

get the email address from various sources---------------------------------------------------------------------FORM get_email_addressUSING p_uname TYPE syunameCHANGING p_address TYPE t_user_data.

init email "note 780623CLEAR p_address.

first try central address managementPERFORM get_email_address_camUSING p_unameCHANGING p_address.

if this failed try the auto-forwarding addressIF p_address-email IS INITIAL.PERFORM get_email_address_auto_forwUSING p_unameCHANGING p_address.ENDIF.ENDFORM. "get_email_address

&--------------------------------------------------------------------*& Form get_email_address_cam&--------------------------------------------------------------------

get address data from the central address management (CAM)---------------------------------------------------------------------FORM get_email_address_camUSING p_uname TYPE syunameCHANGING p_address TYPE t_user_data.

load user data

DATA lt_adsmtp TYPE TABLE OF bapiadsmtp.DATA lt_return TYPE TABLE OF bapiret2 .

Page 48: Sending Notifications for Work Items

DATA ls_address TYPE bapiaddr3.DATA l_uname TYPE syuname.DATA ls_defaults TYPE bapidefaul.

FIELD-SYMBOLS:%LTadsmtp%GT TYPE bapiadsmtp.

entered( 'get_address1' ).

get the other thingsMOVE p_uname TO l_uname.CALL FUNCTION 'BAPI_USER_GET_DETAIL'EXPORTINGusername = l_unameIMPORTINGdefaults = ls_defaults " note 849251address = ls_addressTABLESreturn = lt_returnaddsmtp = lt_adsmtp.

languageIF NOT ls_address-langu_p IS INITIAL.MOVE ls_address-langu_p TO p_address-langu.ELSE.p_address-langu = sy-langu.ENDIF.

note 849251: logon languageIF NOT ls_defaults-langu IS INITIAL.MOVE ls_defaults-langu to p_address-logon_langu.ELSE.p_address-logon_langu = sy-langu.ENDIF.

email address

use standard email address (note 746911)READ TABLE lt_adsmtp WITH KEY std_no = 'X'ASSIGNING %LTadsmtp%GT.IF sy-subrc = 0.MOVE %LTadsmtp%GT-e_mail TO p_address-email.ELSE.

use another email addressREAD TABLE lt_adsmtp ASSIGNING %LTadsmtp%GT INDEX 1.IF sy-subrc = 0.MOVE %LTadsmtp%GT-e_mail TO p_address-email.

Page 49: Sending Notifications for Work Items

ENDIF.ENDIF.

leaving( 'get_address1' ).

ENDFORM. "get_email_address

&--------------------------------------------------------------------*& Form get_email_address_auto_forw&--------------------------------------------------------------------

get e-mail address from auto-forwarding---------------------------------------------------------------------FORM get_email_address_auto_forwUSING p_uname TYPE syunameCHANGING p_address TYPE t_user_data.

compute email address from auto-forwardingDATA l_uname TYPE syuname.DATA l_comart TYPE so_com_art.DATA l_address TYPE so_rec_ext.

MOVE p_uname TO l_uname.CALL FUNCTION 'SO_AUTOMATIC_FORWARD_GET'EXPORTINGuser = l_unameIMPORTINGaddress = l_addresscomart = l_comartEXCEPTIONSsubstitute_not_active = 1x_error = 2OTHERS = 3.IF sy-subrc = 0.IF l_comart = c_com_type_int.p_address-email = l_address.ENDIF.ENDIF.

ENDFORM. "get_email_address_auto_forw

&--------------------------------------------------------------------*& Form string_to_table&--------------------------------------------------------------------

Convert string to SO table---------------------------------------------------------------------FORM string_to_table

Page 50: Sending Notifications for Work Items

USING p_string TYPE stringCHANGING p_table TYPE soli_tab.

DATA: ls_soli TYPE soli,l_strlen TYPE i,l_string TYPE string.

CLEAR p_table.

l_string = p_string.

l_strlen = STRLEN( l_string ).CHECK l_strlen NE 0.

longer than one lineWHILE l_strlen GT 255.ls_soli = l_string.APPEND ls_soli TO p_table .SHIFT l_string BY 255 PLACES.l_strlen = STRLEN( l_string ).ENDWHILE.

ls_soli = l_string.APPEND ls_soli TO p_table.

ENDFORM. "string_to_table

&--------------------------------------------------------------------*& Form table_to_string&--------------------------------------------------------------------

Convert SO table to string---------------------------------------------------------------------FORM table_to_stringUSING p_table TYPE soli_tabCHANGING p_string TYPE string.

DATA: l_string TYPE string.

FIELD-SYMBOLS:%LTline%GT TYPE LINE OF soli_tab.

Trick 17LOOP AT p_table ASSIGNING %LTline%GT.CONCATENATE l_string ' ' INTO l_stringSEPARATED BY %LTline%GT.ENDLOOP.

Page 51: Sending Notifications for Work Items

remove trailing spacesSHIFT l_string RIGHT DELETING TRAILING space.SHIFT l_string LEFT DELETING LEADING space.

MOVE l_string TO p_string.

ENDFORM. "table_to_string

&--------------------------------------------------------------------*& Form tline_to_string&--------------------------------------------------------------------

Convert SAPscript table to string---------------------------------------------------------------------FORM tline_to_stringTABLES p_table "like tline occurs 0CHANGING p_string TYPE string.

DATA: l_string TYPE string.

FIELD-SYMBOLS:%LTline%GT TYPE tline.

Trick 17LOOP AT p_table ASSIGNING %LTline%GT.CONCATENATE l_string %LTline%GT-tdline l_crlf INTO l_string.ENDLOOP.

remove trailing spacesSHIFT l_string RIGHT DELETING TRAILING space.SHIFT l_string LEFT DELETING LEADING space.

MOVE l_string TO p_string.

ENDFORM. "tline_to_string

&--------------------------------------------------------------------*& Form get_document&--------------------------------------------------------------------

retrieve text created with SE61---------------------------------------------------------------------FORM get_document USING p_type LIKE dokhl-idp_object LIKE dokhl-objectp_langu TYPE sylanguCHANGING p_text TYPE string.

DATA: ls_docu_head LIKE thead .DATA: lt_tline TYPE TABLE OF tline.DATA: lt_stream TYPE TABLE OF solisti1.

Page 52: Sending Notifications for Work Items

IF p_object IS INITIAL.EXIT.ENDIF.

get text in SAPscript formatCALL FUNCTION 'DOCU_GET'EXPORTINGid = p_typelangu = p_languobject = p_objectIMPORTINGhead = ls_docu_headTABLESline = lt_tlineEXCEPTIONSOTHERS = 1.

error handlingIF sy-subrc %LT%GT 0.MESSAGE ID 'S4' TYPE 'E' NUMBER '601' WITH p_text sy-langu.EXIT.ENDIF.

replace includesCALL FUNCTION 'TEXT_INCLUDE_REPLACE'EXPORTINGheader = ls_docu_headTABLESlines = lt_tline.

replace variablesCALL FUNCTION 'TEXT_SYMBOL_REPLACE'EXPORTINGheader = ls_docu_headTABLESlines = lt_tline.

format into text streamCALL FUNCTION 'CONVERT_ITF_TO_STREAM_TEXT'TABLESitf_text = lt_tlinetext_stream = lt_stream.

IF lt_stream[] IS INITIAL.INSERT space INTO lt_stream INDEX 1.ENDIF.

convert to string.PERFORM table_to_string USING lt_stream CHANGING p_text.

ENDFORM. "get_document

Page 53: Sending Notifications for Work Items

&--------------------------------------------------------------------*& Form get_dynpro_value&--------------------------------------------------------------------

get value of a particular field on the selection screen---------------------------------------------------------------------FORM get_dynpro_value USING p_fieldCHANGING p_value.

DATA: BEGIN OF dynp_tab OCCURS 1.INCLUDE STRUCTURE dynpread.DATA: END OF dynp_tab.DATA: l_repid LIKE sy-repid.

CLEAR dynp_tab. REFRESH dynp_tab.dynp_tab-fieldname = p_field.dynp_tab-stepl = 0.APPEND dynp_tab.

l_repid = sy-repid.

CALL FUNCTION 'DYNP_VALUES_READ'EXPORTINGdyname = l_repiddynumb = '1000'translate_to_upper = ' 'TABLESdynpfields = dynp_tabEXCEPTIONSOTHERS = 1.

IF sy-subrc NE 0.EXIT.ENDIF.

p_value = dynp_tab-fieldvalue.

ENDFORM. "get_dynpro_value

&--------------------------------------------------------------------*& Form select_modified_workitems&--------------------------------------------------------------------

retrieve SWWLOGHIST entries which contribute---------------------------------------------------------------------FORM select_modified_workitems.

DATA: lt_swwloghist TYPE STANDARD TABLE OF swwloghist.DATA: lr_method TYPE RANGE OF funcname.DATA: ls_method LIKE LINE OF lr_method.

Page 54: Sending Notifications for Work Items

DATA: lt_wi_log TYPE t_wi_data OCCURS 0 WITH HEADER LINE.DATA: l_from_tstamp TYPE timestampl.DATA: l_to_tstamp TYPE timestampl.

FIELD-SYMBOLS: %LTswwloghist%GT TYPE swwloghist.

fill the list of actions affecting workitems in our sense

ls_method-sign = 'I'.ls_method-option = 'EQ'.ls_method-low = 'SWW_WI_FORWARD'.APPEND ls_method TO lr_method.ls_method-low = 'SWW_WI_BACK'.APPEND ls_method TO lr_method.ls_method-low = 'SWW_WI_RESUBMISSION_END'.APPEND ls_method TO lr_method.ls_method-low = 'SWW_WI_STATUS_SET_READY'.APPEND ls_method TO lr_method.

create time stampCONVERT DATE l_from_date TIME l_from_timeINTO TIME STAMP l_from_tstampTIME ZONE l_system_timezone.

create to time stamp (note 865149)CONVERT DATE l_to_date TIME l_to_timeINTO TIME STAMP l_to_tstampTIME ZONE l_system_timezone.

select in SWWLOGHISTSELECT wi_id timestamp FROM swwloghistINTO CORRESPONDING FIELDS OF TABLE lt_swwloghistWHERE timestamp GT l_from_tstampAND timestamp LE l_to_tstampAND method IN lr_method.CHECK lt_swwloghist IS NOT INITIAL.

we need only one entrySORT lt_swwloghist BY wi_id.DELETE ADJACENT DUPLICATES FROM lt_swwloghist COMPARING wi_id.

Page 55: Sending Notifications for Work Items

select header with range tab filtering by taskSELECT wi_id tclass FROM swwwiheadINTO CORRESPONDING FIELDS OF TABLE lt_wi_logFOR ALL ENTRIES IN lt_swwloghistWHERE wi_id EQ lt_swwloghist-wi_idAND wi_rh_task IN task_sel.

merge with existing ID tableAPPEND LINES OF lt_wi_log TO lt_wi_data.

remove duplicatesSORT lt_wi_data BY wi_id.DELETE ADJACENT DUPLICATES FROM lt_wi_data COMPARING wi_id.

ENDFORM. "select_modified_workitems

&---------------------------------------------------------------------*& Form convert_header&---------------------------------------------------------------------

convert header formats----------------------------------------------------------------------

--%GTP_HEAD swwwihead

%LT--P_HDR swr_wihdr----------------------------------------------------------------------form convert_header using p_head TYPE swwwiheadchanging p_hdr TYPE swr_wihdr.move-corresponding p_head to p_hdr.

endform. " convert_header

*Text elements*----------------------------------------------------------

001 *** Text for RSWUWFML2 *** 002 SAPoffice

003 Message

004 Execute the work item by opening the attachment

005 Workflow Inbox

M01 Program Error or Customizing Error:

M02 Form tasks could not be determined

Page 56: Sending Notifications for Work Items

M03 Work item:

M04 Message sent to:

M05 Send failed

M06 No description

M08 No work items to be sent found

M09 Receiver:

M10 A total of & work items were read

M11 Transfer Successful

M12 Transfer failed to following recipients:

M13 Code

M14 Creating trace. ID =

S01 SAP System: &. You have received new work items

S02 &: You have received new work items

S03 Unknown action

S04 Execute Work Item

S05 Business Workplace

S06 Display work item

S07 Work Item in SAP System:

S08 Log on to the SAP system and open your Workflow inbox

T01 Send granularity

T02 Add Executable Attachment to Message For

T03 Standard Text for Notification

T04 Data for an Individual Run (Time Stamp Not Set)

T05 Log

T06 Instance Data

T07 SAP Shortcut Parameter

T08 Exits

*Selection texts*----------------------------------------------------------

Page 57: Sending Notifications for Work Items

P_EPIL After Work Item Description P_EXADR FM for Determining Address

P_EXPRE FM for Preparatory Phase

P_FROMD From work item creation date

P_FROMT From work item creation time

P_JOBSUF Job suffix

P_LOGON SAPLOGON_ID

P_NEW New Work Items Only

P_PROL Before Work Item Description

P_PSUBST With Passive Substitution

P_S_NAC Message Class for Subject

P_S_NAN Message Number for Subject

P_TASKS Tasks (blank = all)

P_USER Users (blank = all)

X_14ALL Collective Message

X_ALW_TR All

X_ERR_TR Errors Only

X_N14ALL One Message per Work Item

X_NO_TR Nothing

X_SC_DIS Work Item Display

X_SC_EXE Work Item Execution

X_SC_INB Workflow Entry

*Messages*----------------------------------------------------------*

Message class: P_MSGNO*P_M*

Message class: P_S_NAC*P_S*

Page 58: Sending Notifications for Work Items

Message class: S4*601 Object & in language & does not exist*

Message class: SWU_NOTIF*003 SAPoffice document &1 sent*004 Work item &1 has no selected agent. Send not possible*005 Error when sending work item &1*006 & work items were read. None were sent*007 Work item &: Send ok*008 Work items sent successfully*009 Work item &: Attempt to send failed*010 Unable to send work items*011 Work item &1 sent to &2*012 Work items sent to &1*013 User &1 has no e-mail address*014 Work item &1 being edited*015 Selection Setting: &1 = &2*019 User &1 does not have an e-mail address. Unable to send*020 No system time zone maintained. Unable to select work items*

Message class: WZ*371 Sending failed for work item &1: Send operation failed*373 Message for work item &1 sent to address &2*374 Sending failed for work item &1: Sender not completed*375 Sending failed for work item &1: Error mailing*376 Sending failed for work item &1: User does not exist*377 Sending failed for work item &1: Address does not exist*378 Sending failed for work item &1: Error in configuration file*379 Sending failed for work item &1: Sendmail token not found*380 Sending failed for work item &1: Pipe could not be opened*381 Sending failed for work item &1: Pipe could not be closed

*Selection texts*----------------------------------------------------------

P_EPIL After Work Item Description P_EXADR FM for Determining Address

P_EXPRE FM for Preparatory Phase

P_FROMD From work item creation date

P_FROMT From work item creation time

P_JOBSUF Job suffix

P_LOGON SAPLOGON_ID

P_NEW New Work Items Only

P_PROL Before Work Item Description

Page 59: Sending Notifications for Work Items

P_PSUBST With Passive Substitution

P_S_NAC Message Class for Subject

P_S_NAN Message Number for Subject

P_TASKS Tasks (blank = all)

P_USER Users (blank = all)

X_14ALL Collective Message

X_ALW_TR All

X_ERR_TR Errors Only

X_N14ALL One Message per Work Item

X_SC_DIS Nothing

X_SC_EXE Work Item Display

X_SC_INB Workflow Entry

*Messages*----------------------------------------------------------*

Message class: P_MSGNO*P_M*

Message class: P_S_NAC*P_S*

Message class: S4*601 Object & in language & does not exist*

Message class: SWU_NOTIF*003 SAPoffice document &1 sent*004 Work item &1 has no selected agent. Send not possible*005 Error when sending work item &1*006 & work items were read. None were sent*007 Work item &: Send ok*008 Work items sent successfully*009 Work item &: Attempt to send failed*010 Unable to send work items*011 Work item &1 sent to &2*012 Work items sent to &1*013 User &1 has no e-mail address*014 Work item &1 being edited*015 Selection Setting: &1 = &2*019 User &1 does not have an e-mail address. Unable to send

Page 60: Sending Notifications for Work Items

*020 No system time zone maintained. Unable to select work items*

Message class: WZ*371 Sending failed for work item &1: Send operation failed*373 Message for work item &1 sent to address &2*374 Sending failed for work item &1: Sender not completed*375 Sending failed for work item &1: Error mailing*376 Sending failed for work item &1: User does not exist*377 Sending failed for work item &1: Address does not exist*378 Sending failed for work item &1: Error in configuration file*379 Sending failed for work item &1: Sendmail token not found*380 Sending failed for work item &1: Pipe could not be opened*381 Sending failed for work item &1: Pipe could not be closed