2008 Apr 05 7:50 AM
Hi ABAPers,
I am very new to ABAP latest release.
I am stuck up in developing a logic which fulfills the following requirement:
If the Task = 3990 (file loaded successfully) in SAP table then those related Company ID general manager should receive a notification email. To fulfil this, I am following the below logic:
ZTAB1 - replication of SAP table '/1SEM_UCV_0A013' (BCS system)
ZTAB2 - Holds GM maild's
I am comparing SAP table with ZTAB1 to check for any records with Task = '3990'. Pick up those check whether there are present in ZTAB1, if YES then do not send any mail and if NO then send the notification mail. After sending the email successfully move those records from SAP table to ZTAB1. So, when the comparison happens for nth time a repeatitive mail will not be sent to the Managers.
The program will be scheduled on hourly basis.
To send the email I have choosen 'SO_NEW_DOCUMENT_SEND_API1' FM.
Could anyone of you please help me out by providing a sample code for the same?
Many thanks,
Sasi
PS: Would definitely reward points for your help
2008 Apr 05 11:51 AM
TABLES : ZBCS_MAIL, ZSEM_UCS, /1SEM/UCV__0A013.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE.
data: w_doc_data LIKE sodocchgi1,
l_lines type i,
l_title LIKE sodocchgi1-obj_descr.
DATA itab1 TYPE standard TABLE OF /1sem/ucv__0a013.
Data wa_tab1 type /1sem/ucv__0a013.
DATA itab2 TYPE standard TABLE OF zsem_ucs.
Data wa_tab2 type zsem_ucs.
DATA itab3 TYPE standard TABLE OF zsem_ucs.
Data wa_tab3 type zsem_ucs.
DATA itab4 TYPE standard TABLE OF zbcS_mail.
Data wa_tab4 type zbcs_mail.
SELECT * from /1sem/ucv__0a013 INTO TABLE itab1 WHERE task = '3990' and <datefield> = sy-datum.
If sy-subrc = 0.
Select * from zsem_ucs into table itab2 where task = '3990' and <datefield> = sy-datum .
If sy-subrc = 0.
LOOP at itab1 into wa_tab1.
Read table itab2 into wa_tab2 with key task = '3990' <datefield> = sy-datum <timefield> = wa_tab1-<timefield> .
If sy-subrc ne 0.
Append wa_tab1 to itab3.
Endif.
Endloop.
Else.
Itab3[] = itab1[].
Endif.
Else.
Exit.
Endif.
Subject line for the mail
l_title = 'Success...Mail program is working!!!'.
Filling the contents
clear it_message.
it_message = 'This is a sample mail for testing'.
append it_message.
Fill the document data and get size of attachment
CLEAR w_doc_data.
describe table it_message lines l_lines.
w_doc_data-doc_size = l_lines * 255.
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'EMAIL'.
w_doc_data-obj_descr = l_title.
Add the recipients email address
CLEAR: t_receivers,
wa_tab3.
REFRESH t_receivers.
If not itab3[] is initital.
Select * from zbcs_mail into
table itab4
For all entries in itab3
Where bukrs = itab3-bukrs.
Loop at itab4 into wa_tab4.
t_receivers-receiver = wa_tab4-emailid.
t_receivers-rec_type = 'U'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
Endloop.
Function module which actually sends the mail
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = w_doc_data
DOCUMENT_TYPE = 'RAW'
COMMIT_WORK = 'X'
TABLES
OBJECT_CONTENT = it_message
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.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
MODIFY zsem_ucs FROM TABLE itab3.
Endif.
Edited by: Ramesh Babu Cikka on Apr 5, 2008 12:57 PM
TABLES : ZBCS_MAIL, ZSEM_UCS, /1SEM/UCV__0A013.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE.
data: w_doc_data LIKE sodocchgi1,
l_lines type i,
l_title LIKE sodocchgi1-obj_descr.
DATA itab1 TYPE standard TABLE OF /1sem/ucv__0a013.
Data wa_tab1 type /1sem/ucv__0a013.
DATA itab2 TYPE standard TABLE OF zsem_ucs.
Data wa_tab2 type zsem_ucs.
DATA itab3 TYPE standard TABLE OF zsem_ucs.
Data wa_tab3 type zsem_ucs.
DATA itab4 TYPE standard TABLE OF zbcS_mail.
Data wa_tab4 type zbcs_mail.
SELECT * from /1sem/ucv__0a013 INTO TABLE itab1 WHERE task = '3990' and <datefield> = sy-datum.
If sy-subrc = 0.
Select * from zsem_ucs into table itab2 where task = '3990' and <datefield> = sy-datum .
If sy-subrc = 0.
LOOP at itab1 into wa_tab1.
Read table itab2 into wa_tab2 with key task = '3990' <datefield> = sy-datum <timefield> = wa_tab1-<timefield> .
If sy-subrc ne 0.
Append wa_tab1 to itab3.
Endif.
Endloop.
Else.
Itab3[] = itab1[].
Endif.
Else.
Exit.
Endif.
Subject line for the mail
l_title = 'Success...Mail program is working!!!'.
Filling the contents
clear it_message.
it_message = 'This is a sample mail for testing'.
append it_message.
Fill the document data and get size of attachment
CLEAR w_doc_data.
describe table it_message lines l_lines.
w_doc_data-doc_size = l_lines * 255.
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'EMAIL'.
w_doc_data-obj_descr = l_title.
Add the recipients email address
CLEAR: t_receivers,
wa_tab3.
REFRESH t_receivers.
If not itab3[] is initital.
Select * from zbcs_mail into
table itab4
For all entries in itab3
Where bukrs = itab3-bukrs.
Loop at itab4 into wa_tab4.
t_receivers-receiver = wa_tab4-emailid.
t_receivers-rec_type = 'U'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
Endloop.
Function module which actually sends the mail
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = w_doc_data
DOCUMENT_TYPE = 'RAW'
COMMIT_WORK = 'X'
TABLES
OBJECT_CONTENT = it_message
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.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
MODIFY zsem_ucs FROM TABLE itab3.
Endif.
Edited by: Ramesh Babu Cikka on Apr 5, 2008 12:57 PM
2008 Apr 05 11:51 AM
TABLES : ZBCS_MAIL, ZSEM_UCS, /1SEM/UCV__0A013.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE.
data: w_doc_data LIKE sodocchgi1,
l_lines type i,
l_title LIKE sodocchgi1-obj_descr.
DATA itab1 TYPE standard TABLE OF /1sem/ucv__0a013.
Data wa_tab1 type /1sem/ucv__0a013.
DATA itab2 TYPE standard TABLE OF zsem_ucs.
Data wa_tab2 type zsem_ucs.
DATA itab3 TYPE standard TABLE OF zsem_ucs.
Data wa_tab3 type zsem_ucs.
DATA itab4 TYPE standard TABLE OF zbcS_mail.
Data wa_tab4 type zbcs_mail.
SELECT * from /1sem/ucv__0a013 INTO TABLE itab1 WHERE task = '3990' and <datefield> = sy-datum.
If sy-subrc = 0.
Select * from zsem_ucs into table itab2 where task = '3990' and <datefield> = sy-datum .
If sy-subrc = 0.
LOOP at itab1 into wa_tab1.
Read table itab2 into wa_tab2 with key task = '3990' <datefield> = sy-datum <timefield> = wa_tab1-<timefield> .
If sy-subrc ne 0.
Append wa_tab1 to itab3.
Endif.
Endloop.
Else.
Itab3[] = itab1[].
Endif.
Else.
Exit.
Endif.
Subject line for the mail
l_title = 'Success...Mail program is working!!!'.
Filling the contents
clear it_message.
it_message = 'This is a sample mail for testing'.
append it_message.
Fill the document data and get size of attachment
CLEAR w_doc_data.
describe table it_message lines l_lines.
w_doc_data-doc_size = l_lines * 255.
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'EMAIL'.
w_doc_data-obj_descr = l_title.
Add the recipients email address
CLEAR: t_receivers,
wa_tab3.
REFRESH t_receivers.
If not itab3[] is initital.
Select * from zbcs_mail into
table itab4
For all entries in itab3
Where bukrs = itab3-bukrs.
Loop at itab4 into wa_tab4.
t_receivers-receiver = wa_tab4-emailid.
t_receivers-rec_type = 'U'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
Endloop.
Function module which actually sends the mail
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = w_doc_data
DOCUMENT_TYPE = 'RAW'
COMMIT_WORK = 'X'
TABLES
OBJECT_CONTENT = it_message
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.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
MODIFY zsem_ucs FROM TABLE itab3.
Endif.
Edited by: Ramesh Babu Cikka on Apr 5, 2008 12:57 PM
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |