Application Development and Automation 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: 
Read only

SO_DOCUMENT_SEND_API1

Former Member
0 Likes
1,802

Hi Experts,

Please see the following code:

open dataset zfile for OUTPUT IN TEXT MODE encoding default.

if sy-subrc = 0.

if not Jtab[] is initial.

loop at Jtab.

transfer Jtab to zfile.

endloop.

else.

endif.

So after else i have to send a mail to a mail id say ravi_test@gmail.com. using above FM: O_DOCUMENT_SEND_API1

So can any body let me know the simple code for this.

I don't want to send any attachments thru mail.

I just want to say "Error in Reading file Zfile".In message body.

So can any body let me know the simple code for this.

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,367

hi,

very simple. u fill <b>g_t_object_content</b> internal table with the text u have to mail.

  • Subject of the mail

g_s_document_data-obj_name = 'Report'.

g_s_document_data-obj_descr = text-t10.

  • Fill internal table with receiver parameters

g_s_receivers-rec_type = 'U'.

g_s_receivers-express = 'X'.

g_s_receivers-receiver = 'ravi_test@gmail.com'.

APPEND g_s_receivers TO g_t_receivers.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = g_s_document_data

document_type = 'RAW'

TABLES

object_content = g_t_object_content

receivers = g_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.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

reward if useful..

12 REPLIES 12
Read only

Former Member
0 Likes
1,367

form SEND_EMAIL tables IT_MESSAGE type T_MESSAGE.

data: IS_DOCDATA type SODOCCHGI1,

IS_RECEIVERS type SOMLRECI1,

IS_RECEIVERS_COPY type SOMLRECI1,

IT_RECEIVERS type table of SOMLRECI1,

IS_CONTENT type SOLISTI1,

IT_CONTENT type table of SOLISTI1,

*500369789+

l_txt(255) type c,

lt_objpack TYPE TABLE OF sopcklsti1 WITH HEADER LINE,

lt_objhead TYPE TABLE OF solisti1 WITH HEADER LINE,

lt_objtxt TYPE TABLE OF solisti1 WITH HEADER LINE,

l_tab_lines TYPE i,

l_att_type LIKE soodk-objtp.

*500369789+

IS_DOCDATA-OBJ_NAME = 'MAIL'.

IS_DOCDATA-PRIORITY = 5.

IS_DOCDATA-OBJ_LANGU = SY-LANGU.

IS_DOCDATA-NO_CHANGE = 'X'.

IS_DOCDATA-OBJ_DESCR = SY-CPROG.

loop at IT_MESSAGE into IS_MESSAGE.

clear : IS_CONTENT, l_txt. "500369789+

move is_message-line to l_txt. "500369789+

  • move IS_MESSAGE-LINE to IS_CONTENT-LINE. "500369789-

move l_txt to IS_CONTENT-LINE. "500369789+

append IS_CONTENT to IT_CONTENT.

endloop.

*---select_email_address

select single

EMAILADDR

CCEMAILADDR

into (IS_RECEIVERS-RECEIVER, IS_RECEIVERS_COPY-RECEIVER)

from ZGL_EMAILCTRL

where IDENT = ''

and ZPROGRAM = 'Z_L_SO_CREA'

and ACTIVE = 'X'.

if IS_RECEIVERS-RECEIVER is not initial.

IS_RECEIVERS-REC_TYPE = 'U'.

IS_RECEIVERS_COPY-REC_TYPE = 'U'.

IS_RECEIVERS_COPY-COPY = 'X'.

append IS_RECEIVERS to IT_RECEIVERS.

append IS_RECEIVERS_COPY to IT_RECEIVERS.

SEND EMAIL FOR PLANTS

call function 'SO_NEW_DOCUMENT_SEND_API1'

exporting

DOCUMENT_TYPE = 'RAW'

DOCUMENT_DATA = IS_DOCDATA

COMMIT_WORK = 'X'

tables

OBJECT_CONTENT = IT_CONTENT

RECEIVERS = IT_RECEIVERS

exceptions

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

others = 99.

if SY-SUBRC <> 0.

endif.

endif.

endform. "send_email

Read only

Former Member
0 Likes
1,367

this program is used to send mails to the users internet mail addresses.

REPORT ZSRIM_PRG_MAIL1 .


 DATA : L_TABLE_LINES LIKE SY-TABIX,                   " table index
         L_TAB TYPE X VALUE '09',                       " TAB value
         L_MANDT TYPE SY-MANDT.                         " Client

  DATA: X_DOC_CHNG LIKE SODOCCHGI1,              " document attributes
        IT_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,
                                                 " attachment table
        IT_OBJHEAD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
                                                 " object header table
        IT_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
                                                 " binary table
        IT_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
        IT_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE.

  CLEAR IT_RECLIST.
  REFRESH IT_RECLIST.

*-popualate email ids
      IT_RECLIST-RECEIVER = 'ABC@YAHOO.com'.
      IT_RECLIST-REC_TYPE = 'U'.
*-append receiver table
      APPEND IT_RECLIST.
      CLEAR  IT_RECLIST.

*-populate document attributes
    CLEAR: X_DOC_CHNG.
    X_DOC_CHNG-OBJ_NAME = 'HEADING'.
    X_DOC_CHNG-OBJ_DESCR = 'SOME DESCRIPTION'.

*-populate body text
    IT_OBJTXT = 'ARCOS Reporting Extraction Error file is attached'.
    APPEND IT_OBJTXT.


*-document size
    CLEAR : L_TABLE_LINES.
    DESCRIBE TABLE IT_OBJTXT LINES L_TABLE_LINES.
    READ TABLE IT_OBJTXT INDEX L_TABLE_LINES.
    X_DOC_CHNG-DOC_SIZE =
                 ( L_TABLE_LINES - 1 ) * 255 + STRLEN( IT_OBJTXT ).

*-populate packing list for body text
    CLEAR IT_OBJPACK-TRANSF_BIN.
    IT_OBJPACK-HEAD_START = 1.
    IT_OBJPACK-HEAD_NUM = 0.
    IT_OBJPACK-BODY_START = 1.
    IT_OBJPACK-BODY_NUM = L_TABLE_LINES.
    IT_OBJPACK-DOC_TYPE = 'RAW'.
    APPEND IT_OBJPACK.
    CLEAR IT_OBJPACK.


*-populate object header
    IT_OBJHEAD = 'Arcos Error Report'(057).

    APPEND IT_OBJHEAD.
    CLEAR  IT_OBJHEAD.
*-Sending the document
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
         EXPORTING
              DOCUMENT_DATA              = X_DOC_CHNG
             PUT_IN_OUTBOX              = 'X'
             COMMIT_WORK                = 'X'
*    IMPORTING
*         SENT_TO_ALL                =
*         NEW_OBJECT_ID              =
         TABLES
              PACKING_LIST               = IT_OBJPACK
             OBJECT_HEADER              = IT_OBJHEAD
             CONTENTS_BIN               = IT_OBJBIN
             CONTENTS_TXT               = IT_OBJTXT
*         CONTENTS_HEX               =
*         OBJECT_PARA                =
*         OBJECT_PARB                =
              RECEIVERS                  = IT_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 SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

Message was edited by: Srikanth Kidambi

Read only

Former Member
0 Likes
1,368

hi,

very simple. u fill <b>g_t_object_content</b> internal table with the text u have to mail.

  • Subject of the mail

g_s_document_data-obj_name = 'Report'.

g_s_document_data-obj_descr = text-t10.

  • Fill internal table with receiver parameters

g_s_receivers-rec_type = 'U'.

g_s_receivers-express = 'X'.

g_s_receivers-receiver = 'ravi_test@gmail.com'.

APPEND g_s_receivers TO g_t_receivers.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = g_s_document_data

document_type = 'RAW'

TABLES

object_content = g_t_object_content

receivers = g_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.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

reward if useful..

Read only

0 Likes
1,367

Hi See the code.

tables: comm_pcat_cty.

data: begin of itab occurs 0,

name(50),

des(50),

ecode(10),

END OF ITAB.

data: begin of Jtab occurs 0,

name(50),

des(50),

ecode(10),

END OF JTAB.

data: zfile(1000),

zfile1(1000).

zfile = 'ztestfile.txt'.

zfile1 = 'ztestfile1'.

*For Sending mail

DATA: g_s_document_data LIKE SODOCCHGI1. " document attributes

data: g_t_object_content like SOLISTI1 occurs 0 with header line.

data: g_t_receivers type SOMLRECI1.

data: g_s_receivers like SOMLRECI1 occurs 0 with header line.

*************mail**

ITAB-NAME = 'ABCD'.

ITAB-DES = 'DEFG'.

ITAB-ECODE = 'HJBK'.

APPEND ITAB.

CLEAR ITAB.

JTAB-NAME = 'KLMN'.

JTAB-DES = 'PQRS'.

JTAB-ECODE = 'GHIJ'.

APPEND JTAB.

CLEAR JTAB.

open dataset zfile1 for input IN TEXT MODE encoding default..

if sy-subrc = 0.

if not Itab[] is initial.

loop at Itab.

transfer Itab to zfile.

endloop.

endif.

else.

*******For mail********

g_s_document_data-obj_name = 'Report'.

g_s_document_data-obj_descr = text-t10.

  • Fill internal table with receiver parameters

g_s_receivers-rec_type = 'U'.

g_s_receivers-express = 'X'.

g_s_receivers-receiver = 'devineedi2000@yahoo.com'.

APPEND g_s_receivers .

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = g_s_document_data

DOCUMENT_TYPE = 'RAW'

  • PUT_IN_OUTBOX = ' '

  • COMMIT_WORK = ' '

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

  • OBJECT_HEADER =

OBJECT_CONTENT = g_t_object_content

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

RECEIVERS = g_s_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

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

After this FM i am getting sy-subrc = 2.

What may be the problem?

Regards

Read only

0 Likes
1,367

Please set the particular parameter in the FM

<b>COMMIT_WORK = 'X'</b>

Read only

0 Likes
1,367

Even then i am getting sy-subrc = 2.

Read only

0 Likes
1,367

U have not filled the content table <b>g_t_object_content </b> in your code..can you please confirm the same ?

Read only

0 Likes
1,367

Hi ,

Now also i am getting sy-subrc = 2.

See the code.

tables: comm_pcat_cty.

data: begin of itab occurs 0,

name(50),

des(50),

ecode(10),

END OF ITAB.

data: begin of Jtab occurs 0,

name(50),

des(50),

ecode(10),

END OF JTAB.

data: zfile(1000),

zfile1(1000).

zfile = 'ztestfile.txt'.

zfile1 = 'ztestfile1'.

*For Sending mail

DATA: g_s_document_data LIKE SODOCCHGI1.

data: g_t_object_content like SOLISTI1 occurs 0 with header line.

data: g_t_receivers type SOMLRECI1.

data: g_s_receivers like SOMLRECI1 occurs 0 with header line.

*************mail**

ITAB-NAME = 'ABCD'.

ITAB-DES = 'DEFG'.

ITAB-ECODE = 'HJBK'.

APPEND ITAB.

CLEAR ITAB.

JTAB-NAME = 'KLMN'.

JTAB-DES = 'PQRS'.

JTAB-ECODE = 'GHIJ'.

APPEND JTAB.

CLEAR JTAB.

open dataset zfile1 for input IN TEXT MODE encoding default..

if sy-subrc = 0.

if not Itab[] is initial.

loop at Itab.

transfer Itab to zfile.

endloop.

endif.

else.

*******For mail********

g_s_document_data-obj_name = 'Report'.

g_s_document_data-obj_descr = text-t10.

  • Fill internal table with receiver parameters

g_s_receivers-rec_type = 'U'.

g_s_receivers-express = 'X'.

g_s_receivers-receiver = 'def@yahoo.com'.

APPEND g_s_receivers .

<b>g_t_object_content-line = 'Error in reading file'.

append g_t_object_content.

clear g_t_object_content.</b>

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = g_s_document_data

DOCUMENT_TYPE = 'RAW'

  • PUT_IN_OUTBOX = ' '

COMMIT_WORK = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

  • OBJECT_HEADER =

OBJECT_CONTENT = g_t_object_content

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

RECEIVERS = g_s_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

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

endif.

Read only

0 Likes
1,367
CLEAR :doc_chng,w_subject.
  CONCATENATE 'You have not logged on for 180 days for client' sy-mandt
                                      INTO w_subject SEPARATED BY space.
  doc_chng-obj_descr  = w_subject.

  it_objtxt-line = w_subject.
  APPEND it_objtxt.
  CLEAR it_objtxt.
  it_objtxt-line = text-001.
  APPEND it_objtxt.
  CLEAR it_objtxt.
  it_objtxt-line = text-002.
  APPEND it_objtxt.
  CLEAR it_objtxt.
  it_objtxt-line = text-003.
  APPEND it_objtxt.
  CLEAR it_objtxt.

  DESCRIBE TABLE it_objtxt LINES w_tab_line.

  READ TABLE it_objtxt INDEX w_tab_line.

  doc_chng-doc_size = ( w_tab_line - 1 ) * 255 + STRLEN( it_objtxt ).

  CLEAR it_objpack-transf_bin.
  it_objpack-head_start = 1.
  it_objpack-head_num   = 0.
  it_objpack-body_start = 1.
  it_objpack-body_num   = w_tab_line.
  it_objpack-doc_type   = 'RAW'.
  APPEND it_objpack.
  CLEAR it_objpack.

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = doc_chng
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = it_objpack
      contents_txt               = it_objtxt
      receivers                  = it_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 EQ 0.
    SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
  ENDIF.
Read only

0 Likes
1,367

I tried the same and it works so I would advice you to run the FM 'SO_NEW_DOCUMENT_SEND_API1' via SE37 and try and give the particular data in the run and check if it sends out the email (you can even debug it).

Read only

0 Likes
1,367

Hi,

It is working..But Mial is not there.

Any mail settings need to be done in SAP system by basis people?

Regards

Read only

0 Likes
1,367

Can you see the particular mail via SCOT transaction and I think they need to run a job to send out the emails, hope that is scheduled and running for emails to work.