You are on page 1of 3

Fichier : C:\SF_vers_PDF.

txt 11/12/2007, 10:25:09

je vous transmets seulement la routine qui génére le PDF ; elle est


inspiré d'un bout de code récupéré sur le forum SAP.

Avant donc l'appel de la routine qui suit, les déclarations suivantes


ont été réalisées :

*----------------------------------------------------------------------*
*_formulaire
DATA: w_nomform TYPE tdsfname.
DATA: w_fm_name TYPE rs38l_fnam.

*........

w_nomform = 'Z_Mon_SF'.

*_identification du formulaire
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = w_nomform
IMPORTING
fm_name = w_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.

PERFORM pdf_out USING lw_control


lw_output.

*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM pdf_out USING plw_control TYPE ssfctrlop
plw_output TYPE ssfcompop.

DATA: lt_otfdata TYPE ssfcrescl.


"SF : valeur retournées à la fin de l'édition
DATA: lt_pdf_tab TYPE TABLE OF tline, "SAPscript: Text Lines
lt_otf TYPE TABLE OF itcoo. "OTF Structure
DATA: lw_title TYPE string.
*_Variables à transmettre à GUI_DOWNLOAD
DATA: lw_filesize TYPE i, "#EC NEEDED
lw_bin_filesize TYPE i.

lw_title = text-t01.
plw_control-getotf = 'X'.
plw_control-no_dialog = 'X'.

plw_output-tdnoprev = 'X'.

*_charger les data à/p du MF du SForms


CALL FUNCTION w_fm_name
EXPORTING
control_parameters = plw_control
output_options = plw_output
user_settings = 'X'
IMPORTING
job_output_info = lt_otfdata
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.

Page : 1
Fichier : C:\SF_vers_PDF.txt 11/12/2007, 10:25:09

IF sy-subrc <> 0.
EXIT.
ENDIF.

lt_otf[] = lt_otfdata-otfdata[].

CALL FUNCTION 'CONVERT_OTF'


EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = lw_bin_filesize
TABLES
otf = lt_otf
lines = lt_pdf_tab
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
IF sy-subrc <> 0.
EXIT.
ENDIF.

*_l'user choisit le path pour éditer


* exemple :
* w_filename = 'MonFic.pdf'
* w_filepath = 'c:\tmp\'
* w_fullpath = 'c:\tmp\MonFic.pdf'

CALL METHOD cl_gui_frontend_services=>file_save_dialog


EXPORTING
window_title = lw_title
default_extension = c_pdf
default_file_name = w_filename
file_filter = 'PDF'
initial_directory = w_filepath
CHANGING
filename = w_filename
path = w_filepath
fullpath = w_fullpath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.

IF sy-subrc <> 0 OR w_fullpath IS INITIAL.


EXIT.
ENDIF.

*_écrire le pdf dans le rép. choisi


CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = lw_bin_filesize
filename = w_fullpath
filetype = 'BIN'
IMPORTING
filelength = lw_filesize
TABLES
data_tab = lt_pdf_tab
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

Page : 2
Fichier : C:\SF_vers_PDF.txt 11/12/2007, 10:25:09

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.
EXIT. "File not downloaded
ENDIF.
ENDFORM. " pdf_out

Page : 3

You might also like