Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Mailing a Smartforms?

Former Member
0 Kudos

Hello Experts,

I have a requirement that i have to generate a smartform and mail it to the vendors mail id.

Please help me with a sample code.

I have developed a code but it is not working.

Following is the code.

After generating the smartforms I have written the following code for mail.

i_otf[] = job_output-otfdata[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

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 <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

LOOP AT i_tline.

  • Replacing space by ~

TRANSLATE i_tline USING ' ~'.

CONCATENATE w_buffer i_tline INTO w_buffer.u201D_buffer type string

ENDLOOP.

  • Replacing ~ by space

TRANSLATE w_buffer USING '~ '.

DO.

i_record = w_buffer.

  • Appending 255 characters as a record

APPEND i_record.u201D i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE

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[].u201Di_objbin LIKE solisti1 OCCURS 0

DESCRIBE TABLE i_objbin LINES v_lines_bin.

  • Object with main text of the mail.

i_objtxt = 'Find attached the output of the smart form.'.

APPEND i_objtxt.

i_objtxt = 'Regards,'.

APPEND i_objtxt.

i_objtxt = 'Fi Team'.

APPEND i_objtxt.

DESCRIBE TABLE i_objtxt LINES v_lines_txt.

  • Document information.

w_doc_chng-obj_name = 'Smartform'.

w_doc_chng-expiry_dat = sy-datum + 10.

w_doc_chng-obj_descr = 'Smart form output'.

w_doc_chng-sensitivty = 'F'. "Functional object

w_doc_chng-doc_size = v_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 = v_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 = v_lines_bin.

i_objpack-doc_type = 'PDF'.

i_objpack-obj_name = 'Smartform'.

CONCATENATE 'Smartform_output' '.pdf'

INTO i_objpack-obj_descr.

i_objpack-doc_size = v_lines_bin * 255.

APPEND i_objpack.

  • Document information.

CLEAR i_reclist.

  • e-mail receivers.

i_reclist-receiver = receiver.

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

else.

write 'message sent'.

ENDIF.

endtry.

endloop.

Please help me coz this not working.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

First convert the smartform output into PDF format using the FM.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

IMPORTING

BIN_FILESIZE = BINFILE

TABLES

otf = datab

lines = pdftab

now you can send that output as an attachment in a mail, for details please refer to the given code.

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.

ld_attdescription = p_attdescription.

ld_attfilename = p_filename

w_doc_data-doc_size = 1.

  • 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[] = pit_attach[].

  • Describe the body of the message

DESCRIBE TABLE it_message LINES t_packing_list-body_num.

t_packing_list-doc_type = 'RAW'.

APPEND t_packing_list.

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

Hope it helps.

Regards,

Rajesh Kumar

7 REPLIES 7

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

HI,

Hope this code solves your problem.

REPORT ZTEST_PDF_MAIL.

  • 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,

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

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

FORMNAME = 'ZTEST'

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'

IMPORTING

JOB_OUTPUT_INFO = W_RETURN

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

IMPORTING

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 <> 0.

ENDIF.

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.

  • Attachment

REFRESH: I_RECLIST,

I_OBJTXT,

I_OBJBIN,

I_OBJPACK.

CLEAR WA_OBJHEAD.

I_OBJBIN[] = I_RECORD[].

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

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.

If you want to send some text as Body of the Mail then follow this once

when u r callin the FM'SO_NEW_DOCUMENT_ATT_SEND_API1'.. points to remember

1.u have to pass the body of content in table CONTENTS_TXT(ia m using I_OBJBIN) (each line a record) then. suppose i have appended 11 records to the table CONTENTS_TXT .

2.PACKING_LIST(iam usign I_OBJPACK) table u ahve to append a redord as follows

I_OBJPACK-TRANSF_BIN = ' '.

I_OBJPACK-HEAD_START = 000000000000001.

I_OBJPACK-HEAD_NUM = 000000000000001.

I_OBJPACK-BODY_START = 000000000000002

I_OBJPACK-BODY_NUM = 000000000000010.

I_OBJPACK-DOC_TYPE = 'RAW'.

append I_OBJPACK-.

by the above code system treat the first line in table I_OBJBIN as header and the 2nd line to 10 lines tread as body.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = WA_DOC_CHNG

PUT_IN_OUTBOX = 'X'

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.

Regards,

Pavan.

0 Kudos

Hello Pavan,

Actualy i have now another requirement that I have to fax a smartforms to a vendor address.

Please provide me with a sample code as attachment.

0 Kudos

Hi,

Please close this post first and raise a new post with your new query. You cannot post two quiries in a single post.

Regards,

Pavan.

Former Member
0 Kudos

If your requirement is only to send a Smartform via mail to Vendor Then you can use parameters

MAIL_RECIPIENT and MAIL_SENDER which are available in Smartform as Standard parameters

Thanks

Sagar

Former Member
0 Kudos

Hi,

First convert the smartform output into PDF format using the FM.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

IMPORTING

BIN_FILESIZE = BINFILE

TABLES

otf = datab

lines = pdftab

now you can send that output as an attachment in a mail, for details please refer to the given code.

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.

ld_attdescription = p_attdescription.

ld_attfilename = p_filename

w_doc_data-doc_size = 1.

  • 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[] = pit_attach[].

  • Describe the body of the message

DESCRIBE TABLE it_message LINES t_packing_list-body_num.

t_packing_list-doc_type = 'RAW'.

APPEND t_packing_list.

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

Hope it helps.

Regards,

Rajesh Kumar

Former Member
0 Kudos

This message was moderated.