*&---------------------------------------------------------------------* *& Report /GRUBE/PDF_TEST_PSLIP_ENCRYP *& *&---------------------------------------------------------------------* *& *& Example for encrypted Payslip (HRFORMS) *& Code was basically copied from class *& CL_HRXSS_REM *& Method: L_PRODUCE_FORM *& *& Please create user IYOMAIL in SU01 with some email address (e.g. *& payroll@mycompany.com to set the sender address *& tested on IDES / Client 800 mit Adobe Document Service (ADS) 8.x *&---------------------------------------------------------------------* * Selection Texts * P_FPPER Payperiod (YYYYMM) * P_PERNR Employee Number REPORT /GRUBE/PDF_TEST_PSLIP_ENCRYP. data: xpayslip type xstring. data: data_lines type /grube/raw256_table. data: len1 type i. data: fl type string. data: file type file_table. data: files type filetable. data: rc type i. data: l_molga type molga. data: l_rgdir type H99_CLST_T_RGDIR. data: wa_rgdir type line of H99_CLST_T_RGDIR. data: lt_evp type H99_CLST_T_RGDIR. data: i0001 TYPE TABLE OF p0001. data: wa_i0001 type p0001. data: pmehf TYPE pmehf. data: hrform_name TYPE hrf_name. data: message1 type bapiret1. data: form_object TYPE REF TO object. data: pass(12). data: o_pdf type ref to /grube/cl_pdf. data: o_encrypt_aes type ref to /grube/cl_pdf_encry_aes_256. data: o_encrypt type ref to /grube/cl_pdf_encryption. data: upass type string. data: opass type string. data: line type SOLI. data: result type xstring. data: len type so_obj_len. data: lt_xpdf type solix_tab. data: l_xpdf type solix. data: send_request type ref to cl_bcs. data: bcs_exception type ref to cx_bcs. data: text_line type soli. data: text type bcsy_text. data: document type ref to cl_document_bcs. data: sender type ref to cl_sapuser_bcs. data: recipient type ref to if_recipient_bcs. data: sent_to_all type os_boolean. parameters: p_pernr type P_PERNR. parameters: p_fpper type FAPER default '200905'. start-of-selection. * Get the payroll runs CALL FUNCTION 'CU_READ_RGDIR' EXPORTING persnr = p_pernr IMPORTING molga = l_molga TABLES in_rgdir = l_rgdir EXCEPTIONS no_record_found = 1 OTHERS = 2. IF sy-subrc <> 0. write: / 'Error reading Molga and RGDIR:', p_pernr. exit. ENDIF. * Find the requested payrun READ TABLE l_rgdir INTO wa_rgdir with key fpper = p_fpper. APPEND wa_rgdir TO lt_evp. * Get some employee details CALL FUNCTION 'HR_READ_INFOTYPE' EXPORTING pernr = p_pernr infty = '0001' TABLES infty_tab = i0001 EXCEPTIONS infty_not_found = 1 OTHERS = 2. IF sy-subrc <> 0. write: 'Error Reading Infotype 1',p_pernr. exit. ENDIF. LOOP AT i0001 INTO wa_i0001 WHERE begda LE wa_rgdir-ipend AND endda GE wa_rgdir-ipend. ENDLOOP. * determine id of hrforms form MOVE-CORRESPONDING wa_i0001 TO pmehf. MOVE-CORRESPONDING wa_rgdir TO pmehf. pmehf-rclas = 'CESS'. pmehf-molga = l_molga. pmehf-uname = sy-uname. * find the name of the HRForm Feature HRFOR (PE03) CALL FUNCTION 'HR_FEATURE_BACKFIELD' EXPORTING feature = 'HRFOR' struc_content = pmehf kind_of_error = space IMPORTING back = hrform_name EXCEPTIONS dummy = 1 error_operation = 2 no_backvalue = 3 feature_not_generated = 4 invalid_sign_in_funid = 5 field_in_report_tab_in_pe03 = 6 OTHERS = 7. IF sy-subrc <> 0. write: 'Config Error Feature: HRFOR', p_pernr. exit. endif. if hrform_name eq '$CEDT$'. "VKI * use classic version of payslip program (RPCEDTx0) CALL FUNCTION 'BAPI_GET_PAYSLIP_PDF' EXPORTING EMPLOYEENUMBER = p_pernr SEQUENCENUMBER = wa_rgdir-seqnr PAYSLIPVARIANT = space IMPORTING RETURN = message1 PAYSLIP = xpayslip PDF_FSIZE = len1. if not message1-type is initial. write: / 'Problem calling BAPI_GET_PAYSLIP_PDF', p_pernr. endif. else. "VKI * use new version of payslip program (HRForms) * init HRFORMS CALL FUNCTION 'HRFORMS_CALL_INIT' EXPORTING hrform_name = hrform_name begin_date = wa_rgdir-fpbeg "VKIN994383 end_date = wa_rgdir-fpend "VKIN994383 IMPORTING form_object = form_object EXCEPTIONS form_error = 1 OTHERS = 2. IF sy-subrc <> 0. write: / 'Error calling HRFORMS_CALL_INIT', p_pernr, hrform_name. exit. ENDIF. * process payroll data of pernr at hrforms to create form CALL FUNCTION 'HRFORMS_CALL_PERNR' EXPORTING form_object = form_object pernr = p_pernr result_list = lt_evp call_evp = 'X' molga = l_molga rgdir = l_rgdir * BUFFER_INFTY = EXCEPTIONS form_error = 1 payroll_read_error = 2 reject = 3 no_form = 4 OTHERS = 5. IF sy-subrc <> 0. write: / 'Error calling HRFORMS_CALL_PERNR', p_pernr, hrform_name. exit. ENDIF. * get form as pdf stream CALL FUNCTION 'HRFORMS_CALL_PDF' EXPORTING form_object = form_object IMPORTING pdf_size = len1 pdf_xstring = xpayslip EXCEPTIONS form_error = 1 OTHERS = 2. IF sy-subrc <> 0. write: / 'Error calling HRFORMS_CALL_PDF', p_pernr, hrform_name. exit. ENDIF. "IF sy-subrc <> 0 ENDIF. "IF 'CEDT' or 'HRForms' len1 = xstrlen( xpayslip ). * generate a password using SAP standard function * to avoid confusion about 1 and l or 0 and O the * alphabet is restricted to clearly identifiable * characters call function 'RSEC_GENERATE_PASSWORD' exporting alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789' output_length = 12 importing output = pass exceptions some_error = 1 others = 2. if sy-subrc <> 0. write: / 'Error when generating password'. exit. endif. * set the PDF and the encryption create object o_pdf. o_pdf->set_pdf_file( xpayslip ). * pass = 'TEST'. upass = pass. concatenate 'O_' pass into opass. create object o_encrypt_aes exporting keylength = 128 . o_encrypt ?= o_encrypt_aes. * set the user permissions for the PDF file o_encrypt->set_permission_ex( print_allowed = 'X' modify_allowed = ' ' copy_allowed = 'X' add_annotations_allowed = ' ' fill_fields_allowed = ' ' copy_accessibility_allowed = 'X' assemble_allowed = ' ' print_highres_allowed = 'X' ). * set the user and the owner password for the PDF o_encrypt->set_passwords( user_password = upass owner_password = opass ). * generate the passwords o_encrypt->generate_passwords( o_pdf ). * encrypt the PDF o_pdf->do_action( o_encrypt ). * get the encrypted and processed PDF xstring result = o_pdf->create_pdf( ). len = xstrlen( result ). * data_lines = /grube/cl_pdf=>convert_xstring_2_table( result ). * len1 = len. * call method cl_gui_frontend_services=>gui_download * EXPORTING * bin_filesize = len1 * filename = fl * filetype = 'BIN' * CHANGING * data_tab = data_lines. * convert to a solix_tab call function 'SCMS_XSTRING_TO_BINARY' exporting buffer = result tables binary_tab = lt_xpdf . data: attch type so_obj_des. data: d_start(10) type c. data: d_end(10) type c. write wa_rgdir-FPBEG to d_start. write wa_rgdir-FPEND to d_end. concatenate 'Payslip_from_' d_start '_to_' d_end into attch. * create the mail and attachment as described in the BCS_EXAMPLE programs try. send_request = cl_bcs=>create_persistent( ). concatenate 'Dear' wa_i0001-ename ',' into line-line separated by ' '. append line to text. line-line = ''. append line to text. append 'please find your payslip in the attachment' to text. line-line = ''. append line to text. concatenate 'Password:' pass into line-line separated by ' '. append line to text. line-line = ''. append line to text. line-line = 'Kind Reagrads'. append line to text. line-line = 'Payroll'. append line to text. document = cl_document_bcs=>create_document( i_type = 'RAW' i_text = text * i_length = '72' i_subject = attch ). call method document->add_attachment exporting i_attachment_type = 'PDF' i_attachment_subject = attch i_attachment_size = len i_att_content_hex = lt_xpdf. call method send_request->set_document( document ). sender = cl_sapuser_bcs=>create( 'IYOMAIL' ). call method send_request->set_sender exporting i_sender = sender. recipient = cl_cam_address_bcs=>create_internet_address( 'joe.doe@crazy-company.com' ). call method send_request->add_recipient exporting i_recipient = recipient i_express = 'X'. call method send_request->send( exporting i_with_error_screen = 'X' receiving result = sent_to_all ). if sent_to_all = 'X'. write: / 'Document Sent Successfully'. endif. commit work. catch cx_bcs into bcs_exception. write: 'Fehler aufgetreten.'(001). write: 'Fehlertyp:'(002), bcs_exception->error_type. exit. endtry.