Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *&---------------------------------------------------------------------*
- *& Report Z_HR_HOUR_CHANGE_REPL_EC *
- *&---------------------------------------------------------------------*
- *& PROGRAMA : Z_HR_2001_AUS_REPLICATION *
- *& AUTOR : Leonardo Martins *
- *& DATA: : 26/12/2019 *
- *&---------------------------------------------------------------------*
- *& Programa para alteração em massa de horários no EC através da API *
- *& EmpJob carregado por um arquivo CSV *
- *& Programa também gerá um CSV modelo a ser seguido para a importação *
- *&---------------------------------------------------------------------*
- report zhrst_job_aprov_ponto.
- "BLD node
- nodes: peras.
- tables: pernr.
- "Infotypes
- infotypes: 0001.
- "Tables
- types: begin of ty_leader_filter,
- pernr_leader type pernr_d,
- name_leader type cname,
- orgeh_leader type orgeh,
- plans_leader type plans,
- werks_leader type persa,
- email_leader type comm_id_long,
- end of ty_leader_filter.
- "Class
- data: send_request type ref to cl_bcs,
- document type ref to cl_document_bcs,
- recipient type ref to if_recipient_bcs,
- bcs_exception type ref to cx_bcs.
- "Tables
- data: t_leaders type table of ty_leader_filter,
- t_p0001 type table of p0001.
- "Variables
- data: sent_to_all type os_boolean,
- pdf_size type so_obj_len,
- pdf_content type solix_tab,
- pdf_xstring type xstring,
- spool_id type char10,
- jobname like tbtco-jobname,
- jobcount like tbtco-jobcount.
- at selection-screen output.
- loop at screen.
- if screen-name cs 'PNPBEGDA' or screen-name cs 'PNPENDDA' or
- screen-name cs 'PNPSTAT2' or
- screen-name cs 'PNPWERKS-LOW'.
- screen-invisible = 1.
- modify screen.
- endif.
- endloop.
- pnpbegda = sy-datum - 7.
- pnpendda = sy-datum.
- start-of-selection.
- "Select Data
- get peras.
- if p0001[] is not initial.
- append lines of p0001[] to t_p0001.
- endif.
- end-of-selection.
- "Fill data
- perform fill_leader.
- data: input_length type i,
- buffer type xstring.
- "Fill and Send emails
- loop at t_leaders assigning field-symbol(<leaders>).
- "Verifica se o lider tem registros não aprovados
- select single pernr
- from zhrt_aprov_ponto
- into @data(check)
- where pernr = @<leaders>-pernr_leader.
- if sy-subrc <> 0.
- continue.
- endif.
- "Caso encontre registro ele chama, pega o resultado e envia por email
- submit zhrst_aprov_ponto with pnppernr = <leaders>-pernr_leader
- with pnpbegda = '20200101'
- with pnpendda = '20200131'
- with p_rad3 = abap_true
- with p_fer = abap_true
- with p_jus = abap_true
- with p_mar = abap_true to sap-spool without spool dynpro
- and return.
- get parameter id 'SPI' field spool_id.
- if sy-subrc = '0000000000'.
- continue.
- endif.
- perform create_pdf.
- perform send using <leaders>.
- clear spool_id.
- endloop.
- form send using params type ty_leader_filter.
- try.
- send_request = cl_bcs=>create_persistent( ).
- pdf_content = cl_document_bcs=>xstring_to_solix( pdf_xstring ).
- document = cl_document_bcs=>create_document(
- i_type = 'PDF'
- i_hex = pdf_content
- i_length = pdf_size
- i_subject = 'Email teste para gestor da area' ). "#EC NOTEXT
- send_request->set_document( document ).
- recipient = cl_cam_address_bcs=>create_internet_address( params-email_leader ).
- send_request->add_recipient( recipient ).
- sent_to_all = send_request->send( i_with_error_screen = 'X' ).
- commit work.
- if sent_to_all is initial.
- message i500(sbcoms) with params-email_leader.
- else.
- message s022(so).
- endif.
- catch cx_bcs into bcs_exception.
- message i865(so) with bcs_exception->error_type.
- endtry.
- clear: sent_to_all,
- pdf_size,
- pdf_content,
- pdf_xstring.
- endform.
- form create_pdf.
- data: rq type tsp01,
- bin_size type i,
- dummy type table of rspoattr,
- rqident type tsp01-rqident,
- lv_begda type begda.
- rqident = spool_id.
- call function 'RSPO_GET_ATTRIBUTES_SPOOLJOB'
- exporting
- rqident = rqident
- importing
- rq = rq
- tables
- attributes = dummy
- exceptions
- no_such_job = 1
- others = 2.
- if sy-subrc <> 0.
- message e126(po) with rqident.
- endif.
- if rq-rqdoctype = 'OTF' or rq-rqdoctype = 'SMART'.
- call function 'CONVERT_OTFSPOOLJOB_2_PDF'
- exporting
- src_spoolid = rqident
- no_dialog = 'X'
- pdf_destination = 'X'
- no_background = 'X'
- importing
- pdf_bytecount = bin_size
- bin_file = pdf_xstring
- exceptions
- err_no_otf_spooljob = 1
- err_no_spooljob = 2
- err_no_permission = 3
- err_conv_not_possible = 4
- err_bad_dstdevice = 5
- user_cancelled = 6
- err_spoolerror = 7
- err_temseerror = 8
- err_btcjob_open_failed = 9
- err_btcjob_submit_failed = 10
- err_btcjob_close_failed = 11
- others = 12.
- if sy-subrc <> 0.
- message e712(po) with sy-subrc 'CONVERT_OTFSPOOLJOB_2_PDF'.
- endif.
- elseif rq-rqdoctype = 'LIST'.
- call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
- exporting
- src_spoolid = rqident
- no_dialog = 'X'
- pdf_destination = 'X'
- no_background = 'X'
- importing
- pdf_bytecount = bin_size
- bin_file = pdf_xstring
- exceptions
- err_no_abap_spooljob = 1
- err_no_spooljob = 2
- err_no_permission = 3
- err_conv_not_possible = 4
- err_bad_destdevice = 5
- user_cancelled = 6
- err_spoolerror = 7
- err_temseerror = 8
- err_btcjob_open_failed = 9
- err_btcjob_submit_failed = 10
- err_btcjob_close_failed = 11
- others = 12.
- if sy-subrc <> 0.
- message e712(po) with sy-subrc 'CONVERT_ABAPSPOOLJOB_2_PDF'.
- endif.
- else.
- message e789(po) with rq-rqdoctype.
- endif.
- pdf_size = bin_size.
- clear: rq,
- bin_size,
- dummy,
- rqident.
- endform.
- form fill_leader.
- data: lt_leader_filter type table of ty_leader_filter.
- data: lv_plvar type plvar,
- lv_objid type realo,
- lv_leader_pernr type realo.
- delete adjacent duplicates from t_p0001 comparing orgeh.
- loop at t_p0001 assigning field-symbol(<p0001>).
- append initial line to lt_leader_filter assigning field-symbol(<filter>).
- <filter>-orgeh_leader = <p0001>-orgeh.
- <filter>-pernr_leader = <p0001>-pernr.
- endloop.
- loop at lt_leader_filter assigning <filter>.
- "Pega Plvar valido
- call function 'RH_GET_PLVAR'
- exporting
- no_message = abap_true
- importing
- plvar = lv_plvar
- exceptions
- no_plvar = 1
- others = 2.
- check sy-subrc = 0.
- lv_objid = <filter>-orgeh_leader.
- "Pega matricula do gestor
- call function 'RH_GET_LEADER'
- exporting
- plvar = lv_plvar
- keydate = '99991231'
- otype = 'O'
- objid = lv_objid
- importing
- leader_id = lv_leader_pernr
- exceptions
- no_leader_found = 1
- no_leading_position_found = 2
- others = 3.
- "Pega email do gestor
- select single usrid_long from pa0105
- into <filter>-email_leader
- where pernr = lv_leader_pernr and
- subty = '0010' and
- endda = '99991231'.
- "Pega nome do gestor
- select single cname from pa0002
- into <filter>-name_leader
- where pernr = lv_leader_pernr and
- endda = '99991231'.
- <filter>-pernr_leader = lv_leader_pernr.
- append <filter> to t_leaders.
- endloop.
- endform.
- *
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement