Skip to Content
0
Former Member
Jul 20, 2007 at 11:28 AM

Email send doubt

71 Views

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.