Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Append PDF to existing PDF file (payslip generation)

Former Member
0 Kudos

Hi experts!!

I have created an SmartForm to get the payslip in pdf format. The steps I followed are:

1) Create the smartform copy of the HR_ESS_PAYSLIP_TO_PDF adding the logo

2) Create a ZRPCEDTE0 report copy of the RPCEDTE0

3) Create ZRPCEDS29 include copy of RPCEDS29

4) Modify the report ZRPCEDTE0 changing the include RPCEDS29 for the ZRPCEDS29

5) Modify The form PRINT_XFORM in the ZRPCEDS29 include with this code:

---

FORM print_xform USING $form TYPE tt_form.

  IF NOT $form[] IS INITIAL.

    DATA: $form_wa LIKE pc408.

    DATA: fm_name TYPE rs38l_fnam.

    DATA: pinfo TYPE pc407.

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

      EXPORTING

        formname = 'ZHR_ESS_PAYSLIP_TO_PDF'

      IMPORTING

        fm_name  = fm_name.

    DATA: l_devtype TYPE rspoptype,

    ls_output_options TYPE ssfcompop,

    ls_output_data TYPE ssfcrescl,

    ls_control_parameters TYPE ssfctrlop.

    ls_control_parameters-no_dialog = 'X'.

    ls_control_parameters-getotf = 'X'.

* ls_output_options-TDPRINTER = 'LOCL'.

* Combina SmartForm con el listado

    CALL FUNCTION fm_name

      EXPORTING

        control_parameters = ls_control_parameters

        output_options     = ls_output_options

        user_settings      = space

        pinfo              = pinfo

        pform              = $form[]

      IMPORTING

        job_output_info    = ls_output_data

      EXCEPTIONS

        formatting_error   = 1

        internal_error     = 2

        send_error         = 3

        user_canceled      = 4

        OTHERS             = 5.

    DATA: l_pdf_xstring TYPE xstring,

    lt_lines TYPE TABLE OF tline,

    ls_line TYPE tline,

    l_pdf_len TYPE i,

    P_DOC TYPE DOCS occurs 0 .

* Crea PDF

    CALL FUNCTION 'CONVERT_OTF_2_PDF'

    IMPORTING

    BIN_FILESIZE = l_pdf_len

    TABLES

    OTF = ls_output_data-otfdata

    DOCTAB_ARCHIVE = p_doc

    LINES = lt_lines

    .

***

      CALL FUNCTION 'GUI_DOWNLOAD'

        EXPORTING

*            BIN_FILESIZE            =

             filename                = 'C:\PAYSLIP.PDF'"p_file        "File Name

             filetype                = 'BIN'

             append                  = 'X'

*       IMPORTING

*            FILELENGTH              =

        TABLES

            data_tab                = lt_lines   "Data table

        EXCEPTIONS

            file_write_error        = 1

            no_batch                = 2

            gui_refuse_filetransfer = 3

            invalid_type            = 4

            OTHERS                  = 5.

***

    IF SY-SUBRC EQ 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

  endif.

ENDFORM. "PRINT_XFORM.


---

All these steps allow create the payslip in PDF format and is working fine if in the selecion parameters I select only one employee.

If I select more than one employee the PDF file generated only shows the last payslip of the employees instead of append every payslip to the pdf file.

The PDF file is ovewritten for each payslip instead of append it.

How should I modify the code to generate only one pdf file with all the payslips of all the employees?

Kind Regards,

Julian.

1 ACCEPTED SOLUTION

kesavadas_thekkillath
Active Contributor
0 Kudos

You can refer my suggestion here Merge Smartform and Script into one pdf | SCN

Append ls_output_data to an internal table inside the loop, convert the otf and send it outside the loop.

3 REPLIES 3

gouravkumar64
Active Contributor
0 Kudos

Hi,

Delete ur all code for PDF conversion purpose

U can use direct option like this(with out any code)

in print preview

write PDF! in transaction command prompt & press enter.

Ur job done...for multiple pdf also will works .

Hope it helps.

Thanks

Gourav.

0 Kudos

Thanks Gourav,

But I think I need to use code because I have added the logo to the payslip and some payslip will be printed (all them) in a PDF file and others will be sent by email.

Kind regards,

Julian.

kesavadas_thekkillath
Active Contributor
0 Kudos

You can refer my suggestion here Merge Smartform and Script into one pdf | SCN

Append ls_output_data to an internal table inside the loop, convert the otf and send it outside the loop.