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: 

Email send doubt

Former Member
0 Kudos

Hi

I have created one email prog. but it shows.

Document <Support Mess> could not be sent

Message no. SO023

my prog.

FUNCTION ZSEND_MAIL_SUPTEAM.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(GUID) LIKE CRMD_ORDERADM_H-GUID

*" VALUE(PRIOR) LIKE CRMT_ACTIVITY_H_WRK-PRIORITY

*"----


Data: docdata like sodocchgi1,

objpack like sopcklsti1 occurs 1 with header line,

objhead like solisti1 occurs 1 with header line,

objtxt like solisti1 occurs 10 with header line,

objbin like solisti1 occurs 10 with header line,

objhex like solix occurs 10 with header line,

reclist like somlreci1 occurs 1 with header line.

Data: listobject like abaplist occurs 1 with header line.

Data: tab_lines type i,

doc_size type i,

att_type like SOODK-OBJTP.

**--


Data Declaration for Message-

data: mtext like tacopca-c254,

sub_text like tacopca-c254,

urlstring like tacopca-c254,

urlstring1 like tacopca-c254.

data: t_stxh like stxh occurs 0 with header line.

**--


Data Declaration for Partner-

data:

itab_part like crmd_order_index occurs 0 with header line.

data:

p_guid like but000-partner_guid,

link_guid like crmd_link-guid_set,

p_func like crmd_partner-partner_fct,

msg_processor like but000-partner,

creator like but000-partner,

PER_NO LIKE ADR6-PERSNUMBER,

NAM1 LIKE BUT000-NAME_FIRST,

NAM2 LIKE BUT000-NAME_LAST,

MAIL LIKE ADR6-SMTP_ADDR,

M_NAME1 LIKE BUT000-NAME_first,

M_NAME2 LIKE BUT000-NAME_LAST,

sp(1) type c value '"'.

**--


For Status--


DATA : ST LIKE TJ30-ESTAT,

STEXT LIKE TJ30T-TXT30,

TXT LIKE TJ30T-TXT30,

TXT1 LIKE TJ30T-TXT30,

description like crmd_orderadm_h-description,

object_id like crmd_orderadm_h-object_id,

D1 LIKE sy-datum value 'ddmmyyyy' ,

d(2) type n,

m(2) type n,

y(4) type n,

DAT(10) type c,

hr(2) type n,

min(2) type n,

sec(2) type n,

TIM(10) type c,

STATUS_FLAG LIKE CRMD_ORDERADM_H-ARCHIVING_FLAG,

S1 TYPE C.

DATA : ITAB LIKE CRM_JEST OCCURS 0 WITH HEADER LINE.

**-----For Name & Email ID

DATA : ITAB_but LIKE BUT000 OCCURS 0 WITH HEADER LINE,

ITAB_CRMD_PARTNER LIKE CRMD_PARTNER OCCURS 0 WITH HEADER LINE .

*--


Reading Description Text--


data :

LINES like TLINE occurs 0 with header line,

  • DESC_TEXT like ZTEXT occurs 0 with header line,

text like SDBLINE512-LINE ,

d3 like stxl-tdname,

d2 LIKE CRMD_ORDERADM_H-HEAD_CHANGED_AT,

G1 LIKE THEAD-TDNAME,

G2 LIKE THEAD-TDNAME,

header like thead.

DATA:

itab_a_guid LIKE bapibus20001_guid_dis OCCURS 0 WITH HEADER LINE,

itab_a_partner LIKE bapibus20001_partner_dis OCCURS 0 WITH HEADER LINE

.

itab_a_guid-guid = guid.

APPEND itab_a_guid.

CALL FUNCTION 'BAPI_ACTIVITYCRM_GETDETAILMULT'

TABLES

GUID = itab_a_guid

PARTNER = itab_a_partner.

G1 = GUID.

loop at itab_a_partner.

if itab_a_partner-REF_PARTNER_FCT = 'SLFN0003'.

creator = itab_a_partner-REF_PARTNER_NO.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = creator

IMPORTING

output = creator.

endif.

if itab_a_partner-REF_PARTNER_FCT = 'SLFN0003'.

msg_processor = itab_a_partner-REF_PARTNER_NO.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = msg_processor

IMPORTING

output = msg_processor.

endif.

endloop.

      • Select the partner numbers of the support Message

  • select * from crmd_order_index into table itab_part

  • where header = g1 and

  • object_type = 'BUS2000116'.

  • if sy-subrc = 0.

      • Select the Link GUID of the Message

  • select single guid_set into link_guid from crmd_link

  • where guid_hi = g1 AND

  • objtype_set = '07'.

  • loop at itab_part.

      • Select the Partner GUID for each partner of the Message

  • select single partner_guid into p_guid from but000

  • where partner = itab_part-partner_no.

*

  • if sy-subrc = 0.

      • Select the partner function for the Partner Number

  • select single partner_fct into p_func from crmd_partner

  • where partner_no = p_guid and guid = link_guid.

  • if sy-subrc = 0.

*

  • if p_func = 'SDSM0004'.

SELECT SINGLE PERSNUMBER NAME_FIRST NAME_LAST INTO

(PER_NO, NAM1, NAM2) FROM BUT000

WHERE PARTNER = msg_processor.

SELECT SINGLE SMTP_ADDR INTO MAIL FROM ADR6

WHERE PERSNUMBER = PER_NO.

reclist-receiver = 'muthu_chemca@rediffmail.com'. "<-- change address

reclist-rec_type = 'U'.

append reclist.

SELECT SINGLE NAME_FIRST NAME_LAST INTO

(M_NAME1, M_NAME2) FROM BUT000

WHERE PARTNER = creator.

**----- Retrieving the Status

--


Selecting the Creation date--

SELECT SINGLE POSTING_DATE description object_id INTO

(D1, description, object_id) FROM CRMD_ORDERADM_H

WHERE GUID = guid.

d = d1+6(2).

m = d1+4(2).

y = d1+0(4).

concatenate d m y into dat separated by '/'.

--


Selecting the status of the tranasction--

SELECT * FROM CRM_JEST INTO TABLE ITAB WHERE OBJNR = GUID.

IF SY-SUBRC = 0.

LOOP AT ITAB.

S1 = ITAB-STAT+0(1).

IF S1 = 'E' AND ITAB-INACT <> 'X'.

ST = ITAB-STAT.

ENDIF.

ENDLOOP.

ENDIF.

----


Selecting the Status text -

SELECT SINGLE TXT30 INTO STEXT FROM TJ30T

WHERE STSMA = 'SMSD0001' AND

ESTAT = ST AND SPRAS = 'EN'.

concatenate 'Dear' nam1 nam2 ':' into mtext separated by space.

objtxt = mtext.

append objtxt.

objtxt = ' '.

append objtxt.

*STATUS = STEXT.

IF ST = 'E0001'.

TXT = 'created'.

ELSEIF ST = 'E0002'.

TXT = ' is in progress'.

ELSEIF ST = 'E0005'.

TXT = 'needs your inputs'.

ELSEIF ST = 'E0008'.

TXT = 'Closed'.

ENDIF.

    • Assigning Subject for the mail

sub_text = 'Support Message'.

concatenate sub_text object_id 'Please Act' into sub_text separated by

space.

  • docdata-obj_name = 'Support Message'.

  • docdata-obj_descr = 'Support Message'.

    • Mail content for Creation

mtext = 'You have been assigned the Support Message dated '.

concatenate mtext dat 'with subject' sp description sp into

mtext separated by space.

concatenate mtext 'Please find the details as follows.' into mtext

separated by space.

objtxt = mtext.

append objtxt.

*sflag = status_flag.

--


Selecting the priority of the transaction--

IF PRIOR = '1'.

TXT1 = 'Very High'.

ELSEIF PRIOR = '2'.

TXT1 = 'High'.

ELSEIF PRIOR = '3'.

TXT1 = 'Medium'.

ELSEIF PRIOR = '4'.

TXT1 = 'Low'.

ENDIF.

*----


URL Link for the Solution Manager -

urlstring1 = guid.

*----


OBJPACK-HEAD_START = 1.

OBJBIN = ' | '. APPEND OBJBIN.

OBJPACK-HEAD_START = 1.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

  • Create Message Body

  • Title and Description

docdata-obj_name = sub_text.

docdata-obj_descr = sub_text.

----


Mail Content -

objtxt = ' '.

append objtxt.

mtext = ' '.

concatenate 'Support Message Id : ' SPACE object_id into mtext.

objtxt = mtext.

append objtxt.

objtxt = ' '.

append objtxt.

mtext = ' '.

concatenate 'Initiator : ' SPACE M_NAME1 M_NAME2 into mtext separated

by space.

objtxt = mtext.

append objtxt.

objtxt = ' '.

append objtxt.

mtext = ' '.

concatenate 'Priority : ' txt1 into mtext separated by space.

objtxt = mtext.

append objtxt.

objtxt = ' '.

append objtxt.

  • objtxt = 'Detail :'.

  • append objtxt.

objtxt = ' '.

append objtxt.

CONCATENATE G1 '%' INTO G2.

select * from stxh into table t_stxh

where TDID = 'SU99' AND

TDNAME LIKE G2.

if sy-subrc = 0.

objtxt = 'Details:'.

append objtxt.

endif.

loop at t_stxh.

--


Using the READ_TEXT function to read the text--

CALL FUNCTION 'READ_TEXT'

EXPORTING

CLIENT = SY-MANDT

ID = 'SU99'

LANGUAGE = 'E'

NAME = t_stxh-TDNAME

OBJECT = 'CRM_ORDERH'

ARCHIVE_HANDLE = 0

LOCAL_CAT = ' '

IMPORTING

HEADER = HEADER

TABLES

LINES = LINES

  • EXCEPTIONS

  • ID = 1

  • LANGUAGE = 2

  • NAME = 3

  • NOT_FOUND = 4

  • OBJECT = 5

  • REFERENCE_CHECK = 6

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

*

LOOP AT LINES.

objtxt = lines-tdline.

append objtxt.

ENDLOOP.

objtxt = ' '.

append objtxt.

endloop.

clear : t_stxh.

refresh t_stxh.

CONCATENATE G1 '%' INTO G2.

select * from stxh into table t_stxh

where TDID = 'SU01' AND

TDNAME LIKE G2.

if sy-subrc = 0.

objtxt = 'Reply : '.

append objtxt.

*--


Using the READ_TEXT function to read the text--

loop at t_stxh.

d = t_stxh-TDFDATE+6(2).

m = t_stxh-TDFDATE+4(2).

y = t_stxh-TDFDATE+0(4).

concatenate d m y into dat separated by '.'.

hr = t_stxh-TDFTIME+0(2).

min = t_stxh-TDFTIME+2(2).

sec = t_stxh-TDFTIME+4(2).

concatenate hr min sec into tim separated by ':'.

concatenate dat tim t_stxh-tdfuser into objtxt

separated by space.

append objtxt.

objtxt = ' '.

append objtxt.

clear: lines.

CALL FUNCTION 'READ_TEXT'

EXPORTING

CLIENT = SY-MANDT

ID = 'SU01'

LANGUAGE = 'E'

NAME = t_stxh-tdname

OBJECT = t_stxh-tdobject

ARCHIVE_HANDLE = 0

LOCAL_CAT = ' '

IMPORTING

HEADER = header

TABLES

LINES = lines

  • EXCEPTIONS

  • ID = 1

  • LANGUAGE = 2

  • NAME = 3

  • NOT_FOUND = 4

  • OBJECT = 5

  • REFERENCE_CHECK = 6

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

loop at lines.

objtxt = lines-tdline.

append objtxt.

endloop.

endloop.

endif.

objtxt = text-001.

append objtxt.

objtxt = ' '.

append objtxt.

objtxt = 'Thanks'.

append objtxt.

objtxt = ' '.

append objtxt.

objtxt = 'Support Desk'.

append objtxt.

objtxt = 'Email : support.com'.

append objtxt.

objtxt = ' '.

append objtxt.

objtxt = text-003.

append objtxt.

objtxt = ' '.

append objtxt.

objtxt = urlstring.

append objtxt.

objtxt = ' '.

append objtxt.

objtxt = text-002.

append objtxt.

objtxt = ' '.

append objtxt.

describe table objtxt lines tab_lines.

read table objtxt index tab_lines.

docdata-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).

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.

break-point.

  • Send Message

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = docdata

PUT_IN_OUTBOX = 'X'

  • COMMIT_WORK = 'X' "used from rel.6.10

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 .

IF sy-subrc <> 0.

message ID 'SO' TYPE 'S' NUMBER '023'

with docdata-obj_name.

ENDIF.

clear objpack. refresh objpack.

clear objhead. refresh objhead.

clear objtxt. refresh objtxt.

clear reclist. refresh reclist.

ENDFUNCTION.

4 REPLIES 4

Former Member
0 Kudos

Hi,

Here is the example program to send Email, you need to fillow the same steps

*&---------------------------------------------------------------------*
*& Report  ZSENDEMAIL                                                  *
*&                                                                     *
*&---------------------------------------------------------------------*
*& Example of sending external email via SAPCONNECT                    *
*&                                                                     *
*&---------------------------------------------------------------------*
REPORT  zsendemail                    .

PARAMETERS: psubject(40) type c default  'Hello',
            p_email(40)   type c default 'test@sapdev.co.uk' .

data:   it_packing_list like sopcklsti1 occurs 0 with header line,
        it_contents like solisti1 occurs 0 with header line,
        it_receivers like somlreci1 occurs 0 with header line,
        it_attachment like solisti1 occurs 0 with header line,
        gd_cnt type i,
        gd_sent_all(1) type c,
        gd_doc_data like sodocchgi1,
        gd_error type sy-subrc.

data:   it_message type standard table of SOLISTI1 initial size 0
                with header line.

***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.

Perform populate_message_table.

*Send email message, although is not sent from SAP until mail send
*program has been executed(rsconn01)
PERFORM send_email_message.

*Instructs mail send program for SAPCONNECT to send email(rsconn01)
perform initiate_mail_execute_program.


*&---------------------------------------------------------------------*
*&      Form  POPULATE_MESSAGE_TABLE
*&---------------------------------------------------------------------*
*       Adds text to email text table
*----------------------------------------------------------------------*
form populate_message_table.
  Append 'Email line 1' to it_message.
  Append 'Email line 2' to it_message.
  Append 'Email line 3' to it_message.
  Append 'Email line 4' to it_message.
endform.                    " POPULATE_MESSAGE_TABLE


*&---------------------------------------------------------------------*
*&      Form  SEND_EMAIL_MESSAGE
*&---------------------------------------------------------------------*
*       Send email message
*----------------------------------------------------------------------*
form send_email_message.
* Fill the document data.
  gd_doc_data-doc_size = 1.

* Populate the subject/generic message attributes
  gd_doc_data-obj_langu = sy-langu.
  gd_doc_data-obj_name  = 'SAPRPT'.
  gd_doc_data-obj_descr = psubject.
  gd_doc_data-sensitivty = 'F'.

* Describe the body of the message
  clear it_packing_list.
  refresh it_packing_list.
  it_packing_list-transf_bin = space.
  it_packing_list-head_start = 1.
  it_packing_list-head_num = 0.
  it_packing_list-body_start = 1.
  describe table it_message lines it_packing_list-body_num.
  it_packing_list-doc_type = 'RAW'.
  append it_packing_list.

* Add the recipients email address
  clear it_receivers.
  refresh it_receivers.
  it_receivers-receiver = p_email.
  it_receivers-rec_type = 'U'.
  it_receivers-com_type = 'INT'.
  it_receivers-notif_del = 'X'.
  it_receivers-notif_ndel = 'X'.
  append it_receivers.

* Call the FM to post the message to SAPMAIL
  call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
       exporting
            document_data              = gd_doc_data
            put_in_outbox              = 'X'
       importing
            sent_to_all                = gd_sent_all
       tables
            packing_list               = it_packing_list
            contents_txt               = it_message
            receivers                  = it_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.

* Store function module return code
  gd_error = sy-subrc.

* Get it_receivers return code
  loop at it_receivers.
  endloop.
endform.                    " SEND_EMAIL_MESSAGE


*&---------------------------------------------------------------------*
*&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
*&---------------------------------------------------------------------*
*       Instructs mail send program for SAPCONNECT to send email.
*----------------------------------------------------------------------*
form initiate_mail_execute_program.
  wait up to 2 seconds.
  if gd_error eq 0.
      submit rsconn01 with mode = 'INT'
                    with output = 'X'
                    and return.
  endif.
endform.                    " INITIATE_MAIL_EXECUTE_PROGRAM

Regards

Sudheer

Former Member
0 Kudos

to whcih mail id u are sending ? check ur SCOT settings.

Regards

Peram

former_member150733
Contributor
0 Kudos

Pls see that sample program :

https://wiki.sdn.sap.com/wiki/display/Snippets/EmailfromSAP

Some BASIS related settings need to be done for sending external mails.

For details please read the blog :

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

Regards,

Anish Thomas

<i>Pls reward useful answers</i>

Former Member
0 Kudos

Hi,

Please check the Sy-subrc value and see the exceptions in fM -SO_NEW_DOCUMENT_ATT_SEND_API1 according to the Exception no.

And check the SCOT - Trnasaction Connectivity Enabled and message is going up to that or not check.

Regards,

Nandha

reward if it helps