Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- method send_notify_for_cd.
- data: l_case_guid type scmg_case_guid,
- ls_swwuserwi type swwuserwi,
- lt_swwuserwi type table of swwuserwi,
- lt_return type table of bapiret2,
- ls_addsmtp type bapiadsmtp,
- lt_addsmtp type table of bapiadsmtp,
- l_email type ad_smtpadr,
- lt_email like table of l_email,
- l_activitydesc type srmactdc,
- l_case_title type scmg_case_title,
- lv_header type so_obj_des,
- ret type c value cl_abap_char_utilities=>cr_lf,
- lt_text type bcsy_text,
- lw_text type soli,
- lt_agents type tswhactor,
- l_agent type srmwfagent,
- l_pos_wiid type srmwfpwid,
- l_gtk type ztrcm_cd_attr-gtk,
- l_orgunit_ident type ztrcm_cd_attr-orgunit_ident,
- l_orgunit_culprit type ztrcm_cd_attr-orgunit_culprit,
- l_werks type ztrcm_cd_attr-werks,
- l_text_str type string
- .
- data: l_wf_container type ref to if_swf_ifs_parameter_container.
- data: pos_ref type swc_object,
- l_case type swc_object
- .
- data: lc_request type ref to cl_bcs,
- lc_document type ref to cl_document_bcs,
- lc_sender type ref to cl_sapuser_bcs,
- lc_recipient type ref to if_recipient_bcs,
- lc_exception_info type ref to if_os_exception_info,
- lc_bcs_exception type ref to cx_bcs,
- lt_actor_tab type table of swhactor,
- ls_actor_tab type swhactor,
- l_user type xubname
- .
- data: ls_actor_container type swcont,
- lt_actor_container type table of swcont
- .
- data: lt_hrus_d2 type table of hrus_d2,
- ls_hrus_d2 type hrus_d2.
- l_wf_container = im_workitem_context->get_wf_container( ).
- try.
- call method l_wf_container->get
- exporting
- name = c_pos_ref_element_name
- importing
- value = pos_ref.
- catch cx_root.
- endtry.
- try.
- call method l_wf_container->get
- exporting
- name = 'Case'
- importing
- value = l_case.
- catch cx_root.
- endtry.
- clear ls_actor_container.
- swc_get_property l_case 'GTK' l_gtk.
- ls_actor_container-element = 'GTK'.
- ls_actor_container-value = l_gtk.
- append ls_actor_container to lt_actor_container.
- clear ls_actor_container.
- swc_get_property l_case 'ORGUNIT_IDENT' l_orgunit_ident.
- ls_actor_container-element = 'ORGUNIT_IDENT'.
- ls_actor_container-value = l_orgunit_ident.
- append ls_actor_container to lt_actor_container.
- clear ls_actor_container.
- swc_get_property l_case 'ORGUNIT_CULPRIT' l_orgunit_culprit.
- ls_actor_container-element = 'ORGUNIT_CULPRIT'.
- ls_actor_container-value = l_orgunit_culprit.
- append ls_actor_container to lt_actor_container.
- clear ls_actor_container.
- swc_get_property l_case 'WERKS' l_werks.
- ls_actor_container-element = 'WERKS'.
- ls_actor_container-value = l_werks.
- append ls_actor_container to lt_actor_container.
- swc_get_property pos_ref 'Agent' l_agent.
- l_pos_wiid = im_workitem_context->get_workitem_id( ).
- call function 'RH_GET_ACTORS'
- exporting
- act_object = l_agent
- act_wi_id = l_pos_wiid
- tables
- actor_container = lt_actor_container
- actor_tab = lt_actor_tab.
- if sy-subrc = 0.
- loop at lt_actor_tab into ls_actor_tab.
- if ls_actor_tab-otype = 'US'.
- l_user = ls_actor_tab-objid.
- call function 'BAPI_USER_GET_DETAIL'
- exporting
- username = l_user
- tables
- return = lt_return
- addsmtp = lt_addsmtp.
- if sy-subrc = 0.
- loop at lt_addsmtp into ls_addsmtp.
- clear l_email.
- l_email = ls_addsmtp-e_mail.
- condense l_email.
- append l_email to lt_email.
- endloop.
- endif.
- * Определяем заместителей для обработчика
- select *
- from hrus_d2 into corresponding fields of table lt_hrus_d2
- where us_name eq l_user
- and begda le sy-datum
- and endda ge sy-datum
- and active = 'X'.
- loop at lt_hrus_d2 into ls_hrus_d2.
- l_user = ls_hrus_d2-rep_name.
- call function 'BAPI_USER_GET_DETAIL'
- exporting
- username = l_user
- tables
- return = lt_return
- addsmtp = lt_addsmtp.
- if sy-subrc = 0.
- loop at lt_addsmtp into ls_addsmtp.
- clear l_email.
- l_email = ls_addsmtp-e_mail.
- condense l_email.
- append l_email to lt_email.
- endloop.
- endif.
- endloop.
- endif.
- endloop.
- swc_get_property pos_ref 'ActivityDesc' l_activitydesc.
- swc_get_property l_case 'CASE_TITLE' l_case_title.
- lv_header = 'Оповещение об обработке карты несоответствия'.
- * Текст письма
- concatenate 'Добрый день.' ret into l_text_str.
- concatenate l_text_str 'В системе СЭД Вам поступила задача обработки карты несоответствия:'
- l_activitydesc l_case_title into l_text_str separated by space.
- concatenate l_text_str '.' ret into l_text_str .
- concatenate l_text_str 'Для обработки задачи войдите в систему SAP ERP (' sy-sysid '/' sy-mandt " Cheyraeva 16/09/2015
- ') в транзакцию SO01 - SAPoffice Входящая почта.' into l_text_str.
- * CONDENSE l_text_str.
- * APPEND l_text_str TO lt_text.
- data: ls_srmwfpthps type srmwfpthps,
- lt_gos_links type obl_t_link,
- ls_gos_links type obl_s_link,
- l_notes_exist type boolean.
- data: document_id type sofmk,
- document_data type sood2,
- l_folder_id type soodk,
- l_object_id type soodk,
- ls_line type soli,
- lt_document_content type standard table of soli.
- clear l_notes_exist.
- select single * from srmwfpthps into ls_srmwfpthps
- where actarea = 'SCMG'
- and posid_wiid = l_pos_wiid.
- if sy-subrc = 0.
- call method cl_srm_wf_path=>read_gos_notes_for_position
- exporting
- im_actarea = 'SCMG'
- im_pathid = ls_srmwfpthps-pathid
- im_posid = ls_srmwfpthps-posid
- importing
- ex_gos_links = lt_gos_links
- ex_notes_exist = l_notes_exist.
- " возвращает дублированные записи
- sort lt_gos_links by brelguid.
- delete adjacent duplicates from lt_gos_links comparing brelguid.
- endif.
- if l_notes_exist = abap_true.
- concatenate l_text_str ret ret 'Для данного этапа имеются примечания:' into l_text_str.
- * CONDENSE l_text_str.
- * APPEND l_text_str TO lt_text.
- loop at lt_gos_links into ls_gos_links.
- concatenate l_text_str space ret into l_text_str.
- * APPEND l_text_str TO lt_text.
- l_folder_id-objtp = ls_gos_links-instid_b+0(3).
- l_folder_id-objyr = ls_gos_links-instid_b+3(2).
- l_folder_id-objno = ls_gos_links-instid_b+5(12).
- l_object_id-objtp = ls_gos_links-instid_b+17(3).
- l_object_id-objyr = ls_gos_links-instid_b+20(2).
- l_object_id-objno = ls_gos_links-instid_b+22(12).
- call function 'SO_OBJECT_READ'
- exporting
- folder_id = l_folder_id
- object_id = l_object_id
- importing
- object_hd_display = document_data
- tables
- objcont = lt_document_content
- exceptions
- object_not_exist = 14
- object_no_authorization = 13
- operation_no_authorization = 21
- parameter_error = 23
- others = 1000.
- if sy-subrc = 0.
- concatenate l_text_str ret 'Заголовок: ' document_data-objdes ret into l_text_str.
- * CONDENSE l_text_str.
- * APPEND l_text_str TO lt_text.
- loop at lt_document_content into ls_line.
- concatenate l_text_str ls_line into l_text_str.
- * CONDENSE l_text_str.
- * APPEND l_text_str TO lt_text.
- endloop.
- endif.
- endloop.
- endif.
- data nn type i.
- data l_length type i.
- data lw_text_str type string.
- l_length = strlen( l_text_str ).
- nn = 0.
- clear lt_text.
- while l_length >= 255.
- lw_text = l_text_str+0(255).
- append lw_text to lt_text.
- shift l_text_str left by 255 places.
- l_length = strlen( l_text_str ).
- endwhile.
- lw_text = l_text_str.
- append lw_text to lt_text.
- try.
- lc_request = cl_bcs=>create_persistent( ).
- * Документ для отправки
- lc_document = cl_document_bcs=>create_document( i_type = 'TXT'
- i_language = 'R'
- i_text = lt_text
- i_subject = lv_header ).
- call method lc_request->set_document( lc_document ).
- * Отправитель
- lc_sender = cl_sapuser_bcs=>create( sy-uname ).
- call method lc_request->set_sender
- exporting
- i_sender = lc_sender.
- * Список адресатов
- loop at lt_email into l_email.
- condense l_email.
- lc_recipient = cl_cam_address_bcs=>create_internet_address( l_email ).
- call method lc_request->add_recipient
- exporting
- i_recipient = lc_recipient
- i_express = ' '
- i_copy = ' '
- i_blind_copy = ' '.
- endloop.
- call method lc_request->set_status_attributes
- exporting
- i_requested_status = 'E'
- i_status_mail = 'E'.
- * Отправить письма немедленно
- call method lc_request->set_send_immediately
- exporting
- i_send_immediately = 'X'.
- * Отправить
- call method lc_request->send( ).
- catch cx_bcs into lc_bcs_exception.
- endtry.
- endif.
- endmethod.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement