You are on page 1of 8

*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*

* Author Name: Anupam Samanta


*
* Creation Date: 29/04/2015
*
* Description: Workflow For Purchase Requisiton
*
*
<Brief description of Object>
*
*
<Brief description of Object>
*
*
<Brief description of Object>
*
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*
* Change History
*
*----------------------------------------------------------------------*
* Date
| User
| TR number
| Description
*
*
*
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*
report zwfmm_purchase_requisition.
tables eban.
types: begin of ty_eban,
banfn type eban-banfn,
werks type eban-werks,
frgst type eban-frgst,
frgkz type eban-frgkz,
ernam type eban-ernam,
badat type eban-badat,
end of ty_eban.
data : objkey
lt_msglines
lt_msgstruc
wa_msglines
wa_msgstruc
it_event_container
wa_event_container
t_geninfo
t_posted
wa_posted
t_final
t_ret
t_eban
wa_eban
mess_tab
wa_mess
lv_subject(50)
t_prwf
wa_ztmm_prwf
wa_t16fw
v_uname
lo_send_request
l_sender
lv_sent_to_all
lo_document
lt_smtp
lt_ret
s_addr
l_email
l_recipient
v_date(10)
v_relcode(2)
rel_done

type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type
type

swr_struct-object_key,
standard table of swr_messag,
standard table of swr_mstruc,
swr_messag,
swr_mstruc,
table of swr_cont,
swr_cont,
table of bapirlgnrq with header line,
table of bapirlcorq with header line,
bapirlcorq,
table of bapirlcorq with header line,
table of bapireturn with header line,
table of ty_eban,
ty_eban,
table of solisti1,
solisti1,
c,
table of ztmm_prwf,
ztmm_prwf,
t16fw,
sy-uname,
ref to cl_bcs value is initial,
ref to if_sender_bcs,
c value is initial,
ref to cl_document_bcs value is initial,
standard table of bapiadsmtp with header line,
standard table of bapiret2 with header line,
bapiaddr3,
ad_smtpadr,
ref to if_recipient_bcs,
c,
c,
c.

selection-screen begin of block b with frame title text-001.


select-options : p_banfn for eban-banfn no intervals.
selection-screen end of block b.
select banfn
werks
frgst
frgkz
ernam
badat
from eban
into table t_eban
where banfn in p_banfn.
select banfn
final_app
wf_exe
erdat
ernam
from ztmm_prwf
into corresponding fields of table t_prwf
where banfn in p_banfn.
loop at p_banfn .
read table t_eban into wa_eban with key banfn = p_banfn-low.
if wa_eban-frgst is not initial. " Check whether Release Strategy Exists
call function 'BAPI_REQUISITION_GETRELINFO'
exporting
number
= p_banfn-low
tables
general_release_info = t_geninfo
release_already_posted = t_posted
release_final
= t_final
return
= t_ret.
*
if wa_eban-frgkz ne 2."Not Fully Released
if t_posted[] is initial. " Send Mail to First Release Level
*
select single frggr
*
frgco
*
werks
*
objid
*
into corresponding fields of wa_t16fw
*
from t16fw
*
where frggr = t_geninfo-rel_group
*
and frgco = t_posted-rel_code1
*
and werks = wa_eban-werks.
*
else. " Check and decide to which level mail has to be sent
*
if t_posted-rel_code2 is initial.
*
v_relcode = t_posted-rel_code2.
*
elseif t_posted-rel_code3 is initial.
*
v_relcode = t_posted-rel_code3.
*
elseif t_posted-rel_code4 is initial.
*
v_relcode = t_posted-rel_code4.
*
elseif t_posted-rel_code5 is initial.
*
v_relcode = t_posted-rel_code5.
*
elseif t_posted-rel_code6 is initial.
*
v_relcode = t_posted-rel_code6.
*
elseif t_posted-rel_code7 is initial.
*
v_relcode = t_posted-rel_code7.
*
elseif t_posted-rel_code8 is initial.
*
v_relcode = t_posted-rel_code8.
*
endif.

*
*
*
*
*
*
*
*
*
*
*

select single frggr


frgco
werks
objid
into corresponding fields of wa_t16fw
from t16fw
where frggr = t_geninfo-rel_group
and frgco = v_relcode
and werks = wa_eban-werks.
endif.
perform mail_to_respective_level.
read table t_final[] into t_final index 1.
read table t_prwf into wa_ztmm_prwf with key banfn = p_banfn-low.
if sy-subrc is not initial.
objkey = p_banfn-low.
wa_event_container-element = 'ReleaseCode'.
wa_event_container-value = t_final-rel_code1."'01'.
append wa_event_container to it_event_container.
clear wa_event_container.
wa_event_container-element = 'Number'.
wa_event_container-value = p_banfn-low.
append wa_event_container to it_event_container.
clear wa_event_container.
call function 'SAP_WAPI_CREATE_EVENT'
exporting
object_type
= 'ZBUS2105'
*
object_type
= 'BUS2105'
object_key
= objkey
event
= 'releaseStepCreated'
commit_work
= 'X'
tables
input_container = it_event_container
message_lines = lt_msglines.
wa_ztmm_prwf-banfn = p_banfn-low.
wa_ztmm_prwf-wf_exe = 'X'.
wa_ztmm_prwf-erdat = sy-datum.
wa_ztmm_prwf-ernam = sy-uname.
modify ztmm_prwf from wa_ztmm_prwf.
clear wa_ztmm_prwf.
endif.
else.
read table t_prwf into wa_ztmm_prwf with key banfn = p_banfn-low
final_app = ''.
if sy-subrc is initial.
wa_ztmm_prwf-final_app = 'X'.
modify ztmm_prwf from wa_ztmm_prwf.
perform mail_final_release.
endif.
endif.
*
endif.
endif.
endloop.
*&---------------------------------------------------------------------*
*&
Form MAIL_TO_RESPECTIVE_LEVEL
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*

form mail_to_respective_level .
refresh : mess_tab.
clear : lv_subject, wa_mess.
concatenate 'Purchase Requisition:'p_banfn-low'Requires Approval' into lv_subj
ect separated by space.
wa_mess-line = '<TABLE width= "100%">'.
append wa_mess to mess_tab.
concatenate '<TR><td align = "LEFT" >' '<FONT COLOR = "BLACK" face="Calibri">D
ear Approver, </FONT>'
'</td></tr>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
concatenate '<TR><td align = "LEFT" ><br>' '</br></td></tr>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
concatenate wa_eban-badat+6(2) '.' wa_eban-badat+4(2) '.' wa_eban-badat(4) int
o v_date.
concatenate '<TR><td align = "LEFT" >' '<FONT COLOR = "BLACK" face="Calibri">
Purchase Requisition:'p_banfn-low'which has been created on:'v_date'requires you
r kind approval. </FONT>'
'</td></tr>' into wa_mess separated by space.
append wa_mess to mess_tab.
clear wa_mess.
concatenate '<TR><td align = "LEFT" ><br>' '</br></td></tr>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
concatenate '<TR><td align = "LEFT" >' '<FONT COLOR = "BLACK" face="Calibri" >
<u>What action you should perform :</u></FONT>'
'</td></tr>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
concatenate '<TR><td align = "LEFT" >' '<FONT COLOR = "BLACK" face="Calibri">1
. Login to SAP </FONT>'
'</td></tr>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
concatenate '<TR><td align = "LEFT" >' '<FONT COLOR = "BLACK" face="Calibri">2
. Go to ME54N Transaction </FONT>'
'</td></tr>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
concatenate '<TR><td align = "LEFT" >' '<FONT COLOR = "BLACK" face="Calibri">3
. Enter PR number as mentioned in subject Line </FONT>'
'</td></tr>' into wa
_mess.
append wa_mess to mess_tab.
clear wa_mess.
concatenate '<TR><td align = "LEFT" >' '<FONT COLOR = "BLACK" face="Calibri">4
. Take action to Either Approve or Reject. </FONT>'
'</td></tr>' into wa_mes
s.
append wa_mess to mess_tab.
clear wa_mess.
concatenate '<TR><td align = "LEFT" >' '</td></tr>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
wa_mess-line = '</TABLE>'.
append wa_mess to mess_tab.
clear wa_mess.
wa_mess-line = '<TABLE width= "100%" >'.
append wa_mess to mess_tab.
concatenate '<TR><td align = "LEFT" ><br>' '</br></td></tr>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
concatenate '<TR><td align = "LEFT" >' '<FONT COLOR = "BLACK" face="Calibri">
Note:-This is a system generated mail, please do not reply </FONT>' '</td></tr>'

into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
concatenate '<TR><td align = "LEFT" >' '</td></tr>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
wa_mess-line = '</TABLE>'.
append wa_mess to mess_tab.
clear wa_mess.
lo_send_request = cl_bcs=>create_persistent( ).
lo_document = cl_document_bcs=>create_document(
i_type
= 'HTM'
i_text
= mess_tab
i_subject = lv_subject ).
v_uname = wa_eban-ernam.
l_sender = cl_sapuser_bcs=>create( v_uname ). " PR Creator ID
call method lo_send_request->set_sender
exporting
i_sender = l_sender.
refresh : lt_smtp,
lt_ret .
clear v_uname.
if wa_t16fw-objid is not initial.
v_uname = wa_t16fw-objid.
call function 'BAPI_USER_GET_DETAIL'
exporting
username = v_uname
tables
return = lt_ret
addsmtp = lt_smtp.
loop at lt_smtp. "Email Address
clear : l_email,
l_recipient.
if lt_smtp-e_mail is not initial.
l_email = lt_smtp-e_mail.
l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ).
call method lo_send_request->add_recipient
exporting
i_recipient = l_recipient
i_express
= 'X'
i_copy
= ''
i_blind_copy = ' '
i_no_forward = ' '.
endif.
endloop.
call method lo_send_request->set_document( lo_document ).
call method lo_send_request->send(
exporting
i_with_error_screen = 'X'
receiving
result
= lv_sent_to_all ).
if lv_sent_to_all is not initial.
commit work.
message 'Mail Sent Successfuly' type 'S'.
endif.
endif.

