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: 

Display Smartform in PDF.

0 Kudos

Hi All,

I have gone through the forum threads to convert a smartform into a pdf document. All of them say to use function module CONVERT_OTF. This function module converts the output of the smartform which is in OTF into the PDF format and we can download the information which opens up with Adobe Reader.

The question is whether we can display the output of the smartform in Adobe at runtime within the SAP GUI because if it is in the portal then we can set the attribute in SAP Connect, to display the output of SAP Script and Smartforms in PDF.

I tried this code

REPORT ZACOSTA_FETCH_DATA_COPY.

DATA : IT_ZACOSTA TYPE ZACOSTA_TAB_DET.

DATA : V_FORM_NAME TYPE TDSFNAME VALUE 'ZACOSTA_FORMS_COPY1',

V_FUNC_NAME TYPE RS38L_FNAM.

DATA: LS_CONTROL_PARAMETERS TYPE SSFCTRLOP,

LS_OUTPUT_OPTIONS TYPE SSFCOMPOP,

LS_JOB_OUTPUT_INFO TYPE SSFCRESCL,

LT_LINES TYPE TABLE OF TLINE,

L_DEVTYPE TYPE RSPOPTYPE,

L_SAM_HAWKINS TYPE INT4,

L_DOC TYPE DOCS OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.

SELECT VBAKVBELN VBAKVKORG VBAK~VTWEG

VBAKSPART VBAKKUNNR VBAP~POSNR

VBAPMATNR VBAPARKTX VBAP~NETWR

VEDAVBEGDAT VEDAVENDDAT

INTO CORRESPONDING FIELDS OF TABLE IT_ZACOSTA

FROM VBAK INNER JOIN VBAP

ON VBAKVBELN = VBAPVBELN

INNER JOIN VEDA

ON VEDAVBELN = VBAPVBELN

WHERE VBAK~VBELN = '0040000264'. "Where Clause to be removed

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

FORMNAME = V_FORM_NAME

  • VARIANT = ' '

  • DIRECT_CALL = ' '

IMPORTING

FM_NAME = V_FUNC_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.

  • Set language

LS_CONTROL_PARAMETERS-LANGU = SY-LANGU.

  • Set control parameters to get the output format (OTF) from Smart Forms

LS_CONTROL_PARAMETERS-NO_DIALOG = 'X'.

LS_CONTROL_PARAMETERS-GETOTF = 'X'.

LS_OUTPUT_OPTIONS-TDNOPREV = 'X'.

CALL FUNCTION V_FUNC_NAME

EXPORTING

OUTPUT_OPTIONS = LS_OUTPUT_OPTIONS

CONTROL_PARAMETERS = LS_CONTROL_PARAMETERS

USER_SETTINGS = SPACE

IT_ZACOSTA = IT_ZACOSTA

IMPORTING

JOB_OUTPUT_INFO = LS_JOB_OUTPUT_INFO.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

MAX_LINEWIDTH = 132

  • ARCHIVE_INDEX = ' '

  • COPYNUMBER = 0

IMPORTING

BIN_FILESIZE = L_SAM_HAWKINS

  • bin_file = p_data " binary file

TABLES

OTF = LS_JOB_OUTPUT_INFO-OTFDATA

LINES = LT_LINES

EXCEPTIONS

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

ERR_BAD_OTF = 4

OTHERS = 5

.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = 'C:\Test.pdf'

FILETYPE = 'BIN'

  • APPEND = ' '

  • WRITE_FIELD_SEPARATOR = ' '

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = LT_LINES

  • FIELDNAMES =

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

The reson why I had to download is because this does not show the PDF at runtime. Am I missing some parameter here or is there some kind of configuration required to display the smartform in PDF at runtime within the SAP GUI.

Any hints on this would be greatly appreciated.

Best Regards,

Sudhi

2 REPLIES 2

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Here is the sample code.This code will download the smartforms as PDF.Kindly reward points by clicking the star on the left of reply,if it helps.

REPORT zswar.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME.

PARAMETER: p_date LIKE sy-datum.

PARAMETER: p_rea TYPE char255.

SELECTION-SCREEN: END OF BLOCK b1.

DATA: ws_ucomm LIKE sy-ucomm.

INITIALIZATION.

SET PF-STATUS 'STANDARD' OF PROGRAM 'ZSWAR'.

AT SELECTION-SCREEN.

ws_ucomm = sy-ucomm.

CASE ws_ucomm.

WHEN '&PDF'.

PERFORM f1000_download_form.

EXIT.

WHEN '&BACK'.

SET SCREEN 0.

EXIT.

WHEN '&EXIT'.

SET SCREEN 0.

EXIT.

WHEN '&canc'.

SET SCREEN 0.

LEAVE TO SCREEN 0.

ENDCASE.

*&----


*

*& Form F1000_DOWNLOAD_FORM

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM f1000_download_form.

DATA: form_name TYPE rs38l_fnam.

DATA: wa_ctrlop TYPE ssfctrlop,

wa_outopt TYPE ssfcompop.

DATA: t_otfdata TYPE ssfcrescl,

t_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.

Tutorial on SMART FORMS

© 2005 SAP AG 7

DATA: t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE.

DATA: w_filesize TYPE i.

DATA: w_bin_filesize TYPE i.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'ZSMARTFORM_SWAR'

  • VARIANT = ' '

  • DIRECT_CALL = ' '

IMPORTING

fm_name = form_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.

wa_ctrlop-getotf = 'X'.

wa_ctrlop-no_dialog = 'X'.

wa_outopt-tdnoprev = 'X'.

CALL FUNCTION form_name

EXPORTING

  • ARCHIVE_INDEX =

  • ARCHIVE_INDEX_TAB =

  • ARCHIVE_PARAMETERS =

control_parameters = wa_ctrlop

  • MAIL_APPL_OBJ =

  • MAIL_RECIPIENT =

  • MAIL_SENDER =

output_options = wa_outopt

user_settings = 'X'

mydate = p_date

reason = p_rea

IMPORTING

  • DOCUMENT_OUTPUT_INFO =

job_output_info = t_otfdata

  • JOB_OUTPUT_OPTIONS =

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

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

t_otf[] = t_otfdata-otfdata[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

Tutorial on SMART FORMS

© 2005 SAP AG 8

max_linewidth = 132

  • ARCHIVE_INDEX = ' '

IMPORTING

bin_filesize = w_bin_filesize

TABLES

otf = t_otf

lines = t_pdf_tab

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

OTHERS = 4

.

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

EXPORTING

bin_filesize = w_bin_filesize

  • CODEPAGE = ' '

filename = 'd: est.PDF'

filetype = 'BIN'

  • MODE = ' '

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • COL_SELECT = ' '

  • COL_SELECTMASK = ' '

  • NO_AUTH_CHECK = ' '

IMPORTING

filelength = w_filesize

TABLES

data_tab = t_pdf_tab

  • FIELDNAMES =

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

OTHERS = 10

.

IF sy-subrc <> 0.

MESSAGE i003(z00) WITH 'File not downloaded succesfully'.

ELSE.

MESSAGE i003(z00) WITH 'File Test.pdf downloaded succesfully '

'under D drive'.

ENDIF.

ENDFORM. " F1000_DOWNLOAD_FORM

0 Kudos

Hi Jayanthi,

The purpose is not to download but I want to display the output in PDF at runtime.

Example: Once you run the report you get an option to print or preview it. Once you hit on the preview the form should open in Adobe. I have seen this functionality in portal but the requirement is to display it in the SAP GUI.

If we pass the attribute wa_ctrlop-no_dialog = 'X' then we do not get the print preview screen. Is there any way to achieve this requirement or should I just continue downloading the form on to the local hard drive ?

Best Regards,

Sudhi