03/03/2010

Download SMARTFORM em PDF

Necessidade: Ao rodar a aplicação a saída do SMARTFORM deve ser gravado diretamente em um caminho informado pelo usuário.

Solução: Vamos Utilizar as funções, SSF_GET_DEVICE_TYPE, SSF_FUNCTION_MODULE_NAME, CONVERT_OTF, GUI_DOWNLOAD para alcançarmos nosso objetivo.

Veja abaixo:


*-----------------------------------------------------------------------
* | REPORT DESCRIPTION : DOWNLOAD SMARTFORM OUTPUT TO HARD DISK DRIVE
*-----------------------------------------------------------------------

REPORT ZRR_SAMPLE NO STANDARD PAGE HEADING.

*-----------------------------------------------------------------------
* | V.A.R.I.A.B.L.E.S D.E.C.L.A.R.A.T.I.O.N.S
*-----------------------------------------------------------------------

DATA : v_pdf_len TYPE i,
v_func TYPE rs38l_fnam,
v_form TYPE tdsfname VALUE 'Z_TESTE_SMARTF'.

*-----------------------------------------------------------------------
* | I.N.T.E.R.N.A.L T.A.B.L.E.S D.E.C.L.A.R.A.T.I.O.N.S
*-----------------------------------------------------------------------

DATA: it_pdf_lines TYPE STANDARD TABLE OF tline,
it_sflight TYPE STANDARD TABLE OF sflight.

*-----------------------------------------------------------------------
* | V.A.R.I.A.B.L.E.S F.O.R S.M.A.R.T.F.O.R.M D.E.C.L.A.R.A.T.I.O.N.S
*-----------------------------------------------------------------------

DATA: output_options TYPE ssfcompop,
control_parameters TYPE ssfctrlop,
output_data TYPE ssfcrescl,
devtype TYPE rspoptype.

*-----------------------------------------------------------------------
* | S.T.A.R.T O.F S.E.L.E.C.T.I.O.N
*-----------------------------------------------------------------------

START-OF-SELECTION.

"$ Region Get Device Type For PDF

CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
EXPORTING
i_language = sy-langu
IMPORTING
e_devtype = devtype
EXCEPTIONS
no_language = 1
language_not_installed = 2
no_devtype_found = 3
system_error = 4
OTHERS = 5.

"$ Endregion Get Device Type For PDF

"$ Region Define Initial Values For Control_Parameters

control_parameters-langu = sy-langu.
control_parameters-no_dialog = 'X'.
control_parameters-getotf = 'X'.
output_options-tdprinter = devtype.

"$ Endregion Define Initial Values For Control_Parameters

"$ Region Bind Interanl Table it_sflight

SELECT *
FROM sflight
INTO TABLE it_sflight.

"$ Endregion Bind Interanl Table it_sflight

"$ Region Get SmartForm Function Code

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = v_form
IMPORTING
fm_name = v_func.

"$ Endregion Get SmartForm Function Code

"$ Region Call SmartForm Function Code

CALL FUNCTION v_func
EXPORTING
user_settings = space
control_parameters = control_parameters
output_options = output_options
IMPORTING
job_output_info = output_data
TABLES
it_sflight = it_sflight
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.

"$ Endregion Call SmartForm Function Code

"$ Region Convert SmartForm OTF OutPut In PDF

CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = v_pdf_len
TABLES
otf = output_data-otfdata
lines = it_pdf_lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.

"$ Endregion Convert SmartForm OTF OutPut In PDF

"$ Region Download PDF File To Disk

CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = v_pdf_len
filename = 'c:/RR_SAMPLE_PDF002.pdf'
filetype = 'BIN'
TABLES
data_tab = it_pdf_lines.

"$ Endregion Download PDF File To Disk

Um comentário: