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: 

Create a FM that generates a PDF file.

Former Member
0 Kudos

Hello Evryone.

I have the following requirement.

I need to create a function module that given a Personnel Number would generate the payslip for that person based on an existing SE51 form and return the payslip as a PDF file, so that it could be used in WebDynpro.

Can any of you help me with this. How should I write this FM?

Thanks a lot in advance.

Francisco.

5 REPLIES 5

Former Member
0 Kudos

Hi,

Use this FM <b>CONVERT_OTF_2_PDF</b> to convert to PDF. Create a FM of your own and code in that to get what all you require from SE51. Pass those parameters to the above FM and it will convert it to PDF.

Regards

Aneesh.

0 Kudos

Hello Aneesh.

Thanks for your answer, but I'm not exactly following you.

How would I generate the input of the FM CONVERT_OTF_2_PDF from a form?

Is there any documentation on that FM that I can read to know what it receives as input and whats is its ouput?

Thanks a lot

Francisco.

0 Kudos

Hi,

Check this link.

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/convertSmartformtoPDFformat&

Reward if useful.

Thanks

Aneesh.

0 Kudos

HI Please refer the following code for converting a smartform into a PDF file

DATA: BIN_FILESIZE TYPE I,

BIN_FILE TYPE XSTRING,

T_OTF LIKE ITCOO OCCURS 200 WITH HEADER LINE,

T_DOC LIKE DOCS OCCURS 200 WITH HEADER LINE,

T_LINES1 LIKE TLINE OCCURS 200 WITH HEADER LINE,

T_FINAL_PDF LIKE TLINE OCCURS 500 WITH HEADER LINE,

filename TYPE string VALUE 'EXP.pdf',

path TYPE string VALUE 'C:\DESKTOP\..',

fullpath TYPE string VALUE 'C:\DESKTOP\PDF\EXP.pdf',

CALL FUNCTION 'CONVERT_OTF_2_PDF'

EXPORTING

use_otf_mc_cmd = 'X'

  • ARCHIVE_INDEX =

IMPORTING

bin_filesize = bin_filesize

TABLES

otf = t_otf

doctab_archive = t_doc

lines = t_lines1

EXCEPTIONS

err_conv_not_possible = 1

err_otf_mc_noendmarker = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

LOOP AT t_lines1 INTO t_lines1.

APPEND t_lines1 TO t_final_pdf.

ENDLOOP.

CALL METHOD cl_gui_frontend_services=>file_save_dialog

EXPORTING

default_file_name = 'EXPO_INVpdf'

prompt_on_overwrite = 'X'

CHANGING

filename = filename

path = path

fullpath = fullpath.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = bin_filesize

filename = fullpath

filetype = 'BIN'

append = 'X'

IMPORTING

filelength = bin_filesize

TABLES

data_tab = t_final_pdf.

IF sy-subrc EQ 0.

MESSAGE s018(zmsg) WITH 'PDF Generated Successfully'.

ELSE.

MESSAGE s011(zmsg) WITH 'PDF Not Generated !!!'.

ENDIF.

0 Kudos

Hello Aneesh and Manik.

Aneesh, I tried the code that I found in the link you provided, but its giving me a short dump when I execute it. It appears to be a problem with the parameters that the SmartForm's function receives.

Manik, there's something I don't understand about the code you posted. Where is the input for the CONVERT_OTF_2_PDF function coming from? Where is the table otf being filled?

I also have another doubt, all of this code refers to my form being a SmartForm, but I think that the forms I'm working with are not SamrtForms since they are created with transaction PE51. My objective is to generate a PDF based on the current payslip of the employee and pass it to webdynpro to be displayed in the portal.

Thanks a lot for your help.

Francisco