cancel
Showing results for 
Search instead for 
Did you mean: 

Smart form Output to external mail - Edit mail body with a form routine

former_member451655
Active Participant
0 Kudos

Hi Experts,

I have developed a smartforms that triggers from VA01 with PDF electronic mail attachement option for order confirmation which needs to be send to the customer ( with V/30 Configuration), its working fine. My issue is , I need to add some content to the mail body [Mail tittle & text in output types are fixed , no variables allowed], but I could be able to change/Add variables to the mail header only with the use of a form routine under the "Replacement of text symbols" section . a sample code to edit the body is very helpful .

Thank you ,

Dilum

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Dilum Alawatte ,

Donno what FM you are suing to send the email with PDF attachement. If you are using 'SO_NEW_DOCUMENT_ATT_SEND_API1'

then you can add text body in internal table SOLISTI1. Check the following code for more explanation :

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

IMPORTING

FM_NAME = V_FORM_NAME

EXCEPTIONS

NO_FORM = 1

NO_FUNCTION_MODULE = 2

OTHERS = 3.

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'

*All your parameters here

IMPORTING

JOB_OUTPUT_INFO = W_RETURN

TABLES

IT_FINAL = IT_FINAL

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

USER_CANCELED = 4

OTHERS = 5.

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.

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[].

**Here you can create your message body****

  • Create Message Body Title and Description

CONCATENATE 'Please Find attached purchase order' P_EBELN INTO I_OBJTXT

SEPARATED BY SPACE.

APPEND I_OBJTXT.

CLEAR I_OBJTXT.

I_OBJTXT = '****Sent from SAP****'.

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 = 'Purchase Order from Sterling & Wilson Ltd.'.

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

APPEND I_OBJPACK.

CLEAR I_RECLIST.

I_RECLIST-RECEIVER = W_MAIL_ID.

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.

MESSAGE I000 WITH 'Error When Sending the File'.

ELSE.

MESSAGE I000 WITH 'Mail succesfully sent to ' W_MAIL_ID.

ENDIF.

Thanks & Regards,

Rock.

former_member451655
Active Participant
0 Kudos

Hi Rock ,

Thank you very much for your quick response , unfortunately I m not referring to any FM , I m doing the this with the sap Standad output type (Defined Transmission medium as 5 - External send ). use any FM is not possible with this method , only option available is "Replacement of text symbols" , i m stuck at the append body text , anyway thanks again for your concern about my post .

Thx,

Dilum

former_member451655
Active Participant
0 Kudos

hi All ,

It can be done through a Function module (SO_OBJECT_SEND) implicit Enhancement , you need to pass what ever the text you need to include in the email body to the NOTE_TEXT table in the FM it self by your own code , Important - just make sure you do the amendment based on your custom requirement ( eg ; use a If statement ..ect ) since this FM is globally used ,

Thanks,

Dilum