Created
November 4, 2014 08:02
-
-
Save js1972/c943b9909a4b450f426c to your computer and use it in GitHub Desktop.
Implementation of PPO order enhancement /SAPPO/CREATE_ORDER (SE18) to raise ALM alerts (and hence email notifications) when PPO orders are created.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*----------------------------------------------------------------------* | |
* CLASS ZCL_PPO_ORDER_ONCREATE DEFINITION | |
*----------------------------------------------------------------------* | |
* This BAdI implementation allows us to send a notification | |
* whenever a Post-Processing Office Order is created. | |
* | |
* Emails are sent via an ALM alert, the PPO worklist is used to | |
* determine who should receive the alert. | |
* | |
* PPO provides config to allow smartforms to be used but | |
* there were issues configuring these initially and using | |
* the BAdI implementation provided simpler implementation | |
*----------------------------------------------------------------------* | |
class zcl_ppo_order_oncreate definition | |
public | |
final | |
create public . | |
public section. | |
interfaces /sappo/if_ex_order_cr_notify . | |
interfaces if_badi_interface . | |
constants c_alm_alert_cat type salrtdcat value 'Z_ECH_PPO_ORDER_CREATED'. | |
methods constructor. | |
protected section. | |
private section. | |
data mo_msglog type ref to if_reca_message_list. | |
types: alert_recipients_tab type standard table of salrtsrcp. | |
methods: get_worklist_txt | |
importing i_component type /sappo/dte_component | |
i_worklist type /sappo/dte_worklist | |
returning value(r_text) type /sappo/dte_worklist_text. | |
methods: get_users_for_worklist | |
importing i_component type /sappo/dte_component | |
i_worklist type /sappo/dte_worklist | |
returning value(r_users) type /sappo/tab_user. | |
methods: send_alert | |
importing i_container type ref to if_swf_cnt_container | |
i_recipients type alert_recipients_tab. | |
ENDCLASS. | |
CLASS ZCL_PPO_ORDER_ONCREATE IMPLEMENTATION. | |
method /sappo/if_ex_order_cr_notify~notify_on_order_creation. | |
data: message_text type string, | |
worklist type string, | |
worklist_users type /sappo/tab_user, | |
alrt_container type ref to if_swf_cnt_container, | |
hr_assist type ref to zcl_hr_assist, | |
recipients type standard table of salrtsrcp, | |
exc type ref to cx_root. | |
field-symbols: <order> like line of i_tab_order_hdr, | |
<recipient> like line of recipients, | |
<user> like line of worklist_users. | |
create object hr_assist. | |
loop at i_tab_order_hdr assigning <order>. | |
worklist_users = get_users_for_worklist( i_component = <order>-component i_worklist = <order>-worklist ). | |
if lines( worklist_users ) = 0. | |
mo_msglog->add( id_msgty = 'W' id_msgid = 'ZC' id_msgno = '000' id_msgv1 = 'No users assigned to worklist '(004) id_msgv2 = <order>-component id_msgv3 = <order>-worklist ). | |
"Skip to next iteration, no point if no users to send alert to... | |
continue. | |
endif. | |
try. | |
alrt_container = cl_swf_cnt_factory=>create( ). | |
catch cx_swf_utl_no_instance_found | |
cx_swf_utl_obj_create_failed into exc. | |
mo_msglog->add( id_msgty = 'E' id_msgid = 'ZC' id_msgno = '000' id_msgv1 = 'Unable to create alert container '(001) id_msgv2 = exc->get_longtext( ) ). | |
continue. "Try next loop iteration, without the container the rest of the code is pointless | |
endtry. | |
message id <order>-msgid type <order>-msgty number <order>-msgno with <order>-msgv1 <order>-msgv2 <order>-msgv3 <order>-msgv4 into message_text. | |
worklist = get_worklist_txt( i_component = <order>-component i_worklist = <order>-worklist ). | |
if worklist is initial. | |
worklist = <order>-worklist. | |
endif. | |
"Texts that apply to all recipients of the message | |
try. | |
alrt_container->element_set( name = 'WORKLIST' value = worklist ). | |
alrt_container->element_set( name = 'COMPONENT' value = <order>-component ). | |
alrt_container->element_set( name = 'MAIN_OBJ' value = <order>-main_objkey ). | |
alrt_container->element_set( name = 'ERROR_SUMMARY' value = message_text ). | |
alrt_container->element_set( name = 'SYSTEM_ID' value = sy-sysid ). | |
alrt_container->element_set( name = 'PPO_ID' value = <order>-order_id ). | |
alrt_container->element_set( name = 'CATEGORY' value = <order>-error_category ). | |
alrt_container->element_set( name = 'BUS_PROCESS' value = <order>-business_process ). | |
catch | |
cx_swf_cnt_cont_access_denied | |
cx_swf_cnt_elem_not_found | |
cx_swf_cnt_elem_access_denied | |
cx_swf_cnt_elem_type_conflict | |
cx_swf_cnt_unit_type_conflict | |
cx_swf_cnt_elem_def_invalid | |
cx_swf_cnt_invalid_qname | |
cx_aab_activation | |
cx_swf_cnt_container into exc. | |
mo_msglog->add( id_msgty = 'E' id_msgid = 'ZC' id_msgno = '000' id_msgv1 = 'Exception raised setting param '(002) id_msgv2 = exc->get_text( ) ). | |
endtry. | |
"Personalising the message text so have to loop and send by user adding the users name in each iteration | |
loop at worklist_users assigning <user>. | |
clear recipients. | |
append initial line to recipients assigning <recipient>. | |
<recipient>-uname = <user>. | |
try. | |
if sy-tabix > 1. | |
alrt_container->element_clear( name = 'USER_FULLNAME' ). | |
endif. | |
alrt_container->element_set( name = 'USER_FULLNAME' value = hr_assist->get_user_fullname_pub( <user> ) ). | |
catch | |
cx_swf_cnt_cont_access_denied | |
cx_swf_cnt_elem_not_found | |
cx_swf_cnt_elem_access_denied | |
cx_swf_cnt_elem_type_conflict | |
cx_swf_cnt_unit_type_conflict | |
cx_swf_cnt_elem_def_invalid | |
cx_swf_cnt_invalid_qname | |
cx_swf_cnt_container into exc. | |
mo_msglog->add( id_msgty = 'E' id_msgid = 'ZC' id_msgno = '000' id_msgv1 = 'Error setting/clearing username '(003) id_msgv2 = <user> id_msgv3 = exc->get_text( ) ). | |
endtry. | |
send_alert( i_container = alrt_container i_recipients = recipients ). | |
endloop. | |
endloop. | |
if mo_msglog->is_empty( ) = abap_false. | |
mo_msglog->store( if_in_update_task = abap_true ). | |
endif. | |
endmethod. "/sappo/if_ex_order_cr_notify~notify_on_order_creation | |
method constructor. | |
constants: c_log_object type balobj_d value 'ZC', | |
c_log_subobj type balsubobj value 'PPO'. | |
"Application log (SLG1) used to record any issues encountered | |
mo_msglog = cf_reca_message_list=>create( | |
id_object = c_log_object | |
id_subobject = c_log_subobj | |
). | |
endmethod. "CONSTRUCTOR | |
method get_users_for_worklist. | |
call function '/SAPPO/API_USERS_OF_WL' | |
exporting | |
i_component = i_component | |
i_worklist = i_worklist | |
importing | |
e_tab_user = r_users. | |
endmethod. "get_users_for_worklist | |
method get_worklist_txt. | |
select single ktext into r_text | |
from /sappo/wlt | |
where language = sy-langu | |
and component = i_component | |
and worklist = i_worklist. | |
if sy-subrc <> 0. | |
clear r_text. | |
endif. | |
endmethod. "get_worklist_txt | |
method send_alert. | |
"Send the email notification / alert as a ALM alert with fixed recipient(s) | |
call function 'SALRT_CREATE_API' | |
exporting | |
ip_category = c_alm_alert_cat | |
ii_container = i_container | |
tables | |
it_recipients = i_recipients | |
exceptions | |
others = 1. | |
if sy-subrc <> 0. | |
mo_msglog->add_symsg( ). | |
endif. | |
endmethod. "send_alert | |
ENDCLASS. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment