06-19-2008 5:50 AM
Hi all,
I have created a smart form , and I can down load it to the local drive in PDF format.
But I want to display my smart form in PDF first , then if the user want to save , he should be able to do so. How can i do thtat.
Many thanks ,
Sandeep.
06-19-2008 5:56 AM
06-19-2008 5:58 AM
Hi Sandeep,
Just copy and paste the below code and change the FM name you will see the smartform is not donwloaded into the PDF format.
&*********** Reward Point if helpful******************&
*--------------------------------------------------------------------*
* Program Name : ZPPREP_SHOPFLOOR_VIEWER_ZOOM
* Author : Chidanand Chauhan[Sparta Consulting.]
* Date : 20th April 2006
* Description : PP3-01 Shop floor paper viewer.
* Mantis issue #1762.
*--------------------------------------------------------------------*
REPORT zpprep_shopfloor_viewer_zoom.
*--------------------------------------------------------------------*
* T A B L E S D E C L A R A T I O N
*--------------------------------------------------------------------*
*---Tables Used.
TABLES: afpo,
mara,
marc,
aufk,
afko,
itcoo,
nast, "Messages
*nast, "Messages
tnapr, "Programs & Forms
addr_key,
arc_params, "Archive parameters
toa_dara. "Archive parameters
*--------------------------------------------------------------------*
* 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
*--------------------------------------------------------------------*
*--Internal Tables Used.
*--------------------------------------------------------------------*
* D A T A D E C L A R A T I O N
*--------------------------------------------------------------------*
*--Global Variables Used.
DATA: ws_matnr LIKE afpo-matnr,
ws_werks LIKE aufk-werks,
ws_mtart LIKE mara-mtart,
ws_wrkst LIKE mara-wrkst,
ws_fname TYPE rs38l_fnam,
ws_ctrlp TYPE ssfctrlop,
ws_optns TYPE ssfcompop,
w_padest LIKE tsp03l-padest. "BMC01+
DATA: da_message_printed(1) TYPE c,
da_preview_processed(1) TYPE c,
repeat(1) TYPE c,
da_subrc LIKE sy-subrc.
DATA: w_otfdata TYPE ssfcrescl.
DATA: BEGIN OF it_itcoo OCCURS 0.
INCLUDE STRUCTURE itcoo.
DATA: END OF it_itcoo.
DATA: w_otf TYPE itcoo.
*--Data Declaration for Printing Layout
DATA: ls_itcpo TYPE itcpo.
DATA: lf_repid TYPE sy-repid.
DATA: lf_device TYPE tddevice.
DATA: cf_retcode TYPE sy-subrc.
DATA: ls_recipient TYPE swotobjid.
DATA: ls_sender TYPE swotobjid.
DATA: ls_control_param TYPE ssfctrlop.
DATA: ls_composer_param TYPE ssfcompop.
DATA: ls_addr_key LIKE addr_key.
DATA: w_screen(1) TYPE c.
DATA: xscreen(1) TYPE c.
DATA: da_mess LIKE vbfs OCCURS 0 WITH HEADER LINE.
*--------------------------------------------------------------------*
* C O N S T A N T S
*--------------------------------------------------------------------*
CONSTANTS: c_fas1(8) TYPE c VALUE 'PRINTFAS',
c_fas2(15) TYPE c VALUE 'PRINTFASDRAWING',
c_wip1(8) TYPE c VALUE 'PRINTWIP',
c_wip2(15) TYPE c VALUE 'PRINTWIPDRAWING'.
*--------------------------------------------------------------------*
* S E L E C T I O N - S C R E E N.
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-bl1.
* Production order
PARAMETERS: p_aufnr LIKE afpo-aufnr OBLIGATORY.
SELECTION-SCREEN END OF BLOCK bl1.
*--------------------------------------------------------------------*
START-OF-SELECTION.
*--------------------------------------------------------------------*
*--Begin of Commenting "Rapidigm04_01+
*--Get Partially processed orders
MOVE: sy-mandt TO nast-mandt,
'V1' TO nast-kappl,
p_aufnr TO nast-objky,
p_aufnr TO nast-parnr,
sy-langu TO nast-spras,
sy-datum TO nast-erdat,
'1' TO nast-nacha,
'3' TO nast-vsztp,
'X' TO nast-manue,
sy-uname TO nast-usnam,
'DFLT' TO nast-ldest,
sy-langu TO nast-tdspras,
'Shop Floor Papers' TO nast-tdcovtitle,
'1' TO nast-tdarmod,
'BUS2032' TO nast-objtype.
*--Printer settings
CALL FUNCTION 'WFMC_PREPARE_SMART_FORM'
EXPORTING
pi_nast = nast
pi_repid = sy-repid
IMPORTING
pe_returncode = cf_retcode
pe_itcpo = ls_itcpo
pe_device = lf_device
pe_recipient = ls_recipient
pe_sender = ls_sender.
MOVE-CORRESPONDING ls_itcpo TO ls_composer_param.
ls_control_param-device = 'PRINTER'.
ls_control_param-no_dialog = 'X'.
ls_control_param-preview = 'X'.
ls_control_param-getotf = ls_itcpo-tdgetotf.
ls_control_param-langu = sy-langu.
*--End of Commenting "Rapidigm04_01+
*--Start of Addition "Rapidigm04_01+
CLEAR: ws_werks.
SELECT SINGLE werks
INTO ws_werks
FROM aufk
WHERE aufnr = p_aufnr.
CLEAR: ws_matnr.
SELECT SINGLE plnbez
INTO ws_matnr
FROM afko
WHERE aufnr = p_aufnr.
CLEAR: marc.
SELECT SINGLE matgr
INTO marc-matgr
FROM marc
WHERE matnr = ws_matnr
AND werks = ws_werks.
*--End of Addition "Rapidigm04_01+
* CHECK NOT ws_matnr IS INITIAL. "Rapidigm01_01-
IF NOT ws_matnr IS INITIAL. "Rapidigm01_01+
*--Start of Addition "Rapidigm04_01+
SELECT SINGLE matgr
INTO marc-matgr
FROM marc
WHERE matnr = ws_matnr
AND werks = ws_werks.
*--Start of Addition BY Rapidigm01_01+
ELSE.
marc-matgr = c_wip1.
ENDIF.
*--End Of Addition BY Rapidigm01_01+
*--End of Addition "Rapidigm04_01+
*--------------------------------------------------------------------*
END-OF-SELECTION.
*--------------------------------------------------------------------*
PERFORM call_smartform.
*--------------------------------------------------------------------*
* F O R M R O U T I N E S
*--------------------------------------------------------------------*
*&-------------------------------------------------------------------*
*& Form call_smartform
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM call_smartform.
CLEAR: ws_ctrlp, ws_optns, ws_fname.
*--Start of Addition "Rapidigm04_01+
TRANSLATE marc-matgr TO UPPER CASE.
IF marc-matgr = c_fas1 OR
marc-matgr = c_fas2.
PERFORM call_paper_a.
ELSEIF marc-matgr = c_wip1 OR
marc-matgr = c_wip2.
PERFORM call_paper_b.
ENDIF.
*--End of Addition "Rapidigm04_01+
ENDFORM. "call_smartform
*&-------------------------------------------------------------------*
*& Form call_paper_a
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM call_paper_a.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
*>>BC SPARTA03 DATE: 19/05/2008
* formname = 'ZPPSF_SHOP_FLOOR_PAPER_A' "Rapidigm03_01-
formname = 'ZPPSF_SHOP_FLOOR_PAPER_C' "Rapidigm03_01-
*<<EC SPARTA03 DATE: 19/05/2008
* formname = 'ZPPSF_SHOP_FLOOR_PAPER_A_2893' "Rapidigm03_01+
IMPORTING
fm_name = ws_fname
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
CHECK NOT ws_fname IS INITIAL.
CLEAR w_otfdata.
ls_control_param-getotf = 'X'.
CALL FUNCTION ws_fname
EXPORTING
archive_index = toa_dara
archive_parameters = arc_params
control_parameters = ls_control_param
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
user_settings = ' '
is_nast = nast
aufnr = p_aufnr
flag_orig = 'X'
IMPORTING
job_output_info = w_otfdata
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
LOOP AT w_otfdata-otfdata INTO w_otf.
APPEND w_otf TO it_itcoo.
ENDLOOP.
CALL FUNCTION 'HR_IT_DISPLAY_WITH_PDF'
TABLES
otf_table = it_itcoo.
ENDFORM. "call_paper_a
*&-------------------------------------------------------------------*
*& Form call_paper_b
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM call_paper_b.
DATA: ws_doknr TYPE draw-doknr,
ws_dokvr TYPE draw-dokvr.
CLEAR: ws_doknr, ws_dokvr.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZPPSF_SHOP_FLOOR_PAPER_B'
IMPORTING
fm_name = ws_fname
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
CHECK NOT ws_fname IS INITIAL.
CLEAR w_otfdata.
ls_control_param-getotf = 'X'.
CALL FUNCTION ws_fname
EXPORTING
archive_index = toa_dara
archive_parameters = arc_params
control_parameters = ls_control_param
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
user_settings = ' '
is_nast = nast
aufnr = p_aufnr
doknr = ws_doknr
dokvr = ws_dokvr
flag_orig = 'X'
IMPORTING
job_output_info = w_otfdata
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
LOOP AT w_otfdata-otfdata INTO w_otf.
APPEND w_otf TO it_itcoo.
ENDLOOP.
CALL FUNCTION 'HR_IT_DISPLAY_WITH_PDF'
TABLES
otf_table = it_itcoo.
ENDFORM. "call_paper_b
06-19-2008 6:00 AM
Hi Sandeep,
Please check this link
Download SMARTFORM output to PDF file.
Smartform to PDF
https://wiki.sdn.sap.com/wiki/display/Snippets/ConvertSmartformtoPDFformat
http://help.sap.com/saphelp_nw04/helpdata/en/27/67443cc0063415e10000000a11405a/frameset.htm
Best regards,
raam
06-19-2008 6:02 AM
Hi,
A simple way of converting smartforms to PDF can be find at the following link.
http://help.sap.com/saphelp_nw2004s/helpdata/en/16/a369b1800e4bdda978ee0fe3b7bd2c/content.htm
http://www.saptechnical.com/Tutorials/Smartforms/OTF2PDF.htm
Regards,
M.K
06-19-2008 6:15 AM
hi friend,
pls go through the code
rewards are expecting .
vivek
&----
*& Report Y_SD_PRE_SHIPMENT
*&
&----
*&
*&
&----
REPORT y_sd_pre_shipment.
**************DATA DECLARATION****************************************
DATA : BEGIN OF i_vbrk OCCURS 0,
vbeln TYPE vbrp-vbeln,
END OF i_vbrk.
DATA: prog TYPE sy-repid,
dynnr TYPE sy-dynnr,
FNAM TYPE RS38L_FNAM,
v_vbeln type ZSDTANNXINV-vbeln,
idx type i,
cnt type i.
DATA: I_FINAL TYPE TABLE OF YPSHIP,
W_FINAL TYPE YPSHIP.
DATA: I_HEAD TYPE TABLE OF YPSHIP1,
W_HEAD TYPE YPSHIP1.
************************************************************************
DATA: it_otf TYPE STANDARD TABLE OF itcoo,
it_docs TYPE STANDARD TABLE OF docs,
it_lines TYPE STANDARD TABLE OF tline,
st_job_output_info TYPE ssfcrescl,
st_document_output_info TYPE ssfcrespd,
st_job_output_options TYPE ssfcresop,
st_output_options TYPE ssfcompop,
st_control_parameters TYPE ssfctrlop,
v_len_in TYPE so_obj_len,
v_language TYPE sflangu VALUE 'E',
v_e_devtype TYPE rspoptype,
v_bin_filesize TYPE i,
v_name TYPE string,
v_path TYPE string,
v_fullpath TYPE string,
v_filter TYPE string,
v_uact TYPE i,
v_guiobj TYPE REF TO cl_gui_frontend_services,
v_filename TYPE string.
****************************************************************
******USER INTERACTION OPTION FOR THE INVOICE NO
****************************************************************
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE r.
PARAMETERS: invoice LIKE ZSDTANNXINV-vbeln obligatory .
SELECTION-SCREEN : END OF BLOCK b1.
*********************************************************************
*********************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR invoice.
REFRESH i_vbrk.
SELECT vbeln FROM vbrk INTO TABLE i_vbrk.
IF sy-subrc IS INITIAL.
prog = sy-repid.
dynnr = sy-dynnr.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
DDIC_STRUCTURE = ' '
retfield = 'VBELN'
dynpprog = prog
dynpnr = dynnr
dynprofield = 'INVOICE'
value_org = 'S'
TABLES
value_tab = i_vbrk.
FIELD_TAB =
RETURN_TAB =
DYNPFLD_MAPPING =
exceptions
parameter_error = 1
no_values_found = 2
others = 3
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
*************************************************************************
at selection-screen on invoice.
if invoice is not initial.
clear v_vbeln.
select single vbeln from ZSDTANNXINV into v_vbeln where vbeln = invoice.
if sy-subrc is not initial.
message 'Enter Valid Document No' type 'E'.
endif.
endif.
*************************************************************************
START-OF-SELECTION.
perform get_data.
perform process_data.
&----
*& Form get_data
&----
text
----
--> p1 text
<-- p2 text
----
form get_data .
IF INVOICE IS NOT INITIAL.
SELECT VBELN
VTEXT
NETWT
GROSSWT
vsslname
kindofpack
INCO1
INCO2
REMDATE
DESTINATION
SHPNGLIN1
CNTRNO
TRAILERNO1
ETDDATE
ETADATE
baanr
FROM ZSDTANNXINV
INTO TABLE I_HEAD
WHERE VBELN = INVOICE.
ENDIF.
IF I_HEAD[] IS NOT INITIAL.
select vbeln
POSNR
MATNR
MAKTX
meins
RATE
VALUE
WAERK
PRPOSNR
from zsafii
into corresponding fields of table i_final
for all entries in i_head
where vbeln = i_head-vbeln.
ENDIF.
describe table i_final lines cnt.
idx = 1.
loop at i_final into w_final.
if idx le cnt.
read table i_head into w_head with key vbeln = w_final-vbeln.
if sy-subrc is initial.
move-corresponding w_head to w_final.
modify i_final from w_final index idx.
idx = idx + 1.
endif.
endif.
endloop.
endform. " get_data
&----
*& Form process_data
&----
text
----
--> p1 text
<-- p2 text
----
form process_data .
***********************************************
CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
EXPORTING
i_language = v_language
i_application = 'SAPDEFAULT'
IMPORTING
e_devtype = v_e_devtype.
st_output_options-tdprinter = v_e_devtype.
*st_output_options-tdprinter = 'locl'.
st_control_parameters-no_dialog = 'X'.
st_control_parameters-getotf = 'X'.
***************************************************
sort i_final by vbeln.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'Y_SSF_PRESHIPMENT'
VARIANT = ' '
DIRECT_CALL = ' '
IMPORTING
FM_NAME = FNAM
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.
if fnam is not initial.
CALL FUNCTION FNAM
EXPORTING
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
CONTROL_PARAMETERS = st_control_parameters
MAIL_APPL_OBJ =
MAIL_RECIPIENT =
MAIL_SENDER =
OUTPUT_OPTIONS = st_output_options
USER_SETTINGS = 'X'
IMPORTING
DOCUMENT_OUTPUT_INFO = st_document_output_info
JOB_OUTPUT_INFO = st_job_output_info
JOB_OUTPUT_OPTIONS = st_job_output_options
TABLES
itab = I_FINAL
i_head = I_HEAD
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.
******************************************************************************
.........................CONVERT TO OTF TO PDF.......................
CALL FUNCTION 'CONVERT_OTF_2_PDF'
IMPORTING
bin_filesize = v_bin_filesize
TABLES
otf = st_job_output_info-otfdata
doctab_archive = it_docs
lines = it_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.
........................GET THE FILE NAME TO STORE....................
CONCATENATE 'smrt' '.pdf' INTO v_name.
CREATE OBJECT v_guiobj.
CALL METHOD v_guiobj->file_save_dialog
EXPORTING
default_extension = 'pdf'
default_file_name = v_name
file_filter = v_filter
CHANGING
filename = v_name
path = v_path
fullpath = v_fullpath
user_action = v_uact.
IF v_uact = v_guiobj->action_cancel.
EXIT.
ENDIF.
..................................DOWNLOAD AS FILE....................
MOVE v_fullpath TO v_filename.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = v_bin_filesize
filename = v_filename
filetype = 'BIN'
TABLES
data_tab = it_lines
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.
ENDIF.
********************************************************************8
endform. " process_data