Applies to:
SAP ECC 6.0. SAP HR-OM, SAP PA, PA-OM integration, CATS, ESS. MSS
Summary
CATS Standard Task – TS31000007 doesn't trigger any email notification to employee (on their email ID maintained in infotype PA0105, subtype 0010) when the Time sheet is rejected by the manager in Portal. SAP also does not send an email to approvers when the time sheet is sent for approval.
This enhancement enables us to send an Rejection email notification to the employee when Time is rejected by the manager in Portal and to send an information email to manager when time sheet is sent for approval by an employee.
This requirement should work for any CATS profile(defined in CAC1) which uses the above Standard Task or for any other standard/custom task configured in CAC1.
This document should help other consultants looking to implement similar kind of functionality for time sheet approvals.
Author:Vamsi Krishna Karanam/Parag Parikh
Company:Deloitte Consulting LLP
Created on: 3rd July 2012
Author Bio
Parag Parikh
Parag Parikh is an SAP ABAP/Workflow consultant with 5 years experience in SAP consulting. Parag has worked extensively on SAP ABAP/OO-ABAP and workflow. Parag has worked on RICEFW development on multiple SAP modules. He is a SAP FS-CD Techno-functional consultant as well.
Parag is currently working with Deloitte Consulting LLP as Senior Consultant.
Author Bio
Vamsi Krishna Karanam
Vamsi Krishna Karanam is an SAP ABAP-HR techno-functional expert with 8 years of consulting experience. Vamsi's experience includes consulting in US Benefits, US Payroll, PA, OM ESS and MSS. He has also worked on SAP HCM Process and Forms. Vamsi has played many roles in consulting environment including process lead, consultant, trainer and manager.
Vamsi is currently working as SAP ABAP HR senior consultant for Deloitte Consulting LLP.
When time sheet is submitted for approval, SAP calls subroutine FORM workflow_approval in include LCATSF6P. This subroutine calls subroutine FORM workflow_approval_default.
In subroutine WORKFLOW_APPROVAL_DEFAULT, SAP determines approvers of the time sheet based on configuration for time entry profile in CAC1.
SAP stores approvers in internal table LT_AGENT. Hence at the end of this subroutine we can place an implicit enhancement implementation to send email to approvers.
Approvers returned by SAP in internal table LT_AGENT can be of any one the organization object types including Position, User, Role, Job, Organization Unit etc. Below is a sample code to put in implicit enhancement above to send email to approvers of type 'S' i.e. position or 'US' i.e. users. This can be modified further as per requirements.
ENHANCEMENT 1 ZHRIE_CATSSUBMIT_MAIL_LCATS028.
DATA: l_message TYPE soli_tab,
l_send_result TYPE c,
l_cnt TYPE i,
l_doc_len TYPE so_obj_len,
l_subject(50) TYPE c,
l_email_body TYPE soli,
lo_sender TYPE REF TO cl_sapuser_bcs,
lo_receiver TYPE REF TO if_recipient_bcs,
lo_email TYPE REF TO cl_bcs,
lo_email_body TYPE REF TO cl_document_bcs,
lx_exception TYPE REF TO cx_bcs, "#EC NEEDED
l_email_id TYPE ad_smtpadr,
l_usrid TYPE pa0105-usrid_long,
l_molga TYPE molga,
l_pernr TYPE pernr_d,
lr_msg_hand TYPE REF TO cl_hrpa_message_list,
lt_object TYPE STANDARD TABLE OF tree_objec,
ls_object TYPE tree_objec,
lt_approvers TYPE STANDARD TABLE OF pernr_d,
ls_approvers TYPE pernr_d.
l_subject = 'Timesheet Submitted for Approval'.
REFRESH: l_message.
CLEAR: l_email_body.
l_email_body = '<html>'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '<body>'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '<p style="font-family:arial;font-size:12px;">'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body. "#EC *
CONCATENATE 'Your worklist for approving time entry contains'
' one or more requests that you need to process.'
' For more information, see your worklist.'
INTO l_email_body SEPARATED BY space.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '<br />'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '<br />'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
CONCATENATE 'To access your worklist, go to '
' Manager Self-Service > Manage My Team > Time and Attendance Management > Review Timesheets.'
INTO l_email_body SEPARATED BY space.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '<br />'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '<br />'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '<br />'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '<br />'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '</body>'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '</html>'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
TRY.
lo_email = cl_bcs=>create_persistent( ).
* Get the length of the line
* Assumption: contents table will not be initial
CLEAR l_cnt.
DESCRIBE TABLE l_message LINES l_cnt.
READ TABLE l_message INTO l_email_body INDEX l_cnt.
l_doc_len = ( l_cnt - 1 ) * 255 + STRLEN( l_email_body ).
lo_email_body = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = l_message
i_length = l_doc_len
i_subject = l_subject
i_language = sy-langu ).
lo_email->set_document( lo_email_body ).
* Sender - System User
lo_sender = cl_sapuser_bcs=>create('WF-BATCH').
lo_email->set_sender( i_sender = lo_sender ).
lo_email->set_status_attributes( i_requested_status = 'E' ).
* Receiver Employee Email ID
LOOP AT lt_agent.
CLEAR l_email_id.
IF lt_agent-otype = 'S'.
CALL FUNCTION 'RH_OM_GET_HOLDER_OF_POSITION'
EXPORTING
otype = lt_agent-otype
objid = lt_agent-objid
TABLES
disp_tab = lt_object
EXCEPTIONS
no_active_plvar = 1
OTHERS = 2.
IF sy-subrc = 0.
DELETE lt_object where NOT ( begda LE sy-datum AND
endda GT sy-datum ).
LOOP AT lt_object INTO ls_object WHERE otype = 'P'.
ls_approvers = ls_object-objid.
APPEND ls_approvers TO lt_approvers.
CLEAR: ls_object, ls_approvers.
ENDLOOP.
ENDIF.
ELSEIF lt_agent-otype = 'US'.
SELECT pernr UP TO 1 ROWS FROM pa0105
INTO ls_approvers WHERE
subty = '0001' AND
usrid = lt_agent-objid AND
begda LT sy-datum AND
endda GT sy-datum.
IF sy-subrc EQ 0.
APPEND ls_approvers TO lt_approvers.
CLEAR ls_approvers.
ENDIF.
ENDSELECT.
ENDIF.
ENDLOOP.
CHECK lt_approvers IS NOT INITIAL.
LOOP AT lt_approvers INTO ls_approvers.
SELECT usrid_long UP TO 1 ROWS FROM pa0105
INTO l_email_id WHERE
subty = '0010' AND
pernr = ls_approvers AND
begda LT sy-datum AND
endda GT sy-datum.
IF sy-subrc EQ 0.
lo_receiver =
cl_cam_address_bcs=>create_internet_address( l_email_id ).
lo_email->add_recipient( i_recipient = lo_receiver
i_express = abap_false ).
ENDIF.
ENDSELECT.
CLEAR: ls_approvers, l_email_id.
ENDLOOP.
*
lo_email->set_send_immediately( abap_true ).
* Sending the email notification to Employee
lo_email->send( EXPORTING
i_with_error_screen = space
RECEIVING
result = l_send_result ).
IF l_send_result = abap_true.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
ENDIF.
CATCH cx_bcs INTO lx_exception. "#EC NO_HANDLER
ENDTRY.
ENDENHANCEMENT.
SAP provides configuration steps in IMG to sent notification fo rejection to employee. SAP sends notification by calling FM CATS_SEND_MAIL. This FM sends email notification to SBWP or UWL of employee. We can put an implicit enhancement at the beginning of this FM to send emails to email ID of employee.
Standard configuration to send email to SAP inbox on rejection can be configured in “Define Profiles and Assign to views” step on SPRO.
Design custom FM ZHRTM_CATS_SEND_EMAIL and put logic below in FM to send email to outlook email ID of employees.
FUNCTION zhrtm_cats_send_email.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_AENAM) LIKE CATSHR-AENAM
*" REFERENCE(I_HEADER) LIKE SOOD1-OBJDES
*" REFERENCE(I_CPERNR) LIKE CATSHR-PERNR
*"---------------------------------------------------------------------
STATICS : lt_pernrs TYPE STANDARD TABLE OF pernr_d.
DATA: l_message TYPE soli_tab,
l_send_result TYPE c,
l_cnt TYPE i,
l_doc_len TYPE so_obj_len,
l_subject(50) TYPE c,
l_email_body TYPE soli,
lo_sender TYPE REF TO cl_sapuser_bcs,
lo_receiver TYPE REF TO if_recipient_bcs,
lo_email TYPE REF TO cl_bcs,
lo_email_body TYPE REF TO cl_document_bcs,
lx_exception TYPE REF TO cx_bcs, "#EC NEEDED
l_email_id TYPE ad_smtpadr,
l_usrid TYPE pa0105-usrid_long,
l_molga TYPE molga,
l_pernr TYPE pernr_d,
lr_msg_hand TYPE REF TO cl_hrpa_message_list.
CONSTANTS: lc_0010 TYPE subty VALUE '0010'.
l_pernr = i_cpernr.
READ TABLE lt_pernrs WITH KEY l_pernr TRANSPORTING NO FIELDS.
IF sy-subrc EQ 0.
EXIT.
ELSE.
APPEND l_pernr TO lt_pernrs.
ENDIF.
CALL FUNCTION 'HR_ECM_GET_EE_MOLGA'
EXPORTING
pernr = l_pernr
message_handler = lr_msg_hand
IMPORTING
molga = l_molga.
IF l_molga NE '10' AND l_molga NE '07'.
EXIT.
ENDIF.
"Get email address of the employee
SELECT SINGLE usrid_long INTO l_usrid FROM pa0105
WHERE pernr EQ i_cpernr
AND subty EQ lc_0010
AND begda LE sy-datum
AND endda GE sy-datum.
CHECK sy-subrc EQ 0.
CHECK l_usrid IS NOT INITIAL.
l_subject = text-001.
REFRESH: l_message.
CLEAR: l_email_body.
l_email_body = '<html>'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '<body>'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '<p style="font-family:arial;font-size:12px;">'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body. "#EC *
CONCATENATE text-002
text-003
INTO l_email_body SEPARATED BY space.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '<br />'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '<br />'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
CONCATENATE text-004 ''
INTO l_email_body SEPARATED BY space.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '<br />'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '<br />'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '</body>'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
l_email_body = '</html>'.
APPEND l_email_body TO l_message.
CLEAR: l_email_body.
TRY.
lo_email = cl_bcs=>create_persistent( ).
* Get the length of the line
* Assumption: contents table will not be initial
CLEAR l_cnt.
DESCRIBE TABLE l_message LINES l_cnt.
READ TABLE l_message INTO l_email_body INDEX l_cnt.
l_doc_len = ( l_cnt - 1 ) * 255 + STRLEN( l_email_body ).
lo_email_body = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = l_message
i_length = l_doc_len
i_subject = l_subject
i_language = sy-langu ).
lo_email->set_document( lo_email_body ).
* Sender - System User
lo_sender = cl_sapuser_bcs=>create('WF-BATCH').
lo_email->set_sender( i_sender = lo_sender ).
lo_email->set_status_attributes( i_requested_status = 'E' ).
* Receiver Employee Email ID
l_email_id = l_usrid.
lo_receiver =
cl_cam_address_bcs=>create_internet_address( l_email_id ).
lo_email->add_recipient( i_recipient = lo_receiver
i_express = abap_false ).
lo_email->set_send_immediately( abap_true ).
* Sending the email notification to Employee
lo_email->send( EXPORTING
i_with_error_screen = space
RECEIVING
result = l_send_result ).
IF l_send_result = abap_true.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
ENDIF.
CATCH cx_bcs INTO lx_exception. "#EC NO_HANDLER
ENDTRY.
ENDFUNCTION.
We can call this FM in implicit enhancement at the beginning of the SAP FM CATS_SEND_MAIL.
Shown below is the sample code inside this enhancement.
ENHANCEMENT 1 ZHRIE_CATS_REJECTION_EMAIL. "active version
CONSTANTS: lc_id type char1 value 'I',
lc_key type char3 value '004'.
DATA: lt_prg_txt TYPE STANDARD TABLE OF TEXTPOOL,
ls_text type textpool.
" Text element Text-004 of report SAPLCAPP is set as Header for
" CATS Rejection email. So read the text-004 from SAPLCAPP
READ TEXTPOOL 'SAPLCAPP' into lt_prg_txt.
READ table lt_prg_txt with KEY ID = lc_id
KEY = lc_key
into ls_text.
IF header = ls_text-entry. "To identify if it is notification of rejection
CALL FUNCTION 'ZHRTM_CATS_SEND_EMAIL'
EXPORTING
i_aenam = aenam
i_header = header
i_cpernr = cpernr.
ENDIF.
"The mail to UWL should not go so need to have EXIT here.
EXIT.
ENDENHANCEMENT.
© Copyright 2012 SAP AG. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology.
Java is a registered trademark of Oracle Corporation.
JavaScript is a registered trademark of Oracle Corporation, used under license for technology invented and implemented by Netscape.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries.
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company.
All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.
These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 |