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: 

Send email through SO_NEW_DOCUMENT_ATT_SEND_API1

Former Member
0 Kudos

hello,

can any one give me a simple code to send mail using SO_NEW_DOCUMENT_ATT_SEND_API1 like wat all parameters to be populated......

for

receiver email addr , sub of the mail, body of the mail.....

give a smiple sample code .....

thanks

5 REPLIES 5

Former Member
0 Kudos

Hello Ajanta,

Try this code..

report yh_email1.
data: email type somlreci1-receiver value '<e-mail id>'.
data: sender type SOEXTRECI1-RECEIVER value 'SAPDEV02'.

data: imessage type standard table of solisti1 with header line,
iattach type standard table of solisti1 with header line,
ipacking_list like sopcklsti1 occurs 0 with header line,
ireceivers like somlreci1 occurs 0 with header line.

start-of-selection.

clear imessage. refresh imessage.
imessage = 'This is a mail from SAP ECC6'.
append imessage.
imessage = 'Thanks and Regards'.
append imessage.
imessage = 'Indu'.
append imessage.

perform send_email tables imessage
using email
'Mail from Indu'.

***********************************************************************
*

* Form SEND_EMAIL

***********************************************************************
*
form send_email tables pit_message
using email
p_mtitle.

data: xdocdata like sodocchgi1,
xcnt type i.

* Fill the document data.

xdocdata-doc_size = 1.

* Populate the subject/generic message attributes

xdocdata-obj_langu = sy-langu .
xdocdata-obj_name = 'SAPRPT' .
xdocdata-obj_descr = p_mtitle .


clear ipacking_list. refresh ipacking_list.
ipacking_list-transf_bin = space.
ipacking_list-head_start = 1.
ipacking_list-head_num = 0.
ipacking_list-body_start = 1.
describe table imessage lines ipacking_list-body_num.
ipacking_list-doc_type = 'RAW'.
append ipacking_list.


clear ireceivers.
refresh ireceivers.
ireceivers-receiver = email.
ireceivers-rec_type = 'U'.

append ireceivers.
call function 'SO_DOCUMENT_SEND_API1'
exporting
document_data = xdocdata
put_in_outbox = 'X'
SENDER_ADDRESS = SENDER
commit_work = 'X'
tables
packing_list = ipacking_list
contents_txt = imessage
receivers = ireceivers
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.

SUBMIT rsconn01 USING SELECTION-SET 'INT' AND RETURN.
CALL FUNCTION 'SO_DEQUEUE_UPDATE_LOCKS'.

endform.

Regards

Indu

former_member181995
Active Contributor
0 Kudos

Ajantha,

REPORT  ZSSO_DOCUMENT_SEND_API1.


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.


* Creating the document to be sent

DOC_CHNG-OBJ_NAME = 'OFFER'.

DOC_CHNG-OBJ_DESCR = 'Auction of a Picasso jr'.

OBJTXT = 'Reserve price : $250000'.

APPEND OBJTXT.

OBJTXT = 'A reproduction of the painting to be auctioned'.

APPEND OBJTXT.

OBJTXT = 'is enclosed as an attachment.'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

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

* Creating 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.

* Creating the document attachment

* (Assume the data in OBJBIN are given in BMP format)

OBJBIN = ' \O/ '. APPEND OBJBIN.

OBJBIN = '  |  '. APPEND OBJBIN.

OBJBIN = ' / \ '. APPEND OBJBIN.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

OBJHEAD = 'picasso.bmp'. APPEND OBJHEAD.

* Creating 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   = 'ATTACHMENT'.

OBJPACK-OBJ_DESCR = 'Reproduction object 138'.

OBJPACK-DOC_SIZE   = TAB_LINES * 255.

APPEND OBJPACK..

* Entering names in the distribution list

RECLIST-RECEIVER = <Email address>.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

RECLIST-RECEIVER = 'DLI-NEUREICH'.

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'

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

      ELSE.

        WRITE 'not sent'.

      ENDIF.

    ENDLOOP.

  WHEN 1.

WRITE: / 'no authorization to send to the specified number of'              'recipients!'.

  WHEN 2.

    WRITE: / 'document could not be sent to any of the recipients!'.

  WHEN 4.

    WRITE: / 'no authorization to send !'.

  WHEN OTHERS.

    WRITE: / 'error occurred during sending !'.

ENDCASE.

Former Member
0 Kudos

Hello check this out,

&----


*& Report ZALERT

*&

&----


*&

*&

&----


report zalert.

----


  • Table declaration

----


tables : vbrk. "Billing Document: Header Data

----


  • Type pool declaration

----


type-pools slis.

----


  • Selection screen

----


selection-screen begin of block b1 with frame.

select-options : p_date for vbrk-aedat.

selection-screen end of block b1.

----


  • Types declaration

----


types : begin of t_vbrk,

vbeln type vbrk-vbeln, "Billing Document

aedat type vbrk-aedat, "Changed on(date)

fksto type vbrk-fksto, "Billing document is cancelled

end of t_vbrk.

----


  • Internal table declaration

----


data : i_vbrk type table of t_vbrk,

w_vbrk type t_vbrk.

----


  • Field catalog declaration

----


data : i_cat type slis_t_fieldcat_alv,

w_cat like line of i_cat,

t_print type slis_print_alv.

data :top type table of slis_listheader with header line.

data : event type table of slis_alv_event with header line.

----


  • start of selection

----


top-of-page.

start-of-selection.

perform get_dat.

if sy-subrc = 0.

perform build_cat.

perform alv_print_info.

perform sub_create_spool_id.

perform display_data.

new-page print off.

perform sub_send_mail.

else.

message 'NO DOCUMENT IS CANCELLED IN THE GIVEN PERIOD' type 'S'.

endif.

----


  • Subroutine GET_DAT

----


form get_dat .

*---To fetch canelled billing documents.

select vbeln

aedat

fksto

from vbrk

into table i_vbrk

where aedat in p_date and fksto = 'X'.

endform. " GET_DAT

----


  • Subroutine DISPLAY_DATA

----


form display_data .

call function 'REUSE_ALV_EVENTS_GET'

importing

et_events = event[]

.

top-typ = 'H'.

top-info = sy-title.

append top.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = sy-repid

i_callback_top_of_page = 'NAN'

i_grid_title = 'Alok Arun (Mr.A)'

it_fieldcat = i_cat

it_events = event[]

is_print = t_print

tables

t_outtab = i_vbrk

.

endform. " DISPLAY_DATA

&----


*& Subroutine BUILD_CAT

&----


form build_cat .

w_cat-seltext_l = 'Billing Document'.

w_cat-col_pos = '1'.

w_cat-tabname = 'I_VBRK'.

w_cat-fieldname = 'VBELN'.

w_cat-ref_fieldname = 'VBELN'.

w_cat-hotspot = 'X'.

append w_cat to i_cat.

clear w_cat.

w_cat-seltext_l = 'Cancelled on'.

w_cat-col_pos = '2'.

w_cat-tabname = 'I_VBRK'.

w_cat-fieldname = 'AEDAT'.

w_cat-ref_fieldname = 'AEDAT'.

w_cat-hotspot = 'X'.

append w_cat to i_cat.

clear w_cat.

endform. " BUILD_CAT

&----


*& Form alv_print_info

&----


form alv_print_info .

t_print-no_print_selinfos = 'X'.

t_print-no_coverpage = 'X'.

t_print-no_print_listinfos = 'X'.

*

endform. " alv_print_info

&----


*& Form sub_create_spool_id

&----


form sub_create_spool_id .

data: lv_text(50) type c.

lv_text = sy-title.

new-page line-size sy-linsz

print on destination 'LP01'

cover text lv_text

list name 'LIST NAME SOL MANAGER'(002)

list dataset 'LIST DATASET'(003)

immediately ' '

keep in spool 'X'

new list identification 'X'

no dialog.

endform. " sub_create_spool_id

&----


*& Form sub_send_mail

&----


form sub_send_mail .

data: v_spono like tsp01-rqident.

v_spono = sy-spono.

data:

v_type like soodk-objtp,

i_pdflist like tline occurs 0,

  • t_print TYPE slis_print_alv,

jobname like tbtcjob-jobname,

jobcount like tbtcjob-jobcount,

numbytes type i,

pdfspoolid like tsp01-rqident,

jobname2 like tbtcjob-jobname,

jobcount2 like tbtcjob-jobcount,

i_compresslist like soli occurs 0.

data: pdf like tline occurs 100 with header line,

objbin like solisti1 occurs 10 with header line.

*--convert into PDF

call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

exporting

src_spoolid = v_spono

no_dialog = ' '

importing

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

btc_jobname = jobname2

btc_jobcount = jobcount2

tables

pdf = pdf

exceptions

err_no_abap_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_destdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 9

err_btcjob_submit_failed = 10

err_btcjob_close_failed = 11.

if sy-subrc <> 0.

endif.

*-- change the width of the pdf table --

call function 'SX_TABLE_LINE_WIDTH_CHANGE'

exporting

line_width_src = 134

line_width_dst = 255

tables

content_in = pdf

content_out = objbin

exceptions

err_line_width_src_too_long = 1

err_line_width_dst_too_long = 2

err_conv_failed = 3

others = 4.

if sy-subrc <> 0.

endif.

data: lv_text1(50) type c.

lv_text1 = sy-title.

data : v1(30) value 'Plz find the attachment of', v3(80).

concatenate v1 lv_text1 into v3.

*--declare the internal table for sending of mail

data: li_objpack like sopcklsti1 occurs 2 with header line,

li_objhead like solisti1 occurs 1 with header line,

li_objbin like solisti1 occurs 0 with header line,

li_objtxt like solisti1 occurs 10 with header line,

li_reclist like somlreci1 occurs 10 with header line.

data: lv_docchng like sodocchgi1,

lv_tablines like sy-tabix.

data: lv_report like trdir-name value 'RSCONN01',

lv_text like solisti1-line.

lv_docchng-obj_name = 'LIST'(l01).

li_objtxt-line = 'Dear Sir / Madam,'.

append li_objtxt.

clear li_objtxt.

append li_objtxt.

li_objtxt-line = v3.

append li_objtxt.

clear li_objtxt.

append li_objtxt.

li_objtxt-line = 'Regards'.

append li_objtxt.

clear li_objtxt.

append li_objtxt.

describe table li_objtxt lines lv_tablines.

read table li_objtxt index lv_tablines transporting all fields.

lv_docchng-doc_size = ( lv_tablines - 1 ) * 255 + strlen( li_objtxt ).

*---Object Pack

  • text content

clear li_objpack-transf_bin.

li_objpack-head_start = 1.

li_objpack-head_num = 0.

li_objpack-body_start = 1.

li_objpack-body_num = lv_tablines.

li_objpack-doc_type = 'RAW'.

append li_objpack.

  • attachement

describe table objbin lines lv_tablines.

li_objpack-transf_bin = 'X'.

li_objpack-head_start = 1.

li_objpack-head_num = 0.

li_objpack-body_start = 1.

li_objpack-body_num = lv_tablines.

li_objpack-doc_type = 'PDF'.

li_objpack-obj_name = 'ATTACHMENT'(a01).

li_objpack-obj_descr = sy-title.

li_objpack-doc_size = lv_tablines * 255 .

append li_objpack.

lv_docchng-obj_descr = sy-title.

li_reclist-receiver = sy-uname.

li_reclist-rec_type = 'B'.

li_reclist-express = 'X'.

append li_reclist.

clear li_reclist.

if li_reclist[] is initial.

message i030(zgso).

leave list-processing.

endif. " IF li_reclist[] IS INITIAL

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = lv_docchng

put_in_outbox = 'X'

commit_work = 'X'

tables

packing_list = li_objpack

object_header = li_objhead

contents_bin = objbin

contents_txt = li_objtxt

receivers = li_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 is initial.

submit (lv_report) with mode = 'INT' and return .

message 'Alert Sent and check it out in T-code : SBWP' type 'S'.

else.

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

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

endif. " IF sy-subrc IS INITIAL

endform. " sub_send_mail

form nan.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = top[]

  • I_LOGO =

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

.

endform.

Former Member
0 Kudos

hi,

see the below code...

REPORT ZSSO_DOCUMENT_SEND_API1.

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.

  • Creating the document to be sent

DOC_CHNG-OBJ_NAME = 'OFFER'.

DOC_CHNG-OBJ_DESCR = 'Auction of a Picasso jr'.

OBJTXT = 'Reserve price : $250000'.

APPEND OBJTXT.

OBJTXT = 'A reproduction of the painting to be auctioned'.

APPEND OBJTXT.

OBJTXT = 'is enclosed as an 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 ).

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

  • Creating the document attachment

  • (Assume the data in OBJBIN are given in BMP format)

OBJBIN = ' \O/ '. APPEND OBJBIN.

OBJBIN = ' '. APPEND OBJBIN.

OBJBIN = ' / \ '. APPEND OBJBIN.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

OBJHEAD = 'picasso.bmp'. APPEND OBJHEAD.

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

OBJPACK-OBJ_DESCR = 'Reproduction object 138'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK..

  • Entering names in the distribution list

RECLIST-RECEIVER = 'email address'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

RECLIST-RECEIVER = 'DLI-NEUREICH'.

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'

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

ELSE.

WRITE 'not sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'no authorization to send to the specified number of'

'recipients!'.

WHEN 2.

WRITE: / 'document could not be sent to any of the recipients!'.

WHEN 4.

WRITE: / 'no authorization to send !'.

WHEN OTHERS.

WRITE: / 'error occurred during sending !'.

ENDCASE.

Regards,

Jagadeesh.

Former Member
0 Kudos

Hi,

Here is the sample code using the function you were asking for....

just go through this i hope this will add a lttl help to u..

start-of-selection.

perform send_mail.

FORM SEND_MAIL.

  • PARAMETERS FOR SO_NEW_DOCUMENT_SEND_API1

DATA: W_OBJECT_ID LIKE SOODK,

W_SONV_FLAG LIKE SONV-FLAG.

DATA: T_RECEIVERS LIKE SOMLRECI1 OCCURS 1 WITH HEADER LINE,

W_OBJECT_CONTENT LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE,

W_DOC_DATA LIKE SODOCCHGI1 OCCURS 0 WITH HEADER LINE.

*

DATA: W_DATE(10).

CLEAR T_RECEIVERS.

T_RECEIVERS-RECEIVER = SY-UNAME.

T_RECEIVERS-REC_TYPE = 'B'.

T_RECEIVERS-EXPRESS = ' '.

APPEND T_RECEIVERS.

W_DOC_DATA-OBJ_DESCR = 'Change Expiry date'.

  • Delivery NO

CONCATENATE 'Delivery No' M_VMVMA-VBELN INTO W_OBJECT_CONTENT

SEPARATED BY ' '.

APPEND W_OBJECT_CONTENT.

  • material Batch

CONCATENATE 'Material' ZGREC-MATNR 'Batch' ZGREC-CHARG

INTO W_OBJECT_CONTENT SEPARATED BY ' '.

APPEND W_OBJECT_CONTENT.

  • Expiry date

WRITE B_VFDAT TO W_DATE DD/MM/YYYY.

CONCATENATE 'Change expiry date to' W_DATE

INTO W_OBJECT_CONTENT SEPARATED BY ' '.

APPEND W_OBJECT_CONTENT.

*

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = W_DOC_DATA

PUT_IN_OUTBOX = ' '

TABLES

OBJECT_CONTENT = W_OBJECT_CONTENT

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.

ENDFORM. " SEND_MAIL

Thanks & Regards

Ashu Singh