CONVERTING SMARTFORM INTO PDF AND PRINTING DIRECTLY
Hai guys,
I got a problem.
First the Smartform I created doesnt show all TABLE LINES(the rows coloumns)...
so I have converted the SMART FORM to ADOBE FORM PROGRAMITICALY ...
now in order to PRINT ..
one has to first SAVE the FORM(adobe form) onto desktop(or whereever) and give it to PRINT...
unfortunately my CLIENT doeasnt like the EXTRA STEP..
so i best i can SAVE the file to a hardcoded location and
OPEN it ..
But then CAN I
a)PRINT DIRECTLY without SAVING??
b)ISSUE PRINT PROGRAMITICALY
c)I learnt that a SMARTFORM can be GENERATED INTO PDF only at RUNNTIME(from SMARTFORMS>UTILITIES etc)..i briefly tried that..can I use that to GET THE PDF to PRINT when one gives PRINT from SPOOL REQUEST(sp01)
hoping to give some quick points
Hi,
http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
or
*& Report ZSPOOLTOPDF *
*& Converts spool request into PDF document and emails it to *
*& recipicant. *
*& Execution *
*& This program must be run as a background job in-order for the write *
*& commands to create a Spool request rather than be displayed on *
*& screen *
REPORT zspooltopdf.
PARAMETER: p_email1 LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_sender LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_delspl AS CHECKBOX.
*DATA DECLARATION
DATA: gd_recsize TYPE i.
Spool IDs
TYPES: BEGIN OF t_tbtcp.
INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.
DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
wa_tbtcp TYPE t_tbtcp.
Job Runtime Parameters
DATA: gd_eventid LIKE tbtcm-eventid,
gd_eventparm LIKE tbtcm-eventparm,
gd_external_program_active LIKE tbtcm-xpgactive,
gd_jobcount LIKE tbtcm-jobcount,
gd_jobname LIKE tbtcm-jobname,
gd_stepcount LIKE tbtcm-stepcount,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
DATA: w_recsize TYPE i.
DATA: gd_subject LIKE sodocchgi1-obj_descr,
it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
gd_sender_type LIKE soextreci1-adr_typ,
gd_attachment_desc TYPE so_obj_nam,
gd_attachment_name TYPE so_obj_des.
Spool to PDF conversions
DATA: gd_spool_nr LIKE tsp01-rqident,
gd_destination LIKE rlgrap-filename,
gd_bytecount LIKE tst01-dsize,
gd_buffer TYPE string.
Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0.
INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.
CONSTANTS: c_dev LIKE sy-sysid VALUE 'DEV',
c_no(1) TYPE c VALUE ' ',
c_device(4) TYPE c VALUE 'LOCL'.
*START-OF-SELECTION.
START-OF-SELECTION.
Write statement to represent report output. Spool request is created
if write statement is executed in background. This could also be an
ALV grid which would be converted to PDF without any extra effort
WRITE 'Hello World'.
new-page.
commit work.
new-page print off.
IF sy-batch EQ 'X'.
PERFORM get_job_details.
PERFORM obtain_spool_id.
Alternative way could be to submit another program and store spool
id into memory, will be stored in sy-spono.
*submit ZSPOOLTOPDF2
to sap-spool
spool parameters %_print
archive parameters %_print
without spool dynpro
and return.
Get spool id from program called above
IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
PERFORM convert_spool_to_pdf.
PERFORM process_email.
if p_delspl EQ 'X'.
PERFORM delete_spool.
endif.
IF sy-sysid = c_dev.
wait up to 5 seconds.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ELSE.
SKIP.
WRITE:/ 'Program must be executed in background in-order for spool',
'request to be created.'.
ENDIF.
FORM obtain_spool_id *
FORM obtain_spool_id.
CHECK NOT ( gd_jobname IS INITIAL ).
CHECK NOT ( gd_jobcount IS INITIAL ).
SELECT * FROM tbtcp
INTO TABLE it_tbtcp
WHERE jobname = gd_jobname
AND jobcount = gd_jobcount
AND stepcount = gd_stepcount
AND listident <> '0000000000'
ORDER BY jobname
jobcount
stepcount.
READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
IF sy-subrc = 0.
message s004(zdd) with gd_spool_nr.
gd_spool_nr = wa_tbtcp-listident.
MESSAGE s004(zdd) WITH gd_spool_nr.
ELSE.
MESSAGE s005(zdd).
ENDIF.
ENDFORM.
FORM get_job_details *
FORM get_job_details.
Get current job details
CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
IMPORTING
eventid = gd_eventid
eventparm = gd_eventparm
external_program_active = gd_external_program_active
jobcount = gd_jobcount
jobname = gd_jobname
stepcount = gd_stepcount
EXCEPTIONS
no_runtime_info = 1
OTHERS = 2.
ENDFORM.
FORM convert_spool_to_pdf *
FORM convert_spool_to_pdf.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gd_spool_nr
no_dialog = c_no
dst_device = c_device
IMPORTING
pdf_bytecount = gd_bytecount
TABLES
pdf = it_pdf_output
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
CHECK sy-subrc = 0.
Transfer the 132-long strings to 255-long strings
LOOP AT it_pdf_output.
TRANSLATE it_pdf_output USING ' ~'.
CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
ENDLOOP.
TRANSLATE gd_buffer USING '~ '.
DO.
it_mess_att = gd_buffer.
APPEND it_mess_att.
SHIFT gd_buffer LEFT BY 255 PLACES.
IF gd_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
ENDFORM.
FORM process_email *
FORM process_email.
DESCRIBE TABLE it_mess_att LINES gd_recsize.
CHECK gd_recsize > 0.
PERFORM send_email USING p_email1.
perform send_email using p_email2.
ENDFORM.
FORM send_email *
--> p_email *
FORM send_email USING p_email.
CHECK NOT ( p_email IS INITIAL ).
REFRESH it_mess_bod.
Default subject matter
gd_subject = 'Subject'.
gd_attachment_desc = 'Attachname'.
CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
it_mess_bod = 'Message Body text, line 1'.
APPEND it_mess_bod.
it_mess_bod = 'Message Body text, line 2...'.
APPEND it_mess_bod.
If no sender specified - default blank
IF p_sender EQ space.
gd_sender_type = space.
ELSE.
gd_sender_type = 'INT'.
ENDIF.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_mess_bod
it_mess_att
using p_email
'Example .xls documnet attachment'
'PDF'
gd_attachment_name
gd_attachment_desc
p_sender
gd_sender_type
changing gd_error
gd_reciever.
ENDFORM.
FORM delete_spool *
FORM delete_spool.
DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
ld_spool_nr = gd_spool_nr.
CHECK p_delspl <> c_no.
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
spoolid = ld_spool_nr.
ENDFORM.
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
Send email
FORM send_file_as_email_attachment tables it_message
it_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
data: t_packing_list like sopcklsti1 occurs 0 with header line,
t_contents like solisti1 occurs 0 with header line,
t_receivers like somlreci1 occurs 0 with header line,
t_attachment like solisti1 occurs 0 with header line,
t_object_header like solisti1 occurs 0 with header line,
w_cnt type i,
w_sent_all(1) type c,
w_doc_data like sodocchgi1.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = it_attach[].
Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
Regards,
Kumar
Similar Messages
-
How to convert smartform into pdf and send through mail
Hi Guru,
I want to send smartform to mail after converting into pdf format.
if anyof u gives solution its greate.
Thanks & Regards,
Lakshmi..Hi,
i can help you till
downloading the smartform as pdf format
check this
DATA: GIT_BSIK LIKE BSIK OCCURS 0 WITH HEADER LINE.
Variable declarations
DATA:
W_FORM_NAME TYPE TDSFNAME VALUE 'ZFII_EDD001',
W_FMODULE TYPE RS38L_FNAM,
W_CPARAM TYPE SSFCTRLOP,
W_OUTOPTIONS TYPE SSFCOMPOP,
W_BIN_FILESIZE TYPE I, " Binary File Size
W_FILE_NAME TYPE STRING,
W_FILE_PATH TYPE STRING,
W_FULL_PATH TYPE STRING.
Internal tables declaration
Internal table to hold the OTF data
DATA:
T_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE,
Internal table to hold OTF data recd from the SMARTFORM
T_OTF_FROM_FM TYPE SSFCRESCL,
Internal table to hold the data from the FM CONVERT_OTF
T_PDF_TAB LIKE TLINE OCCURS 0 WITH HEADER LINE.
This function module call is used to retrieve the name of the Function
module generated when the SMARTFORM is activated
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = W_FORM_NAME
VARIANT = ' '
DIRECT_CALL = ' '
IMPORTING
FM_NAME = W_FMODULE
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.
Calling the SMARTFORM using the function module retrieved above
GET_OTF parameter in the CONTROL_PARAMETERS is set to get the OTF
format of the output
W_CPARAM-NO_DIALOG = 'X'.
W_CPARAM-PREVIEW = SPACE. " Suppressing the dialog box
" for print preview
W_CPARAM-GETOTF = 'X'.
Printer name to be used is provided in the export parameter
OUTPUT_OPTIONS
W_OUTOPTIONS-TDDEST = 'ZPC_'.
CALL FUNCTION W_FMODULE
EXPORTING
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
CONTROL_PARAMETERS = W_CPARAM
MAIL_APPL_OBJ =
MAIL_RECIPIENT =
MAIL_SENDER =
OUTPUT_OPTIONS = W_OUTOPTIONS
USER_SETTINGS = 'X'
IMPORTING
DOCUMENT_OUTPUT_INFO =
JOB_OUTPUT_INFO = T_OTF_FROM_FM
JOB_OUTPUT_OPTIONS =
TABLES
ITAB = GIT_BSIK
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_OTF_FROM_FM-OTFDATA[].
Function Module CONVERT_OTF is used to convert the OTF format to PDF
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 132
ARCHIVE_INDEX = ' '
COPYNUMBER = 0
ASCII_BIDI_VIS2LOG = ' '
PDF_DELETE_OTFTAB = ' '
IMPORTING
BIN_FILESIZE = W_BIN_FILESIZE
BIN_FILE =
TABLES
OTF = T_OTF
LINES = T_PDF_TAB
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.
*To display File SAVE dialog window
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
WINDOW_TITLE =
DEFAULT_EXTENSION =
DEFAULT_FILE_NAME =
FILE_FILTER =
INITIAL_DIRECTORY =
WITH_ENCODING =
PROMPT_ON_OVERWRITE = 'X'
CHANGING
filename = w_FILE_NAME
path = w_FILE_PATH
fullpath = w_FULL_PATH
USER_ACTION =
FILE_ENCODING =
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 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.
Use the FM GUI_DOWNLOAD to download the generated PDF file onto the
presentation server
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE = W_bin_filesize
filename = w_FULL_PATH
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'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
IMPORTING
FILELENGTH =
tables
data_tab = T_pdf_tab
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.
thanks & regards,
Venkatesh -
Convert SmartForm into PDF(PDF should be password protected)
Hi Friends,
This is my requirement.
Need to convert SmartForm into PDF and this PDF should be send as an email with attachment and PDF should be password protected.
Can anyone plz help me???Dear Jena,
This is my code.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZBIN_SMARTFORM'
IMPORTING
fm_name = v_fm.
*& ASSIGNING VALUES TO FORM CONTROL STRUCTURE AND FORM COMPOSER
gs_ctrlop-getotf = 'X'.
gs_ctrlop-device = 'PRINTER'.
gs_ctrlop-preview = ' '.
gs_ctrlop-no_dialog = 'X'.
gs_outopt-tddest = 'LOCL'.
* GETTING THE OTF DATA
CALL FUNCTION v_fm
EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
control_parameters = gs_ctrlop
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
output_options = gs_outopt
user_settings = ' '
wa_lfa1 = wa_lfa1
wa_t001 = wa_t001
wa_ekko = wa_ekko
wa_adrc = wa_adrc
IMPORTING
* DOCUMENT_OUTPUT_INFO =
job_output_info = gs_otfdata
* JOB_OUTPUT_OPTIONS =
TABLES
it_ekpo = it_ekpo
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.
* ASSIGNING THE OTFDATA TO OTF STRUCTURE TABLE
CLEAR gt_otf.
gt_otf[] = gs_otfdata-otfdata[].
* CONVERTING THE OTFDATA
CLEAR gt_lines.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
* ARCHIVE_INDEX = ' '
* COPYNUMBER = 0
* ASCII_BIDI_VIS2LOG = ' '
* PDF_DELETE_OTFTAB = ' '
* PDF_USERNAME = ' '
* PDF_PREVIEW = ' '
* USE_CASCADING = ' '
IMPORTING
bin_filesize = bin_file
* bin_file = bin_file
TABLES
otf = gt_otf
lines = gt_lines
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.
DATA l_file TYPE string .
CONCATENATE 'D:\usr\sap\CID\DVEBMGS00\work' '.PDF' INTO l_file.
OPEN DATASET l_file FOR OUTPUT IN BINARY MODE .
IF sy-subrc = 0 .
LOOP AT gt_lines INTO gs_lines .
TRANSFER gs_lines TO l_file .
ENDLOOP.
CLOSE DATASET l_file .
ELSE.
WRITE : / 'operating system could not open file' .
ENDIF.
* ASSIGNING THE DESCRIPTION OF THE OBJECT SENT IN MAIL
CLEAR gs_docdata.
gs_docdata-obj_name = gc_tst.
gs_docdata-obj_descr = gc_testing.
gs_docdata-obj_langu = sy-langu.
* ASSIGNING THE EMAIL-ID TO STRUCTURE OF API RECIPIENT LIST TABLE
CLEAR : gt_reclist,gs_reclist.
***IF INTERNAL MAIL-ID
* gs_reclist-receiver = sy-uname.
* gs_reclist-rec_type = 'B'.
***IF EXTERNAL MAIL-ID
gs_reclist-receiver = '[email protected]'.
gs_reclist-rec_type = 'U'.
APPEND gs_reclist TO gt_reclist.
* PASSING THE SAP SCRIPT LINES TO SAP OFFICE
CLEAR : gs_objbin,gs_lines.
LOOP AT gt_lines INTO gs_lines.
gv_pos = 255 - gv_len.
IF gv_pos > 134.
gv_pos = 134.
ENDIF.
gs_objbin+gv_len = gs_lines(gv_pos).
gv_len = gv_len + gv_pos.
IF gv_len = 255.
APPEND gs_objbin TO gt_objbin.
CLEAR : gs_objbin,gv_len.
IF gv_pos < 134.
gs_objbin = gs_lines+gv_pos.
gv_len = 134 - gv_pos.
ENDIF.
ENDIF.
ENDLOOP.
IF gv_len > 0.
APPEND gs_objbin TO gt_objbin.
ENDIF.
* FILLING THE DETAILS IN SAP OFFICE
DESCRIBE TABLE gt_objbin LINES gv_tab_lines.
CLEAR gs_objbin.
READ TABLE gt_objbin INTO gs_objbin INDEX gv_tab_lines.
IF sy-subrc = 0.
gs_objpack-doc_size = ( gv_tab_lines - 1 ) * 255 + strlen( gs_objbin ).
gs_objpack-transf_bin = 'X'.
gs_objpack-head_start = 1.
gs_objpack-head_num = 0.
gs_objpack-body_start = 1.
gs_objpack-body_num = gv_tab_lines.
gs_objpack-doc_type = 'PDF'.
gs_objpack-obj_name = 'ATTACHMENT'.
gs_objpack-obj_descr = 'TEST'.
APPEND gs_objpack TO gt_objpack.
ENDIF.
DATA: BEGIN OF command_list OCCURS 0.
INCLUDE STRUCTURE sxpgcolist.
DATA: END OF command_list .
DATA: BEGIN OF exec_protocol OCCURS 0.
INCLUDE STRUCTURE btcxpm.
DATA: END OF exec_protocol.
DATA: status LIKE btcxp3-exitstat,
commandname LIKE sxpgcolist-name VALUE 'ZB_TEST',
sel_no LIKE sy-tabix.
* GET LIST OF EXTERNAL COMMANDS
CALL FUNCTION 'SXPG_COMMAND_LIST_GET'
EXPORTING
commandname = commandname
operatingsystem = sy-opsys
TABLES
command_list = command_list
EXCEPTIONS
OTHERS = 1.
CALL FUNCTION 'SXPG_COMMAND_CHECK'
EXPORTING
commandname = command_list-name
operatingsystem = sy-opsys
EXCEPTIONS
no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
x_error = 6
too_many_parameters = 7
parameter_expected = 8
illegal_command = 9
communication_failure = 10
system_failure = 11
OTHERS = 12.
CLEAR command_list.
REFRESH command_list.
DATA: v_dir_input TYPE sxpgcolist-parameters.
DATA: v_dir_input1 TYPE sxpgcolist-parameters.
command_list-name = 'ZB_TEST'.
command_list-opsystem = 'Windows NT'.
DATA : doc TYPE string.
DATA : pass TYPE string ,
name(40).
doc = 'invoice'.
pass = '123456'.
CONCATENATE 'cnd/c d:\pdf\encryptpdf.exe' doc'.PDF' INTO name.
CONCATENATE 'cmd /c d:\pdf\encryptpdf.exe' '-i' name '-o ' name '-u' pass INTO v_dir_input SEPARATED BY space .
READ TABLE command_list INDEX sel_no.
CONCATENATE command_list-opcommand v_dir_input INTO command_list-opcommand SEPARATED BY space.
* CHECK AUTHORIZATION
command_list-addpar = 'X'.
APPEND command_list.
CONSTANTS: c_extcom TYPE sxpgcolist-name VALUE 'ZB_TEST',
c_oper TYPE syopsys VALUE 'Windows NT'.
DATA: t_result TYPE STANDARD TABLE OF btcxpm.
v_dir_input = command_list-opcommand.
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
commandname = c_extcom
additional_parameters = v_dir_input
operatingsystem = c_oper
TABLES
exec_protocol = t_result
EXCEPTIONS
no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
wrong_asynchronous_parameters = 12
cant_enq_tbtco_entry = 13
jobcount_generation_error = 14
OTHERS = 15.
OPEN DATASET l_file FOR INPUT IN BINARY MODE.
IF sy-subrc = 0.
READ DATASET l_file INTO itab_attach.
CLOSE DATASET l_file.
ENDIF.
CALL METHOD cl_bcs_convert=>xstring_to_solix
EXPORTING
iv_xstring = itab_attach
RECEIVING
et_solix = t_attachment.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gs_docdata
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
TABLES
packing_list = gt_objpack
* OBJECT_HEADER =
CONTENTS_BIN = gt_objbin
* CONTENTS_TXT =
CONTENTS_HEX = t_attachment
* OBJECT_PARA =
* OBJECT_PARB =
receivers = gt_reclist
* EXCEPTIONS
* TOO_MANY_RECEIVERS = 1
* DOCUMENT_NOT_SENT = 2
* DOCUMENT_TYPE_NOT_EXIST = 3
* OPERATION_NO_AUTHORIZATION = 4
* PARAMETER_ERROR = 5
* X_ERROR = 6
* ENQUEUE_ERROR = 7
* OTHERS = 8
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
WRITE 'SENT SUCCESSFULLY'.
ENDIF.
SUBMIT rsconn01 WITH mode EQ 'INT' AND RETURN.
The mail is sent to inbox successfully,but when am opening the attachment am getting the below error as,
---> There was an error while opening this file.The file is damaged and couldnt be repaired. -
Smartform into PDF and store in folder of application server
Hi Gurus,
I have to solve this issue please help meu2026
1.Convert Smartform into PDF and store in folder of application server
2.print the PDF stored in folder(Application Server) automatically
Please give suggestion for the above..
Moderator message: "spec dumping", please work yourself first on your requirement.
Edited by: Thomas Zloch on Oct 7, 2011 10:39 AMhi uma,
http://www.kodyaz.com/articles/sap-smartforms-download-as-smartform-pdf-using-ws_download-and-cl_gui_frontend_services.aspx
check this out...
thanks,
ram -
Convert a web report into pdf and print (in BW 3.5)
Hello gurus,
i have few web reports ( created using WAD). i am looking for a possibility to convert a web report (viewed in a browser by a user) into pdf and print them and this should be done by pressing a button.
Is it possible in BW 3.5 version?.
could anyone please help me?
Any how to docs. would be really helpful.
thanks and regards
kumarHere it is
<HTML>
<!-- BW data source object tags -->
<object>
<param name="OWNER" value="SAP_BW"/>
<param name="CMD" value="SET_DATA_PROVIDER"/>
<param name="NAME" value="DATAPROVIDER_1"/>
<param name="DATA_PROVIDER_ID" value=""/>
DATA_PROVIDER: DATAPROVIDER_1
</object>
<object>
<param name="OWNER" value="SAP_BW"/>
<param name="CMD" value="SET_PROPERTIES"/>
<param name="TEMPLATE_ID" value="ZPD_ADHOC_PAGE"/>
<param name="MENU_BACK" value=""/>
<param name="MENU_BACK_TO_START" value=""/>
<param name="SUPPRESS_WARNINGS" value="X"/>
<param name="MENU_FILTER" value=""/>
<param name="MENU_FILTER_ON_AXIS" value=""/>
<param name="MENU_SELECT_FILTER" value=""/>
<param name="MENU_FILTER_ON_AXIS_CHART" value=""/>
<param name="MENU_FILTER_CHART" value=""/>
<param name="MENU_FILTER_DRILL_DOWN" value=""/>
<param name="MENU_DRILL_UP_GIS" value=""/>
<param name="MENU_DRILL_DOWN" value=""/>
<param name="MENU_EXCHANGE_OBJECTS" value=""/>
<param name="MENU_REMOVE_DRILL_DOWN" value=""/>
<param name="MENU_SWITCH_AXIS" value=""/>
<param name="MENU_HIERARCHY_NODE_DRILL" value=""/>
<param name="MENU_HIERARCHY_DRILL" value=""/>
<param name="MENU_HIERARCHY_STATE" value=""/>
<param name="MENU_SORT" value=""/>
<param name="MENU_CALCULATE_RESULT" value=""/>
<param name="MENU_CALCULATE_VALUE" value=""/>
<param name="MENU_CUMULATE_VALUE" value=""/>
<param name="MENU_DISPLAY_DOCUMENTS" value=""/>
<param name="MENU_DOCUMENT_CREATE" value=""/>
<param name="MENU_DISPLAY_DOCUMENT_PROP" value=""/>
<param name="MENU_DISPLAY_DOCUMENT_SELEC" value=""/>
<param name="MENU_RRI" value=""/>
<param name="MENU_EXPORT_TO_CSV" value=""/>
<param name="MENU_EXPORT_TO_XLS" value=""/>
<param name="MENU_BOOKMARK" value=""/>
<param name="MENU_CHARACTERISTIC_PROPERTIES" value=""/>
<param name="MENU_VALUE_PROPERTIES" value=""/>
<param name="MENU_QUERY_PROPERTIES" value=""/>
<param name="MENU_VARIABLE_SCREEN" value=""/>
<param name="MENU_CURRENCY_CONVERSION" value=""/>
<param name="MENU_ENHANCED" value=""/>
TEMPLATE PROPERTIES
</object>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft DHTML Editing Control">
<TITLE>SAP BW Reporting Print Page</TITLE>
<link href="/sap/bw/Mime/BEx/StyleSheets/BWReports.css" type="text/css" rel="stylesheet"/>
<script type"text/javascript">
<!--
// Global Variable Definition
var dataTable = "";
var pageRowCnt = 0;
var prevPage = 0;
var ColumnCnt = 0;
var PrintDateTimeStamp = new Date();
var rptWidth = 0;
//DATE STAMP FUNCTION
function datestamp(){
var Today = new Date()
document.write(Today);
function getReportTitle() {
var myQueryString = window.location.search;
var startOfRptTitle = myQueryString.indexOf("QTITLE=");
if (startOfRptTitle != -1)
var endOfRptTitle = myQueryString.indexOf("&", startOfRptTitle + 7);
var myTitle = unescape(myQueryString.substring(startOfRptTitle + 7, endOfRptTitle));
var rpttitle = "";
for(i=0;i<myTitle.length;i++){
if (myTitle.substring(i,i+1) == "+"){
rpttitle = rpttitle + ' ';
else
rpttitle = rpttitle + (myTitle.substring(i,i+1));
else
var rpttitle = "Unspecified Query Title";
return rpttitle;
queryTitle=getReportTitle();
function getHeading2() {
var myQueryString = window.location.search;
var startOfHdr2 = myQueryString.indexOf("HDR2=");
if (startOfHdr2 != -1)
var endOfHdr2 = myQueryString.indexOf("&", startOfHdr2 + 5);
var myHdr2 = unescape(myQueryString.substring(startOfHdr2 + 5, endOfHdr2));
var hdr2 = "";
for(i=0;i<myHdr2.length;i++){
if (myHdr2.substring(i,i+1) == "+"){
hdr2 = hdr2 + ' ';
else
hdr2 = hdr2 + (myHdr2.substring(i,i+1));
else
var hdr2 = "#";
return hdr2;
header2=getHeading2();
function getHeading3() {
var myQueryString = window.location.search;
var startOfHdr3 = myQueryString.indexOf("HDR3=");
if (startOfHdr3 != -1)
var endOfHdr3 = myQueryString.indexOf("&", startOfHdr3 + 5);
var myHdr3 = unescape(myQueryString.substring(startOfHdr3 + 5, endOfHdr3));
var hdr3 = "";
for(i=0;i<myHdr3.length;i++){
if (myHdr3.substring(i,i+1) == "+"){
hdr3 = hdr3 + ' ';
else
hdr3 = hdr3 + (myHdr3.substring(i,i+1));
else
var hdr3 = "#";
return hdr3;
header3=getHeading3();
function getAsOfDate() {
var myQueryString = window.location.search;
var startOfRelevance = myQueryString.indexOf("ASOFDATE=");
if (startOfRelevance != -1)
var endOfRelevance = myQueryString.indexOf("&", startOfRelevance + 9);
var myRelevance = unescape(myQueryString.substring(startOfRelevance + 9, endOfRelevance));
var asof = "";
for(i=0;i<myRelevance.length;i++){
if (myRelevance.substring(i,i+1) == "+"){
asof = asof + ' ';
else
asof = asof + (myRelevance.substring(i,i+1));
else
var asof = "";
return asof;
asofDateTime=getAsOfDate();
function getPaperSize() {
var myQueryString = window.location.search;
var startOfPaperSize = myQueryString.indexOf("PSIZE=");
if (startOfPaperSize != -1)
var endOfPaperSize = myQueryString.indexOf("&", startOfPaperSize + 6);
var myPaperSize = unescape(myQueryString.substring(startOfPaperSize + 6, endOfPaperSize));
var psize = "";
for(i=0;i<myPaperSize.length;i++){
psize = psize + (myPaperSize.substring(i,i+1));
else
var psize = "0"; // default if none supplied (normal 8x11)
return psize;
varPaperSize=getPaperSize();
var PaperSizeParamString='&PSIZE=' + escape(varPaperSize);
switch(varPaperSize){
case "0": // Landscape - Letter
var WidthMax = 910;
var RowsPerPageMax = 38;
break;
case "1": // Landscape - Legal
var WidthMax = 1190;
var RowsPerPageMax = 38;
break;
case "2": // Portrait - Letter
var WidthMax = 660;
var RowsPerPageMax = 54;
break;
function getTotalColumns() {
var myHTML = dataTable.rows[1].innerHTML;
var TotalTDs = 0;
var nextTD = 0;
for (i=0;i<myHTML.length;i++) {
nextTD = myHTML.indexOf("<TD", i);
if (nextTD != -1) {
i=nextTD;
TotalTDs++;
else break;
return TotalTDs;
function GetPageHeadings() {
var headingHTM = "";
var leftspancnt = 0;
var rightspancnt = 0;
var headingspancnt = 2;
if (header2 != '#') headingspancnt = headingspancnt + 1; // adjust for extra headings
if (header3 != '#') headingspancnt = headingspancnt + 1;
if (currPage > 1) {
headingHTM += '<TR style="page-break-before:always; display:none; visibility:hidden; "><TD Colspan="' + ColumnCnt + '"></td></tr>';
else {
headingHTM += '<TABLE id="THEREPORT" name="MYREPORT" cellSpacing=0 cellPadding=0 width=' + WidthMax + ' border=0>';
if (ColumnCnt == 1) {
headingHTM += '<TR><TD vAlign=top align=left nowrap><font Size=3><STRONG>';
headingHTM += queryTitle;
headingHTM += '</STRONG></font></TD><TD Rowspan="' + headingspancnt + '" align="right" vAlign="top"><input type="image" border="0" name="SAPLogo" src="/sap/bw/Mime/Customer/Images/images.jpg" alt="SAP Logo"></TD></TR>';
if (header2 != '#') headingHTM += '<TR><TD vAlign="top" align="left"><FONT Size=1>' + header2 + '</FONT></TD></TR>';
if (header3 != '#') headingHTM += '<TR><TD vAlign="top" align="left"><FONT Size=1>' + header3 + '</FONT></TD></TR>';
headingHTM += '<TR><TD vAlign="top" align="left"><FONT Size=1>' + asofDateTime + '</FONT></TD></TR>';
headingHTM += '<TR><TD vAlign="top" align="left" Colspan="2"><hr size=2 color=black align=left></TD></TR>';
headingHTM += '<tr>' + dataTable.rows[0].innerHTML + '<TD> </TD></TR>';
else {
leftspancnt = Math.floor(ColumnCnt/2);
rightspancnt = ColumnCnt - leftspancnt;
headingHTM += '<TR><TD vAlign=top align=left nowrap Colspan="' + leftspancnt + '"><font Size=3><STRONG>';
headingHTM += queryTitle;
headingHTM += '</STRONG></font></TD><TD Rowspan="' + headingspancnt + '" Colspan="' + rightspancnt + '" align="right" vAlign="top"><input type="image" border="0" name="SAPLogo" src="/sap/bw/Mime/Customer/Images/images.jpg" alt="SAP Logo"></TD></TR>';
if (header2 != '#') headingHTM += '<TR><TD vAlign="top" align="left" Colspan="' + leftspancnt + '"><FONT Size=1>' + header2 + '</FONT></TD></TR>';
if (header3 != '#') headingHTM += '<TR><TD vAlign="top" align="left" Colspan="' + leftspancnt + '"><FONT Size=1>' + header3 + '</FONT></TD></TR>';
headingHTM += '<TR><TD vAlign="top" align="left" Colspan="' + leftspancnt + '"><FONT Size=1>' + asofDateTime + '</FONT></TD></TR>';
headingHTM += '<TR><TD vAlign="top" align="left" Colspan="' + ColumnCnt + '"><hr size=2 color=black align=left></TD></TR>';
headingHTM += '<tr>' + dataTable.rows[0].innerHTML + '</TR>';
return headingHTM;
function GetPageFooting() {
var footingHTM = "";
var leftspancnt = 0;
var rightspancnt = 0;
if (ColumnCnt == 1) {
footingHTM += '<TR><TD vAlign="top" align="left" Colspan="2"><hr size=2 color=black align=left></TD></TR>';
footingHTM += '<TR><TD vAlign="top" align="left" nowrap><FONT Size=1>Prepared: ';
footingHTM += PrintDateTimeStamp;
footingHTM += '</FONT></TD><TD vAlign="top" align="right"><FONT Size=1>';
footingHTM = footingHTM + 'Page ' + currPage.toString() + ' of ' + varPageTotal.toString();
footingHTM += '</FONT></TD></TR>';
else {
leftspancnt = Math.floor(ColumnCnt/2);
rightspancnt = ColumnCnt - leftspancnt;
footingHTM += '<TR><TD vAlign="top" align="left" Colspan="' + ColumnCnt + '"><hr size=2 color=black align=left></TD></TR>';
footingHTM += '<TR><TD vAlign="top" align="left" nowrap Colspan="' + leftspancnt + '"><FONT Size=1>Prepared: ';
footingHTM += PrintDateTimeStamp;
footingHTM += '</FONT></TD><TD vAlign="top" align="right" Colspan="' + rightspancnt + '"><FONT Size=1>';
footingHTM = footingHTM + 'Page ' + currPage.toString() + ' of ' + varPageTotal.toString();
footingHTM += '</FONT></TD></TR>';
return footingHTM;
function GetReportFooting() {
var footingHTM = "";
footingHTM += '</TABLE>';
return footingHTM;
function formatToPrint() {
var PrintHTM = "";
PrintHTM += GetPageHeadings();
if (ColumnCnt != 1) {
for (var i=1;i<dataTable.rows.length;i++) {
(currPage > prevPage)?prevPage=currPage:""; //increment current page count
if ((pageRowCnt + 1)>RowsPerPageMax){
PrintHTM += GetPageFooting();
pageRowCnt = 0;
currPage++;
if (prevPage != currPage) {
PrintHTM += GetPageHeadings();
else
PrintHTM += '<tr>' + dataTable.rows<i>.innerHTML + '</tr>';
pageRowCnt++;
PrintHTM += GetPageFooting();
PrintHTM += GetReportFooting();
return PrintHTM;
function DisplayPrintNotice() {
// Paper Size "0" is Letter with Landscape
// Paper Size "1" is Legal with Landscape
// Paper Size "2" is Letter with Portrait
if (varPaperSize == "0") {var varMessage ="nn From your browser File Menu, select Page Setup and do the following: nn 1) Adjust the Printer Orientation to Landscape n 2) select Print menu, then select the Print button.";}
if (varPaperSize == "1") {var varMessage ="nn From your browser File Menu, select Page Setup and do the following: nn 1) Adjust the Paper Size to Legal n 2) Adjust the Printer Orientation to Landscape n 3) select Print menu, then select the Print button.";}
//if (varPaperSize == "2") {var varMessage ="nn From your browser File Menu, select Page Setup and do the following: nn 1) Adjust the Paper Size to Letter n 2) Adjust the Paper Source (if necessary) n 3) Adjust the Orientation to Portrait (default) n 4) Select the Okay button nn Again select the File Menu, select Print, then select the Print button.";}
alert(varMessage);
//window.print()
/* SAP BW Reporting Stylesheet Revisions */
function writeStyleRevisions() {
function writeDynamicFontRevisions(dynafont) {
//Writes the Dynamic Stylesheet
-->
</script>
</HEAD>
<BODY>
<TABLE id="tp1" cellSpacing=0 cellPadding=0 width=660 border=0 >
<TR>
<TD vAlign=top align=left nowrap>
<object>
<param name="OWNER" value="SAP_BW"/>
<param name="CMD" value="GET_ITEM"/>
<param name="NAME" value="MYQUERY"/>
<param name="ITEM_CLASS" value="CL_RSR_WWW_ITEM_GRID"/>
<param name="DATA_PROVIDER" value="DATAPROVIDER_1"/>
<param name="GENERATE_CAPTION" value=""/>
<param name="GENERATE_LINKS" value=""/>
<param name="WIDTH" value="660"/>
<param name="BORDER_STYLE" value="NO_BORDER"/>
<param name="SUPPRESS_REPETITION_TEXTS" value=""/>
<param name="BLOCK_SIZE" value="3500"/>
<param name="SHOW_PAGING_AREA_TOP" value="X"/>
<param name="TARGET_DATA_PROVIDER_1" value="DATAPROVIDER_1"/>
ITEM: MYQUERY
</object>
</TD>
</TR>
</TABLE>
<SCRIPT type="text/javascript">
<!--
var tbls = document.body.getElementsByTagName("TABLE");
for (var i=0;i<tbls.length;i++) {
if (tbls<i>.name == "MYQUERY"){
var dataTable = tbls<i>;
break;
document.title = queryTitle;
rptWidth = dataTable.clientWidth;
rptHeight = dataTable.clientHeight;
originalRptWidth = rptWidth;
originalRptHeight = rptHeight;
originalRowHeight = Math.floor(rptHeight/(dataTable.rows.length+1));
rptPageHeightMax = 580; //660 less basic header and footer of 80
if (header2 != '#') rptPageHeightMax = rptPageHeightMax - 20; // adjust for extra headings
if (header3 != '#') rptPageHeightMax = rptPageHeightMax - 20;
if (dataTable.rows.length == 1) {
ColumnCnt = 1; //No Applicable Data found message
else {
ColumnCnt = getTotalColumns();
startingFont = 65;
varFontSize = startingFont;
if (rptWidth > WidthMax) {
while ((rptWidth > WidthMax) && (varFontSize > 15))
writeDynamicFontRevisions(varFontSize);
rptWidth = dataTable.clientWidth;
rptHeight = dataTable.clientHeight;
varFontSize = varFontSize - 5;
// calculate max rows per page
rowHeight = Math.floor(rptHeight/(dataTable.rows.length+1)) + 1; // add 1 for 2 row heading, add 1 for padding
RowsPerPageMax = Math.floor(rptPageHeightMax/rowHeight) - 2; // adjust for column headings
if (dataTable.rows.length == 1) {
varPageTotal = 1; //No Applicable Data found message
else {
totalRows = dataTable.rows.length-1; // total rows less headings
varPageTotal = Math.floor(totalRows/RowsPerPageMax); // compute total pages
if (totalRows != (varPageTotal * RowsPerPageMax)) {
varPageTotal = varPageTotal + 1; // if not a complete last page, add 1 for partial page
currPage = 1;
document.write(formatToPrint());
document.all.tp1.style.display = "none";
document.all.tp1.style.visibility = "hidden";
// DisplayPrintNotice();
-->
</SCRIPT>
<STYLE>
input.ie55 { display: none }
</STYLE>
<!-- special style sheet for printing -->
<STYLE media=print>
.noprint { display: none }
</STYLE>
<script defer>
function window.onload() {
if (!factory.object) {
return
else {
// factory.printing.header = "SAP"
// factory.printing.footer = "SAP"
if ( varPaperSize == "2" ) { factory.printing.portrait = true; }
else { factory.printing.portrait = false; }
factory.printing.Print(true);
// enable control buttons
/* var templateSupported = factory.printing.IsTemplateSupported();
var controls = idControls.all.tags("input");
for ( i = 0; i < controls.length; i++ ) {
controls<i>.disabled = false;
if ( templateSupported && controls<i>.className == "ie55" )
controls<i>.style.display = "inline";
</script>
<P>
<div id=idControls class="noprint" style="VISIBILITY: hidden">
<input disabled type="button" value="Print this page"
onclick="factory.printing.Print(true)">
<input disabled type="button" value="Page Setup..."
onclick="factory.printing.PageSetup()">
<input class=ie55 disabled type="button" value="Print Preview..."
onclick="factory.printing.Preview()">
<input class=ie55 disabled type="button" value="Landscape"
onclick="factory.printing.portrait=false">
<input class=ie55 disabled type="button" value="Portrait"
onclick="factory.printing.portrait=true">
</div>
</BODY>
</HTML> -
Want to create a function module which will convert smartform into PDF .
Hi All ,
Requirement : I want to create a function module/report which will convert smartform into PDF .
Thanks in advanceHi All ,
zsuresh_test : for converting smartform into pdf.
when I am excuting this report(zsuresh_test) and by passing the smartform name FOPCR_STANDARD_F1
I am getting error :
Incorrect parameter with CALL FUNCTION
Can you please help me out..
REPORT zsuresh_test.
Variable declarations
DATA:
w_form_name TYPE tdsfname VALUE 'FOPCR_STANDARD_F1',
w_fmodule TYPE rs38l_fnam,
w_cparam TYPE ssfctrlop,
w_outoptions TYPE ssfcompop,
W_bin_filesize TYPE i, " Binary File Size
w_FILE_NAME type string,
w_File_path type string,
w_FULL_PATH type string.
Internal tables declaration
Internal table to hold the OTF data
DATA:
t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
Internal table to hold OTF data recd from the SMARTFORM
t_otf_from_fm TYPE ssfcrescl,
Internal table to hold the data from the FM CONVERT_OTF
T_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.
This function module call is used to retrieve the name of the Function
module generated when the SMARTFORM is activated
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = w_form_name
VARIANT = ' '
DIRECT_CALL = ' '
IMPORTING
fm_name = w_fmodule
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.
Calling the SMARTFORM using the function module retrieved above
GET_OTF parameter in the CONTROL_PARAMETERS is set to get the OTF
format of the output
w_cparam-no_dialog = 'X'.
w_cparam-preview = space. " Suppressing the dialog box
" for print preview
w_cparam-getotf = 'X'.
Printer name to be used is provided in the export parameter
OUTPUT_OPTIONS
w_outoptions-tddest = 'LP01'.
CALL FUNCTION w_fmodule
EXPORTING
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
control_parameters = w_cparam
MAIL_APPL_OBJ =
MAIL_RECIPIENT =
MAIL_SENDER =
output_options = w_outoptions
USER_SETTINGS = 'X'
IMPORTING
DOCUMENT_OUTPUT_INFO =
job_output_info = t_otf_from_fm
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_otf_from_fm-otfdata[].
Function Module CONVERT_OTF is used to convert the OTF format to PDF
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 132
ARCHIVE_INDEX = ' '
COPYNUMBER = 0
ASCII_BIDI_VIS2LOG = ' '
PDF_DELETE_OTFTAB = ' '
IMPORTING
BIN_FILESIZE = W_bin_filesize
BIN_FILE =
TABLES
otf = T_OTF
lines = T_pdf_tab
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.
To display File SAVE dialog window
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
WINDOW_TITLE =
DEFAULT_EXTENSION =
DEFAULT_FILE_NAME =
FILE_FILTER =
INITIAL_DIRECTORY =
WITH_ENCODING =
PROMPT_ON_OVERWRITE = 'X'
CHANGING
filename = w_FILE_NAME
path = w_FILE_PATH
fullpath = w_FULL_PATH
USER_ACTION =
FILE_ENCODING =
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 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.
Use the FM GUI_DOWNLOAD to download the generated PDF file onto the
presentation server
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE = W_bin_filesize
filename = w_FULL_PATH
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'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
IMPORTING
FILELENGTH =
tables
data_tab = T_pdf_tab
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. -
Unable to print directly from vf03 txn after converting smartform into PDF
Dear All,
I have converted ond smartform into pdf.now when i am trying to print one document using vf03 transaction whatever button i click(ex-print preview/print) it is asking to save the pdf as local file. but i want to print that document as pdf directly from vf03 without saving it into local file.
I am giving you the code below:-
(all modification done by me are in BOLD)
Print of a invoice by SAPscript SMART FORMS *
REPORT zrlb_invoice5.
declaration of data
INCLUDE zrlb_invoice_data_declare5.
*INCLUDE ZRLB_INVOICE_DATA_DECLARE.
*INCLUDE rlb_invoice_data_declare.
definition of forms
INCLUDE zrlb_invoice_form015.
*INCLUDE ZRLB_INVOICE_FORM01.
*INCLUDE rlb_invoice_form01.
INCLUDE zrlb_print_forms5.
*INCLUDE ZRLB_PRINT_FORMS.
*INCLUDE rlb_print_forms.
START-OF-SELECTION.
FORM ENTRY
FORM entry USING return_code us_screen.
DATA: lf_retcode TYPE sy-subrc.
CLEAR retcode.
xscreen = us_screen.
PERFORM processing USING us_screen
CHANGING lf_retcode.
IF lf_retcode NE 0.
return_code = 1.
ELSE.
return_code = 0.
ENDIF.
ENDFORM. "ENTRY
FORM PROCESSING *
FORM processing USING proc_screen
CHANGING cf_retcode.
DATA: lv_medium LIKE tnapr-nacha.
DATA: lwa_print_data_to_read TYPE lbbil_print_data_to_read.
DATA: lwa_bil_invoice TYPE lbbil_invoice.
DATA: lf_fm_name TYPE rs38l_fnam.
DATA: lwa_control_param TYPE ssfctrlop.
DATA: lwa_composer_param TYPE ssfcompop.
DATA: lwa_recipient TYPE swotobjid.
DATA: lwa_sender TYPE swotobjid.
DATA: lf_formname TYPE tdsfname.
DATA: lwa_addr_key LIKE addr_key.
DATA: ls_dlv-land LIKE vbrk-land1.
DATA:lv_job_output_info TYPE ssfcrescl,
lv_document_output_info TYPE ssfcrespd,
lv_job_output_options TYPE ssfcresop,
lv_bin_filesize TYPE i,
gt_docs TYPE STANDARD TABLE OF docs,
gt_lines TYPE STANDARD TABLE OF tline,
gt_otf TYPE TABLE OF itcoo, " OTF Structure
lv_name TYPE string VALUE 'INVOICE',
lv_guiobj TYPE REF TO cl_gui_frontend_services,
lv_path TYPE string VALUE 'D:\',
lv_fullpath TYPE string VALUE 'D:\INVOICE',
lv_filter TYPE string,
lv_uact TYPE i,
lv_filename TYPE string,
++lv_fm_name TYPE rs38l_fnam. +*****************************************
SmartForm from customizing table TNAPR
lf_formname = tnapr-sform.
lv_medium = tnapr-nacha.
determine print data
PERFORM set_print_data_to_read USING lf_formname
CHANGING lwa_print_data_to_read
cf_retcode.
IF cf_retcode EQ 0.
select print data
PERFORM get_data USING lwa_print_data_to_read
CHANGING lwa_addr_key
ls_dlv-land
lwa_bil_invoice
cf_retcode.
ENDIF.
IF cf_retcode EQ 0.
PERFORM set_print_param USING lwa_addr_key
ls_dlv-land
CHANGING lwa_control_param
lwa_composer_param
lwa_recipient
lwa_sender
cf_retcode.
ENDIF.
IF cf_retcode EQ 0.
determine smartform function module for invoice
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING formname = lf_formname
variant = ' '
direct_call = ' '
IMPORTING fm_name = lf_fm_name
EXCEPTIONS no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc NE 0.
error handling
cf_retcode = sy-subrc.
PERFORM protocol_update.
ENDIF.
ENDIF.
IF cf_retcode EQ 0.
PERFORM check_repeat.
IF lwa_composer_param-tdcopies EQ 0.
nast_anzal = 1.
ELSE.
nast_anzal = lwa_composer_param-tdcopies.
ENDIF.
lwa_composer_param-tdcopies = 1.
DO nast_anzal TIMES.
In case of repetition only one time archiving
IF sy-index GT 1 AND nast-tdarmod EQ 3.
nast_tdarmod = nast-tdarmod.
nast-tdarmod = 1.
lwa_composer_param-tdarmod = 1.
ENDIF.
IF sy-index NE 1 AND repeat IS INITIAL.
repeat = 'X'.
ENDIF.
call smartform invoice
CALL FUNCTION lf_fm_name
EXPORTING
archive_index = toa_dara
archive_parameters = arc_params
control_parameters = ls_control_param
mail_appl_obj =
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
user_settings = space
is_bil_invoice = ls_bil_invoice
is_nast = nast
is_repeat = repeat
importing document_output_info =
job_output_info =
job_output_options =
EXCEPTIONS formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
lwa_control_param-getotf = 'X'.
lwa_control_param-no_dialog = 'X'.
lwa_control_param-device = 'PRINTER'.
CALL FUNCTION lf_fm_name
EXPORTING
archive_index = toa_dara
Begin of Changes 24/10/2007*
ARCHIVE_INDEX_TAB =*
ARCHIVE_PARAMETERS = arc_params*
control_parameters = lwa_control_param
MAIL_APPL_OBJ =*
MAIL_RECIPIENT = lwa_recipient*
MAIL_SENDER = lwa_sender*
*End of changes 04/12/2007
output_options = lwa_composer_param
user_settings = 'X'
is_bil_invoice = lwa_bil_invoice
is_nast = nast
is_repeat = repeat
iv_medium = lv_medium
Begin OF Changes 04/12/2007*
IMPORTING
document_output_info = lv_document_output_info
job_output_info = lv_job_output_info
*job_output_options = lv_job_output_options *
End Of Changes 04/12/2007*
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
CALL FUNCTION lf_fm_name
EXPORTING
ARCHIVE_INDEX = toa_dara
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS = arc_params
CONTROL_PARAMETERS = lWA_control_param
MAIL_APPL_OBJ =
MAIL_RECIPIENT = lwa_recipient
MAIL_SENDER = lwa_sender
OUTPUT_OPTIONS = lwa_composer_param
USER_SETTINGS = space
IS_BIL_INVOICE = LWA_BIL_INVOICE
IS_NAST = nast
IS_REPEAT = repeat
IV_MEDIUM = lv_medium
IMPORTING
DOCUMENT_OUTPUT_INFO =
JOB_OUTPUT_INFO =
JOB_OUTPUT_OPTIONS =
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5
gt_otf[] = lv_job_output_info-otfdata[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 132
ARCHIVE_INDEX = ' '*
COPYNUMBER = 0*
ASCII_BIDI_VIS2LOG = ' '*
IMPORTING
BIN_FILESIZE = lv_bin_filesize
BIN_FILE =*
TABLES
otf = gt_otf
lines = gt_lines
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.
*.......................GET THE FILE NAME TO STORE.........
CONCATENATE 'smrt' '.pdf' INTO lv_name.
CREATE OBJECT lv_guiobj.
CALL METHOD lv_guiobj->file_save_dialog
EXPORTING
default_extension = 'pdf'
default_file_name = lv_name
file_filter = lv_filter
CHANGING
filename = lv_name
path = lv_path
fullpath = lv_fullpath.
user_action = lv_uact.*
IF lv_uact = lv_guiobj->action_cancel.
EXIT.
ENDIF.*
MOVE lv_fullpath TO lv_filename.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
BIN_FILESIZE = lv_bin_filesize
filename = lv_fullpath
FILETYPE = 'BIN'
APPEND = SPACE
WRITE_FIELD_SEPARATOR = SPACE
HEADER = '00'
TRUNC_TRAILING_BLANKS = SPACE
WRITE_LF = 'X'
COL_SELECT = SPACE
COL_SELECT_MASK = SPACE
DAT_MODE = SPACE
CONFIRM_OVERWRITE = SPACE
NO_AUTH_CHECK = SPACE
CODEPAGE = SPACE
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = SPACE
TRUNC_TRAILING_BLANKS_EOL = 'X'
IMPORTING
FILELENGTH =
changing
data_tab = gt_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
NOT_SUPPORTED_BY_GUI = 22
ERROR_NO_GUI = 23
others = 24
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.*
ENDIF.
Else.
IF sy-subrc NE 0.*
error handling
cf_retcode = sy-subrc.
PERFORM protocol_update.
get SmartForm protocoll and store it in the NAST protocoll
PERFORM add_smfrm_prot.
ENDIF.
ENDDO.
lwa_composer_param-tdcopies = nast_anzal.
IF NOT nast_tdarmod IS INITIAL.
nast-tdarmod = nast_tdarmod.
CLEAR nast_tdarmod.
ENDIF.
ENDIF.
get SmartForm protocoll and store it in the NAST protocoll
PERFORM ADD_SMFRM_PROT.
ENDFORM. "PROCESSING
kindly give me a sloution.Hi,
Check for the print mode in the print options and set it as 3- print and archive .
Regards,
Ram -
Converting Smartforms to PDF and displaying Smartforms on print preview
Hi,
How to convert smartforms to pdf?
How to attach this pdf to email?
How to attach this pdf to the email and at the same time can print preview the smartforms?
Thanks.Hi Navi,
Code Snippet for Simple Mail
*& Report ZZ_TEST *
REPORT zz_test .
INCLUDE zz_test_top.
INCLUDE zz_test01.
FORM entry *
--> RETURN_CODE *
--> US_SCREEN *
FORM entry USING return_code us_screen.
CLEAR retcode.
xscreen = us_screen.
PERFORM processing USING us_screen.
CASE retcode.
WHEN 0.
return_code = 0.
WHEN 3.
return_code = 3.
WHEN OTHERS.
return_code = 1.
ENDCASE.
ENDFORM. "entry
*& Include ZZ_TEST_TOP *
TABLES : nast,
tnapr.
TYPES : BEGIN OF t_SOUDNAMEI1.
INCLUDE STRUCTURE SOUDNAMEI1.
TYPES : END OF t_SOUDNAMEI1.
Internal Table declarations
DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
i_tline TYPE TABLE OF tline WITH HEADER LINE,
i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
*Objects to send mail.
i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
i_lips LIKE lips OCCURS 0 WITH HEADER LINE,
i_SOUDNAMEI1 TYPE STANDARD TABLE OF t_SOUDNAMEI1.
Work Area declarations
DATA:w_objhead TYPE soli_tab,
wa_control_parameters TYPE ssfctrlop,
wa_output_options TYPE ssfcompop,
w_return TYPE ssfcrescl,
w_doc_chng TYPE sodocchgi1,
w_data TYPE sodocchgi1,
w_buffer TYPE string,"To convert from 132 to 255
wa_SOUDNAMEI1 TYPE t_SOUDNAMEI1,
Variables declarations
w_form_name TYPE rs38l_fnam,
w_len_in LIKE sood-objlen,
w_len_out LIKE sood-objlen,
w_len_outn TYPE i,
w_lines_txt TYPE i,
w_lines_bin TYPE i,
retcode TYPE sy-subrc,
xscreen TYPE c,
w_spld TYPE usr01-spld,
w_receiver TYPE SOXNA-FULLNAME,
w_OBJ_RECORD TYPE OBJ_RECORD,
w_user type sy-uname,
w_email TYPE ad_smtpadr.
Constants Declaration
CONSTANTS : c_x TYPE c VALUE 'X',
c_atrate(1) TYPE c VALUE '@'.
*& Include ZZ_TEST01 *
FORM PROCESSING *
FORM processing USING proc_screen.
SELECT * FROM lips
INTO TABLE i_lips
WHERE vbeln = nast-objky.
Call Function module to Getfunction Module name Generated by Smartform
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = tnapr-sform
IMPORTING
fm_name = w_form_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
retcode = sy-subrc.
ENDIF.
CLEAR : wa_control_parameters,
wa_output_options.
CASE nast-nacha.
WHEN '1'.
wa_control_parameters-device = 'PRINTER'.
WHEN '7'.
DATA: l_email TYPE ad_smtpadr.
wa_output_options-tdnoprev = c_x.
wa_control_parameters-getotf = c_x.
To get the default output device maintained in the
User profile
SELECT SINGLE spld FROM usr01
INTO w_spld
WHERE bname EQ nast-usnam.
IF sy-subrc EQ 0.
MOVE w_spld TO wa_output_options-tddest .
ENDIF.
wa_output_options-tdnoprev = c_x.
wa_control_parameters-getotf = c_x.
To get the email address maintained for the particular output
CALL FUNCTION 'NAST_GET_MESSAGE_OBJECT_RECV'
EXPORTING
pi_objkey = nast-tdname
IMPORTING
pe_addr = w_receiver
CHANGING
pc_objhandle = w_obj_record
EXCEPTIONS
maildata_not_readable = 1
OTHERS = 2.
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 w_receiver NA c_atrate.
To retrieve the E-Mail Id in case we get the User name from NAST
CLEAR wa_soudnamei1.
REFRESH i_soudnamei1.
MOVE w_receiver TO wa_soudnamei1-fullname.
To get the user name
CALL FUNCTION 'SO_NAME_CONVERT_API1'
EXPORTING
name = wa_soudnamei1
TABLES
names = i_soudnamei1
EXCEPTIONS
user_not_exist = 1
parameter_error = 2
x_error = 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.
CLEAR wa_soudnamei1.
READ TABLE i_soudnamei1 INTO wa_soudnamei1 INDEX 1.
MOVE wa_soudnamei1-sapname TO w_user.
To get the e-mail Id maintained in the user profile
CALL FUNCTION 'FTR_CORR_CHECK_EMAIL_SAP_USER'
EXPORTING
i_user = w_user
IMPORTING
e_email_address = l_email
EXCEPTIONS
mail_address = 1
determination_error = 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.
MOVE l_email TO w_receiver.
ENDIF.
MOVE w_receiver TO w_email.
ENDCASE.
wa_control_parameters-no_dialog = c_x.
wa_control_parameters-langu = nast-spras .
wa_output_options-tdteleland = nast-tland.
wa_output_options-tdtelenum = nast-telfx .
wa_output_options-tdsenddate = nast-erdat .
wa_output_options-tdsendtime = nast-eruhr .
wa_output_options-tddataset = nast-dsnam .
wa_output_options-tdsuffix1 = nast-dsuf1 .
wa_output_options-tdsuffix2 = nast-dsuf2 .
wa_output_options-tdimmed = nast-dimme .
wa_output_options-tddelete = nast-delet .
wa_output_options-tdautority = nast-tdautority.
wa_output_options-tdcovtitle = nast-tdcovtitle .
wa_output_options-tdcover = nast-tdocover .
wa_output_options-tdreceiver = nast-tdreceiver.
wa_output_options-tddivision = nast-tddivision.
wa_output_options-tdcopies = nast-anzal .
wa_output_options-tdnewid = c_x.
wa_output_options-tdarmod = nast-tdarmod.
wa_output_options-tdnoarmch = c_x.
CALL FUNCTION w_form_name
EXPORTING
archive_index = toa_dara
archive_parameters = arc_params
control_parameters = wa_control_parameters
output_options = wa_output_options
user_settings = ' '
IMPORTING
job_output_info = w_return
TABLES
it_lips = i_lips
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF nast-nacha EQ 7 AND sy-subrc EQ 0.
i_otf[] = w_return-otfdata[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = w_len_in
TABLES
otf = i_otf
lines = i_tline
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.
Convert PDF from 132 to 255.
LOOP AT i_tline.
Replacing space by ~
TRANSLATE i_tline USING ' ~'.
CONCATENATE w_buffer i_tline INTO w_buffer.
ENDLOOP.
Replacing ~ by space
TRANSLATE w_buffer USING '~ '.
DO.
i_record = w_buffer.
Appending 255 characters as a record
APPEND i_record.
SHIFT w_buffer LEFT BY 255 PLACES.
IF w_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
REFRESH: i_reclist,
i_objtxt,
i_objbin,
i_objpack.
CLEAR w_objhead.
Object with PDF.
i_objbin[] = i_record[].
DESCRIBE TABLE i_objbin LINES w_lines_bin.
Document information.
w_doc_chng-obj_name = 'Smartform'.
w_doc_chng-expiry_dat = sy-datum + 10.
CONCATENATE 'Delivery' 'Note'
INTO w_doc_chng-obj_descr.
*w_doc_chng-obj_descr = 'Smart form output'.
w_doc_chng-sensitivty = 'F'. "Functional object
w_doc_chng-doc_size = w_lines_txt * 255.
Pack to main body as RAW.
Obj. to be transported not in binary form
CLEAR i_objpack-transf_bin.
Start line of object header in transport packet
i_objpack-head_start = 1.
Number of lines of an object header in object packet
i_objpack-head_num = 0.
Start line of object contents in an object packet
i_objpack-body_start = 1.
Number of lines of the object contents in an object packet
i_objpack-body_num = w_lines_txt.
Code for document class
i_objpack-doc_type = 'RAW'.
APPEND i_objpack.
Packing as PDF.
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 1.
i_objpack-body_start = 1.
i_objpack-body_num = w_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'Smartform'.
CONCATENATE 'Delivery' 'Note' '.pdf'
INTO i_objpack-obj_descr.
i_objpack-doc_size = w_lines_bin * 255.
APPEND i_objpack.
Document information.
CLEAR i_reclist.
e-mail receivers.
i_reclist-receiver = w_email.
i_reclist-express = 'X'.
i_reclist-rec_type = 'U'. "Internet address
APPEND i_reclist.
sending mail.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_doc_chng
put_in_outbox = 'X'
TABLES
packing_list = i_objpack
object_header = w_objhead
contents_bin = i_objbin
contents_txt = i_objtxt
receivers = i_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
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.
ENDFORM. "processing
OTF to PDF
========================================================================
Program1
*& REPORT zpmm_print1
REPORT zpmm_print1.
DATA : gw_ssfcrescl TYPE ssfcrescl.
DATA: gt_otf TYPE STANDARD TABLE OF itcoo ,
gt_tline TYPE STANDARD TABLE OF tline,
gv_len LIKE sood-objlen,
gw_ssfctrlop TYPE ssfctrlop, "for CONTROL_PARAMETERS
gw_ssfcompop TYPE ssfcompop. "for OUTPUT_OPTIONS
DATA fm_name TYPE rs38l_fnam.
gw_ssfctrlop-getotf = 'X'.
gw_ssfctrlop-no_dialog = 'X'.
gw_ssfcompop-tdnoprev = 'X'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZPMM_1'
IMPORTING
fm_name = fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
<error handling>
ENDIF.
CALL FUNCTION fm_name
EXPORTING
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
control_parameters = gw_ssfctrlop
MAIL_APPL_OBJ =
MAIL_RECIPIENT =
MAIL_SENDER =
output_options = gw_ssfcompop
user_settings = 'X'
IMPORTING
DOCUMENT_OUTPUT_INFO =
job_output_info = gw_ssfcrescl
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.
gt_otf[] = gw_ssfcrescl-otfdata[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = gv_len
TABLES
otf = gt_otf
lines = gt_tline
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.
DATA : gv_filename LIKE rlgrap-filename VALUE 'C:\swet.pdf'.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
bin_filesize = gv_len
filename = gv_filename
filetype = 'BIN'
filetype_no_show = 'X'
IMPORTING
act_filename = gv_filename
filesize = gv_len
cancel = ''
TABLES
data_tab = gt_tline.
Program 2
*& REPORT zpmm_print2
REPORT zpmm_print2.
DATA : gw_ssfcrescl TYPE ssfcrescl.
DATA: gt_otf TYPE STANDARD TABLE OF itcoo ,
gt_tline TYPE STANDARD TABLE OF tline,
gv_len LIKE sood-objlen,
gw_ssfctrlop TYPE ssfctrlop, "for CONTROL_PARAMETERS
gw_ssfcompop TYPE ssfcompop. "for OUTPUT_OPTIONS
DATA fm_name TYPE rs38l_fnam.
gw_ssfctrlop-getotf = 'X'.
gw_ssfctrlop-no_dialog = 'X'.
gw_ssfcompop-tdnoprev = 'X'.
CALL FUNCTION '/1BCDWB/SF00000041'
EXPORTING
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
control_parameters = gw_ssfctrlop
MAIL_APPL_OBJ =
MAIL_RECIPIENT =
MAIL_SENDER =
output_options = gw_ssfcompop
user_settings = 'X'
IMPORTING
DOCUMENT_OUTPUT_INFO =
job_output_info = gw_ssfcrescl
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.
gt_otf[] = gw_ssfcrescl-otfdata[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = gv_len
TABLES
otf = gt_otf
lines = gt_tline
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.
DATA : gv_filename LIKE rlgrap-filename VALUE 'C:\swet.pdf'.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
bin_filesize = gv_len
filename = gv_filename
filetype = 'BIN'
filetype_no_show = 'X'
IMPORTING
act_filename = gv_filename
filesize = gv_len
cancel = ''
TABLES
data_tab = gt_tline.
=========================================================================
Cheers
Mohinder Singh Chauhan -
Convert Smartform to PDF and send to SAP Workplace user
Hi to all.
I need help of somebody expert in SMARTFORM's.
I need to convert a smartform into PDF format and to send as attachement for SAP workplace
of the user.
I developed the next code.
IT is to function and to send the mail for SAP workplace, but it happens that smartform
contains images (logos) and tables, when the user tries to open the file pdf in inbox gives
to error - "An unrecognized token ' q0 ' was found".
I tried to call a smartform only with text and functioned well.
Somebody can help me?
My code:
Begin ***********************************************
REPORT zteste_nsa_send_pdf_sap_office.
DATA: t_print LIKE zeps_fm04 OCCURS 0 WITH HEADER LINE,
v_size TYPE i.
DATA: ls_bil_invoice TYPE lbbil_invoice.
TABLES: nast.
DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
i_tline TYPE TABLE OF tline WITH HEADER LINE,
i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
Objects to send mail.
i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
Work Area declarations
wa_objhead TYPE soli_tab,
w_ctrlop TYPE ssfctrlop,
w_compop TYPE ssfcompop,
w_return TYPE ssfcrescl,
wa_doc_chng TYPE sodocchgi1,
w_data TYPE sodocchgi1,
wa_buffer TYPE string,"To convert from 132 to 255
Variables declarations
v_form_name TYPE rs38l_fnam,
v_len_in LIKE sood-objlen,
v_len_out LIKE sood-objlen,
v_len_outn TYPE i,
v_lines_txt TYPE i,
v_lines_bin TYPE i.
START-OF-SELECTION.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZFPS_FICHA_VALORIZACAO'
IMPORTING
fm_name = v_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.
w_ctrlop-getotf = 'X'.
w_ctrlop-no_dialog = 'X'.
w_compop-tdnoprev = 'X'.
CALL FUNCTION v_form_name
EXPORTING
control_parameters = w_ctrlop
output_options = w_compop
user_settings = 'X'
is_bil_invoice = ls_bil_invoice
is_nast = nast
is_repeat = 'X'
IMPORTING
job_output_info = w_return
TABLES
t_list = t_print
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.
i_otf[] = w_return-otfdata[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
bin_filesize = v_len_in
TABLES
otf = i_otf
lines = i_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
IF sy-subrc EQ 0.
ENDIF.
Convert PDF from 132 to 255.
LOOP AT i_tline.
TRANSLATE i_tline USING '~'.
CONCATENATE wa_buffer i_tline INTO wa_buffer.
ENDLOOP.
TRANSLATE wa_buffer USING '~'.
DO.
i_record = wa_buffer.
APPEND i_record.
SHIFT wa_buffer LEFT BY 255 PLACES.
IF wa_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
SEND MAIL
REFRESH: i_reclist,
i_objtxt,
i_objbin,
i_objpack.
CLEAR wa_objhead.
Object with PDF.
i_objbin[] = i_record[].
Object with main text of the mail.
i_objtxt = 'Fichas de Valorização e Esquemas Tipo'.
APPEND i_objtxt.
Document information.
wa_doc_chng-obj_name = 'SMART'.
wa_doc_chng-expiry_dat = sy-datum + 10.
wa_doc_chng-obj_descr = 'Ficha de Valorização'.
wa_doc_chng-sensitivty = 'F'. "Functional object
wa_doc_chng-doc_size = ( v_lines_txt - 1 ) * 255 + STRLEN( i_objtxt ).
Pack to main body as RAW.
Obj. to be transported not in binary form
DESCRIBE TABLE i_objtxt LINES v_lines_txt.
READ TABLE i_objtxt INDEX v_lines_txt.
CLEAR i_objpack-transf_bin.
i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_txt.
i_objpack-doc_type = 'RAW'.
APPEND i_objpack.
Packing as PDF.
Obj. to be transported in binary form
DESCRIBE TABLE i_objbin LINES v_lines_bin.
READ TABLE i_objbin INDEX v_lines_bin.
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'SMART'.
CONCATENATE 'Ficha_Valorizacao' '.pdf' INTO i_objpack-obj_descr.
i_objpack-doc_size = ( v_lines_bin - 1 ) * 255 + STRLEN( i_objbin ).
APPEND i_objpack.
e-mail receivers.
CLEAR i_reclist.
i_reclist-receiver = sy-uname.
i_reclist-rec_type = 'B'.
i_reclist-express = 'X'.
APPEND i_reclist.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_doc_chng
put_in_outbox = 'X'
commit_work = ' '
TABLES
packing_list = i_objpack
object_header = wa_objhead
contents_bin = i_objbin
contents_txt = i_objtxt
receivers = i_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc EQ 0.
ENDIF.
End *************************************************
Thanks very much to all and Happy New year...
NelsonHi
See this report as example:
http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
I believe before converting the print to pdf, you should print your document, get the spool and convert it.
Max -
Convert smartforms to pdf and sending it as email
hi,
i am converting smart form into PDF and sending it as an attachment with the e-mail. the e-mail is getting delivered but i am unable to open the PDF. it shows error saying "unable to open as it is not a supported file type or it has been damaged".
can any one please help me.Hi Gouthaman,
Check this code.
*& Report ZSPOOLTOPDF *
*& Converts spool request into PDF document and emails it to *
*& recipicant. *
*& Execution *
*& This program must be run as a background job in-order for the write *
*& commands to create a Spool request rather than be displayed on *
*& screen *
REPORT zspooltopdf.
PARAMETER: p_email1 LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_sender LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_delspl AS CHECKBOX.
*DATA DECLARATION
DATA: gd_recsize TYPE i.
Spool IDs
TYPES: BEGIN OF t_tbtcp.
INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.
DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
wa_tbtcp TYPE t_tbtcp.
Job Runtime Parameters
DATA: gd_eventid LIKE tbtcm-eventid,
gd_eventparm LIKE tbtcm-eventparm,
gd_external_program_active LIKE tbtcm-xpgactive,
gd_jobcount LIKE tbtcm-jobcount,
gd_jobname LIKE tbtcm-jobname,
gd_stepcount LIKE tbtcm-stepcount,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
DATA: w_recsize TYPE i.
DATA: gd_subject LIKE sodocchgi1-obj_descr,
it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
gd_sender_type LIKE soextreci1-adr_typ,
gd_attachment_desc TYPE so_obj_nam,
gd_attachment_name TYPE so_obj_des.
Spool to PDF conversions
DATA: gd_spool_nr LIKE tsp01-rqident,
gd_destination LIKE rlgrap-filename,
gd_bytecount LIKE tst01-dsize,
gd_buffer TYPE string.
Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0.
INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.
CONSTANTS: c_dev LIKE sy-sysid VALUE 'DEV',
c_no(1) TYPE c VALUE ' ',
c_device(4) TYPE c VALUE 'LOCL'.
*START-OF-SELECTION.
START-OF-SELECTION.
Write statement to represent report output. Spool request is created
if write statement is executed in background. This could also be an
ALV grid which would be converted to PDF without any extra effort
WRITE 'Hello World'.
new-page.
commit work.
new-page print off.
IF sy-batch EQ 'X'.
PERFORM get_job_details.
PERFORM obtain_spool_id.
Alternative way could be to submit another program and store spool
id into memory, will be stored in sy-spono.
*submit ZSPOOLTOPDF2
to sap-spool
spool parameters %_print
archive parameters %_print
without spool dynpro
and return.
Get spool id from program called above
IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
PERFORM convert_spool_to_pdf.
PERFORM process_email.
if p_delspl EQ 'X'.
PERFORM delete_spool.
endif.
IF sy-sysid = c_dev.
wait up to 5 seconds.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ELSE.
SKIP.
WRITE:/ 'Program must be executed in background in-order for spool',
'request to be created.'.
ENDIF.
FORM obtain_spool_id *
FORM obtain_spool_id.
CHECK NOT ( gd_jobname IS INITIAL ).
CHECK NOT ( gd_jobcount IS INITIAL ).
SELECT * FROM tbtcp
INTO TABLE it_tbtcp
WHERE jobname = gd_jobname
AND jobcount = gd_jobcount
AND stepcount = gd_stepcount
AND listident <> '0000000000'
ORDER BY jobname
jobcount
stepcount.
READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
IF sy-subrc = 0.
message s004(zdd) with gd_spool_nr.
gd_spool_nr = wa_tbtcp-listident.
MESSAGE s004(zdd) WITH gd_spool_nr.
ELSE.
MESSAGE s005(zdd).
ENDIF.
ENDFORM.
FORM get_job_details *
FORM get_job_details.
Get current job details
CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
IMPORTING
eventid = gd_eventid
eventparm = gd_eventparm
external_program_active = gd_external_program_active
jobcount = gd_jobcount
jobname = gd_jobname
stepcount = gd_stepcount
EXCEPTIONS
no_runtime_info = 1
OTHERS = 2.
ENDFORM.
FORM convert_spool_to_pdf *
FORM convert_spool_to_pdf.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gd_spool_nr
no_dialog = c_no
dst_device = c_device
IMPORTING
pdf_bytecount = gd_bytecount
TABLES
pdf = it_pdf_output
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
CHECK sy-subrc = 0.
Transfer the 132-long strings to 255-long strings
LOOP AT it_pdf_output.
TRANSLATE it_pdf_output USING ' ~'.
CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
ENDLOOP.
TRANSLATE gd_buffer USING '~ '.
DO.
it_mess_att = gd_buffer.
APPEND it_mess_att.
SHIFT gd_buffer LEFT BY 255 PLACES.
IF gd_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
ENDFORM.
FORM process_email *
FORM process_email.
DESCRIBE TABLE it_mess_att LINES gd_recsize.
CHECK gd_recsize > 0.
PERFORM send_email USING p_email1.
perform send_email using p_email2.
ENDFORM.
FORM send_email *
--> p_email *
FORM send_email USING p_email.
CHECK NOT ( p_email IS INITIAL ).
REFRESH it_mess_bod.
Default subject matter
gd_subject = 'Subject'.
gd_attachment_desc = 'Attachname'.
CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
it_mess_bod = 'Message Body text, line 1'.
APPEND it_mess_bod.
it_mess_bod = 'Message Body text, line 2...'.
APPEND it_mess_bod.
If no sender specified - default blank
IF p_sender EQ space.
gd_sender_type = space.
ELSE.
gd_sender_type = 'INT'.
ENDIF.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_mess_bod
it_mess_att
using p_email
'Example .xls documnet attachment'
'PDF'
gd_attachment_name
gd_attachment_desc
p_sender
gd_sender_type
changing gd_error
gd_reciever.
ENDFORM.
FORM delete_spool *
FORM delete_spool.
DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
ld_spool_nr = gd_spool_nr.
CHECK p_delspl <> c_no.
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
spoolid = ld_spool_nr.
ENDFORM.
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
Send email
FORM send_file_as_email_attachment tables it_message
it_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
data: t_packing_list like sopcklsti1 occurs 0 with header line,
t_contents like solisti1 occurs 0 with header line,
t_receivers like somlreci1 occurs 0 with header line,
t_attachment like solisti1 occurs 0 with header line,
t_object_header like solisti1 occurs 0 with header line,
w_cnt type i,
w_sent_all(1) type c,
w_doc_data like sodocchgi1.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = it_attach[].
Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
Hope this resolves your query.
Reward all the helpful answers.
Regards -
Converting Smartform into pdf in encrypted format
Hi All,
I have a requirement to download smartform into pdf format. I have done this,but this pdf is editable with pdf editor tool.
is there any way to encrypt pdf data and downloading it? I find some FM's in forum but those are used to encrypt and decrypt the passwords etc....
Thanks in advance..
AnjiHi
SMART form to PDF
https://wiki.sdn.sap.com/wiki/display/Snippets/ConvertSmartformtoPDFformat
smartform to MAIL
https://wiki.sdn.sap.com/wiki/display/Snippets/SmartformtoMailasPDF+attachment -
Convert OTF to PDF and print PDF from Spool
Hi,
I have searched all the forums and service market place but could not find solution to my problem.
I am using Function module
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = p_spool
no_dialog = 'X'
dst_device = 'ISJB'
pdf_destination = 'S'
IMPORTING
pdf_bytecount = lv_bytecount
pdf_spoolid = lv_spoolid
otf_pagecount = lv_pagecount
btc_jobname = lv_jobname
btc_jobcount = lv_jobcount
TABLES
pdf = gt_pdf
EXCEPTIONS
err_no_otf_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_dstdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
this generates spool in SP01. Ideally it should generate a PDF spool file but it generates a BIN file of Format G_RAW. When I display the spool it displays all kinds of japanese characters which does not make sense,.
I setup printer ISJB with device type JPPDF (PDF converted for Japanese characters). Does any one know where the problem could be? Why I could not print the Spool in PDF?
Thank you,
JagadishHi,
check out this program which will convert spool to pdf
REPORT zsmartform_spool_g.
*************Types Declaration ****************************
TYPES : BEGIN OF gty_tab, " Spool Requests
rqident TYPE tsp01-rqident, " Spool request number
rqdoctype TYPE tsp01-rqdoctype, " Spool: document type
rqo1name TYPE tsp01-rqo1name, " TemSe object name
END OF gty_tab.
*********Work Area ****************************************
DATA: form_name TYPE rs38l_fnam, " Used to get the function module of Smartform
wa_outopt TYPE ssfcompop, " SAP Smart Forms: Smart Composer (transfer) options
gs_tab TYPE gty_tab. " Spool Requests
*******Internal Table Declarations ************************
DATA: gt_tab TYPE STANDARD TABLE OF gty_tab, " Spool Requests
gt_pdf TYPE STANDARD TABLE OF tline, " SAPscript: Text Lines
gt_spoolid TYPE tsfspoolid, " Table with Spool IDs
gt_otfdata TYPE ssfcrescl. " Smart Forms: Return value at end of form prnt
*********Variable Declarations ****************************
DATA: gv_bytecount TYPE i, "#EC NEEDED " PDF Byte Count
gv_file_name TYPE string, " File name
gv_file_path TYPE string, " File Path
gv_full_path TYPE string, " Path
gv_binfilesize TYPE i, " Bin File size
gv_rqident TYPE tsp01-rqident, " Spool request number
gv_name TYPE tst01-dname, " TemSe object name
gv_objtype TYPE rststype-type, " TemSe: Object type name
gv_type TYPE rststype-type. " TemSe: Object type name
START-OF-SELECTION.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZPDF_G'
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.
*Get Spool IDs
wa_outopt-tdnewid = 'X'.
wa_outopt-tddest = 'LP01'.
CALL FUNCTION form_name
EXPORTING
output_options = wa_outopt
user_settings = 'X'
IMPORTING
job_output_info = gt_otfdata
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.
*Assign the spool id
gt_spoolid = gt_otfdata-spoolids.
Generate spool and pdf for the output of the form
PERFORM sub_generate_spool_pdf.
END-OF-SELECTION.
*& Form sub_generate_spool_pdf
Generate Spool and PDF output
FORM sub_generate_spool_pdf .
DATA: ls_spoolid LIKE LINE OF gt_spoolid.
*----Get the Spool Number
CLEAR ls_spoolid.
READ TABLE gt_spoolid INTO ls_spoolid INDEX 1.
IF sy-subrc = 0.
gv_rqident = ls_spoolid.
ENDIF.
CLEAR gt_tab.
SELECT rqident rqdoctype rqo1name INTO TABLE gt_tab
FROM tsp01 WHERE rqident = gv_rqident.
IF sy-subrc = 0.
CLEAR gs_tab.
Get the TemSe: Object name into variable gv_name
READ TABLE gt_tab INTO gs_tab INDEX 1.
IF sy-subrc = 0.
gv_name = gs_tab-rqo1name.
ENDIF.
ENDIF.
CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
EXPORTING
authority = 'SP01'
client = sy-mandt
name = gv_name
part = 1
IMPORTING
type = gv_type
objtype = gv_objtype
EXCEPTIONS
fb_error = 1
fb_rsts_other = 2
no_object = 3
no_permission = 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.
Check if temse object name type is 'OTF' or 'LIST'
IF gv_objtype(3) = 'OTF'.
PERFORM get_otf_spool_in_pdf.
ELSE.
PERFORM get_abap_spool_in_pdf.
ENDIF.
Generate F4 functionality from spool to pdf
PERFORM write_pdf_spool_to_pc.
ENDFORM. " sub_generate_spool_pdf
*& Form get_abap_spool_in_pdf
Generate the Spool number
FORM get_abap_spool_in_pdf .
REFRESH gt_pdf.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gv_rqident
IMPORTING
pdf_bytecount = gv_bytecount
TABLES
pdf = gt_pdf
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " get_abap_spool_in_pdf
*& Form get_otf_spool_in_pdf
Generate OTF data from the Spool Number
FORM get_otf_spool_in_pdf .
REFRESH gt_pdf.
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gv_rqident
IMPORTING
pdf_bytecount = gv_bytecount
TABLES
pdf = gt_pdf
EXCEPTIONS
err_no_otf_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_dstdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
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. " get_otf_spool_in_pdf
*& Form write_pdf_spool_to_pc
Generate PDF format
FORM write_pdf_spool_to_pc .
CALL METHOD cl_gui_frontend_services=>file_save_dialog
CHANGING
filename = gv_file_name
path = gv_file_path
fullpath = gv_full_path
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 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.
----DOWNLOADING THE PDF DATA***
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = gv_binfilesize
filename = gv_full_path
filetype = 'BIN'
TABLES
data_tab = gt_pdf
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. " write_pdf_spool_to_pc -
Converting Smartform to PDF and send as email attachment
Hi
I want to send the Smartform to mail as PDF attachment.
I found the program in code gallery., it name was 'ZTEST_NREDDY_PDF_MAIL' .
I used this program and it send the Smartform to mail as PDF attachment but when open the pdf file it gave me error.
error : 'An unrecognized token Qq was found'.
Please help me out.
Thanks
AninaHi,
Following is the code logic:
Tables for OTF to PDF Conversion
DATA: g_t_docs TYPE STANDARD TABLE OF docs, " Table for Stored Document
g_t_lines TYPE STANDARD TABLE OF tline. " Table for Text lines
Objects to send mail.
DATA: g_t_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE, " SAPoffice: Description of Imported Object Components
g_t_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
g_t_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
g_t_contout LIKE solisti1 OCCURS 0 WITH HEADER LINE,
g_t_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE. " SAPoffice: Structure of the API Recipient List
Addresses (Business Address Services)
DATA: g_t_adrc LIKE adrc OCCURS 0,
g_t_adrc2 LIKE adrc OCCURS 0,
g_t_adrc3 LIKE adrc OCCURS 0,
g_t_adrc_wa TYPE adrc,
g_t_adrc2_wa TYPE adrc,
g_t_adrc3_wa TYPE adrc.
Sales Document: Partner
DATA: g_t_vbpa_wa TYPE vbpa.
E-Mail Addresses (Business Address Services)
DATA: g_t_adr6 LIKE adr6 OCCURS 0,
g_t_adr6_2 LIKE adr6 OCCURS 0,
g_t_adr6_wa TYPE adr6,
g_t_adr6_2_wa TYPE adr6.
DATA:
Work Area declarations
g_wa_objhead TYPE soli_tab, " Work Area for Objcont and Objhead as Table Type
g_wa_doc_chng TYPE sodocchgi1, " Work Area - Data of an object which can be changed
Variables declarations
g_lines_txt TYPE i,
g_lines_bin TYPE i,
g_email_id(40) VALUE '', " E-mail Address
PDF related data declarations
g_wa_job_output_info TYPE ssfcrescl, " Smart Forms: Return value at end of form printing
g_wa_control_parameters TYPE ssfctrlop,"#EC NEEDED " Smart Forms: Control structure
g_name TYPE string,
g_path TYPE string,
g_fullpath TYPE string,
g_filename TYPE string,
g_filter TYPE string,
g_bin_filesize TYPE i,
g_uact TYPE i,
g_guiobj TYPE REF TO cl_gui_frontend_services.
PERFORM f0100_download_pdf.
PERFORM f200_convert_to_pdf.
PERFORM f300_attach_and_mail_pdf.
*& Form f0100_download_pdf
To Download the PDF Format of SmartForm on
Presentation Server
FORM f0100_download_pdf. "#EC CALLED
Downloading PDF File
CREATE OBJECT g_guiobj.
CALL METHOD g_guiobj->file_save_dialog
EXPORTING
default_extension = 'pdf'
default_file_name = g_name
file_filter = g_filter
CHANGING
filename = g_name
path = g_path
fullpath = g_fullpath
user_action = g_uact.
IF g_uact = g_guiobj->action_cancel.
EXIT.
ENDIF.
MOVE g_fullpath TO g_filename.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = g_bin_filesize
filename = g_filename
filetype = 'BIN'
TABLES
data_tab = g_t_lines.
ENDFORM. "f0100_download_pdf
*& Form f0200_convert_to_pdf
To convert the SmartForm to PDF format
FORM f0200_convert_to_pdf . "#EC CALLED
CALL FUNCTION 'CONVERT_OTF_2_PDF'
IMPORTING
bin_filesize = g_bin_filesize
TABLES
otf = g_wa_job_output_info-otfdata
doctab_archive = g_t_docs
lines = g_t_lines.
CONCATENATE text-001 g_sales_order_no '.pdf' INTO g_name.
ENDFORM. " f0200_convert_to_pdf
*& Form f0300_attach_and_mail_pdf
To E-Mail the PDF form as an Attachment
FORM f0300_attach_and_mail_pdf . "#EC CALLED
Attachment
REFRESH: g_t_reclist,
g_t_objtxt,
g_t_objbin,
g_t_objpack.
CLEAR g_wa_objhead.
Create Message Body Title and Description
g_t_objtxt = g_name.
APPEND g_t_objtxt.
DESCRIBE TABLE g_t_objtxt LINES g_lines_txt.
READ TABLE g_t_objtxt INDEX g_lines_txt.
g_wa_doc_chng-obj_name = g_name.
g_wa_doc_chng-expiry_dat = sy-datum + 10.
g_wa_doc_chng-obj_descr = g_name.
g_wa_doc_chng-sensitivty = 'F'.
g_wa_doc_chng-doc_size = g_lines_txt * 255.
Main Text
CLEAR g_t_objpack-transf_bin.
g_t_objpack-head_start = 1.
g_t_objpack-head_num = 0.
g_t_objpack-body_start = 1.
g_t_objpack-body_num = g_lines_txt.
g_t_objpack-doc_type = 'RAW'.
APPEND g_t_objpack.
Attachment (PDF-Attachment)
g_t_objpack-transf_bin = 'X'.
g_t_objpack-head_start = 1.
g_t_objpack-head_num = 0.
g_t_objpack-body_start = 1.
Convert TLINE to SOLISTI1
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_src = 134
line_width_dst = 255
TABLES
content_in = g_t_lines
content_out = g_t_contout
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE s000(0k) WITH text-002.
EXIT.
ENDIF.
Create Message Attachment
APPEND LINES OF g_t_contout[] TO g_t_objbin[].
DESCRIBE TABLE g_t_objbin LINES g_lines_bin.
READ TABLE g_t_objbin INDEX g_lines_bin.
g_t_objpack-doc_size = g_lines_bin * 255 .
g_t_objpack-body_num = g_lines_bin.
g_t_objpack-doc_type = 'PDF'.
g_t_objpack-obj_name = text-003.
g_t_objpack-obj_descr = text-004.
APPEND g_t_objpack.
CLEAR g_t_reclist.
g_t_reclist-receiver = g_email_id.
g_t_reclist-rec_type = 'U'.
APPEND g_t_reclist.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = g_wa_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = g_t_objpack
object_header = g_wa_objhead
contents_bin = g_t_objbin
contents_txt = g_t_objtxt
receivers = g_t_reclist.
ENDFORM. " f0300_attach_and_mail_pdf -
Converting Smartform into PDF preview layout
Hi ABAP experts,
We have converted an existing invoice layout smart form into PDF layout in print preview mode. However, we have an issue with PDF layout alignment. Earlier, it used to print the documents correctly (layout is aligned properly at the middle of the page). But when use this 'PDF' preview layout (triggered from smart form) the layout is left aligned/ larger right margin (but not at the middle).
We have gone through the existing forum links on this PDF layout generating from smart form. But no luck on this left alignment issue. Do we need to modify the OTF data that is being populated in the layout. Can it be modifed with the position of the layout dynamically. Please advise.
Technical team has used "CONVERT_OTF_2_PDF" to populate the OTF data.
In SAP note # 323736 (issued in 2006), the below limitation was mentioned. But do we have any way to resolve this page alignment issue.
Page size for SAPscript/SmartForms: PDF conversion uses the page format from the form definition as page size for the PDF document. If this has been defined larger than the page size that is actually used (for example for INCH12, INCH11 and so on), a reduced document or a larger right margin are the
result when you view/print in Acrobat Reader.
Thanks in advance.
Regards,
SatyaHi Satya,
'We tried that option of "PDF!" but it didn't work for this smart form. Do we need to include/activate any option for this in the smart form.'..What do you mean by it didn't work for this smartform.?
Execute your smartform and when you are in the print preview mode of the form means you get the output, then type PDF! in the command and hit ENTER. A popup will get displayed if you are using windows 7
or Allow and decline type of radiobutton option will be displayed if you are using Windows XP. So just click Allow and your smartform output will be displayed in pdf. Now you can save the pdf output file while clicking the save option in PDF. Your smartform output will be aligned properly in the PDF.
You don't need any activation or any FM for converting the output in pdf for this.
Basically, we do this to attach the smartform output in test plan.
NOTE: This is for only to get the output in PDF while you are in Print preview of the form.
Regards
Syed -
Making spool, convert it into PDF and send that PDf throgh EMAIl
Hi,
In my making ALV report. In that i want to make the spool and then convert it into the pdf and send mail to the recepient.
AtulHi,
please try the following code. It works for me.
DATA : itab LIKE tline OCCURS 0 WITH HEADER LINE.
DATA : file_name TYPE string.
DATA : path LIKE pcfile-path.
DATA : extension(5) TYPE c.
DATA : name(100) TYPE c.
DATA:receiver TYPE somlreci1-receiver ,
p_file LIKE rlgrap-filename.
declarations for PDF convertion
DATA: path1 TYPE string ,
fullpath TYPE string.
DATA :textlines LIKE tline OCCURS 100 WITH HEADER LINE.
DATA otf LIKE itcoo OCCURS 1000 WITH HEADER LINE.
DATA it_lines LIKE tline OCCURS 100 WITH HEADER LINE.
DATA options LIKE itcpo.
DATA header LIKE thead.
DATA result LIKE itcpp.
DATA: bin_filesize TYPE i.
fullpath type string.
DATA: docdata LIKE sodocchgi1,
objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objhex LIKE solix OCCURS 10 WITH HEADER LINE,
reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
DATA: tab_lines TYPE i,
doc_size TYPE i,
att_type LIKE soodk-objtp.
DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.
DATA: filesize TYPE i,
convcount TYPE i,
cancel(1).
textlines-tdformat = '*'.
textlines-tdline = 'Hello Hao'.
APPEND textlines.
options-tdgetotf = 'X'.
options-tdnoprev = 'X'.
CALL FUNCTION 'PRINT_TEXT'
EXPORTING
APPLICATION = 'TX'
ARCHIVE_INDEX = ' '
ARCHIVE_PARAMS = ' '
DEVICE = 'PRINTER'
dialog = ' '
header = header
OPTIONS = options
IMPORTING
NEW_ARCHIVE_PARAMS =
RESULT = RESULT
tables
lines = textlines
otfdata = otf
EXCEPTIONS
CANCELED = 1
DEVICE = 2
FORM = 3
OPTIONS = 4
UNCLOSED = 5
UNKNOWN = 6
FORMAT = 7
TEXTFORMAT = 8
COMMUNICATION = 9
BAD_PAGEFORMAT_FOR_PRINT = 10
OTHERS = 11
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 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = filesize
TABLES
otf = otf
lines = it_lines
EXCEPTIONS
err_conv_not_possible = 1
err_bad_otf = 2.
fullpath = 'C:/foldername/test.pdf'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = bin_filesize
filename = fullpath
filetype = 'BIN'
APPEND = ' '
CODEPAGE = ' '
NO_BYTEORDER_MARK = ' '
IMPORTING
FILELENGTH = c
TABLES
data_tab = it_lines
FORMAT_TAB =
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6.
*filename = fullpath.
CLEAR docdata.
REFRESH objpack.
CLEAR objpack.
REFRESH objhead.
REFRESH objtxt.
CLEAR objtxt.
REFRESH objbin.
CLEAR objbin.
REFRESH objhex.
CLEAR objhex.
REFRESH reclist.
CLEAR reclist.
REFRESH listobject.
CLEAR listobject.
CLEAR tab_lines.
CLEAR doc_size.
CLEAR att_type.
Set Variables
docdata-obj_name = 'Tst'.
docdata-obj_descr = 'Testing'.
reclist-receiver = give the mail id.
reclist-rec_type = 'U'.
APPEND reclist.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = fullpath
filetype = 'BIN'
TABLES
data_tab = itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
path = fullpath.
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
complete_filename = path
CHECK_DOS_FORMAT =
IMPORTING
DRIVE =
extension = extension
name = name
NAME_WITH_EXT =
PATH =
EXCEPTIONS
invalid_drive = 1
invalid_extension = 2
invalid_name = 3
invalid_path = 4
OTHERS = 5
DATA : pos TYPE i.
DATA : len TYPE i.
Loop And Put Data
LOOP AT itab.
pos = 255 - len.
IF pos > 134. "length of pdf_table
pos = 134.
ENDIF.
objbin+len = itab(pos).
len = len + pos.
IF len = 255. "length of out (contents_bin)
APPEND objbin.
CLEAR: objbin, len.
IF pos < 134.
objbin = itab+pos.
len = 134 - pos.
ENDIF.
ENDIF.
ENDLOOP.
IF len > 0.
APPEND objbin.
ENDIF.
Packing Info For Text Data
DESCRIBE TABLE objtxt LINES tab_lines.
READ TABLE objtxt INDEX tab_lines.
docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
CLEAR objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'TXT'.
APPEND objpack.
Packing Info Attachment
name = extension.
DESCRIBE TABLE objbin LINES tab_lines.
READ TABLE objbin INDEX tab_lines.
objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = name.
objpack-obj_name = 'ATTACHMENT'.
objpack-obj_descr = name.
APPEND objpack.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = docdata
put_in_outbox = 'X'
commit_work = 'X' "used from rel. 6.10
TABLES
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = objtxt
receivers = reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8
IF sy-subrc <> 0.
MESSAGE ID 'SO' TYPE 'S' NUMBER '023'
WITH docdata-obj_name.
ENDIF.
Keerthi
Maybe you are looking for
-
ICal not syncing to iPhone anymore!
I just plugged my phone in to my MacBookPro and everything but my ical synced. I went into advanced settings on the Mac and unchecked and rechecked sync all calendars; apply; and sync and still nothing. When I go into 'calendar' on my menu bar in ica
-
I'm going to install a 120gb SSD in my 27" iMac core i7. Currently I have a 2TB Hitatchi drive installed. I would like to install OSX as well as all my apps on the SSD and then keep all my user files on the 2TB drive. I'm trying to figure out the bes
-
It would seem I need a "Thread URL" so I can send a message to the people who will be reading the "Details of your query", so here is my post.
-
BlazeDS, RemoteService on Linux
Hi Folks. I have installed the Flex Compiler as standalone (meaning not the eclipse plugin) on Linux. Compiling a simple Flex application works fine. My Problem: I can not access my BlazeDS remoteservice. With tracing, I found out, that the Flex appl
-
Please recommend a good sleeve for the pismo
Hi, Can any of you loving pismo owners please recommend a good sleeve for our beloved pismos. I'm looking for one that would fit the pismo pretty much like a glove, so it won't slide and then I can put the pismo in an another bag. Thanks so much for