cancel
Showing results for 
Search instead for 
Did you mean: 

How to write mail body for PO through message output (transaction:ME9F)

Former Member
0 Kudos

Hi friends,

I have a Purchase Order and I am mailing it to my e-mail address through message output (ME9F) and my requirement is, I have to write something in mail body of this mail.

In driver program i am using function module:

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = tnapr-sform

IMPORTING

fm_name = lv_fm_name <b>----->"This returns FM name"

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE i006. "Information message on error cases

ELSE.

The return FM is called for futher processing:

CALL FUNCTION lv_fm_name

EXPORTING

control_parameters = lwa_control_parameters

mail_recipient = lwa_recipient

mail_sender = lwa_sender

output_options = lwa_composer_param

user_settings = space

i_ekko = pr_wa_ekko

i_pekko = pr_wa_pekko

i_nast = pr_wa_nast

TABLES

t_xekpa = pr_i_xekpa "MSGPA entries

t_xekpo = pr_i_xekpo "PEKPO entries

t_xpekpo = pr_i_xpekpo "PEKPO entries

t_xeket = pr_i_xeket "EKET entries

t_xekkn = pr_i_xekkn "EKKN entries

t_xekek = pr_i_xekek "EKEK entries

t_xekeh = pr_i_xekeh "EKEH entries

t_xaend = pr_i_xaend "XAEND entries

t_xtkomv = pr_i_xtkomv. "KOMV entries

Please help and mail to me at: sunil.srivastava@capgemini.com

Thanks in Advance.

Sunil Srivastava.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi sunil

For sending a form as an mail attachment,you need to make use of the function module 'SO_NEW_DOCUMENT_ATT_SEND_API1'.

Lemme know whether u wanna send it as an attachment or as an email stating the subject header and body of the mail coz to achieve this u need to create ur own FM .

Regards

Zarina

Former Member
0 Kudos

Hi zarina,

ya i have the same requirement that u stated, could u help me in this.

and secondly i am using the same FM as u suggested but Created PDF is not readble i.e all binary data is there.

thanks in advance

waiting for ur reply.

Former Member
0 Kudos

Hi

Just check with this code whether u r doing the same.

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.

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 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 = 'Zarina'.

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.

SELECT SINGLE ADDRNUMBER

SMTP_ADDR

FROM ADR6

INTO CORRESPONDING FIELDS OF WA_ADR6 WHERE ADDRNUMBER = WA_LFA1-ADRNR.

IF SY-SUBRC = 0.

  • e-mail receivers.

I_RECLIST-RECEIVER = WA_ADR6-SMTP_ADDR.

I_RECLIST-EXPRESS = 'X'.

I_RECLIST-REC_TYPE = 'U'. "Internet address

APPEND I_RECLIST.

ENDIF.

  • Sending mail.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = W_DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = '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.

Former Member
0 Kudos

Hi Zarina,

Thanks for replying.

i am getting attachment as pdf but the problem is when i try to open it i get error:

<b>"not supported file type or file has been damaged or not correctly decoded"</b>

i have coded same only one change becuse i was getting dump

while calling FM

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

at the place of:

CONTENTS_BIN = I_OBJBIN

i have done:

CONTENTS_HEX = I_OBJBIN

Please reply..

Former Member
0 Kudos

Hi sunil

Try using this code,hope it should not give u that error.

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.

  • 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 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 = 'Zarina'.

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 = 'zareena.ali@gmail.com'.

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'

COMMIT_WORK = '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.

Regards

Zarina

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi sunil,

Just go through this hope u can.

Step1:

Call the function module of the smartform and pass the final internal table (output table) into the form interface, also exporting the control parameters output options and user settings importing the structure job_output_info and transfer the contents of STRUC_JOB_OUTPUT_INFO-OTFDATA[] into an internal table I_OTFDATA[] which contains the records in OTF format.

Sample Code

CALL FUNCTION v_function_module

EXPORTING

CONTROL_PARAMETERS = STRUC_SSFCTRLOP

OUTPUT_OPTIONS = STRUC_OUTPUT_OPTIONS

USER_SETTINGS = C_NO

IMPORTING

JOB_OUTPUT_INFO = STRUC_JOB_OUTPUT_INFO

TABLES

p_write_file = i_write_file

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

USER_CANCELED = 4

OTHERS = 5 .

Transferring the data into an internal table

I_OTFDATA[] = STRUC_JOB_OUTPUT_INFO-OTFDATA[].

Step 2:

Creation of the document to be sent .Populate the exporting structure doc_chng with the text containing the name of the document and the calculated document size and also populate the table objtxt .

Sample Code

doc_chng-obj_name = text-001. "'ACCOUNT_STATEMENT'.

doc_chng-obj_descr = text-001. "'ACCOUNT_STATEMENT'.

objtxt = text-001. "'ACCOUNT_STATEMENT'.

APPEND objtxt.

CLEAR objtxt.

APPEND objtxt.

APPEND objtxt.

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

Step 3:

Creation of the entry for the compressed document by populating the table objpack.

Sample Code

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = c_raw.

APPEND objpack.

Step 4:

Converting the form to PDF format by passing the table in OTF format and storing the returned value in PDF format.

Sample Code

CALL FUNCTION 'CONVERT_OTF_2_PDF'

IMPORTING

bin_filesize = l_numbytes

TABLES

otf = i_otfdata

doctab_archive = doctab

lines = i_pdf

EXCEPTIONS

err_conv_not_possible = 1

err_otf_mc_noendmarker = 2

OTHERS = 3.

Step 5:

Creation of the document to be attached and storing it in the table objbin to be later on passed on, in the function module.

Sample Code

LOOP AT i_pdf.

CLEAR l_str.

l_str+0(2) = i_pdf-tdformat.

l_str+2(132) = i_pdf-tdline.

v2 = v1 + c_134.

IF v2 LE c_255.

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

ELSE.

v3 = v2 - c_255.

v2 = c_255 - v1.

IF NOT v2 IS INITIAL.

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

ENDIF.

APPEND objbin.

CLEAR objbin.

v1 = v3.

v3 = 134 - v1.

IF NOT v1 IS INITIAL.

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

ENDIF.

ENDIF.

ENDLOOP.

APPEND objbin.

CLEAR objbin.

DESCRIBE TABLE objbin LINES tab_lines.

Step 6:

Populating the table objhead to be later on passed in the function module.

Sample Code

Describe table objbin lines tab_lines.

objhead = text-001. "'Account Statement'.

APPEND objhead.

Step 7: Creation of the entry for the compressed attachment

Sample Code

objpack-transf_bin = c_x.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = c_pdf.

objpack-obj_name = text-001. "''

objpack-obj_descr = text-001. "''

objpack-doc_size = tab_lines * 255.

APPEND objpack.

Step 8: Populating the recipient internet addresses where mails are to be sent in the table reclist to be passed on the function module.

Sample Code

IF NOT i_reclist[] is initial.

SELECT addrnumber

smtp_addr

INTO TABLE i_reclist

FROM adr6

FOR ALL ENTRIES IN i_adrc

WHERE addrnumber = i_adrc-addrnumber.

if sy-subrc = 0.

LOOP AT i_reclist.

reclist-receiver = i_reclist-smtp_addr.

reclist-rec_type = c_u.

APPEND reclist.

CLEAR reclist.

ENDLOOP.

Step 9: CALL FUNCTION 'SO_DOCUMENT_SEND_API1' and pass the already populated structures and tables. The sender address type is ‘INT’ and the sender address can be left as default blank.This will mail the contents of OBJBIN (PDF file containing the smartform output) to the recipient internet addresses stored in the table reclist.

Sample Code

EXPORTING

document_data = doc_chng

put_in_outbox = c_x

sender_address = l_sender

sender_address_type = c_int

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.

Reward points if helpful.

Thanks

Naveen khan

Former Member
0 Kudos

Hi ,

Thanks Naveen for your feedback.

i have tried ur changes and when iam passing the contents of i_tline to

contents_hex table of SO_DOCUMENT_SEND_API1.Iam getting an error or the pdf is coming empty.

Please give ur suggestions as how can we correctly convert the contents of i_tline which is of type tline structure (tdformat dt char2,tdline char 132) to contents_hex which is of type solix structure(line,DT raw255).I am using ECC 6.

thanks

Sunil

Former Member
0 Kudos

Hi

welcome to SDN forum

Look at the links for sending mail from Smartforms

/people/pavan.bayyapu/blog/2005/08/30/sending-html-email-from-sap-crmerp

<b>Reward points for useful Answers</b>

Regards

Anji