Skip to Content
0
Former Member
Feb 16, 2007 at 09:09 AM

smart form to pdf conversion

25 Views

i have created a smart form which is converting into pdf and downloading into pc but when i am opening the pdf file its saying the file is correpted, and the file is not opening. here is the code. i need it urgent.!!!!!!!!!!!!!!!!!!!!!

&----


*& Include Z_PDF_CONVERSIONF *

&----


&----


*& Form f_validate_input

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f_validate_input .

DATA: l_temp_ebeln(10) TYPE c .

*Checking if field is empty.

IF s_vbeln IS INITIAL.

MESSAGE i000(zcommon).

ENDIF.

*Checking whether purchase docuemnt no contains any character.

l_temp_ebeln = s_vbeln-low.

IF l_temp_ebeln+0(1) CA sy-abcde.

MESSAGE i001(zcommon).

ENDIF.

ENDFORM. " f_validate_input

&----


*& Form f_data_selection

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f_data_selection .

select vbeln from vbak into table i_vbak where vbeln = s_vbeln-low.

*This gets form name and function module name.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = c_formname

  • VARIANT = ' '

  • DIRECT_CALL = ' '

IMPORTING

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

*Setting print parameters.

v_control_parameters-no_dialog = 'x'. "(Is this necessary)

----


  • Setting of output options *

----


*Setting up language.

v_language = sy-langu.

TRANSLATE v_language TO UPPER CASE.

v_control_parameters-langu = v_language.

*Set control parameters to get the output format(OTF) from smart forms.

v_control_parameters-no_dialog = 'X'.

v_control_parameters-getotf = 'X'.

*Fetch device type from language.

CALL FUNCTION 'SSF_GET_DEVICE_TYPE'

EXPORTING

i_language = v_language

  • I_APPLICATION = 'SAPDEFAULT'

IMPORTING

e_devtype = v_devtype

EXCEPTIONS

no_language = 1

language_not_installed = 2

no_devtype_found = 3

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

----


  • Set Device type in output options *

----


*Fetches device type name.

v_ssfcompop-tdprinter = v_devtype. "Device type name.

CALL FUNCTION v_fun_name

EXPORTING

control_parameters = v_control_parameters

output_options = v_ssfcompop

IMPORTING

document_output_info = v_ssfcrespd

job_output_info = v_ssfcrescl

job_output_options = v_ssfcresop

TABLES

i_vbak = i_vbak

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.

----


  • Conversion of output format OTF into PDF *

----


*FM converts OTF format into pdf.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

  • ARCHIVE_INDEX = ' '

  • COPYNUMBER = 0

  • ASCII_BIDI_VIS2LOG = ' '

IMPORTING

bin_filesize = v_pdf_len

bin_file = v_pdf_xstring

TABLES

otf = i_itcoo

lines = i_tline

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.

----


  • Concateneting file name to variable *

----


CONCATENATE 'arun' '.pdf' INTO v_fname.

CREATE OBJECT v_guiobject.

CALL METHOD v_guiobject->file_save_dialog

EXPORTING

default_extension = 'PDF'

default_file_name = v_fname

file_filter = v_filter

CHANGING

filename = v_fname

path = v_path

fullpath = v_fullpath

user_action = v_uact.

IF v_uact = v_guiobject->action_cancel.

EXIT.

ENDIF.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = v_pdf_len

filename = v_fname

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 = i_tline

  • 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.

ENDFORM. " f_data_selection