cancel
Showing results for 
Search instead for 
Did you mean: 

smartform

Former Member
0 Kudos

hi,

How to convert form into pdf to attach with mail.can anybody explain me in detail.

regards,

jak

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi ,

Please see my code for sending mail attachment of samrtform converted to PDF format using CONVERT_OTF function module .

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

ARCHIVE_INDEX = ' '

COPYNUMBER = 0

ASCII_BIDI_VIS2LOG = ' '

pdf_delete_otftab = ' '

IMPORTING

bin_filesize = v_binsize

BIN_FILE =

TABLES

otf = it_otf[]

lines = it_line[]

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.

*Send converted pdf to email as attachment .

DATA :wa_buffer TYPE string, "To convert from 132 to 255

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

v_lines_txt TYPE i,

v_lines_bin TYPE i,

wa_doc_chng TYPE sodocchgi1,

w_data TYPE sodocchgi1,

wa_objhead TYPE soli_tab,

I_objbin type table of solix with header line.

data:objbin type table of solix with header line.

REFRESH: i_reclist,

i_objtxt,

i_objbin,

i_objpack.

CLEAR wa_objhead.

i_objbin] = objbin[.

Create Message Body Title and Description

i_objtxt = 'test with pdf-Attachment!'.

APPEND i_objtxt.

DESCRIBE TABLE i_objtxt LINES v_lines_txt.

READ TABLE i_objtxt INDEX v_lines_txt.

wa_doc_chng-obj_name = 'smartform'.

wa_doc_chng-expiry_dat = sy-datum + 10.

wa_doc_chng-obj_descr = 'smartform'.

wa_doc_chng-sensitivty = 'F'.

wa_doc_chng-doc_size = v_lines_txt * 255.

Main Text

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.

Attachment (pdf-Attachment)

i_objpack-transf_bin = 'X'.

i_objpack-head_start = 1.

i_objpack-head_num = 0.

i_objpack-body_start = 1.

DESCRIBE TABLE i_objbin LINES v_lines_bin.

READ TABLE i_objbin INDEX v_lines_bin.

i_objpack-doc_size = v_lines_bin * 255 .

i_objpack-body_num = v_lines_bin.

i_objpack-doc_type = 'PDF'.

i_objpack-obj_name = 'smart'.

i_objpack-obj_descr = 'test'.

APPEND i_objpack.

CLEAR i_reclist.

i_reclist-receiver = 'shishupal.reddy@gmail.com'.

i_reclist-rec_type = 'U'.

APPEND i_reclist.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = wa_doc_chng

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = i_objpack

object_header = wa_objhead

contents_bin = i_objbin

contents_txt = i_objtxt

contents_hex = i_objbin

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.

WRITE:/ 'Error When Sending the File', sy-subrc.

ELSE.

WRITE:/ 'Mail sent'.

ENDIF.

I am getting sy-subrc = 3 and document could nto be send .

Please provide me the correct place where iam commiting mistake in the above code .

Regards,

santosh thorat

Posts: 326

Registered: 12/13/05

Forum Points: 496

Re: Samrtform sending to mail as pdf attachment Issue

Posted: Nov 30, 2007 5:25 PM in response to: shishupalreddy ... E-mail this message Reply

Hi,

The problem is this line.

i_objpack-doc_type = 'PDF'. wrong,

correct it to i_objpack-doc_type = 'OTF'.

regards,

Santosh Thorat

shishupalreddy ...

Posts: 472

Registered: 9/5/06

Forum Points: 194

Re: Samrtform sending to mail as pdf attachment Issue

Posted: Dec 3, 2007 11:21 AM in response to: santosh thorat E-mail this message Reply

hI Santosh,

Thanks for the reply ...

I corrected as you said , but again i am getting the same error

sy-subrc = 2 .

Document could nto be sent.

Please help .....urgent

thanks

Naresh Nelapatla

Posts: 3,375

Registered: 8/24/07

Forum Points: 3,634

Re: Samrtform sending to mail as pdf attachment Issue

Posted: Dec 3, 2007 11:25 AM in response to: shishupalreddy ... E-mail this message Reply

Procedure

When we activate the Smartform the system generates a Function Module. The function module name we can get from Smartfrom screen from menubar

“Environment => Function Module_Name” . In a report we can get this Function module name by calling a Function Module standard SSF_FUNCTION_MODULE_NAME. This function module at runtime calls the FM generated by smartform, which in turn is then used to pass data from the report to Smartform. In the report given below the FM generated is “ /1BCDWB/SF00000152 ”. In this FM we can see CONTROL_PARAMETERS in import tab. This is of type SSFCTRLOP. We need to set the GETOTF of this to be ‘X’. Setting this field will activate the OTF field in smartform.

In export tab of the FM generated by smartform we can see a parameter JOB_OUTPUT_INFO which is of type SSFCRESCL. The SSFCRESCL is a structure of having one of fields as OTFDATA. OTFDATA in turn is a table of type ITCOO. ITCOO has two fields TDPRINTCOM and TDPRINTPAR. TDPRINTCOM represents command line of OTF format data and TDPRINTPAR contains command parameters of OTF format data.

In every Smartform output in OTF format, TDPRINTCOM begins and ends with ‘//’. ‘EP’ represents the end-of-page value for TDPRINTCOM field.

In addition we need to set few fields at the place where we call this FM(generated by smartform) in our program. While calling this FM we should set control_parameters, output_options, user_settings and job_putput_info fields as shown in program.

Once these settings are done we can call Function Module CONVERT_OTF to convert the OTF data of smartfrom output to PDF data format. Once these are done we can call method “cl_gui_fronted_services=>file_save_dialog” to specify the directory path where we want to save the output PDF file. After this we can call Function Module GUI_DOWNLOAD to download the PDF file on our local system.

Here is a sample code of program to perform the function.

SAMPLE CODE

&----


*& Report ZAMIT_SMART_FORM_PDF *

*& *

&----


*& *

*& *

&----


REPORT ZAMIT_SMART_FORM_PDF .

data: carr_id type sbook-carrid,

cparam type ssfctrlop,

outop type ssfcompop,

fm_name type rs38l_fnam.

DATA: tab_otf_data TYPE ssfcrescl,

pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE,

tab_otf_final TYPE itcoo OCCURS 0 WITH HEADER LINE,

file_size TYPE i,

bin_filesize TYPE i,

FILE_NAME type string,

File_path type string,

FULL_PATH type string.

parameter: p_custid type scustom-id default 1.

select-options: s_carrid for carr_id default 'LH' to 'LH'.

parameter: p_form type tdsfname default 'ZAMIT_SMART_FORM'.

data: customer type scustom,

bookings type ty_bookings,

connections type ty_connections.

start-of-selection.

suppressing the dialog box for print preview****************************

outop-tddest = 'LP01'.

cparam-no_dialog = 'X'.

cparam-preview = SPACE.

cparam-getotf = 'X'.

select single * from scustom into customer where id = p_custid.

check sy-subrc = 0.

select * from sbook into table bookings

where customid = p_custid

and carrid in s_carrid

order by primary key.

select * from spfli into table connections

for all entries in bookings

where carrid = bookings-carrid

and connid = bookings-connid

order by primary key.

call function 'SSF_FUNCTION_MODULE_NAME'

exporting formname = p_form

variant = ' '

direct_call = ' '

importing fm_name = fm_name

exceptions no_form = 1

no_function_module = 2

others = 3.

if sy-subrc 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

exit.

endif.

calling the generated function module

call function fm_name

exporting

archive_index =

archive_parameters =

control_parameters = cparam

mail_appl_obj =

mail_recipient =

mail_sender =

output_options = outop

user_settings = SPACE

bookings = bookings

customer = customer

connections = connections

importing

document_output_info =

job_output_info = tab_otf_data

job_output_options =

exceptions formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

others = 5.

if sy-subrc 0.

error handling

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

tab_otf_final] = tab_otf_data-otfdata[.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

ARCHIVE_INDEX = ' '

COPYNUMBER = 0

ASCII_BIDI_VIS2LOG = ' '

IMPORTING

bin_filesize = bin_filesize

BIN_FILE =

TABLES

otf = tab_otf_final

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

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

path = FILE_PATH

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

************downloading the converted PDF data to your local PC*******

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = bin_filesize

filename = 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'

IMPORTING

filelength = file_size

TABLES

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

ENDIF.

refer this thread

also refer these

https://www.sdn.sap.com/irj/sdn/advancedsearch?query=smartform%20to%20pdf%20%20%20&cat=sdn_forums

Answers (1)

Answers (1)

Former Member
0 Kudos

hi,

pls refer this program and if u want material/tutorial on this concept dopdown ur mail_id in my inbox ok..

&----


*& Report Z50818_TEST_SMARTFORM

*&

&----


*&

*&

&----


REPORT z50818_test_smartform.

DATA: formname TYPE tdsfname,

fm_name TYPE rs38l_fnam,

control_parameters TYPE ssfctrlop,

job_output_info TYPE ssfcrescl,

otf_data TYPE tsfotf,

bin_filesize TYPE i,

otf TYPE TABLE OF itcoo WITH HEADER LINE,

doctab_archive TYPE TABLE OF docs WITH HEADER LINE,

lines TYPE TABLE OF tline WITH HEADER LINE.

INITIALIZATION.

formname = 'Z50818_TEST_SMARTFROM'.

START-OF-SELECTION.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = formname

  • VARIANT = ' '

  • DIRECT_CALL = ' '

IMPORTING

fm_name = fm_name

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

control_parameters-no_dialog = 'X'.

  • control_parameters-preview = ''.

control_parameters-getotf = 'X'.

CALL FUNCTION fm_name

EXPORTING

  • ARCHIVE_INDEX = ARCHIVE_INDEX

  • ARCHIVE_INDEX_TAB = ARCHIVE_INDEX_TAB

  • ARCHIVE_PARAMETERS = ARCHIVE_PARAMETERS

control_parameters = control_parameters

  • MAIL_APPL_OBJ = MAIL_APPL_OBJ

  • MAIL_RECIPIENT = MAIL_RECIPIENT

  • MAIL_SENDER = MAIL_SENDER

  • OUTPUT_OPTIONS = OUTPUT_OPTIONS

  • USER_SETTINGS = 'X'

IMPORTING

  • DOCUMENT_OUTPUT_INFO = DOCUMENT_OUTPUT_INFO

job_output_info = job_output_info

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

otf_data[] = job_output_info-otfdata[].

CALL FUNCTION 'CONVERT_OTF_2_PDF'

  • EXPORTING

  • USE_OTF_MC_CMD = 'X'

  • ARCHIVE_INDEX = ARCHIVE_INDEX

IMPORTING

bin_filesize = bin_filesize

TABLES

otf = otf_data[]

doctab_archive = doctab_archive[]

lines = lines

EXCEPTIONS

ERR_CONV_NOT_POSSIBLE = 1

ERR_OTF_MC_NOENDMARKER = 2

OTHERS = 3

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

DATA: filename TYPE string.

filename = 'c:\test\smart.pdf'.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = bin_filesize

filename = filename

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

TABLES

data_tab = lines[]

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

DATA: document_data LIKE sodocchgi1 ,

contents_txt TYPE TABLE OF solisti1 WITH HEADER LINE,

contents_bin TYPE TABLE OF solisti1 WITH HEADER LINE,

tab_lines TYPE i,

packing_list TYPE TABLE OF sopcklsti1 WITH HEADER LINE,

OBJECT_HEADER type table of SOLISTI1 with header line,

RECEIVERS TYPE TABLE OF SOMLRECI1 WITH HEADER LINE,

l_str(255) ,

v1 TYPE i,

v2 TYPE i,

v3 type i.

CONSTANTS: c_raw TYPE so_obj_tp VALUE 'RAW',

c_pdf TYPE so_obj_tp VALUE 'PDF',

c_255 TYPE i VALUE 255,

c_134 TYPE i VALUE 134,

C_X TYPE C VALUE 'X',

C_U TYPE C VALUE 'U'.

document_data-obj_name = 'EMAIL'.

document_data-obj_descr = 'subject'.

contents_txt = 'THIS IS first line DATA'.

APPEND contents_txt.

CLEAR contents_txt.

contents_txt = 'THIS IS second line DATA'.

APPEND contents_txt.

CLEAR contents_txt.

APPEND contents_txt.

APPEND contents_txt.

DESCRIBE TABLE contents_txt LINES tab_lines.

READ TABLE contents_txt INDEX tab_lines.

  • document_data-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( contents_txt ).

document_data-doc_size = tab_lines .

CLEAR packing_list-transf_bin.

packing_list-head_start = 1.

packing_list-head_num = 0.

packing_list-body_start = 1.

packing_list-body_num = tab_lines.

packing_list-doc_type = c_raw.

packing_list-doc_size = document_data-doc_size.

APPEND packing_list.

LOOP AT lines.

CLEAR l_str.

l_str+0(2) = lines-tdformat.

l_str+2(132) = lines-tdline.

v2 = v1 + c_134.

IF v2 LE c_255.

contents_bin-line+v1(c_134) = l_str. v1 = v2.

ELSE.

v3 = v2 - c_255.

v2 = c_255 - v1.

IF NOT v2 IS INITIAL.

contents_bin-linev1(v2) = l_str0(v2).

ENDIF.

APPEND contents_bin.

CLEAR contents_bin.

v1 = v3.

v3 = 134 - v1.

IF NOT v1 IS INITIAL.

contents_bin-line0(v1) = l_strv3(v1).

ENDIF.

ENDIF.

ENDLOOP.

APPEND contents_bin.

CLEAR contents_bin.

DESCRIBE TABLE contents_bin LINES tab_lines.

READ TABLE contents_bin INDEX tab_lines.

OBJECT_HEADER = 'objhead'.

APPEND OBJECT_HEADER.

packing_list-transf_bin = c_x.

packing_list-head_start = 1.

packing_list-head_num = 1.

packing_list-body_start = 1.

packing_list-body_num = tab_lines.

packing_list-doc_type = c_pdf.

packing_list-obj_name = 'text1'.

packing_list-obj_descr = 'filename'.

packing_list-doc_size = tab_lines * 255 + STRLEN( contents_bin ).

APPEND packing_list.

RECEIVERS-receiver = 'FAREEDAS@INTELLIGROUP.COM'.

RECEIVERS-rec_type = c_u.

APPEND RECEIVERS.

CLEAR RECEIVERS.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = document_data

PUT_IN_OUTBOX = 'X'

  • SENDER_ADDRESS = SY-UNAME

  • SENDER_ADDRESS_TYPE = 'B'

COMMIT_WORK = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID = NEW_OBJECT_ID

  • SENDER_ID = SENDER_ID

TABLES

packing_list = packing_list

OBJECT_HEADER = OBJECT_HEADER

CONTENTS_BIN = CONTENTS_BIN

CONTENTS_TXT = CONTENTS_TXT

  • CONTENTS_HEX = CONTENTS_HEX

  • OBJECT_PARA = OBJECT_PARA

  • OBJECT_PARB = OBJECT_PARB

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

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

reward points if usefull to u .dont forget.

thanks & Regards

fareedas