Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Convert Smartform Output to PDF

Hi all,

I am trying to save Output of Smartform in PDF file format. for that purpose i am calling "CONVERT_OTF" FM from my driver program.

But it is giving me Information "OTF end command // missing in OTF data"

while executing FM "CONVERT_OTF". i debug it it is giving Sy-subrc = 2.

Please Help me in this context. I am also givin code of my driver program:

TABLES: vbrp.

DATA: fm_name TYPE rs38l_fnam,

it_invoice TYPE STANDARD TABLE OF vbrp,

it_invoice_wa TYPE vbrp,

it_inv TYPE STANDARD TABLE OF vbrp,

it_inv_wa TYPE vbrp,

invoice_no(25) TYPE c,

invoice_l(10) TYPE c,

invoice_h(10) TYPE c.

                  • Converting Output to PDF Declaration **********

DATA: tab_otf_data TYPE ssfcrescl,

pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE,

bin_filesize LIKE sood-objlen,

outop TYPE ssfcompop, " Output Parameters

cparam TYPE ssfctrlop, " Control Parameters

tab_otf_final TYPE itcoo OCCURS 0 WITH HEADER LINE,

my_tabix TYPE sy-tabix,

file_size TYPE i.

SELECT-OPTIONS doc_no FOR vbrp-vbeln.

SELECT vbeln posnr fkimg vrkme meins netwr matnr

FROM vbrp INTO CORRESPONDING FIELDS

OF TABLE it_invoice

WHERE vbeln IN doc_no.

  • Inserting Unique Invoice Numbers for Displaying Individual Details in

  • Smart Form

LOOP AT it_invoice INTO it_invoice_wa.

AT NEW vbeln.

MOVE it_invoice_wa-vbeln TO it_inv_wa-vbeln.

APPEND it_inv_wa TO it_inv.

ENDAT.

ENDLOOP.

invoice_no = doc_no.

invoice_l = doc_no-low.

invoice_h = doc_no-high.

                                  • suppressing the Print dialog box *********************

*outop-tddest = 'locl'.

*cparam-no_dialog = 'X'.

*cparam-preview = space.

*cparam-getotf = 'X'.

START-OF-SELECTION.

                                      • Calling Smart Form *********************************

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'ZSB_SMARTFORM_INVOICE'

  • VARIANT = ' '

  • DIRECT_CALL = ' '

IMPORTING

fm_name = fm_name

.

CALL FUNCTION fm_name

EXPORTING

invoice_no_h = invoice_h

invoice_no_l = invoice_l

  • ARCHIVE_INDEX =

  • ARCHIVE_INDEX_TAB =

  • ARCHIVE_PARAMETERS =

  • control_parameters = cparam

  • MAIL_APPL_OBJ =

  • MAIL_RECIPIENT =

  • MAIL_SENDER =

  • output_options = outop

  • user_settings = ''

IMPORTING

  • DOCUMENT_OUTPUT_INFO =

JOB_OUTPUT_INFO = tab_otf_data

  • JOB_OUTPUT_OPTIONS =

TABLES

it_invoice = it_invoice

it_inv = it_inv

.

*

***removing the initial and final markers from the OTF data*********

  • DELETE tab_otf_data-otfdata WHERE tdprintcom = '//'.

                                  • searching for the end-of-page in OTF table************

  • READ TABLE tab_otf_final WITH KEY tdprintcom = 'EP'.

  • my_tabix = sy-tabix + 1.

                        • appending the modified OTF table to the final OTF table****

*INSERT LINES OF tab_otf_data-otfdata INTO tab_otf_final INDEX my_tabix.

tab_otf_final[] = tab_otf_data-otfdata[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

  • ARCHIVE_INDEX = ' '

  • COPYNUMBER = 0

  • ASCII_BIDI_VIS2LOG = ' '

IMPORTING

bin_filesize = bin_filesize

  • BIN_FILE =

TABLES

otf = tab_otf_final

lines = pdf_tab

  • EXCEPTIONS

  • ERR_MAX_LINEWIDTH = 1

  • ERR_FORMAT = 2

  • ERR_CONV_NOT_POSSIBLE = 3

  • ERR_BAD_OTF = 4

  • OTHERS = 5

.

*IF sy-subrc <> 0.

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

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

*ENDIF.

write :/ bin_filesize.

*

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE = bin_filesize

filename = 'E:/Test.pdf'

FILETYPE = 'ASC'

IMPORTING

FILELENGTH = file_size

tables

data_tab = pdf_tab

  • FIELDNAMES =

.

Help will be rewarded.

Regards,

Sachin

Former Member
Former Member replied

hi

good

go through this ,hope this ll help you to solve this problem

Check out the following documentation and example program and help links

s_control_parameters-no_dialog = 'X'.

s_control_parameters-getotf = 'X'.

CALL FUNCTION v_func_name "call your smartform

EXPORTING

output_options = s_output_options

control_parameters = s_control_parameters

IMPORTING

job_output_info = s_job_output_info

call function 'CONVERT_OTF_2_PDF'

tables

otf = s_job_output_info-otfdata

lines = t_pdf

here is the example for SAMRTFORM TO PDF.

http://www.sap4.com/wiki/index.php/Genera_PDF_a_partir_de_Smartforms

Example Program

data:

fm_name TYPE RS38L_FNAM, "Smart Forms: FM Name

sf_name TYPE TDSFNAME

value 'YOUR_FORM_NAME', "Smart Forms: Form Name

P_OUTPUT_OPTIONS TYPE SSFCOMPOP,

P_JOB_OUTPUT_INFO TYPE SSFCRESCL,

P_CONTROL_PARAMETERS TYPE SSFCTRLOP,

P_LANGUAGE TYPE SFLANGU value 'E',

P_E_DEVTYPE TYPE RSPOPTYPE.

data:

P_BIN_FILESIZE TYPE I,

P_BIN_FILE TYPE XSTRING,

P_OTF type table of ITCOO,

P_DOCS type table of DOCS,

P_LINES type table of TLINE,

name type string,

path type string,

fullpath type string,

filter type string,

guiobj type ref to cl_gui_frontend_services,

uact type i,

filename(128).

*"----


GET SMARTFORM FUNCTION MODULE NAME ---

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

FORMNAME = sf_name

IMPORTING

FM_NAME = fm_name

EXCEPTIONS

NO_FORM = 1

NO_FUNCTION_MODULE = 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.

CALL FUNCTION 'SSF_GET_DEVICE_TYPE'

EXPORTING

I_LANGUAGE = P_LANGUAGE

I_APPLICATION = 'SAPDEFAULT'

IMPORTING

E_DEVTYPE = P_E_DEVTYPE.

P_OUTPUT_OPTIONS-XSFCMODE = 'X'.

P_OUTPUT_OPTIONS-XSF = SPACE.

P_OUTPUT_OPTIONS-XDFCMODE = 'X'.

P_OUTPUT_OPTIONS-XDF = SPACE.

P_OUTPUT_OPTIONS-TDPRINTER = P_E_DEVTYPE.

P_CONTROL_PARAMETERS-NO_DIALOG = 'X'.

P_CONTROL_PARAMETERS-GETOTF = 'X'.

****...................................PRINTING.........................

CALL FUNCTION fm_name

EXPORTING

CONTROL_PARAMETERS = P_CONTROL_PARAMETERS

OUTPUT_OPTIONS = P_OUTPUT_OPTIONS

  • (....) <--- your form import parameters

IMPORTING

JOB_OUTPUT_INFO = P_JOB_OUTPUT_INFO.

IF SY-SUBRC <> 0.

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

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

ENDIF.

P_OTF[] = P_JOB_OUTPUT_INFO-OTFDATA.

****...................................CONVERT TO PDF...............

CALL FUNCTION 'CONVERT_OTF_2_PDF'

IMPORTING

BIN_FILESIZE = P_BIN_FILESIZE

TABLES

OTF = P_OTF

DOCTAB_ARCHIVE = P_DOCS

LINES = P_LINES

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.

concatenate 'xxxx' '.pdf' into name.

****..................................REQUEST FILE NAME.................

create object guiobj.

call method guiobj->file_save_dialog

EXPORTING

default_extension = 'pdf'

default_file_name = name

file_filter = filter

CHANGING

filename = name

path = path

fullpath = fullpath

user_action = uact.

if uact = guiobj->action_cancel.

exit.

endif.

move fullpath to filename.

****..................................DOWNLOAD AS FILE................

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

BIN_FILESIZE = P_BIN_FILESIZE

FILENAME = filename

FILETYPE = 'BIN'

TABLES

DATA_TAB = P_LINES

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

NO_AUTHORITY = 10

OTHERS = 11.

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

reward poing if helpful..

thanks

mrutyun^

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question