Human Capital Management Blog Posts by Members
Gain valuable knowledge and tips on SAP SuccessFactors HCM suite and human capital management market from member blog posts. Share your insights with a post of your own.
cancel
Showing results for 
Search instead for 
Did you mean: 
UdhayaGuru
Discoverer
890

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

  • Install the ZIP application in SAP Application Server
  • Create the External Command ZIP in SM69
  • Create the AL11 Application Server File Folder to temporary Store the Payslip file for perform the ZIP Password Enabled 
  • Payslip Email Logic are written in BADI “HRFORM_HRF02” and Method “AFTER_PDF_PRINT”

S0011763008_0-1724659502941.png

S0011763008_1-1724659502961.png

 

 

BADI Logic

  1. BADI “HRFORM_HRF02” Implementation and Method “AFTER_PDF_PRINT”
  2. Get the employee Email ID from Infotype 0105 (Communication), Subtype 0010.
  3. Use the Employee PAN Card No to the Password of the Payslip
  4. Get the employee PAN Card No from Infotype 0185 (Identification), Subtype 02.
  5. Sender Email ID Stored in the TVARV Table
  6. Constant

    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'.

 

  1. Get PDF xstring and convert it to BCS format

        pdf_size1 = xstrlen( im_form_out_params-pdf ).

        lt_content = cl_document_bcs=>xstring_to_solix( ip_xstring = im_form_out_params-pdf ).

 

  1. Create path for PDF, ZIP file upload at AL11 (application server)

        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.

 

  1. Prepare zip file of payslip PDF content

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.

 

  1. Get the ZIP File Data from Application Server

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.

 

  1. Delete Temporary Application Server Files

*  ------------ 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.

 

  1. Email

*     -------- 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.

1 Comment
Labels in this area