REPORT zhr_r_email_time_reject.
INFOTYPES : 0105.
TABLES pernr.
TYPES : BEGIN OF gty_pernr,
pernr TYPE pernr_d,
ename TYPE emnam,
email TYPE comm_id_long,
END OF gty_pernr,
BEGIN OF gty_final,
pernr TYPE pernr_d,
ename TYPE emnam,
date TYPE catsdate,
hours TYPE catshours,
text TYPE catsretext,
email TYPE comm_id_long,
END OF gty_final,
BEGIN OF gty_catsdb,
pernr TYPE pernr_d,
workdate TYPE catsdate,
catshours TYPE catshours,
status TYPE catsstatus,
laetm TYPE cats_laetm,
reason TYPE catsreason,
END OF gty_catsdb.
DATA : gs_pernr TYPE gty_pernr,
gs_final TYPE gty_final,
gs_catsdb TYPE gty_catsdb,
gs_catsdb1 TYPE gty_catsdb,
gs_body_msg LIKE solisti1,
gs_tcatsdt TYPE tcatsdt,
gt_tcatsdt TYPE STANDARD TABLE OF tcatsdt,
gt_body_msg TYPE STANDARD TABLE OF solisti1,
gt_catsdb TYPE STANDARD TABLE OF gty_catsdb,
gt_final TYPE STANDARD TABLE OF gty_final,
gt_pernr TYPE STANDARD TABLE OF gty_pernr.
DATA : lv_string TYPE string,
lv_string1 TYPE string,
lv_reason TYPE catsdb-reason,
gv_email TYPE comm_id_long,
gv_time TYPE cats_laetm.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_status TYPE catsstatus OBLIGATORY DEFAULT '40',
p_time TYPE cats_laetm.
SELECT-OPTIONS : s_reason FOR lv_reason NO INTERVALS.
PARAMETERS : p_test AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b1.
INITIALIZATION.
s_reason-sign = 'I'.
s_reason-option = 'EQ'.
s_reason-low = 'YB15'.
APPEND s_reason.
s_reason-low = 'YB20'.
APPEND s_reason.
s_reason-low = 'YB25'.
APPEND s_reason.
s_reason-low = 'YB30'.
APPEND s_reason.
s_reason-low = 'YB35'.
APPEND s_reason.
GET pernr.
gs_pernr-pernr = pernr-pernr.
gs_pernr-ename = pernr-ename.
rp-provide-from-last p0105 '0010' pn-begda pn-endda.
IF pnp-sw-found = 1.
gs_pernr-email = p0105-usrid_long.
ENDIF.
APPEND gs_pernr TO gt_pernr.
END-OF-SELECTION.
IF gt_pernr IS NOT INITIAL.
IF p_time IS NOT INITIAL.
gv_time = sy-uzeit - p_time.
ELSE.
ENDIF.
SELECT * FROM tcatsdt INTO TABLE gt_tcatsdt
WHERE reason IN s_reason.
IF sy-subrc = 0.
SORT gt_tcatsdt BY reason.
ENDIF.
SELECT pernr
workdate
catshours
status
laetm
reason FROM catsdb INTO TABLE gt_catsdb
FOR ALL ENTRIES IN gt_pernr
WHERE pernr = gt_pernr-pernr
AND status = p_status
AND laeda >= pn-begda AND laeda <= pn-endda
AND reason IN s_reason.
IF sy-subrc = 0.
IF p_time IS NOT INITIAL.
DELETE gt_catsdb WHERE laetm NOT BETWEEN gv_time AND sy-uzeit.
ENDIF.
SORT gt_catsdb BY pernr.
LOOP AT gt_catsdb INTO gs_catsdb1.
gs_catsdb = gs_catsdb1.
gs_final-pernr = gs_catsdb-pernr.
gs_final-date = gs_catsdb-workdate.
gs_final-hours = gs_catsdb-catshours.
CLEAR gs_tcatsdt.
READ TABLE gt_tcatsdt INTO gs_tcatsdt
WITH KEY reason = gs_catsdb-reason.
IF sy-subrc = 0.
gs_final-text = gs_tcatsdt-text.
ENDIF.
READ TABLE gt_pernr INTO gs_pernr WITH KEY pernr = gs_catsdb-pernr.
IF sy-subrc = 0.
gs_final-ename = gs_pernr-ename.
gv_email = gs_final-email = gs_pernr-email.
ENDIF.
AT NEW pernr.
IF p_test IS INITIAL.
"Body
CLEAR : gt_body_msg, lv_string.
CONCATENATE 'Hi' gs_final-ename ','
INTO lv_string SEPARATED BY space.
PERFORM body_mail USING:space, lv_string, space,
'Hours on your timesheet have been REJECTED'.
ENDIF.
ENDAT.
IF p_test IS INITIAL.
CLEAR : lv_string1, lv_string.
CONCATENATE gs_final-date+4(2) '/' gs_final-date+6(2) '/'
gs_final-date+0(4) INTO lv_string.
CONCATENATE 'Date : ' lv_string space
INTO lv_string1 SEPARATED BY space.
* PERFORM body_mail USING: lv_string.
CLEAR lv_string.
lv_string = gs_final-hours.
CONCATENATE lv_string1 'Hours : ' lv_string space
INTO lv_string1 SEPARATED BY space.
* PERFORM body_mail USING: lv_string.
* CLEAR lv_string.
CONCATENATE lv_string1 'Reason : ' gs_final-text space
INTO lv_string1 SEPARATED BY space.
PERFORM body_mail USING: lv_string1.
ENDIF.
APPEND gs_final TO gt_final.
CLEAR gs_final.
AT END OF pernr.
IF p_test IS INITIAL AND gv_email IS NOT INITIAL.
PERFORM body_mail USING:space,
'If you are an hourly employee, please contact your manager immediately for discussion regarding this. Then please correct your time in the system and resubmit.',
space,
'Please Note:',
'If you are a salaried employee and your hours exceeded 40 in a week, and the rejection reason is SALARIED, you are receiving this message because our system, while capturing all hours worked, only passes the initial 40 on to the payroll system',
'please disregard this message.',
space,
'If you are a salaried employee and your hours are being rejected for some other reason, please contact your manager immediately for discussion regarding this. Then please correct your time in the system and resubmit.',
space,
'If your manager is not available, please reach out to your HR Representative for support.',
space,
'Regards,',
'Time System Administration',
'-------------------------------------------------------------------------------------------'.
PERFORM email.
ENDIF.
CLEAR : lv_string, gt_body_msg, gv_email.
ENDAT.
ENDLOOP.
ENDIF.
ENDIF.
IF gt_final IS NOT INITIAL.
PERFORM display.
ELSE.
MESSAGE 'No Data Found' TYPE 'I'.
ENDIF.
FORM email.
DATA: lv_lines TYPE i,
ls_doc TYPE sodocchgi1,
ls_receivers TYPE somlreci1,
ls_packing_list TYPE sopcklsti1,
lt_packing_list TYPE STANDARD TABLE OF sopcklsti1,
lt_receivers TYPE STANDARD TABLE OF somlreci1.
ls_receivers-rec_type = 'U'. "Internet address
ls_receivers-receiver = gv_email.
ls_receivers-com_type = 'INT'.
APPEND ls_receivers TO lt_receivers .
"Subject of the
ls_doc-obj_name = 'Timesheet'.
ls_doc-obj_descr = 'SAP Timesheet – Request has been rejected'.
ls_doc-obj_langu = sy-langu.
"Write Packing List for Body
DESCRIBE TABLE gt_body_msg LINES lv_lines.
ls_packing_list-head_start = 1.
ls_packing_list-head_num = 0.
ls_packing_list-body_start = 1.
ls_packing_list-body_num = lv_lines.
ls_packing_list-doc_type = 'RAW'.
APPEND ls_packing_list TO lt_packing_list.
CLEAR ls_packing_list.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = ls_doc
put_in_outbox = 'X'
commit_work = 'X'
sender_address = 'SAP@csscorp.com'
sender_address_type = 'INT'
TABLES
packing_list = lt_packing_list
contents_txt = gt_body_msg
receivers = lt_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
AND RETURN.
ENDFORM.
FORM body_mail USING p_space.
gs_body_msg = p_space.
APPEND gs_body_msg TO gt_body_msg.
CLEAR gs_body_msg.
ENDFORM.
FORM display.
DATA : lo_alv TYPE REF TO cl_salv_table,
lo_functions TYPE REF TO cl_salv_functions,
lo_columns TYPE REF TO cl_salv_columns_table,
lo_column TYPE REF TO cl_salv_column_table.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = gt_final.
lo_functions = lo_alv->get_functions( ).
lo_functions->set_all( abap_true ).
CALL METHOD lo_alv->get_columns
RECEIVING
value = lo_columns.
lo_columns->set_optimize( 'X' ).
CALL METHOD lo_alv->display.
ENDFORM.
No comments:
Post a Comment