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: 

SENDING TEXT FILE AS AN ATTACHMENT

Former Member
0 Kudos
438

Hi,

I want to send an email as a TEXT file attachment.

Thanks

Vikranth Khimavath

4 REPLIES 4

Former Member
0 Kudos
89

hi,

Use the FM SO_NEW_DOCUMENT_ATT_SEND_API1 to send mail with an attachment. Here is the sample code.

FUNCTION Z_SEND_MAIL.

*"----


""Local interface:

*" IMPORTING

*" VALUE(MESSAGE) TYPE STRING OPTIONAL

*" VALUE(RECEIVER_MAIL) TYPE STRING OPTIONAL

*" VALUE(TO) TYPE STRING OPTIONAL

*"----


  • data for send function

DATA doc_data TYPE sodocchgi1.

DATA object_id TYPE soodk.

DATA objcont TYPE TABLE OF soli INITIAL SIZE 10.

DATA wa_objcont LIKE LINE OF objcont.

DATA receiver TYPE TABLE OF somlreci1 INITIAL SIZE 1.

DATA wa_receiver LIKE LINE OF receiver.

move message

TO doc_data-obj_descr .

  • This is the subject for your mail.

  • WRITE 'Sub:test Mail' TO doc_data-obj_descr.

  • This is the body of your mail.

concatenate ' Hi ' to into wa_objcont-line separated by space.

append wa_objcont to objcont.

wa_objcont-line = message.

append wa_objcont to objcont.

  • Specify receipent id.

MOVE: RECEIVER_MAIL TO wa_receiver-receiver,

  • 'X' TO wa_receiver-express,

'U' TO wa_receiver-rec_type.

APPEND wa_receiver TO receiver.

  • Finally call the function module.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = doc_data

put_in_outbox = 'X' "Save Document in Outbox

COMMIT_WORK = 'X'

IMPORTING

new_object_id = object_id

TABLES

object_content = objcont

receivers = receiver

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.

SUBMIT rsconn01 USING SELECTION-SET 'SAP&CONNECTINT' AND RETURN.

ENDFUNCTION.

REPORT RSCONN01 MESSAGE-ID XS NO STANDARD PAGE HEADING.

INCLUDE <SYMBOL>. " 11.11.96

TYPE-POOLS: SX.

TYPE-POOLS: KKBLO.

PARAMETERS: MODE(3) TYPE C DEFAULT '*',

OUTPUT TYPE C DEFAULT ' '. "B20K072036 new parameter

selection-screen skip.

parameters maxjobs type sx_maxjobs default 1.

parameters rfcgroup type bdfields-rfcgr.

selection-screen skip.

parameters maxpsize type sx_maxpsize default 1000.

parameters minpsize type sx_minpsize default 20.

parameters maxsel type sx_maxqrows default 20000.

parameters timepo type sx_timepo default 2.

parameters timeout type sx_arfctimeout default 100.

parameters commit type sx_commit default 1.

data address_types type sx_addrtab.

data job_params type sxjobs.

data jobdata type sxjobdata.

--- initialization -


initialization.

  • get default parameters

call function 'SX_JOBDATA_GET'

changing

jobdata = jobdata.

  • give defaults to parameters

maxjobs = jobdata-maxjobs.

maxpsize = jobdata-maxpsize.

minpsize = jobdata-minpsize.

maxsel = jobdata-maxsel.

timepo = jobdata-timepo.

timeout = jobdata-arfc_timeout.

commit = jobdata-commit_after.

--- start-of-selection -


start-of-selection.

perform addr_type_to_table using mode

changing address_types.

job_params-maxjobs = maxjobs.

job_params-rfcgroup = rfcgroup.

job_params-maxpsize = maxpsize.

job_params-minpsize = minpsize.

job_params-maxsel = maxsel.

job_params-timepo = timepo.

job_params-arfc_timeout = timeout.

job_params-commit_after = commit.

call function 'SX_OBJECTS_SEND'

exporting

address_types = address_types

output = output

job_params = job_params

exceptions

others = 1.

.

if sy-subrc <> 0.

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

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

endif.

exit.

----


TABLES: SXADDRTYPE.

DATA: selection type SX_ADDRTAB,

NR_SO_OBJECTS TYPE I,

OBJ_CAT TYPE SX_OBJ_CAT OCCURS 20 WITH HEADER LINE.

if sy-batch = 'X'.

message I078 with 'RSCONN01' SY-HOST SY-MANDT.

endif.

*fill selection table

refresh selection.

if mode = '*'.

clear mode.

endif.

IF NOT ( MODE IS INITIAL ).

SELECT SINGLE * FROM SXADDRTYPE WHERE ADDR_TYPE EQ MODE.

IF SY-SUBRC NE 0.

IF OUTPUT EQ 'X'.

WRITE: MODE, TEXT-001, TEXT-002.

ENDIF.

EXIT.

ENDIF.

IF SXADDRTYPE-METHOD NE 'SAPCONNECT'.

IF OUTPUT EQ 'X'.

WRITE: MODE, TEXT-003, TEXT-004, TEXT-005.

ENDIF.

EXIT.

ENDIF.

append sxaddrtype-addr_type to selection.

ELSE.

select * from sxaddrtype

where method = 'SAPCONNECT'

and extern = sx_true.

case sxaddrtype-addr_type.

when 'INT' or 'FAX' or 'PAG' or

'PRT' or 'RML' or 'X40'.

append sxaddrtype-addr_type to selection.

endcase.

endselect.

ENDIF.

CALL FUNCTION 'SX_OBJECTS_SEND'

EXPORTING

ADDRESS_TYPES = SELECTION

IMPORTING

NR_SO_OBJECTS = NR_SO_OBJECTS

TABLES

OBJ_CAT = OBJ_CAT

EXCEPTIONS

INTERNAL_ERROR = 1

OTHERS = 2.

IF SY-SUBRC NE 0.

  • IF OUTPUT EQ 'X'.

  • Always write out this error message:

WRITE: TEXT-006, SY-SUBRC.

  • ENDIF.

EXIT.

ENDIF.

IF NR_SO_OBJECTS = 0.

IF OUTPUT EQ 'X'.

WRITE: TEXT-007.

ENDIF.

EXIT.

ENDIF.

IF OUTPUT EQ 'X'.

PERFORM DISPLAY_OBJECT_CATALOGUE.

ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR MODE.

PERFORM F_SHOW_ADDR_TYPES CHANGING MODE.

AT SELECTION-SCREEN ON HELP-REQUEST FOR OUTPUT.

PERFORM F_HELP_OUTPUT.

&----


*& Form addr_type_to_table

&----


  • text

----


form addr_type_to_table using address_type type sx_addrtyp

changing address_types type sx_addrtab.

data adrtp_wa type sxaddrtype.

data adrtp type sx_addrtyp.

if address_type <> '*'.

adrtp = address_type.

endif.

if not adrtp is initial.

select single * from sxaddrtype into adrtp_wa

where addr_type = adrtp.

if sy-subrc <> 0.

message i009 with adrtp.

exit.

endif.

if adrtp_wa-method ne 'SAPCONNECT'.

message i027 with adrtp.

exit.

endif.

append adrtp_wa-addr_type to address_types.

else.

select * from sxaddrtype into adrtp_wa

where method = 'SAPCONNECT'

and extern = sx_true.

case adrtp_wa-addr_type.

when 'INT' or 'FAX' or 'PAG' or

'PRT' or 'RML' or 'X40'.

append adrtp_wa-addr_type to address_types.

endcase.

endselect.

endif.

endform. " addr_type_to_table

&----


*& Form DISPLAY_OBJECT_CATALOGUE

&----


  • Anzeige der Liste der zum Versenden selektierten Objekte

----


  • --> p1 text

  • <-- p2 text

----


FORM DISPLAY_OBJECT_CATALOGUE.

DATA: FIELD_LST TYPE KKBLO_T_FIELDCAT.

DATA: FIELD_CAT TYPE KKBLO_FIELDCAT.

DATA: IS_LAYOUT TYPE KKBLO_LAYOUT.

IS_LAYOUT-NO_ZEBRA = 'X'.

FIELD_CAT-REF_TABNAME = 'SXOBJCAT'.

FIELD_CAT-NO_SUM = 'X'.

FIELD_CAT-JUST = 'L'.

FIELD_CAT-OUTPUTLEN = 3.

FIELD_CAT-REPTEXT = 'Trc'.

FIELD_CAT-FIELDNAME = 'DISPL_TRC'.

FIELD_CAT-HOTSPOT = 'X'.

FIELD_CAT-SYMBOL = 'X'.

APPEND FIELD_CAT TO FIELD_LST.

FIELD_CAT-SYMBOL = ' '.

FIELD_CAT-OUTPUTLEN = 0.

FIELD_CAT-HOTSPOT = ' '.

FIELD_CAT-REPTEXT = ' '.

CLEAR: FIELD_CAT-NO_ZERO, FIELD_CAT-KEY .

FIELD_CAT-FIELDNAME = 'ID'. APPEND FIELD_CAT TO FIELD_LST.

FIELD_CAT-FIELDNAME = 'TITLE'. APPEND FIELD_CAT TO FIELD_LST.

FIELD_CAT-FIELDNAME = 'TYPE'. APPEND FIELD_CAT TO FIELD_LST.

FIELD_CAT-FIELDNAME = 'NR_RECIP'. APPEND FIELD_CAT TO FIELD_LST.

LOOP AT FIELD_LST INTO FIELD_CAT.

FIELD_CAT-COL_POS = SY-TABIX.

MODIFY FIELD_LST FROM FIELD_CAT.

ENDLOOP.

LOOP AT OBJ_CAT.

OBJ_CAT-DISPL_TRC = SYM_PENCIL.

MODIFY OBJ_CAT.

ENDLOOP.

CALL FUNCTION 'K_KKB_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = 'RSCONN01'

I_CALLBACK_USER_COMMAND = 'CB_OL_UCOMM'

I_CALLBACK_TOP_OF_PAGE = 'CB_OL_TOP'

I_CALLBACK_PF_STATUS_SET = 'CB_OL_PFSTATUS'

I_TABNAME = 'OBJ_CAT'

IS_LAYOUT = IS_LAYOUT

IT_FIELDCAT = FIELD_LST

TABLES

T_OUTTAB = OBJ_CAT

EXCEPTIONS

OTHERS = 1.

ENDFORM. " DISPLAY_OBJECT_CATALOGUE

&----


*& Form CB_OL_PFSTATUS

&----


  • Callback Funktion (wird aus Listtool heraus gerufen) *

----


  • --> p1 text

  • <-- p2 text

----


FORM CB_OL_PFSTATUS

USING EXTAB TYPE KKBLO_T_EXTAB.

SET PF-STATUS 'CATALOG' EXCLUDING EXTAB.

SET TITLEBAR 'CAT'.

ENDFORM. " CB_OL_PFSTATUS

&----


*& Form CB_OL_TOP

&----


  • Callback Funktion (wird aus Listtool heraus gerufen) *

----


  • --> p1 text

  • <-- p2 text

----


FORM CB_OL_TOP.

ENDFORM. " CB_OL_TOP

&----


*& Form CB_OL_UCOMM

&----


  • text *

----


  • --> p1 text

  • <-- p2 text

----


FORM CB_OL_UCOMM

USING UCOMM LIKE SY-UCOMM

SELFIELD TYPE KKBLO_SELFIELD.

DATA: NUMC5(5) TYPE N.

NUMC5 = SELFIELD-TABINDEX.

CASE UCOMM.

WHEN 'PIC1'.

CASE SELFIELD-SEL_TAB_FIELD.

WHEN 'OBJ_CAT-DISPL_TRC' OR 'OBJ_CAT-TITLE' OR 'OBJ_CAT-ID'.

READ TABLE OBJ_CAT INDEX SELFIELD-TABINDEX.

IF SY-SUBRC NE 0.

MESSAGE E042.

ENDIF.

SUBMIT RSWTTR01

WITH P_TYPE = 'D'

WITH P_UNAME = SPACE

WITH P_OBJ = OBJ_CAT-ID AND RETURN.

WHEN OTHERS.

MESSAGE I041 WITH NUMC5 SELFIELD-SEL_TAB_FIELD UCOMM.

ENDCASE.

WHEN OTHERS.

MESSAGE I041 WITH NUMC5 SELFIELD-SEL_TAB_FIELD UCOMM.

ENDCASE.

ENDFORM. " CB_OL_UCOMM

&----


*& Form F_SHOW_ADDR_TYPES

&----


  • text

----


  • <--P_MODE text *

----


FORM F_SHOW_ADDR_TYPES CHANGING A_TYPE.

DATA: HELP_INFO LIKE HELP_INFO

  • , sel_value like help_info-fldvalue

, CUCOL LIKE SY-CUCOL

, CUROW LIKE SY-CUROW

  • , value like help_info-fldvalue value 'SE38'

, IND LIKE SY-INDEX

, C_SY_SUBRC(3) TYPE C

.

DATA: BEGIN OF FIELDS OCCURS 5.

INCLUDE STRUCTURE HELP_VALUE.

DATA: END OF FIELDS.

DATA: BEGIN OF LIST_OF_FIELDS OCCURS 5,

NAME(21) TYPE C.

DATA: END OF LIST_OF_FIELDS.

DATA: BEGIN OF FULL_LIST OCCURS 5,

ADDRESS_TYPE LIKE SXADDRTYPE-ADDR_TYPE,

END OF FULL_LIST.

REFRESH FIELDS.

REFRESH LIST_OF_FIELDS.

REFRESH FULL_LIST.

HELP_INFO-TABNAME = 'SXADDRTYPE'.

HELP_INFO-FIELDNAME = 'ADDR_TYPE'.

SELECT * FROM SXADDRTYPE.

IF SXADDRTYPE-METHOD NE 'SAPCONNECT'

OR SXADDRTYPE-EXTERN NE SX_TRUE.

CONTINUE.

ENDIF.

MOVE SXADDRTYPE-ADDR_TYPE TO FULL_LIST-ADDRESS_TYPE.

APPEND FULL_LIST.

ENDSELECT.

MOVE '*' TO FULL_LIST-ADDRESS_TYPE.

APPEND FULL_LIST.

LIST_OF_FIELDS-NAME = 'SXADDRTYPE-ADDR_TYPE'.

APPEND LIST_OF_FIELDS.

CALL FUNCTION 'TRANSFER_NAMES_TO_FIELDS'

EXPORTING

SELECTFIELD = HELP_INFO-FIELDNAME

TABLES

FIELDS = FIELDS

NAMELIST = LIST_OF_FIELDS

EXCEPTIONS

WRONG_FORMAT_GIVEN = 1

OTHERS = 2.

CALL FUNCTION 'HELP_VALUES_GET_WITH_VALUE'

EXPORTING

DISPLAY = ' '

FIELDNAME = HELP_INFO-FIELDNAME

TABNAME = HELP_INFO-TABNAME

GIVEN_VALUE = HELP_INFO-FLDVALUE

TITEL = TEXT-002

IMPORTING

SELECT_VALUE = HELP_INFO-FLDVALUE

SELECT_INDEX = IND

TABLES

FIELDS = FIELDS

VALUETAB = FULL_LIST

EXCEPTIONS

FIELD_NOT_IN_DDIC = 1

MORE_THEN_ONE_SELECTFIELD = 2

NO_SELECTFIELD = 3

OTHERS = 4.

C_SY_SUBRC = SY-SUBRC.

CASE SY-SUBRC.

WHEN '0'.

READ TABLE FULL_LIST INTO A_TYPE INDEX IND.

WHEN OTHERS.

MESSAGE E022 WITH C_SY_SUBRC.

ENDCASE.

ENDFORM. " F_SHOW_ADDR_TYPES

&----


*& Form F_HELP_OUTPUT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM F_HELP_OUTPUT.

DATA: CANCELLED TYPE C,

C_SY_SUBRC(8) TYPE C.

CALL FUNCTION 'POPUP_DISPLAY_TEXT'

EXPORTING

LANGUAGE = SY-LANGU

POPUP_TITLE = 'SAPconnect'

TEXT_OBJECT = 'RSCONN01_F1_OUTPUT_40B'

IMPORTING

CANCELLED = CANCELLED

EXCEPTIONS

TEXT_NOT_FOUND = 1

OTHERS = 2.

C_SY_SUBRC = SY-SUBRC.

IF SY-SUBRC NE 0.

  • MESSAGE E035 WITH C_SY_SUBRC. leads to dump !

ENDIF.

ENDFORM. " F_HELP_OUTPUT

Regards,

Richa

Former Member
0 Kudos
89

Check out Amit's Answer in this thread

https://forums.sdn.sap.com/click.jspa?searchID=872861&messageID=1736429

Regards,

Santosh

Former Member
0 Kudos
89

below is ex for sending attachment. Instead of XLS you can make it txt.

***Sending mail to the receipients

if not it_final[] is initial.

PERFORM SUB_GET_MAIL_ADDR.

  • Populate table with detaisl to be entered into .xls file

PERFORM BUILD_XLS_DATA_TABLE.

PERFORM POPULATE_EMAIL_MESSAGE_BODY.

      • Send file by email as .xls speadsheet

PERFORM SEND_FILE_AS_EMAIL_ATTACHMENT

TABLES IT_MESSAGE

IT_ATTACH

USING P_EMAIL

'Sales Register Report - Set Top Box / Accessories'

'XLS'

'SSTB'

' '

' '

' '

CHANGING GD_ERROR

GD_RECIEVER.

  • Instructs mail send program for SAPCONNECT to send email(rsconn01)

PERFORM INITIATE_MAIL_EXECUTE_PROGRAM.

&----


*& Form BUILD_XLS_DATA_TABLE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BUILD_XLS_DATA_TABLE .

data: wa_itab like it_final.

CONSTANTS:

CON_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,

CON_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.

CONCATENATE 'Business Place' 'Region Code' 'Region' 'Branch Code'

'Branch' 'Material Desc' 'Area off Code'

'Area Name' 'Zone code' 'Zone Name' 'Cust No' 'Cust Name'

'Bill Doc No' 'Bill Date' 'Base Val' 'Total Val' 'Quantity'

INTO IT_ATTACH SEPARATED BY CON_TAB.

CONCATENATE CON_CRET IT_ATTACH INTO IT_ATTACH.

APPEND IT_ATTACH.

LOOP AT IT_FINAL INTO WA_ITAB.

CONCATENATE WA_ITAB-BUSINESS_PLACE

WA_ITAB-KVGR1

WA_ITAB-REGION

WA_ITAB-VKBUR

WA_ITAB-SALES_OFF

WA_ITAB-ARKTX

WA_ITAB-vkgrp

WA_ITAB-sales_grp

WA_ITAB-bzirk

WA_ITAB-zone

WA_ITAB-kunnr

WA_ITAB-name

WA_ITAB-vbeln

WA_ITAB-fkdat

WA_ITAB-base_value

WA_ITAB-total_value

WA_ITAB-fkimg

INTO IT_ATTACH SEPARATED BY CON_TAB.

CONCATENATE CON_CRET IT_ATTACH INTO IT_ATTACH.

APPEND IT_ATTACH.

ENDLOOP.

ENDFORM. " BUILD_XLS_DATA_TABLE

&----


*& Form POPULATE_EMAIL_MESSAGE_BODY

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM POPULATE_EMAIL_MESSAGE_BODY .

REFRESH IT_MESSAGE.

CONCATENATE SY-DATUM6(2) '/' SY-DATUM4(2) '/' SY-DATUM+0(4) INTO G_DATE.

IT_MESSAGE = 'Please find attached excel sheet.'.

APPEND IT_MESSAGE.

Concatenate 'Report generated date' ':' G_Date '.' into IT_MESSAGE.

APPEND IT_MESSAGE.

clear it_message.

append it_message.

IT_MESSAGE = 'This is an autogenerated mail, please do not reply'.

APPEND IT_MESSAGE.

ENDFORM. " POPULATE_EMAIL_MESSAGE_BODY

&----


*& Form SEND_FILE_AS_EMAIL_ATTACHMENT

&----


  • Send email

----


FORM SEND_FILE_AS_EMAIL_ATTACHMENT TABLES PIT_MESSAGE

PIT_ATTACH

USING P_EMAIL

P_MTITLE

P_FORMAT

P_FILENAME

P_ATTDESCRIPTION

P_SENDER_ADDRESS

P_SENDER_ADDRES_TYPE

CHANGING P_ERROR

P_RECIEVER.

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_EMAIL = P_EMAIL.

LD_MTITLE = P_MTITLE.

LD_FORMAT = P_FORMAT.

LD_ATTDESCRIPTION = P_ATTDESCRIPTION.

LD_ATTFILENAME = P_FILENAME.

LD_SENDER_ADDRESS = P_SENDER_ADDRESS.

LD_SENDER_ADDRESS_TYPE = P_SENDER_ADDRES_TYPE.

  • Fill the document data.

W_DOC_DATA-DOC_SIZE = 1.

  • Populate the subject/generic message attributes

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

  • 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

CLEAR T_PACKING_LIST.

REFRESH T_PACKING_LIST.

T_PACKING_LIST-TRANSF_BIN = SPACE.

T_PACKING_LIST-HEAD_START = 1.

T_PACKING_LIST-HEAD_NUM = 0.

T_PACKING_LIST-BODY_START = 1.

T_PACKING_LIST-OBJ_NAME = 'stb'.

DESCRIBE TABLE IT_MESSAGE LINES T_PACKING_LIST-BODY_NUM.

T_PACKING_LIST-DOC_TYPE = 'RAW'.

APPEND T_PACKING_LIST.

  • Create attachment notification

T_PACKING_LIST-TRANSF_BIN = 'X'.

T_PACKING_LIST-HEAD_START = 1.

T_PACKING_LIST-HEAD_NUM = 1.

T_PACKING_LIST-BODY_START = 1.

DESCRIBE TABLE T_ATTACHMENT LINES T_PACKING_LIST-BODY_NUM.

  • T_PACKING_LIST-DOC_TYPE = LD_FORMAT.

T_PACKING_LIST-DOC_TYPE = 'XLS'.

  • T_PACKING_LIST-OBJ_DESCR = LD_ATTDESCRIPTION.

T_PACKING_LIST-OBJ_DESCR = 'Sales_STB'.

  • T_PACKING_LIST-OBJ_NAME = LD_ATTFILENAME.

T_PACKING_LIST-OBJ_NAME = 'stb'.

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.

LOOP AT IT_RECV.

T_RECEIVERS-RECEIVER = IT_RECV-EMAIL.

T_RECEIVERS-REC_TYPE = 'U'.

  • T_RECEIVERS-COM_TYPE = 'INT'.

  • T_RECEIVERS-COPY = 'X'.

  • T_RECEIVERS-NOTIF_DEL = 'X'.

  • T_RECEIVERS-NOTIF_NDEL = 'X'.

APPEND T_RECEIVERS.

ENDLOOP.

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

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.

  • Populate zerror return code

LD_ERROR = SY-SUBRC.

  • Populate zreceiver return code

LOOP AT T_RECEIVERS.

LD_RECEIVER = T_RECEIVERS-RETRN_CODE.

ENDLOOP.

ENDFORM. "SEND_FILE_AS_EMAIL_ATTACHMENT

&----


*& Form INITIATE_MAIL_EXECUTE_PROGRAM

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM INITIATE_MAIL_EXECUTE_PROGRAM .

WAIT UP TO 2 SECONDS.

SUBMIT RSCONN01 WITH MODE = 'INT'

WITH OUTPUT = ''

AND RETURN.

ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM

&----


*& Form SUB_GET_MAIL_ADDR

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM SUB_GET_MAIL_ADDR .

select * from ZSD_REP_MAIL INTO TABLE IT_RECV.

ENDFORM. " SUB_GET_MAIL_ADDR

Former Member
0 Kudos
89

HI,

/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

Check these link..

Cofiguration:

/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

Sample Code:

http://www.sap-img.com/abap/sending-email-with-attachment.htm

Have a look at below code:

REPORT ZSENDEXTERNAL.

DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: TAB_LINES LIKE SY-TABIX.

  • Creation of the document to be sent

  • File Name

DOC_CHNG-OBJ_NAME = 'SENDFILE'.

  • Mail Subject

DOC_CHNG-OBJ_DESCR = 'Send External Mail'.

  • Mail Contents

OBJTXT = 'Minimum bid : $250000'.

APPEND OBJTXT.

OBJTXT = 'A representation of the pictures up for auction'.

APPEND OBJTXT.

OBJTXT = 'was included as attachment.'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

  • Creation of the entry for the compressed document

CLEAR OBJPACK-TRANSF_BIN.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'RAW'.

APPEND OBJPACK.

  • Creation of the document attachment

  • (Assume that the data in OBJBIN is in BMP format)

*OBJBIN = ' \O/ '. APPEND OBJBIN.

*OBJBIN = ' | '. APPEND OBJBIN.

*OBJBIN = ' / \ '. APPEND OBJBIN.

*DESCRIBE TABLE OBJBIN LINES TAB_LINES.

*OBJHEAD = 'PICTURE.BMP'.

*APPEND OBJHEAD.

    • Creation of the entry for the compressed attachment

*OBJPACK-TRANSF_BIN = 'X'.

*OBJPACK-HEAD_START = 1.

*OBJPACK-HEAD_NUM = 1.

*OBJPACK-BODY_START = 1.

*OBJPACK-BODY_NUM = TAB_LINES.

*OBJPACK-DOC_TYPE = 'BMP'.

*OBJPACK-OBJ_NAME = 'PICTURE'.

*OBJPACK-OBJ_DESCR = 'Representation of object 138'.

*OBJPACK-DOC_SIZE = TAB_LINES * 255.

*APPEND OBJPACK.

  • Completing the recipient list

RECLIST-RECEIVER = 'youremail@sap.com'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

*RECLIST-RECEIVER = 'SAPUSERNAME'.

*RECLIST-REC_TYPE = 'P'.

*APPEND RECLIST.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_CHNG

PUT_IN_OUTBOX = 'X'

TABLES

PACKING_LIST = OBJPACK

OBJECT_HEADER = OBJHEAD

CONTENTS_BIN = OBJBIN

CONTENTS_TXT = OBJTXT

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

CASE SY-SUBRC.

WHEN 0.

WRITE: / 'Result of the send process:'.

LOOP AT RECLIST.

WRITE: / RECLIST-RECEIVER(48), ':'.

IF RECLIST-RETRN_CODE = 0.

WRITE 'The document was sent'.

ELSE.

WRITE 'The document could not be sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'No authorization for sending to the specified number',

'of recipients'.

WHEN 2.

WRITE: / 'Document could not be sent to any recipient'.

WHEN 4.

WRITE: / 'No send authorization'.

WHEN OTHERS.

WRITE: / 'Error occurred while sending'.

ENDCASE.

Reward points if this helps.

Manish