endform.
*&---------------------------------------------------------------------*
*&
Form MAIL_FINAL_RELEASE
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form mail_final_release .
refresh : lt_smtp,
lt_ret .
clear : v_relcode,
v_uname.
if t_posted-rel_code2 is initial.
v_relcode = t_posted-rel_code1.
elseif t_posted-rel_code3 is initial.
v_relcode = t_posted-rel_code2.
elseif t_posted-rel_code4 is initial.
v_relcode = t_posted-rel_code3.
elseif t_posted-rel_code5 is initial.
v_relcode = t_posted-rel_code4.
elseif t_posted-rel_code6 is initial.
v_relcode = t_posted-rel_code5.
elseif t_posted-rel_code7 is initial.
v_relcode = t_posted-rel_code6.
elseif t_posted-rel_code8 is initial.
v_relcode = t_posted-rel_code7.
else.
v_relcode = t_posted-rel_code8.
endif.
select single frggr
frgco
werks
objid
into corresponding fields of wa_t16fw
from t16fw
where frggr = t_geninfo-rel_group
and frgco = v_relcode
and werks = wa_eban-werks.
if wa_t16fw-objid is not initial.
v_uname = wa_t16fw-objid.
call function 'BAPI_USER_GET_DETAIL'
exporting
username = v_uname
importing
address = s_addr
tables
return = lt_ret
addsmtp = lt_smtp.
refresh : mess_tab.
clear : lv_subject, wa_mess.
concatenate 'Purchase Requisition:'p_banfn-low'has been Approved' into lv_su
bject separated by space.
wa_mess-line = '<TABLE width= "100%">'.
append wa_mess to mess_tab.
concatenate '<TR><td align = "LEFT" >' '<FONT COLOR = "BLACK" face="Calibri"
>Dear Requisitioner, </FONT>'
'</td></tr>' into wa_mess.

append wa_mess to mess_tab.


clear wa_mess.
concatenate '<TR><td align = "LEFT" ><br>' '</br></td></tr>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
concatenate wa_eban-badat+6(2) '.' wa_eban-badat+4(2) '.' wa_eban-badat(4) i
nto v_date.
concatenate '<TR><td align = "LEFT" >' '<FONT COLOR = "BLACK" face="Calibri"
>Your Purchase Requisition which has been created on:<b><u>'v_date'</u></b>has b
een finally approved by:<b><u>'s_addr-fullname'</u></b>. </FONT>'
'</td></tr>
' into
wa_mess separated
by space.
append wa_mess to mess_tab.
clear wa_mess.
concatenate '<TR><td align = "LEFT" ><br>' '</br></td></tr>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
concatenate '<TR><td align = "LEFT" >' '<FONT COLOR = "BLACK" face="Calibri"
>This is for your kind information</FONT>'
'</td></tr>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
concatenate '<TR><td align = "LEFT" >' '</td></tr>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
wa_mess-line = '</TABLE>'.
append wa_mess to mess_tab.
clear wa_mess.
wa_mess-line = '<TABLE width= "100%" >'.
append wa_mess to mess_tab.
concatenate '<TR><td align = "LEFT" ><br>' '</br></td></tr>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
concatenate '<TR><td align = "LEFT" >' '<FONT COLOR = "BLACK" face="Calibri"
> Note:-This is a system generated mail, please do not reply </FONT>' '</td></tr
>' into wa_mess.
append wa_mess to mess_tab.
clear wa_mess.
* append wa_mess to mess_tab.
clear wa_mess.
wa_mess-line = '</TABLE>'.
append wa_mess to mess_tab.
clear wa_mess.
lo_send_request = cl_bcs=>create_persistent( ).
lo_document = cl_document_bcs=>create_document(
i_type
= 'HTM'
i_text
= mess_tab
i_subject = lv_subject ).
v_uname = wa_eban-ernam.
l_sender = cl_sapuser_bcs=>create( v_uname ). " PR Creator ID
call method lo_send_request->set_sender
exporting
i_sender = l_sender.
loop at lt_smtp. "Email Address
clear : l_email,
l_recipient.
if lt_smtp-e_mail is not initial.
l_email = lt_smtp-e_mail.
l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ).

call method lo_send_request->add_recipient


exporting
i_recipient = l_recipient
i_express
= 'X'
i_copy
= ''
i_blind_copy = ' '
i_no_forward = ' '.
endif.
endloop.
call method lo_send_request->set_document( lo_document ).
call method lo_send_request->send(
exporting
i_with_error_screen = 'X'
receiving
result
= lv_sent_to_all ).
if lv_sent_to_all is not initial.
commit work.
message 'Mail Sent Successfuly' type 'S'.
endif.
endif.
endform.

You might also like