
Requirement – Send the Password Protected Pay slip to Employee official Email.
Background – Standard Transaction Code HINU_HRFORMS_MAIL in India Payroll use to generate the Employee payslip using the HRFORMs and have option to Send the payslip to the employee email.
Solution
BADI Logic
CONSTANTS: lc_oper TYPE sxpgcolist-opsystem VALUE 'Linux',
lc_extcom TYPE sxpgcolist-name VALUE 'ZENCRYPT_PDF',
lc_j TYPE c LENGTH 2 VALUE '-j',
lc_rj TYPE c LENGTH 3 VALUE '-rj',
lc_p TYPE c LENGTH 2 VALUE '-P',
lc_slash TYPE c LENGTH 1 VALUE '/',
lc_pdf TYPE c LENGTH 4 VALUE '.PDF',
lc_zip TYPE c LENGTH 4 VALUE '.zip',
lc_zip_zip TYPE c LENGTH 8 VALUE '_zip.zip',
lc_hcm_payslip TYPE rvari_vnam VALUE 'ZHCM_PAYSLIP'.
pdf_size1 = xstrlen( im_form_out_params-pdf ).
lt_content = cl_document_bcs=>xstring_to_solix( ip_xstring = im_form_out_params-pdf ).
IF lv_appl_path IS NOT INITIAL.
lv_appl_path = |{ lv_appl_path }| && |{ lc_slash }|.
CONCATENATE lv_appl_path lv_pernr lc_pdf INTO lv_file. " '.PDF'
CONCATENATE lv_appl_path lv_pernr lc_zip INTO lv_file_zip. "'.zip'
OPEN DATASET lv_file FOR OUTPUT IN BINARY MODE.
IF sy-subrc = 0.
LOOP AT lt_content INTO DATA(lwa_pdfcontent).
TRANSFER lwa_pdfcontent-line TO lv_file.
ENDLOOP.
ENDIF.
CLOSE DATASET lv_file.
CONCATENATE lc_j lc_p lv_panno lv_file_zip lv_file INTO lv_dir_input SEPARATED BY space.
CLEAR:lt_result[].
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
commandname = lc_extcom
additional_parameters = lv_dir_input
operatingsystem = lc_oper
TABLES
exec_protocol = lt_result
EXCEPTIONS
no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
wrong_asynchronous_parameters = 12
cant_enq_tbtco_entry = 13
jobcount_generation_error = 14
OTHERS = 15.
OPEN DATASET lv_file_zip FOR INPUT IN BINARY MODE .
IF sy-subrc = 0.
REFRESH:lt_attach_hex[].
READ DATASET lv_file_zip INTO lv_xstr_content.
CLOSE DATASET lv_file_zip.
ENDIF.
*------------- Convert Xstring to Solix ------------- *
IF lv_xstr_content IS NOT INITIAL.
CALL METHOD cl_bcs_convert=>xstring_to_solix
EXPORTING
iv_xstring = lv_xstr_content
RECEIVING
et_solix = lt_attach_hex.
ENDIF.
* ------------ Delete zip containing PDF file -----------------*
OPEN DATASET lv_file_zip FOR INPUT IN BINARY MODE .
IF sy-subrc EQ 0.
DELETE DATASET lv_file_zip.
CLOSE DATASET lv_file_zip.
ENDIF.
* ----------- Delete PDF file ---------------*
OPEN DATASET lv_file FOR INPUT IN BINARY MODE .
IF sy-subrc EQ 0.
DELETE DATASET lv_file.
CLOSE DATASET lv_file.
ENDIF.
* -------- create persistent send request ------------------------*
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document -------------------------------*
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = text
i_length = '72'
i_subject = lv_subject ). "#EC NOTEXT
IF lt_attach_hex IS NOT INITIAL.
CALL METHOD document->add_attachment(
i_attachment_type = 'ZIP'
i_att_content_hex = lt_attach_hex
i_attachment_subject = lv_subject ).
ELSE.
CALL METHOD document->add_attachment(
i_attachment_type = 'PDF'
i_att_content_hex = lt_content
i_attachment_size = pdf_size1
i_attachment_subject = lv_subject ).
ENDIF.
* ------------add document object to send request-----------*
send_request->set_document( document ).
* --------- add recipient (e-mail address) -----------------------*
lr_sender = cl_cam_address_bcs=>create_internet_address( lv_sender_email ).
send_request->set_sender( lr_sender ).
* --------- add recipient (e-mail address) -----------------------(
recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
*------------add recipient object to send request------------*
send_request->add_recipient( recipient ).
send_request->set_status_attributes( i_requested_status = 'E' ).
* ---------- send document ---------------------------------------*
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
COMMIT WORK.
Thank you for the time to read this blog. I hope this blog will be helpful to payroll consultants.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
4 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |