0% found this document useful (0 votes)
78 views6 pages

Zsend Notif Fte Probation

This document contains code for a report that sends notification emails regarding employee probation forms. It retrieves employee data, inserts new probation forms, and generates emails to managers with a link to the form. Email recipients are determined from employee master data and the emails are sent using BCS functionality. Any errors encountered are also handled.

Uploaded by

DiptimayeeGupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views6 pages

Zsend Notif Fte Probation

This document contains code for a report that sends notification emails regarding employee probation forms. It retrieves employee data, inserts new probation forms, and generates emails to managers with a link to the form. Email recipients are determined from employee master data and the emails are sent using BCS functionality. Any errors encountered are also handled.

Uploaded by

DiptimayeeGupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

*&---------------------------------------------------------------------*

*& Report ZSEND_NOTIF_FTE_PROBATION


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report zsend_notif_fte_probation.
nodes : pernr.
infotypes : 0001,0002,0019.

data : lv_url type string,


lt_cont type standard table of swr_cont,
ls_cont type swr_cont,
lv_okey type swo_typeid,
lv_message type string,
lt_message type standard table of swr_mstruc,
ls_message type swr_mstruc,
lv_return type sy-subrc..
data: lt_p0019 type table of p0019,
ls_p0019 type p0019,
lt_p0001 type standard table of pa0001,
ls_p0001 type pa0001.
data : wa_hr_prob_frm type zhr_fte_prob_frm,
it_hr_prob_frm type table of zhr_fte_prob_frm.
data : it_fteh type table of zthr_fte_prob,
wa_fteh type zthr_fte_prob.
data : it_fte type table of zhr_fte_prob_frm,
wa_fte type zhr_fte_prob_frm.
data : wa_fte_prb type zthr_fte_prob,
it_fte_prb type table of zthr_fte_prob.
data : lv_mail1 type comm_id_long,
lv_mail2 type comm_id_long.
data: t_message_body type bcsy_text ,
g_objcont type solix_tab,
w_record type string,
w_pdf_xstring type xstring,
wo_send_request type ref to cl_bcs ,
wo_document type ref to cl_document_bcs,
wo_sender type ref to if_sender_bcs ,
wo_recipient type ref to if_recipient_bcs ,
wx_document_bcs type ref to cx_document_bcs ,
w_send type ad_smtpadr, " VALUE '[email protected]',
w_recpt type ad_smtpadr," VALUE '[email protected]',
w_recpt_1 type ad_smtpadr,
w_recpt_2 type ad_smtpadr,
w_sent_to_all type os_boolean,
w_subject(50) type c,
w_name(40) type c,
w_subj type so_obj_des, "STRING, "so_obj_des,
w_invoice type vbeln_vf,
w_msg type string,
w_msg1 type string,
w_msg2 type string,
w_resn type string,
lv_sender(500) type c.
types: begin of ty_pa0000,
pernr type pa0000-pernr, "PERSONNEL NO.
begda type pa0000-endda, "START DATE
massn type pa0000-massn, "ACTION TYPE
end of ty_pa0000.
data: it_pa0000 type standard table of ty_pa0000,
wa_pa0000 type ty_pa0000.

get pernr.
* select single * from zhr_probation into ls_prob_chk where pernr = p0019 and begda = sy-datum.
* if sy-subrc <> 0.
rp_provide_from_last p0019 space pn-begda pn-endda.
rp_provide_from_last p0001 space pn-begda pn-endda.
if p0019-subty = '13' .
move-corresponding p0019 to ls_p0019.
append ls_p0019 to lt_p0019.
move-corresponding p0001 to ls_p0001.
append ls_p0001 to lt_p0001.
* elseif p0019-subty = '50' .
* move-corresponding p0019 to ls_p0019.
* append ls_p0019 to lt_p0019.
* move-corresponding p0001 to ls_p0001.
* append ls_p0001 to lt_p0001.
endif.
clear: ls_p0019,ls_p0001.
* endif.

end-of-selection.
clear : it_fteh , it_fte , wa_fteh , wa_fte , it_pa0000 , wa_pa0000.
select * from zthr_fte_prob into table it_fteh.
select * from zhr_fte_prob_frm into table it_fte.

if lt_p0019 is not initial.


loop at lt_p0019 into ls_p0019.
if ls_p0019-mndat eq sy-datum.
read table it_fte into wa_fte with key pernr = ls_p0019-pernr.
if sy-subrc ne 0.
wa_hr_prob_frm-pernr = ls_p0019-pernr.
select single pernr begda dar01 from pa0041 into wa_pa0000 where pernr = ls_p0019-pernr a
if sy-subrc ne 0.
select single pernr begda massn from pa0000 into wa_pa0000 where pernr = ls_p0019-pernr
endif.
wa_hr_prob_frm-begda = wa_pa0000-begda.
wa_hr_prob_frm-endda = sy-datum.
read table it_fteh into wa_fteh with key pernr = ls_p0019-pernr.
if sy-subrc = 0 .
wa_hr_prob_frm-manager2 = wa_fteh-app_pernr.
wa_hr_prob_frm-manager1 = wa_fteh-man_pernr.
endif.
wa_hr_prob_frm-man_stat = 'I'.
append wa_hr_prob_frm to it_hr_prob_frm.
* insert into ZHR_FTE_PROB_FRM values wa_hr_prob_frm.
clear : ls_p0019.
endif.
endif.
endloop.
endif.

if it_hr_prob_frm[] is not initial .


insert zhr_fte_prob_frm from table it_hr_prob_frm.
if sy-subrc = 0 .
loop at it_hr_prob_frm into wa_hr_prob_frm.
call method cl_wd_utilities=>construct_wd_url
exporting
application_name = 'ZHR_FTE_PROBATION'
importing
out_absolute_url = lv_url.

ls_cont-element = 'URL'.
ls_cont-value = lv_url.
append ls_cont to lt_cont.
clear ls_cont.

lv_okey = wa_hr_prob_frm-pernr.
ls_cont-element = 'PersonnelNumber'.
ls_cont-value = wa_hr_prob_frm-pernr.
append ls_cont to lt_cont.
clear ls_cont.

call function 'SAP_WAPI_CREATE_EVENT'


exporting
object_type = 'ZBO_FTEPRO'
object_key = lv_okey
event = 'CREATE'
commit_work = 'X'
user = sy-uname
importing
return_code = lv_return
tables
input_container = lt_cont
message_struct = lt_message.

if lt_message is not initial.


read table lt_message into ls_message with key msgno = '736'.
if sy-subrc eq 0.

"""""""""""""""""""""""""" Mail """"""""""""""""""""""""


class cl_bcs definition load.
clear:t_message_body,
w_subj,
w_msg,
w_invoice,
w_recpt,
w_send,
g_objcont,
w_subject.

* Create send request


wo_send_request = cl_bcs=>create_persistent( ).

clear t_message_body.
w_msg = '<HTML>'.
append w_msg to t_message_body.
clear w_msg.
w_msg = '<HEAD>'.
append w_msg to t_message_body.
clear w_msg.
w_msg = '<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="TEXT/HTML;'.
append w_msg to t_message_body.
clear w_msg.
w_msg = 'CHARSET=ISO-8859-1">'.
append w_msg to t_message_body.
clear w_msg.
w_msg = '</HEAD>'.
append w_msg to t_message_body .
clear w_msg.
w_msg = '<BODY><FONT FACE="CALIBRI">'.
append w_msg to t_message_body .
clear w_msg.

w_msg = 'Dear Sir/Madam,<BR></BR>'.


append w_msg to t_message_body.
clear w_msg.
w_msg = '<BR>'.
append w_msg to t_message_body .
clear w_msg.
concatenate 'FTE form for Employee ' wa_hr_prob_frm-pernr 'has been sent by HR.' into w
append w_msg to t_message_body .
clear w_msg.
w_msg = 'Kindly , Check and fill up.'.
append w_msg to t_message_body .
clear w_msg.

w_msg = '<BR><BR><FONT FACE="CALIBRI">Thank You!'.


append w_msg to t_message_body.
clear w_msg.

w_msg = '<BR><BR><BR><BR>'.
append w_msg to t_message_body.
clear w_msg.

w_msg = '* THIS IS SYSTEM GENERATED EMAIL, PLEASE DO NOT REPLY TO THIS EMAIL.'.
append w_msg to t_message_body.
clear w_msg.

w_msg = '</FONT></BODY>'.
append w_msg to t_message_body.
clear w_msg.

w_msg = '</HTML>'.
append w_msg to t_message_body.
clear w_msg.

concatenate 'FTE Form for Employee' wa_hr_prob_frm-pernr into w_subj separated by space

* Email Body
wo_document = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = t_message_body
i_subject = w_subj ).
" Pass the document to send request
call method wo_send_request->set_document( wo_document ).
"---------------------------- FROM Mail --------------------------------
* Create Sender
wo_sender = cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
* Add sender to send request

call method wo_send_request->set_sender(


exporting
i_sender = wo_sender ).

"------------------------------- TO Mail -------------------------------


clear : wa_fte_prb.
select single * from zthr_fte_prob into wa_fte_prb
where pernr = wa_hr_prob_frm-pernr and man1_pernr ne ' ' .
if sy-subrc = 0.
clear : lv_mail1 .
select single usrid_long into lv_mail1
from pa0105 where pernr = wa_fte_prb-man1_pernr and subty = '0010'.
if lv_mail1 is not initial .
clear : w_recpt_1.
w_recpt_1 = lv_mail1.
wo_recipient = cl_cam_address_bcs=>create_internet_address( w_recpt_1 ).
call method wo_send_request->add_recipient
exporting
i_recipient = wo_recipient
i_express = 'X'.
endif.
endif.

clear : wa_fte_prb.
select single * from zthr_fte_prob into wa_fte_prb
where pernr = wa_hr_prob_frm-pernr and man2_pernr ne ' ' .
if sy-subrc = 0.
clear : lv_mail2.
select single usrid_long into lv_mail2
from pa0105 where pernr = wa_fte_prb-man2_pernr and subty = '0010'.
if lv_mail2 is not initial .
clear : w_recpt_1.
w_recpt_1 = lv_mail2.
wo_recipient = cl_cam_address_bcs=>create_internet_address( w_recpt_1 ).
call method wo_send_request->add_recipient
exporting
i_recipient = wo_recipient
i_express = 'X'.
endif.
endif.
if lv_mail1 is not initial or lv_mail2 is not initial .
* Set send immediately
wo_send_request->set_send_immediately( 'X' ).
* Send email.
wo_send_request->send( exporting i_with_error_screen = 'X'
receiving result = w_sent_to_all ).
if sy-subrc eq space and w_sent_to_all eq 'X'.
message 'Mail sent successfully.' type 'S'.
commit work.
submit rsconn01 with mode = 'INT' and return.

wait up to 1 seconds.
endif.
endif.
concatenate 'Workflow triggered for employee no :' wa_hr_prob_frm-pernr into lv_message
write : / lv_message.
if lv_mail1 is initial .
write : / 'Manager1 Intimation Mail id Not Maintained'.
endif.
if lv_mail2 is initial .
write : / 'Manager2 Intimation Mail id Not Maintained'.
endif.
else.
concatenate 'Workflow not triggered for employee no :' wa_hr_prob_frm-pernr into lv_mes
write : / lv_message.
endif.
endif.
clear : lt_message , lt_cont , lv_return , lv_okey.
endloop.
else.
message 'Data Not Found' type 'E'.
endif.
endif.

You might also like