2023 Nov 24 9:38 AM
Hi, experts i've got a problem where cl_bcs=>send() sends a message for several times.
Why it's happening and how to fix that?
data : begin of user_msg OCCURS 0.
data : usnam type usnam.
data end of user_msg.
delete ADJACENT DUPLICATES FROM user_msg comparing usnam.
loop at user_msg into ls_user_msg.
select * from zstorn_logs
INTO CORRESPONDING FIELDS OF TABLE lt_tab
WHERE usnam = ls_user_msg-usnam
and zstorndate = sy-datum.
try.
perform htm.
send_request = cl_bcs=>create_persistent( ).
document = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = lt_html
i_subject = 'Автоматический отпуск поставок' ).
CALL METHOD send_request->set_document( document ).
recipient = cl_sapuser_bcs=>create( ls_user_msg-usnam ).
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
CALL METHOD send_request->send( ).
COMMIT WORK and WAIT.
catch cx_bcs into bcs_exception.
* write: ls_vbeln_user-usnam.
write: 'Fehlertyp:'(002), bcs_exception->error_type.
exit.
ENDTRY.
clear lt_html.
clear send_request.
clear text.
clear document.
clear recipient.
clear str.
clear lt_tab.
clear curr_matnr.
endloop.
Here's in select i get data for every user in a loop.
And in 'perform htm' making an gtml table.
2023 Nov 24 11:23 AM
As the internal table user_msg is not sorted by its definition, did you sort it explicitly before delete adjacent duplicates or is it sorted by construction (select order by)
2023 Nov 24 10:08 AM
You may edit the question instead of deleting and then reposting it: notifications are sent out twice!
2023 Nov 24 10:33 AM
by 'several times' as in how many times? each user receive 2, 3, or how many mails?
perhaps you are receiving an extra status notification mail?
2023 Nov 24 10:43 AM
sometimes 2, sometimes 3, sometimes 8. It's absolutely random
No, it's just sent the same message for several times
2023 Nov 24 11:23 AM
As the internal table user_msg is not sorted by its definition, did you sort it explicitly before delete adjacent duplicates or is it sorted by construction (select order by)
2023 Nov 24 12:19 PM
Love that you have lt_html, which is filled in a form HTM and therefore is clearly global, not local as the l prefix usually indicates.
Btw. CALL METHOD isn't necessary any more. You can use the more modern functional form.
And FORMs are considered obsolete and shouldn't be used for new programs.
Have you tried debugging?
2023 Nov 24 2:14 PM
In short, cl_bcs=>send() does never send a message several times.
If a message is sent several times, it's because your program calls cl_bcs=>send() several times.
Debug your program consciously and rigorously till you understand where the bug really is and fix it.