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

FM SO _NEW_DOCUMENT_SEND_API1'

Former Member
0 Likes
828

Hi,,

cud u plz check the below code and let me know why it is not working.

it is giving sy-subrc = 2 in FM 'SO_NEW_DOCUMENT_SEND_API1'

tables: tbtco.

types: begin of job_info,

job_count type btcjobcnt,

job_status type btcstatus,

end of job_info.

data: ls_job_info type job_info,

lt_job_info type table of job_info,

lv_dlist type so_recname.

*Selection Screen with Job Names and Dates

selection-screen begin of block b1 with frame title text-001.

select-options: job_name for tbtco-jobname.

selection-screen : skip 2.

select-options:j_date for tbtco-strtdate default sy-datum.

selection-screen end of block b1.

  • Read the failed jobs from the Database , based on the input provided

select jobcount status from tbtco

into table lt_job_info

where jobname in job_name

and strtdate in j_date

and status eq 'F'.

if not lt_job_info is initial.

  • Read the Distribution List from TVARVC Table

select single low

from tvarvc

into lv_dlist

where name = 'DL_BJ_FAILED'.

if sy-subrc eq 0.

perform sub_send_email_to_dlist using lv_dlist.

endif.

else.

write: / 'No Jobs Found '.

endif.

&----


*& Form SUB_SEND_EMAIL_TO_DLIST

&----


  • Send Email to the distribution list

----


form sub_send_email_to_dlist using lv_dlist.

data: lt_reclist type table of somlreci1 with header line.

data: lw_doc_data type sodocchgi1,

it_send_text like solisti1 occurs 2 with header line,

lv_lines type i.

  • Object description is concatenation of table, table name, allert

lw_doc_data-obj_name = 'crmd_order_index'.

lw_doc_data-obj_descr = 'Alert regarding fialed jobs'.

  • Distribution list from drop down

if not lv_dlist is initial.

lt_reclist-receiver = lv_dlist.

lt_reclist-rec_type = 'B'.

lt_reclist-express = 'X'.

append lt_reclist.

lt_reclist-receiver = ''. "ENTER EMAIL ADDRESS"

lt_reclist-rec_type = 'B'.

lt_reclist-express = 'X'.

append lt_reclist.

endif.

  • Body of the E-Mail

clear it_send_text[].

describe table lt_job_info lines lv_lines.

move 'List of Failed Jobs' to it_send_text-line.

append it_send_text.

  • LOOP AT lt_job_info INTO ls_job_info.

  • APPEND ls_job_info TO it_send_text.

  • ENDLOOP.

move 'Please take necessary action' to it_send_text-line.

append it_send_text.

  • Send the E-Mail to the distribution List

call function 'SO_NEW_DOCUMENT_SEND_API1'

exporting

document_data = lw_doc_data

document_type = 'RAW'

put_in_outbox = 'X'

commit_work = 'X'

tables

object_content = it_send_text[]

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

else.

write:/1 'An email has been sent to the distribution List'.

endif.

endform. " SUB_SEND_EMAIL_TO_DLIST

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
773

You will need to debug a little more. Check the receiver details.

Check this link: [;

6 REPLIES 6
Read only

VXLozano
Active Contributor
0 Likes
773

For Pete's Sake, try to put your code into a code tag. My eyes hurt!

sy-subrc = 2 means the mail has not been sent.

If I had to face the problem I will do two things:

1) debug

2) try to send a mail manually with the same data from SAP, if able

or

2) check if I have authorizations for transaction SCOT and continue from there

Read only

Clemenss
Active Contributor
0 Likes
773

Hi Pawan,

Please check the link [SO_NEW_DOCUMENT_SEND_API1|http://www.google.cn/search?hl=zh-CN&q=abapFMSO_NEW_DOCUMENT_SEND_API1] to get the complete answer for this and any other questions.

Regards,

Clemens

Read only

Former Member
0 Likes
773

Hi Pawan,

It took me some time to interprete your code. Hope the below is the one you are referring to.


TABLES: TBTCO.

TYPES: BEGIN OF JOB_INFO,
JOB_COUNT TYPE BTCJOBCNT,
JOB_STATUS TYPE BTCSTATUS,
END OF JOB_INFO.

DATA: LS_JOB_INFO TYPE JOB_INFO,
LT_JOB_INFO TYPE TABLE OF JOB_INFO,
LV_DLIST TYPE SO_RECNAME.


*SELECTION SCREEN WITH JOB NAMES AND DATES

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: JOB_NAME FOR TBTCO-JOBNAME.
SELECTION-SCREEN : SKIP 2.
SELECT-OPTIONS:J_DATE FOR TBTCO-STRTDATE DEFAULT SY-DATUM.
SELECTION-SCREEN END OF BLOCK B1.

* READ THE FAILED JOBS FROM THE DATABASE , BASED ON THE INPUT PROVIDED
SELECT JOBCOUNT STATUS FROM TBTCO INTO TABLE LT_JOB_INFO
WHERE JOBNAME IN JOB_NAME AND
      STRTDATE IN J_DATE AND STATUS EQ 'F'.
IF NOT LT_JOB_INFO IS INITIAL.
* READ THE DISTRIBUTION LIST FROM TVARVC TABLE 

SELECT SINGLE LOW FROM TVARVC 
  INTO LV_DLIST WHERE NAME = 'DL_BJ_FAILED'.
  IF SY-SUBRC EQ 0.
    PERFORM SUB_SEND_EMAIL_TO_DLIST USING LV_DLIST.
  ENDIF.
ELSE.
  WRITE: /
'No Jobs Found '.
ENDIF.

The form part is in my 2nd post due limitation of caracters.

Read only

Former Member
0 Likes
773

*&---------------------------------------------------------------------*
*& FORM SUB_SEND_EMAIL_TO_DLIST
*&---------------------------------------------------------------------*
* SEND EMAIL TO THE DISTRIBUTION LIST
*----------------------------------------------------------------------*

FORM SUB_SEND_EMAIL_TO_DLIST USING LV_DLIST.
  DATA: LT_RECLIST TYPE TABLE OF SOMLRECI1 WITH HEADER LINE.
  DATA: LW_DOC_DATA TYPE SODOCCHGI1,
        IT_SEND_TEXT LIKE SOLISTI1 OCCURS 2 WITH HEADER LINE,
        LV_LINES TYPE I.
*OBJECT DESCRIPTION IS CONCATENATION OF TABLE, TABLE NAME, ALLERT
  LW_DOC_DATA-OBJ_NAME = 'crmd_order_index'.
  LW_DOC_DATA-OBJ_DESCR = 'Alert regarding fialed jobs'.
* DISTRIBUTION LIST FROM DROP DOWN IF NOT LV_DLIST IS INITIAL.
  LT_RECLIST-RECEIVER = LV_DLIST.
  LT_RECLIST-REC_TYPE = 'B'.
  LT_RECLIST-EXPRESS = 'X'.
  APPEND LT_RECLIST.
  LT_RECLIST-RECEIVER = ''. "ENTER EMAIL ADDRESS"
  LT_RECLIST-REC_TYPE = 'B'.
  LT_RECLIST-EXPRESS = 'X'.
  APPEND LT_RECLIST.
ENDIF.

* BODY OF THE E-MAIL
CLEAR IT_SEND_TEXT[].
DESCRIBE TABLE LT_JOB_INFO LINES LV_LINES.
MOVE 'List of Failed Jobs' TO IT_SEND_TEXT-LINE.
APPEND IT_SEND_TEXT.

* LOOP AT LT_JOB_INFO INTO LS_JOB_INFO.
* APPEND LS_JOB_INFO TO IT_SEND_TEXT.
* ENDLOOP.

MOVE 'Please take necessary action' TO IT_SEND_TEXT-LINE.
APPEND IT_SEND_TEXT.

* SEND THE E-MAIL TO THE DISTRIBUTION LIST

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
     EXPORTING
          DOCUMENT_DATA              = LW_DOC_DATA
          DOCUMENT_TYPE              = 'RAW'
          PUT_IN_OUTBOX              = 'X'
          COMMIT_WORK                = 'X'
     TABLES
          OBJECT_CONTENT             = IT_SEND_TEXT[]
          RECEIVERS                  = LT_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.
ELSE.
  WRITE:/1 'An email has been SENT TO THE DISTRIBUTION LIST'.
ENDIF.
ENDFORM. " SUB_SEND_EMAIL_TO_DLIST
Read only

Former Member
0 Likes
774

You will need to debug a little more. Check the receiver details.

Check this link: [;

Read only

Former Member
0 Likes
773

Hi all,

solved by myself....