Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Adding a new entry in table TSOTD

Hi Experts!!!

I'm using the FM SO_NEW_DOCUMENT_ATT_SEND_API1 to send an email from an program abap.

The program is working perfectly, but need to send a txt file as an attachment in this email.

When I execute the FM has an error in the execution of another FM: SBCOMS_SEND_REQUEST_CREATE.

I'm debuging the FM and found that the error is because there is no entry TXT in the table TSOTD.

How do I add a new entry? Or, I'm using the FM correctly?

PACKING_LIST-DOC_TYPE = 'TXT'

Best Regards,

Rafael Sá

Former Member replied

Hi Rafael,

First of all: Do not use FM SO_NEW_DOCUMENT_ATT_SEND_API1 but CL_BCS.

FORM mail .
  DATA:
    lo_bcs                    TYPE REF TO cl_bcs,
    lt_soli                   TYPE TABLE OF soli,
    lo_document_bcs           TYPE REF TO cl_document_bcs,
    lo_sapuser_bcs            TYPE REF TO cl_sapuser_bcs,
    lo_recipient_bcs          TYPE REF TO if_recipient_bcs,
    lv_soli                   TYPE soli,
    lx_bcs                    TYPE REF TO cx_bcs,
    lv_string                 TYPE string,
    lv_done                   TYPE flag,
    lv_len                    TYPE sy-linsz,
    lv_strlen                 TYPE int4,
    lv_ofs                    TYPE sy-fdpos.
  FIELD-SYMBOLS:
    <soli>                      TYPE soli.
  TRY.
      CONCATENATE:
        'Hi.'
        'I created a program before (which runs dialog and save local TXT file) that worked fine to store up to 240 characters.'
        'But now, I create a new program to run in BACKGROUND and built a TXT file and send it attached by mail.'
        'When inside a form preparing the table lines, I use CONCATENATE statement to concatenate all fields (type c) into ls_line type text2048.'
        'Table also has type text2048.'
        'It''s truncating this text line to 255 characters.'
        'PS: When debugguing I can see all variables filled in concatenate statement, but its result is a line size truncated to 255. Even the result variable having size of 2048.'
        'What is wrong with program or concatenate ?'
        'thanks.'
        'Glauco' INTO lv_string SEPARATED BY cl_abap_char_utilities=>cr_lf.
      lv_strlen = strlen( lv_string ).
      APPEND INITIAL LINE TO lt_soli ASSIGNING <soli>.
      DESCRIBE FIELD <soli> LENGTH lv_len IN CHARACTER MODE.
      WHILE lv_done IS INITIAL.
        IF lv_ofs + lv_len > lv_strlen.
          lv_len = lv_strlen - lv_ofs.
        ENDIF.
        <soli> = lv_string+lv_ofs(lv_len).
        ADD lv_len TO lv_ofs.
        IF lv_ofs >= lv_strlen.
          lv_done = abap_true.
        ELSE.
          APPEND INITIAL LINE TO lt_soli ASSIGNING <soli>.
        ENDIF.
      ENDWHILE.
      lo_bcs = cl_bcs=>create_persistent( ).
 
*     -------- create and set lo_document_bcs -------------------------------
*     create lo_document_bcs from internal table with text
      lo_document_bcs = cl_document_bcs=>create_document(
                      i_type    = 'RAW'
                      i_text    = lt_soli
                      i_subject = 'More than 255 characters mail' ).
 
      lo_document_bcs->add_attachment(
           i_attachment_type     = 'TXT'
          i_attachment_subject  = 'Attachment 1'
           i_att_content_text    = lt_soli
             ).
      lo_document_bcs->add_attachment(
           i_attachment_type     = 'TXT'
          i_attachment_subject  = 'Attachment 2'
           i_att_content_text    = lt_soli
             ).
*     add lo_document_bcs to send request
      lo_bcs->set_document( lo_document_bcs ).
 
*     --------- set lo_sapuser_bcs -------------------------------------------
*     note: this is necessary only if you want to set the lo_sapuser_bcs
*           different from actual user (SY-UNAME). Otherwise lo_sapuser_bcs is
*           set automatically with actual user.
 
      lo_sapuser_bcs = cl_sapuser_bcs=>create( sy-uname ).
      lo_bcs->set_sender( i_sender = lo_sapuser_bcs ).
 
*     --------- add lo_recipient_bcs (e-mail address) -----------------------
*     create lo_recipient_bcs - please replace e-mail address !!!
      lo_recipient_bcs = cl_cam_address_bcs=>create_internet_address(
                                        'mail_ID_at_subdomain.domain' ).
 
*     add lo_recipient_bcs with its respective attributes to send request
      lo_bcs->add_recipient(
          i_recipient = lo_recipient_bcs
          i_express   = abap_true ).
      lo_bcs->set_send_immediately( abap_true ).
*     ---------- send lo_document_bcs ---------------------------------------
      lo_bcs->send( abap_true ).
 
      COMMIT WORK.
    CATCH cx_send_req_bcs cx_document_bcs cx_address_bcs .
      MESSAGE 'Mail sending failed' TYPE 'E' .
  ENDTRY.
ENDFORM.                    " MAIL

Here I sent a mail with two text attachments. Once you tried CL_BCS you'll never again have questions about mail from ABAP - never again will use SO_NEW_DOCUMENT....

Regards,

Clemen

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question