Advertisement
kaio1001

Untitled

Jun 18th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.72 KB | None | 0 0
  1. *&---------------------------------------------------------------------*
  2. *& Report Z_HR_HOUR_CHANGE_REPL_EC *
  3. *&---------------------------------------------------------------------*
  4. *& PROGRAMA : Z_HR_2001_AUS_REPLICATION *
  5. *& AUTOR : Leonardo Martins *
  6. *& DATA: : 26/12/2019 *
  7. *&---------------------------------------------------------------------*
  8. *& Programa para alteração em massa de horários no EC através da API *
  9. *& EmpJob carregado por um arquivo CSV *
  10. *& Programa também gerá um CSV modelo a ser seguido para a importação *
  11. *&---------------------------------------------------------------------*
  12. report zhrst_job_aprov_ponto.
  13.  
  14. "BLD node
  15. nodes: peras.
  16.  
  17. tables: pernr.
  18.  
  19. "Infotypes
  20. infotypes: 0001.
  21.  
  22.  
  23. "Tables
  24. types: begin of ty_leader_filter,
  25. pernr_leader type pernr_d,
  26. name_leader type cname,
  27. orgeh_leader type orgeh,
  28. plans_leader type plans,
  29. werks_leader type persa,
  30. email_leader type comm_id_long,
  31. end of ty_leader_filter.
  32.  
  33.  
  34.  
  35. "Class
  36. data: send_request type ref to cl_bcs,
  37. document type ref to cl_document_bcs,
  38. recipient type ref to if_recipient_bcs,
  39. bcs_exception type ref to cx_bcs.
  40.  
  41. "Tables
  42. data: t_leaders type table of ty_leader_filter,
  43. t_p0001 type table of p0001.
  44.  
  45. "Variables
  46. data: sent_to_all type os_boolean,
  47. pdf_size type so_obj_len,
  48. pdf_content type solix_tab,
  49. pdf_xstring type xstring,
  50. spool_id type char10,
  51. jobname like tbtco-jobname,
  52. jobcount like tbtco-jobcount.
  53.  
  54. at selection-screen output.
  55. loop at screen.
  56. if screen-name cs 'PNPBEGDA' or screen-name cs 'PNPENDDA' or
  57. screen-name cs 'PNPSTAT2' or
  58. screen-name cs 'PNPWERKS-LOW'.
  59.  
  60. screen-invisible = 1.
  61. modify screen.
  62. endif.
  63. endloop.
  64. pnpbegda = sy-datum - 7.
  65. pnpendda = sy-datum.
  66.  
  67.  
  68. start-of-selection.
  69.  
  70.  
  71. "Select Data
  72. get peras.
  73.  
  74. if p0001[] is not initial.
  75. append lines of p0001[] to t_p0001.
  76. endif.
  77.  
  78. end-of-selection.
  79.  
  80. "Fill data
  81. perform fill_leader.
  82.  
  83. data: input_length type i,
  84. buffer type xstring.
  85.  
  86.  
  87. "Fill and Send emails
  88. loop at t_leaders assigning field-symbol(<leaders>).
  89.  
  90. "Verifica se o lider tem registros não aprovados
  91. select single pernr
  92. from zhrt_aprov_ponto
  93. into @data(check)
  94. where pernr = @<leaders>-pernr_leader.
  95. if sy-subrc <> 0.
  96. continue.
  97. endif.
  98.  
  99. "Caso encontre registro ele chama, pega o resultado e envia por email
  100. submit zhrst_aprov_ponto with pnppernr = <leaders>-pernr_leader
  101. with pnpbegda = '20200101'
  102. with pnpendda = '20200131'
  103. with p_rad3 = abap_true
  104. with p_fer = abap_true
  105. with p_jus = abap_true
  106. with p_mar = abap_true to sap-spool without spool dynpro
  107. and return.
  108.  
  109. get parameter id 'SPI' field spool_id.
  110. if sy-subrc = '0000000000'.
  111. continue.
  112. endif.
  113.  
  114.  
  115.  
  116. perform create_pdf.
  117. perform send using <leaders>.
  118. clear spool_id.
  119. endloop.
  120.  
  121.  
  122.  
  123. form send using params type ty_leader_filter.
  124.  
  125.  
  126. try.
  127.  
  128. send_request = cl_bcs=>create_persistent( ).
  129. pdf_content = cl_document_bcs=>xstring_to_solix( pdf_xstring ).
  130.  
  131. document = cl_document_bcs=>create_document(
  132. i_type = 'PDF'
  133. i_hex = pdf_content
  134. i_length = pdf_size
  135. i_subject = 'Email teste para gestor da area' ). "#EC NOTEXT
  136.  
  137. send_request->set_document( document ).
  138. recipient = cl_cam_address_bcs=>create_internet_address( params-email_leader ).
  139. send_request->add_recipient( recipient ).
  140. sent_to_all = send_request->send( i_with_error_screen = 'X' ).
  141.  
  142. commit work.
  143.  
  144. if sent_to_all is initial.
  145. message i500(sbcoms) with params-email_leader.
  146. else.
  147. message s022(so).
  148. endif.
  149.  
  150. catch cx_bcs into bcs_exception.
  151. message i865(so) with bcs_exception->error_type.
  152. endtry.
  153.  
  154. clear: sent_to_all,
  155. pdf_size,
  156. pdf_content,
  157. pdf_xstring.
  158.  
  159. endform.
  160.  
  161. form create_pdf.
  162.  
  163. data: rq type tsp01,
  164. bin_size type i,
  165. dummy type table of rspoattr,
  166. rqident type tsp01-rqident,
  167. lv_begda type begda.
  168.  
  169. rqident = spool_id.
  170. call function 'RSPO_GET_ATTRIBUTES_SPOOLJOB'
  171. exporting
  172. rqident = rqident
  173. importing
  174. rq = rq
  175. tables
  176. attributes = dummy
  177. exceptions
  178. no_such_job = 1
  179. others = 2.
  180. if sy-subrc <> 0.
  181. message e126(po) with rqident.
  182. endif.
  183.  
  184.  
  185. if rq-rqdoctype = 'OTF' or rq-rqdoctype = 'SMART'.
  186. call function 'CONVERT_OTFSPOOLJOB_2_PDF'
  187. exporting
  188. src_spoolid = rqident
  189. no_dialog = 'X'
  190. pdf_destination = 'X'
  191. no_background = 'X'
  192. importing
  193. pdf_bytecount = bin_size
  194. bin_file = pdf_xstring
  195. exceptions
  196. err_no_otf_spooljob = 1
  197. err_no_spooljob = 2
  198. err_no_permission = 3
  199. err_conv_not_possible = 4
  200. err_bad_dstdevice = 5
  201. user_cancelled = 6
  202. err_spoolerror = 7
  203. err_temseerror = 8
  204. err_btcjob_open_failed = 9
  205. err_btcjob_submit_failed = 10
  206. err_btcjob_close_failed = 11
  207. others = 12.
  208. if sy-subrc <> 0.
  209. message e712(po) with sy-subrc 'CONVERT_OTFSPOOLJOB_2_PDF'.
  210. endif.
  211. elseif rq-rqdoctype = 'LIST'.
  212. call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
  213. exporting
  214. src_spoolid = rqident
  215. no_dialog = 'X'
  216. pdf_destination = 'X'
  217. no_background = 'X'
  218. importing
  219. pdf_bytecount = bin_size
  220. bin_file = pdf_xstring
  221. exceptions
  222. err_no_abap_spooljob = 1
  223. err_no_spooljob = 2
  224. err_no_permission = 3
  225. err_conv_not_possible = 4
  226. err_bad_destdevice = 5
  227. user_cancelled = 6
  228. err_spoolerror = 7
  229. err_temseerror = 8
  230. err_btcjob_open_failed = 9
  231. err_btcjob_submit_failed = 10
  232. err_btcjob_close_failed = 11
  233. others = 12.
  234. if sy-subrc <> 0.
  235. message e712(po) with sy-subrc 'CONVERT_ABAPSPOOLJOB_2_PDF'.
  236. endif.
  237. else.
  238. message e789(po) with rq-rqdoctype.
  239. endif.
  240.  
  241. pdf_size = bin_size.
  242.  
  243. clear: rq,
  244. bin_size,
  245. dummy,
  246. rqident.
  247.  
  248. endform.
  249. form fill_leader.
  250.  
  251. data: lt_leader_filter type table of ty_leader_filter.
  252.  
  253. data: lv_plvar type plvar,
  254. lv_objid type realo,
  255. lv_leader_pernr type realo.
  256.  
  257.  
  258. delete adjacent duplicates from t_p0001 comparing orgeh.
  259.  
  260. loop at t_p0001 assigning field-symbol(<p0001>).
  261. append initial line to lt_leader_filter assigning field-symbol(<filter>).
  262. <filter>-orgeh_leader = <p0001>-orgeh.
  263. <filter>-pernr_leader = <p0001>-pernr.
  264. endloop.
  265.  
  266. loop at lt_leader_filter assigning <filter>.
  267.  
  268. "Pega Plvar valido
  269. call function 'RH_GET_PLVAR'
  270. exporting
  271. no_message = abap_true
  272. importing
  273. plvar = lv_plvar
  274. exceptions
  275. no_plvar = 1
  276. others = 2.
  277. check sy-subrc = 0.
  278.  
  279. lv_objid = <filter>-orgeh_leader.
  280.  
  281. "Pega matricula do gestor
  282. call function 'RH_GET_LEADER'
  283. exporting
  284. plvar = lv_plvar
  285. keydate = '99991231'
  286. otype = 'O'
  287. objid = lv_objid
  288. importing
  289. leader_id = lv_leader_pernr
  290. exceptions
  291. no_leader_found = 1
  292. no_leading_position_found = 2
  293. others = 3.
  294.  
  295. "Pega email do gestor
  296. select single usrid_long from pa0105
  297. into <filter>-email_leader
  298. where pernr = lv_leader_pernr and
  299. subty = '0010' and
  300. endda = '99991231'.
  301.  
  302. "Pega nome do gestor
  303. select single cname from pa0002
  304. into <filter>-name_leader
  305. where pernr = lv_leader_pernr and
  306. endda = '99991231'.
  307.  
  308. <filter>-pernr_leader = lv_leader_pernr.
  309. append <filter> to t_leaders.
  310. endloop.
  311.  
  312.  
  313. endform.
  314.  
  315. *
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement