Search code examples
emailabapidentification

Get SOST database ID of sent emails


I have an ABAP program that sends emails. A sent email is stored in SOOD table. After sending an email I would like to get some ID of the email to be able to check its status later (in SOST table). I have seen more functions/methods to send email (e.g. cl_bcs/send, SO_NEW_DOCUMENT_SEND_API1), but none of them returns any ID. Is there a reliable way to get it?


Solution

  • Two other answers gave me together valuable clues to get it done (+1). But both missed some accuracy and code snippets, so I sum it all up in my answer.

    using cl_bcs

    DATA gr_send_request  TYPE REF TO cl_bcs.
    DATA emailid LIKE soodk.
    gr_send_request = cl_bcs=>create_persistent( ).
    
    " ...
    
    CALL METHOD gr_send_request->send(EXPORTING i_with_error_screen = 'X'
                                      RECEIVING result = gv_sent_to_all ).
    
    IF gv_sent_to_all = 'X'.
      emailid = gr_send_request->send_request->doc_wrapper_id( ).
    ENDIF.
    

    SOODK (not sood) is structure containing three components (OBJTP, OBJYR, OBJNO) which are together the key in SOOD table.

    using SO_NEW_DOCUMENT_SEND_API1

    DATA LT_OBJECTID TYPE SOFOLENTI1-OBJECT_ID.
    
    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
      EXPORTING
        DOCUMENT_DATA              = LT_MAILSUBJECT
        DOCUMENT_TYPE              = 'HTM'
      IMPORTING
        new_object_id              = lt_objectid
    " ...
    

    lt_objectid (SOFOLENTI1-OBJECT_ID) is char(17), that contains concatenated SOODK structure OBJTP+OBJYR+OBJNO. When divided to parts, it can be used to lookup a record in SOODK table. (I didn't find it in BCST_SR-SCOM_KEY, but it was not necessary.)