Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 10.60 KB | None | 0 0
  1. method send_notify_for_cd.
  2.  
  3.   data: l_case_guid type scmg_case_guid,
  4.            ls_swwuserwi type swwuserwi,
  5.            lt_swwuserwi type table of swwuserwi,
  6.            lt_return type table of bapiret2,
  7.            ls_addsmtp  type  bapiadsmtp,
  8.            lt_addsmtp  type table of bapiadsmtp,
  9.            l_email type ad_smtpadr,
  10.            lt_email like table of l_email,
  11.            l_activitydesc type srmactdc,
  12.            l_case_title type scmg_case_title,
  13.            lv_header  type so_obj_des,
  14.            ret type c value cl_abap_char_utilities=>cr_lf,
  15.            lt_text    type bcsy_text,
  16.            lw_text    type soli,
  17.            lt_agents type tswhactor,
  18.            l_agent   type srmwfagent,
  19.            l_pos_wiid type srmwfpwid,
  20.            l_gtk type ztrcm_cd_attr-gtk,
  21.            l_orgunit_ident type ztrcm_cd_attr-orgunit_ident,
  22.            l_orgunit_culprit type ztrcm_cd_attr-orgunit_culprit,
  23.            l_werks type ztrcm_cd_attr-werks,
  24.            l_text_str type string
  25.               .
  26.  
  27.   data: l_wf_container type ref to if_swf_ifs_parameter_container.
  28.   data: pos_ref type swc_object,
  29.         l_case  type swc_object
  30.         .
  31.  
  32.   data:  lc_request        type ref to cl_bcs,
  33.          lc_document       type ref to cl_document_bcs,
  34.          lc_sender         type ref to cl_sapuser_bcs,
  35.          lc_recipient      type ref to if_recipient_bcs,
  36.            lc_exception_info type ref to if_os_exception_info,
  37.          lc_bcs_exception  type ref to cx_bcs,
  38.          lt_actor_tab      type table of swhactor,
  39.          ls_actor_tab      type swhactor,
  40.          l_user            type xubname
  41.          .
  42.  
  43.   data: ls_actor_container type  swcont,
  44.         lt_actor_container type table of swcont
  45.         .
  46.  
  47.   data: lt_hrus_d2 type table of hrus_d2,
  48.         ls_hrus_d2 type hrus_d2.
  49.  
  50.   l_wf_container = im_workitem_context->get_wf_container( ).
  51.  
  52.   try.
  53.       call method l_wf_container->get
  54.         exporting
  55.           name  = c_pos_ref_element_name
  56.         importing
  57.           value = pos_ref.
  58.  
  59.     catch cx_root.
  60.   endtry.
  61.  
  62.   try.
  63.       call method l_wf_container->get
  64.         exporting
  65.           name  = 'Case'
  66.         importing
  67.           value = l_case.
  68.  
  69.     catch cx_root.
  70.   endtry.
  71.  
  72.   clear ls_actor_container.
  73.   swc_get_property l_case 'GTK' l_gtk.
  74.   ls_actor_container-element = 'GTK'.
  75.   ls_actor_container-value = l_gtk.
  76.   append ls_actor_container to lt_actor_container.
  77.  
  78.   clear ls_actor_container.
  79.   swc_get_property l_case 'ORGUNIT_IDENT' l_orgunit_ident.
  80.   ls_actor_container-element = 'ORGUNIT_IDENT'.
  81.   ls_actor_container-value = l_orgunit_ident.
  82.   append ls_actor_container to lt_actor_container.
  83.  
  84.   clear ls_actor_container.
  85.   swc_get_property l_case 'ORGUNIT_CULPRIT' l_orgunit_culprit.
  86.   ls_actor_container-element = 'ORGUNIT_CULPRIT'.
  87.   ls_actor_container-value = l_orgunit_culprit.
  88.   append ls_actor_container to lt_actor_container.
  89.  
  90.   clear ls_actor_container.
  91.   swc_get_property l_case 'WERKS' l_werks.
  92.   ls_actor_container-element = 'WERKS'.
  93.   ls_actor_container-value = l_werks.
  94.   append ls_actor_container to lt_actor_container.
  95.  
  96.   swc_get_property pos_ref 'Agent' l_agent.
  97.  
  98.   l_pos_wiid  = im_workitem_context->get_workitem_id( ).
  99.  
  100.   call function 'RH_GET_ACTORS'
  101.     exporting
  102.       act_object      = l_agent
  103.       act_wi_id       = l_pos_wiid
  104.     tables
  105.       actor_container = lt_actor_container
  106.       actor_tab       = lt_actor_tab.
  107.  
  108.   if sy-subrc = 0.
  109.  
  110.     loop at lt_actor_tab into ls_actor_tab.
  111.  
  112.       if ls_actor_tab-otype = 'US'.
  113.  
  114.         l_user = ls_actor_tab-objid.
  115.  
  116.         call function 'BAPI_USER_GET_DETAIL'
  117.           exporting
  118.             username = l_user
  119.           tables
  120.             return   = lt_return
  121.             addsmtp  = lt_addsmtp.
  122.  
  123.         if sy-subrc = 0.
  124.           loop at lt_addsmtp into ls_addsmtp.
  125.             clear l_email.
  126.             l_email = ls_addsmtp-e_mail.
  127.             condense l_email.
  128.             append l_email to lt_email.
  129.           endloop.
  130.         endif.
  131.  
  132. *       Определяем заместителей для обработчика
  133.  
  134.         select *
  135.          from hrus_d2 into corresponding fields of table lt_hrus_d2
  136.              where us_name eq l_user
  137.                and begda le sy-datum
  138.                and endda ge sy-datum
  139.                and active = 'X'.
  140.  
  141.         loop at lt_hrus_d2 into ls_hrus_d2.
  142.  
  143.           l_user = ls_hrus_d2-rep_name.
  144.           call function 'BAPI_USER_GET_DETAIL'
  145.             exporting
  146.               username = l_user
  147.             tables
  148.               return   = lt_return
  149.               addsmtp  = lt_addsmtp.
  150.  
  151.           if sy-subrc = 0.
  152.             loop at lt_addsmtp into ls_addsmtp.
  153.               clear l_email.
  154.               l_email = ls_addsmtp-e_mail.
  155.               condense l_email.
  156.               append l_email to lt_email.
  157.             endloop.
  158.           endif.
  159.         endloop.
  160.       endif.
  161.     endloop.
  162.  
  163.     swc_get_property pos_ref 'ActivityDesc' l_activitydesc.
  164.     swc_get_property l_case 'CASE_TITLE' l_case_title.
  165.  
  166.     lv_header = 'Оповещение об обработке карты несоответствия'.
  167.  
  168. * Текст письма
  169.     concatenate 'Добрый день.' ret into l_text_str.
  170.     concatenate l_text_str 'В системе СЭД Вам поступила задача обработки карты несоответствия:'
  171.                 l_activitydesc l_case_title into l_text_str separated by space.
  172.     concatenate l_text_str '.' ret into l_text_str .
  173.     concatenate l_text_str 'Для обработки задачи войдите в систему SAP ERP (' sy-sysid '/' sy-mandt     " Cheyraeva 16/09/2015
  174.                         ') в транзакцию SO01 - SAPoffice Входящая почта.' into l_text_str.
  175. *    CONDENSE l_text_str.
  176. *    APPEND l_text_str TO lt_text.
  177.  
  178.     data: ls_srmwfpthps type srmwfpthps,
  179.           lt_gos_links    type  obl_t_link,
  180.           ls_gos_links    type  obl_s_link,
  181.           l_notes_exist   type  boolean.
  182.     data: document_id        type sofmk,
  183.           document_data      type sood2,
  184.           l_folder_id        type soodk,
  185.           l_object_id        type soodk,
  186.           ls_line            type soli,
  187.           lt_document_content   type standard table of soli.
  188.  
  189.     clear l_notes_exist.
  190.     select single * from srmwfpthps into ls_srmwfpthps
  191.       where actarea = 'SCMG'
  192.         and posid_wiid = l_pos_wiid.
  193.     if sy-subrc = 0.
  194.       call method cl_srm_wf_path=>read_gos_notes_for_position
  195.         exporting
  196.           im_actarea     = 'SCMG'
  197.           im_pathid      = ls_srmwfpthps-pathid
  198.           im_posid       = ls_srmwfpthps-posid
  199.         importing
  200.           ex_gos_links   = lt_gos_links
  201.           ex_notes_exist = l_notes_exist.
  202.       " возвращает дублированные записи
  203.  
  204.       sort lt_gos_links by brelguid.
  205.  
  206.       delete adjacent duplicates from lt_gos_links comparing brelguid.
  207.     endif.
  208.  
  209.     if l_notes_exist = abap_true.
  210.       concatenate  l_text_str ret ret 'Для данного этапа имеются примечания:' into l_text_str.
  211. *      CONDENSE l_text_str.
  212. *      APPEND l_text_str TO lt_text.
  213.  
  214.       loop at lt_gos_links into ls_gos_links.
  215.         concatenate l_text_str space ret into l_text_str.
  216. *        APPEND l_text_str TO lt_text.
  217.         l_folder_id-objtp = ls_gos_links-instid_b+0(3).
  218.         l_folder_id-objyr = ls_gos_links-instid_b+3(2).
  219.         l_folder_id-objno = ls_gos_links-instid_b+5(12).
  220.         l_object_id-objtp = ls_gos_links-instid_b+17(3).
  221.         l_object_id-objyr = ls_gos_links-instid_b+20(2).
  222.         l_object_id-objno = ls_gos_links-instid_b+22(12).
  223.  
  224.         call function 'SO_OBJECT_READ'
  225.           exporting
  226.             folder_id                  = l_folder_id
  227.             object_id                  = l_object_id
  228.           importing
  229.             object_hd_display          = document_data
  230.           tables
  231.             objcont                    = lt_document_content
  232.           exceptions
  233.             object_not_exist           = 14
  234.             object_no_authorization    = 13
  235.             operation_no_authorization = 21
  236.             parameter_error            = 23
  237.             others                     = 1000.
  238.  
  239.         if sy-subrc = 0.
  240.           concatenate l_text_str ret 'Заголовок:  ' document_data-objdes ret into l_text_str.
  241. *          CONDENSE l_text_str.
  242. *          APPEND l_text_str TO lt_text.
  243.           loop at lt_document_content into ls_line.
  244.             concatenate l_text_str ls_line into l_text_str.
  245. *            CONDENSE l_text_str.
  246. *            APPEND l_text_str TO lt_text.
  247.           endloop.
  248.         endif.
  249.  
  250.       endloop.
  251.  
  252.     endif.
  253.  
  254.     data nn type i.
  255.     data l_length type i.
  256.     data lw_text_str type string.
  257.  
  258.  
  259.     l_length = strlen( l_text_str ).
  260.     nn = 0.
  261.  
  262.     clear lt_text.
  263.  
  264.     while l_length >= 255.
  265.       lw_text = l_text_str+0(255).
  266.       append lw_text to lt_text.
  267.       shift l_text_str left by 255 places.
  268.       l_length = strlen( l_text_str ).
  269.     endwhile.
  270.  
  271.     lw_text = l_text_str.
  272.     append lw_text to lt_text.
  273.  
  274.     try.
  275.         lc_request = cl_bcs=>create_persistent( ).
  276.  
  277. *   Документ для отправки
  278.         lc_document = cl_document_bcs=>create_document( i_type    = 'TXT'
  279.                                                         i_language = 'R'
  280.                                                         i_text    = lt_text
  281.                                                         i_subject = lv_header ).
  282.  
  283.         call method lc_request->set_document( lc_document ).
  284.  
  285. *   Отправитель
  286.         lc_sender = cl_sapuser_bcs=>create( sy-uname ).
  287.  
  288.         call method lc_request->set_sender
  289.           exporting
  290.             i_sender = lc_sender.
  291.  
  292. *   Список адресатов
  293.         loop at lt_email into l_email.
  294.  
  295.           condense l_email.
  296.           lc_recipient = cl_cam_address_bcs=>create_internet_address( l_email ).
  297.  
  298.           call method lc_request->add_recipient
  299.             exporting
  300.               i_recipient  = lc_recipient
  301.               i_express    = ' '
  302.               i_copy       = ' '
  303.               i_blind_copy = ' '.
  304.         endloop.
  305.  
  306.         call method lc_request->set_status_attributes
  307.           exporting
  308.             i_requested_status = 'E'
  309.             i_status_mail      = 'E'.
  310.  
  311. *   Отправить письма немедленно
  312.         call method lc_request->set_send_immediately
  313.           exporting
  314.             i_send_immediately = 'X'.
  315.  
  316. *   Отправить
  317.         call method lc_request->send( ).
  318.  
  319.       catch cx_bcs into lc_bcs_exception.
  320.  
  321.     endtry.
  322.   endif.
  323.  
  324.  
  325. endmethod.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement