cancel
Showing results for 
Search instead for 
Did you mean: 

Can we attach a PDF file to a Smartform

Former Member
0 Kudos

Hi Friends,

I have a typical situation in which I need to attach a PDF file to the output of the smartform. Can it be done ? If yes, then how. Kindly send me your valuable answers with correct examples.

Or

The PDF attachement can be printed alongwith the smartform?

Regard,

Pradeep

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Answers (2)

Answers (2)

Former Member
0 Kudos

hi ,

we can attach the pdf file, pls go throug this example.

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.

hope this will solve u r proble. reward if useull,dontforget.

thanks

fareedas

Former Member
0 Kudos

hi,

if u want to convert whole output to pdf than do this thing:

first convert tat output into PDF format and then attach the file by

using FM .. SO_NEW_DOCUMENT_ATT_SEND_API

thanks

reward points if useful