Function 'SO_DOCUMENT_SEND_API1' in BADI

I am encountering difficulty using the function module  'SO_DOCUMENT_SEND_API1'  in a BADI; when the BADI executes the mail is partially created (new entries exits in table SOOD) it is however not sent nor is it viewable in BWP.
Executing the same code segment in a standard program outside of the BADI results in successful message creation and delivery.
I think it has something to do with how COMMIT WORK is handled in the BADI, but I'm not sure.
Is it possible to send external mail from a BADI? What am I missing?
TIA

Hi,
Try this..Call the FM in BACKGROUND TASK..
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
         IN BACKGROUND TASK
Thanks,
Naren

Similar Messages

  • Problem using function SO_DOCUMENT_SEND_API1,

    Dear All,
    I used this function for attach the txt file and send the e-mail to relate user.
    Now, My output file print out all the data in the same line.
    how i can split the data line by line ?
    below is my coding.
    Please kindly to help me.
    Regards,
    Luke
    PERFORM send_file_as_email_attachment
                                   TABLES it_mess_bod
                                          it_mess_att
                                    USING  P_TITLE
                                          'FIX'
                                          gd_attachment_name
                                          gd_attachment_desc
                                          p_FROM
                                          'INT'
                                 CHANGING gd_error
                                          gd_reciever.
    *&      Form  send_file_as_email_attachment
          text
         -->IT_MESSAGE            text
         -->IT_ATTACH             text
         -->P_MTITLE              text
         -->P_FORMAT              text
         -->P_FILENAME            text
         -->P_ATTDESCRIPTION      text
         -->P_SENDER_ADDRESS      text
         -->P_SENDER_ADDRES_TYPE  text
         -->P_ERROR               text
         -->P_RECIEVER            text
    FORM send_file_as_email_attachment TABLES it_message
                                              it_attach
                                       USING p_email
                                        USING p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     CHANGING p_error
                                              p_reciever.
      DATA: ld_error    TYPE sy-subrc,
             ld_reciever TYPE sy-subrc,
             ld_mtitle LIKE sodocchgi1-obj_descr,
             ld_email LIKE  somlreci1-receiver,
             ld_format TYPE  so_obj_tp ,
             ld_attdescription TYPE  so_obj_nam ,
             ld_attfilename TYPE  so_obj_des ,
             ld_sender_address LIKE  soextreci1-receiver,
             ld_sender_address_type LIKE  soextreci1-adr_typ,
             ld_receiver LIKE  sy-subrc.
      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,
              w_cnt TYPE i,
              w_sent_all(1) TYPE c,
              w_doc_data LIKE sodocchgi1.
    ld_email   = p_email.
      ld_mtitle  = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    Fill the document data.
      w_doc_data-doc_size = 1.
    Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      LOOP AT itab_mailto.
        t_receivers-receiver = itab_mailto-smtp_addr.
        t_receivers-rec_type = 'U'.
        t_receivers-com_type = 'INT'.
        t_receivers-notif_del = 'X'.
        t_receivers-notif_ndel = 'X'.
        t_receivers-copy       = ''.
        APPEND t_receivers.
      ENDLOOP.
      LOOP AT S_CC.
        t_receivers-receiver = S_CC-low.
        t_receivers-rec_type = 'U'.
        t_receivers-com_type = 'INT'.
        t_receivers-notif_del = 'X'.
        t_receivers-notif_ndel = 'X'.
        t_receivers-copy       = 'X'.
        APPEND t_receivers.
      ENDLOOP.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
        EXPORTING
          document_data              = w_doc_data
          put_in_outbox              = 'X'
          sender_address             = ld_sender_address
          sender_address_type        = ld_sender_address_type
          commit_work                = 'X'
        IMPORTING
          sent_to_all                = w_sent_all
        TABLES
          packing_list               = t_packing_list
          contents_bin               = t_attachment
          contents_txt               = 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.
    Populate zerror return code
      ld_error = sy-subrc.
    Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.                    "send_file_as_email_attachment

    Hi,
    Try This ....
    DATA: l_tab_lines TYPE i,
            l_error TYPE string.
      CONSTANTS : l_c_name(13)  TYPE c VALUE 'HC Error File',   "#EC NOTEXT
                  l_c_255(255)  TYPE c VALUE '255',
                  l_c_txt(3)    TYPE c VALUE 'TXT'.
      DATA: lt_reclist  TYPE STANDARD TABLE OF somlreci1,        "Recipients
            lt_objpack  TYPE STANDARD TABLE OF sopcklsti1,
            lt_objhead  TYPE STANDARD TABLE OF solisti1,
            lt_objtxt   TYPE STANDARD TABLE OF solisti1,      "Body of EMail
            lt_objbin   TYPE STANDARD TABLE OF solisti1."Attachment of EMail
      DATA: l_wa_doc_chng TYPE sodocchgi1,   "attributes of document to send
            l_wa_reclist  LIKE LINE OF lt_reclist,
            l_wa_objpack  LIKE LINE OF lt_objpack,
            l_wa_obj      LIKE LINE OF lt_objhead.
    Begin of Insert CHRK941885
      DATA :
        l_hex LIKE solix,
        lt_contents_hex LIKE STANDARD TABLE OF solix ,
        conv TYPE REF TO cl_abap_conv_out_ce,
        l_buffer TYPE xstring,
        l_hexa(510) type x.
    End of Insert CHRK941885
    Fill attachment contents: body of email message
      CONCATENATE 'Click on attachment to view the extract file :'(t01)
                   l_c_name INTO l_wa_obj-line SEPARATED BY space.
      APPEND l_wa_obj TO lt_objtxt.   CLEAR l_wa_obj.
      APPEND l_wa_obj TO lt_objtxt.   CLEAR l_wa_obj.
      DESCRIBE TABLE lt_objtxt LINES l_tab_lines.
    Information about the email body data
      CLEAR l_wa_objpack-transf_bin.                  "Attachment not binary
      l_wa_objpack-head_start = 1.
      l_wa_objpack-head_num   = 0.
      l_wa_objpack-body_start = 1.
      l_wa_objpack-body_num   = l_tab_lines * l_c_255.
      l_wa_objpack-doc_type   = 'TXT'.
      APPEND l_wa_objpack TO lt_objpack.
      CLEAR :l_wa_objpack.
    Move error records to the file, semi-colon delimited
      LOOP AT e_error INTO g_error.
        CONCATENATE g_error-pernr ';'
                    g_error-nachn ';'
                    g_error-vorna ';'
                    g_error-werks ';'
                    g_error-persg ';'
                    g_error-eligr ';'
                    g_error-msg INTO l_error.
        APPEND l_error TO lt_objbin.
      ENDLOOP.
    Document type is TXT
      l_wa_objpack-doc_type   = l_c_txt.
    APPEND object_header.
      CALL FUNCTION 'SO_RAW_TO_RTF'
        TABLES
          objcont_old = lt_objbin
          objcont_new = lt_objbin.
    Begin of Insert CHRK941885
      LOOP AT lt_objbin into l_error.
       conv = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' endian = 'B').
        CALL METHOD conv->write( data = l_error ).
        l_buffer = conv->get_buffer( ).
        move l_buffer to l_hexa.
        move l_hexa to l_hex-line.
        APPEND l_hex to lt_contents_hex.
      ENDLOOP.
    End of Insert CHRK941885
    File name for attachment
      l_wa_obj = l_c_name.
      APPEND l_wa_obj TO lt_objhead.
      CLEAR  l_wa_obj.
      DESCRIBE TABLE lt_objbin LINES l_tab_lines.
    Creation of the entry for the compressed attachment
      l_wa_objpack-transf_bin = 'X'.
      l_wa_objpack-head_start = 1.
      l_wa_objpack-head_num   = 1.
      l_wa_objpack-body_start = 1.
      l_wa_objpack-obj_name   = l_c_name.
      l_wa_objpack-obj_descr  = l_c_name.
      l_wa_objpack-body_num   = l_tab_lines.
      l_wa_objpack-doc_size   = l_tab_lines * l_c_255.
      APPEND l_wa_objpack TO lt_objpack.
      CLEAR  l_wa_objpack.
    Completing the recipient list
      LOOP AT s_email.
        l_wa_reclist-receiver = s_email-low.
        l_wa_reclist-express  = 'X'.
        l_wa_reclist-rec_type = 'U'.
        APPEND l_wa_reclist TO lt_reclist.
        CLEAR  l_wa_reclist.
      ENDLOOP.
    Document to send
      MOVE 'Health Risk Assessment Batch extract'(h01)
        TO l_wa_doc_chng-obj_descr.
    Send mail as a confidential
      l_wa_doc_chng-sensitivty = 'P'.
    Send the document
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
        EXPORTING
          document_data              = l_wa_doc_chng
          put_in_outbox              = ' '
          commit_work                = 'X'
        TABLES
          packing_list               = lt_objpack
          object_header              = lt_objhead
         contents_bin               = lt_objbin       " Comment CHRK941885
          contents_txt               = lt_objtxt
          contents_hex               = lt_contents_hex  " Insert CHRK941885
          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 s000(oo) WITH 'Email sent to recipients'(s12).
      To refresh SAP Work Office so that mail can be recieved immediataly.
        WAIT UP TO 2 SECONDS.
        SUBMIT rsconn01 WITH mode = 'INT'
                      WITH output = ''
                      AND RETURN.
      ELSE.
        MESSAGE e000(oo) WITH 'Problem sending Email.'(e02).
      ENDIF.

  • Problem with sender name CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

    Hi All ,
    I am using below function module to send a mail to external email Id's  , Everything is working perfectly  .
    But  in the sender address I have passed text as 'infomation '  , In email which i am recieving sender address is like text and '@xyz.com' .
    Any idea from where this @xyz.com is picking  ? .
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = gd_doc_data
                put_in_outbox              = 'X'
                sender_address             =  'Information'
                sender_address_type        = 'INT'
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = gd_sent_all
           TABLES
                packing_list               = it_packing_list
                contents_bin               = it_attachment
                contents_txt               = it_message
                receivers                  = it_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.

    Hi All ,
    I am using below function module to send a mail to external email Id's  , Everything is working perfectly  .
    But  in the sender address I have passed text as 'infomation '  , In email which i am recieving sender address is like text and '@xyz.com' .
    Any idea from where this @xyz.com is picking  ? .
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = gd_doc_data
                put_in_outbox              = 'X'
                sender_address             =  'Information'
                sender_address_type        = 'INT'
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = gd_sent_all
           TABLES
                packing_list               = it_packing_list
                contents_bin               = it_attachment
                contents_txt               = it_message
                receivers                  = it_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.

  • Function module in BADI

    hi,
    have anyone worked with function module in BADI.if so plz
    let me know how how to do
    my current requirment is on that
    poits will be rewarded
    regards
    raj

    Hi Raj,
    check out these links
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d0456c54-0901-0010-f0b3-cd765fb99702
    Differences between BADI and User Exits
    BADI's
    BADI
    CMOD Vs BADI....!!!!!!!!!
    http://help.sap.com/saphelp_erp2005/helpdata/en/a3/1d40425c459923e10000000a155106/frameset.htm
    BAdI(Business Addins) are enhancement techniques using Object Oriented Technique.
    Users of BAdI can customize the logic according to the specific requirements (User-defined) or use the standard logic available.
    Each Business Add-In has
    At least one BAdI definition
    A BAdI interface
    A BAdI class that implements the interface
    For User-defined BAdI,
    developer creates an interface for the add-in.
    Enhancement management creates an adapter class that implements the interface
    Developer creates an instance of the class in the application program and calls the corresponding methods.
    For standard BAdI, interface and class will be predefined by SAP.
    Adapter class performs these tasks
    Control ( the class calls all active implementations)
    Filtering (If the Add-in has to be executed under certain conditions, the class ensures that only certain implementations are executed)

  • Function SO_DOCUMENT_SEND_API1 (send mails)   Substitutions-user-exit

    Hello Forum,
    I have to make a substitution (user-exit) for this perform.
    PERFORM U999 (ZRGGBS000) IF FOUND.
    As this code is standard, I gather that I can not touch it.
    My development is in the FORM and I can't control the parameters
    I leave the code here, you can try to find the solution that I need:
    FORM u999.
    *FORM u999 TABLES tab_contents_txt
    * it_attach
    * USING p_email
    * p_mtitle
    * p_format
    * p_filename
    * p_attdescription
    * p_sender_address
    * p_sender_addres_type
    * CHANGING p_error
    * p_reciever.
    DATA: int_error TYPE sy-subrc,
    int_receiver LIKE sy-subrc.
    DATA: w_doc_data LIKE sodocchgi1,
    chr_email LIKE somlreci1-receiver.
    DATA:
    tab_contents_txt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    tab_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
    tab_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
    document_data = w_doc_data
    put_in_outbox = 'X'
    * SENDER_ADDRESS = SY-UNAME
    * SENDER_ADDRESS_TYPE = 'B'
    commit_work = 'X'
    * IMPORTING
    * SENT_TO_ALL =
    * NEW_OBJECT_ID =
    * SENDER_ID =
    TABLES
    packing_list = tab_packing_list
    * OBJECT_HEADER =
    * CONTENTS_BIN =
    contents_txt = tab_contents_txt
    * CONTENTS_HEX =
    * OBJECT_PARA =
    * OBJECT_PARB =
    receivers = tab_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

    Hi,
    Try this..Call the FM in BACKGROUND TASK..
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
             IN BACKGROUND TASK
    Thanks,
    Naren

  • Provide me Technical Speck or Functional Speck regarding BADIs

    Hi,
    can any one provide me the Technical Speck or Functional Speck regarding BADIs  its very urgent for me. you can send to my mail id: [email protected]
    waiting for your cooperation.
    Ramarao
    Message was edited by:
            rama rao

    Hi Rama !
    You can visit the following link:
    http://mysapbi.blogspot.com/2006/12/abap-certification.html
    You will find documentation and tutorials for whatever material you wish.
    Apart from that would be sending you step by step docs for both ALE and BADI.
    Reward if its helpful.
    Abir

  • List of Functional Module and BADIs

    Hi Forum,
    I m new in this CRM, started as a CRM functional.
    Just want to know from where can i get list of all FUNCTIONAL MODULES and BADI.
    and also is it mandatory for functional consultant to have gud knowledge and expert in usage of mentioned BADI and Functional Modules..
    Kindly reply soon...
    Points will surely be awarded.
    Regards
    Rajeev Singh

    Hi Rajeev,
    Your can view the function modules in transaction SE37.
    And BADIs in SE18.Its not mandatory to know the function module details or Badi details for a functional consultant , but it always good to have a knowledge. It will reduce the task of technical consultant.
    Like Function Module CRM_ORDER_READ, is used to get the details of any business transaction. Simlarly BADI ORDER_SAVE is called every time u save a transaction etc.
    Regards,
    Shalini Chauhan

  • Email attachments created by function SO_DOCUMENT_SEND_API1 are unusable

    WE did a unicode upgrade about 2 weeks ago and since then, when using function module SO_DOCUMENT_SEND_API1 to attach a .txt file to an email, the TEXT file looks to be spaced incorrectly.  what I mean it there is a LOW-VALUE/Space between every character in the file, so when Notepad opens it, the CR_LFis there  but there is a space between each so it just becomes one continuous string of data.  is this a code page thing or a SCOT setting?
    I could not past a screen shot in here but in  a Hex Editor it shows TWO ZEROS '00' between every character,  which are low-values.

    We have been using this general code below for sometime now.  Unicode upgrade of the databases has caused the attachments to have spaces between each character in the attachment.  We get the attachment but the data inside is over spaced.   if you go thru the attached .txt file, you can delete all the extra spaces, including those between the CR/LF and
    Notepad looks to be able to understand where each line ends now.
    it_reclist = email addresses
    it_objtxt = body of the email message
    it_objbin = attachment table of type solisti1
    it_packing_list = table of sopcklsti1
    *Calling the FM SO_DOCUMENT_SEND_API1 to send the email and passing all
    *the values and then commiting the work
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
        EXPORTING
          document_data              = wa_doc_data
          put_in_outbox              = c_x
          commit_work                = c_x
        TABLES
          packing_list               = it_packing_list
          contents_bin               = it_objbin
          contents_txt               = it_objtxt
          receivers                  = it_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.
      CASE sy-subrc.
        WHEN 0.
          wa_errlog-msg = 'Email send successfully'(021).
          APPEND wa_errlog TO it_errlog.
        WHEN OTHERS.
          wa_errlog-msg = 'Email sending failed'(022).
          APPEND wa_errlog TO it_errlog.
      ENDCASE.

  • RC 6 (x_error) at function SO_DOCUMENT_SEND_API1  (XLS attachment)

    Hi at all,
    I've a problem with sending an e-mail with an attached XLS file.
    I want to generate the XLS directly from SAP no download solution or anything else. I searched the threads for any solution, but nothing works. With the implemented code below I get the exception x_error and I don't what it means.
    I have another program where I can send txt files as attachment, but no excel. Can somebody helps me?
    I work on an Unicode System.
    Thanks for your help.
    Regards, Markus
    *& Report  ZTEST_XLS_ATT
    REPORT  ztest_xls_att.
    PARAMETERS: p_email TYPE somlreci1-receiver
    DEFAULT 'test(at)test.de'.
    TYPES: BEGIN OF sol,
    text(35),
    END OF sol.
    DATA: BEGIN OF it001 OCCURS 0,
    bukrs TYPE pa0001-bukrs,
    ename TYPE pa0001-ename,
    END OF it001.
    DATA: imessage TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,
              iattach TYPE STANDARD TABLE OF sol WITH HEADER LINE,
              ipacking_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
              ireceivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
              iattachment LIKE solisti1 OCCURS 0 WITH HEADER LINE.
    START-OF-SELECTION.
      SELECT bukrs ename INTO TABLE it001 FROM pa0001 WHERE pernr = 'XXXXXX'.
    Populate table with details to be entered into .xls file
      PERFORM build_xls_data .
    Populate message body text
      CLEAR imessage.
      REFRESH imessage.
      imessage = 'Please find attached excel file'.
      APPEND imessage.
    Send file by email as .xls spreadsheet
      PERFORM send_email_with_xls TABLES imessage
      iattach
      USING p_email
      'Example Excel Attachment'
      'XLS'
      'TestFileName'
      'CompanyCodes'.
      IF sy-subrc = 0.
        MESSAGE i000(zsai).
      ENDIF.
    Form BUILD_XLS_DATA
    FORM build_xls_data .
    constants: con_cret(2) type C value '0D', "OK for non Unicode
    con_tab(2) type C value '09'. "OK for non Unicode
    *If you have Unicode check active in program attributes then you will
    *need to declare constants as follows
      CLASS cl_abap_char_utilities DEFINITION LOAD.
      CONSTANTS:
      con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
      con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
      CONCATENATE 'BUKRS' 'BUTXT'
      INTO iattach SEPARATED BY con_tab.
      CONCATENATE con_cret iattach INTO iattach.
      APPEND iattach.
      LOOP AT it001.
        CONCATENATE it001-bukrs it001-ename
        INTO iattach SEPARATED BY con_tab.
        CONCATENATE con_cret iattach INTO iattach.
    iattach = iattach(30).
        APPEND iattach.
      ENDLOOP.
    ENDFORM.                    "build_xls_data
    Form SEND_EMAIL_WITH_XLS
    Send file by email as .xls spreadsheet
    perform send_email_with_xls tables imessage
    iattach
    using p_email
    'Example Excel Attachment'
    'XLS'
    'TestFileName'
    'CompanyCodes'.
    FORM send_email_with_xls TABLES pit_message
    pit_attach
    USING p_email
    p_mtitle
    p_format
    p_filename
    p_attdescription.
      DATA: xdocdata LIKE sodocchgi1,
      xcnt TYPE i.
    Fill the document data.
      xdocdata-doc_size = 1.
    Populate the subject/generic message attributes
      xdocdata-obj_langu = sy-langu.
      xdocdata-obj_name = 'SAPRPT'.
      xdocdata-obj_descr = p_mtitle .
    Fill the document data and get size of attachment
      CLEAR xdocdata.
      READ TABLE iattach INDEX xcnt.
      xdocdata-doc_size =
      ( xcnt - 1 ) * 255 + STRLEN( iattach ).
      xdocdata-obj_langu = sy-langu.
      xdocdata-obj_name = 'SAPRPT'.
      xdocdata-obj_descr = p_mtitle.
      CLEAR iattachment.
      REFRESH iattachment.
      iattachment[] = pit_attach[].
    Describe the body of the message
      CLEAR ipacking_list.
      REFRESH ipacking_list.
      ipacking_list-transf_bin = space.
      ipacking_list-head_start = 1.
      ipacking_list-head_num = 0.
      ipacking_list-body_start = 1.
      DESCRIBE TABLE imessage LINES ipacking_list-body_num.
      ipacking_list-doc_type = 'RAW'.
      APPEND ipacking_list.
    Create attachment notification
      ipacking_list-transf_bin = 'X'.
      ipacking_list-head_start = 1.
      ipacking_list-head_num = 1.
      ipacking_list-body_start = 1.
      DESCRIBE TABLE iattachment LINES ipacking_list-body_num.
      ipacking_list-doc_type = p_format. "XLS
      ipacking_list-obj_descr = p_attdescription.
      ipacking_list-obj_name = p_filename.
      ipacking_list-doc_size = ipacking_list-body_num * 255.
      APPEND ipacking_list.
    Add the recipients email address
      CLEAR ireceivers. REFRESH ireceivers.
      ireceivers-receiver = p_email.
      ireceivers-rec_type = 'U'.
      ireceivers-com_type = 'INT'.
      ireceivers-notif_del = 'X'.
      ireceivers-notif_ndel = 'X'.
      APPEND ireceivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
        EXPORTING
          document_data              = xdocdata
          put_in_outbox              = 'X'
          commit_work                = 'X'
        TABLES
          packing_list               = ipacking_list
          contents_bin               = iattachment
          contents_txt               = imessage
          receivers                  = ireceivers
        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.
        SUBMIT rsconn01 WITH mode EQ 'INT' AND RETURN.
        COMMIT WORK .
      ENDIF.
    ENDFORM.                    "send_email_with_xls

    Hi Pekula,
    I checked your code with small modifications:
    * Mail's body
      DESCRIBE TABLE imessage LINES v_lines.
      REFRESH i_objpack.
      CLEAR i_objpack.
      v_indice = 1.
      i_objpack-transf_bin = ' '.
      i_objpack-head_start = v_indice.
      i_objpack-body_start = 1.
      i_objpack-body_num = v_lines.
      i_objpack-doc_type = 'RAW'.
      APPEND i_objpack.
    * append lines of attach to body's mail
      APPEND LINES OF iattachment TO imessage.
      v_indice = v_indice + 1.
      i_objpack-transf_bin = ' '.
      i_objpack-head_start = v_indice.
      i_objpack-body_start = v_lines + 1.
      i_objpack-obj_descr = p_attdescription. "CompanyCodes
      DESCRIBE TABLE iattachment LINES v_lines.
      i_objpack-body_num = v_lines.
      i_objpack-doc_type = p_format. "XLS
      APPEND i_objpack.
    * Information about attach
      CLEAR e_datos_doc.
      e_datos_doc-obj_descr = p_mtitle. "'Example Excel Attachment'
      e_datos_doc-doc_size = ( v_lines - 1 ) * 255 + STRLEN( iattach ).
      e_datos_doc-obj_langu  = sy-langu.
      e_datos_doc-obj_name   = 'SAPRPT'.
      e_datos_doc-sensitivty = 'F'.
    * Information of receiver
      REFRESH i_destinatario.
      CLEAR i_destinatario.
      i_destinatario-receiver = p_email. "test[at]test.de
      i_destinatario-rec_type = 'U'.
      i_destinatario-com_type = 'INT'.
      i_destinatario-notif_del = 'X'.
      i_destinatario-notif_ndel = 'X'.
      APPEND i_destinatario.
    * Envio del mail
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = e_datos_doc
          put_in_outbox              = 'X'
          commit_work                = 'X'
        TABLES
          packing_list               = i_objpack
          contents_bin               = iattachment
          contents_txt               = imessage
          receivers                  = i_destinatario
        EXCEPTIONS
          too_many_receivers         = 1
          document_not_sent          = 2
          operation_no_authorization = 4
          OTHERS                     = 99.
    I think, my iattachment or i_objpack is not correct. Can you help me?
    Whats about your i_cont_bin? I think there can be my problem.
    Regards, Markus
    Edited by: Markus Rodehutskors on Mar 13, 2009 9:12 AM

  • Enhancement points option: Function modules or BADI

    Hi, I am on ECC 6.0 and I need to validate and set some requirement in customer sales area data when user input the document output message in Documents tab strip screen 7003 of sapmf02d  in transaction XD01 or XD02.
      I found that there is function module EXIT_SAPMF02D_001 that I probably can use to create an implicit enhancement point to validate table T_KNVD or  I can use BADI customer_add_data.  Can someone suggest which way is better and why?  I am new to this so could someone show me screen by screen on how to create and implement BADI.
    I am confusing about should I create a ZBADI or using existing BADI customer_add_data.  If I use existing BADI how can I add my own method with my own code. 
    Thanks.

    Thanks. Could you explain to me how does the custom BADI get call to execute my code?  Say
    I have a customer document screen 7326 (Customer Master Subscreen SD Documents in program  SAPMF02D).  What I want is when user click save, I want to do some validation on the output message that they enter and issue some warning or error messages.
      I am on ECC 6.0 so I can create a BADI from Enhancement spot not from SE18.   SAP has a BADI called CUSTOMER_ADD_DATA with class CL_EX_CUSTOMER_ADD_DATA and interface IF_EX_CUSTOMER_ADD_DATA. 
    When I create a ZBADI_CUST, which interface class I put in the IF_EX_CUSTOMER_ADD_DATA
    or a ZIF_EX_XX so that I can create my own method?  How does the BADI get called when I am in transaction XD02 and click the save button?  Could you kindly show me step by step the procedure.
    Thanks.

  • Function module and BADI

    Hi BW gurus
    I have a datasource 0CRM_SRV_PROCESS_H and i need to enhance it where the table is BUT000 source field is PARTNER
    in the datasource im taking ZZENDCUST as the enhanced field for that i have a pseudo code like (Use FM CRM_ORDER_READ. Pass Transaction number GUID and get Partner from the table ET_PARTNER (Field: PARTNER_NO) where PARTNER_FCT = u2018ZECu2019.).This pseudo code is for my reference .My requirement is that i need to use a standard BADI RSU5_SAPI_BADI for this .how to go with this requirement.I need to know that how the BADI and function module can be linked.
    Regards,
    Siva

    Hi Siva:
    You need to look for "Enhancing datasources". Basically, in the source system, go to
    t-code: SE18
    Select: BADI NAME: RSU5_SAPI_BADI
    In the Menu: Enhancement Implementation, select: Create.
    You can also display the BADI and click on the documentation, there is good information there.
    See this link for more information:
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/3001894b-b1fb-2910-77ba-e80b6f2053b7?QuickLink=index&overridelayout=true

  • Function codes in BADI

    HI,
    I am learning BADI's. while going thru a document i got strucked with this can anyone explain me and how to do this.
    1)"*Function codes can be entered for a BADI *for the corresponding menu entries in the user interface definition"
    2) "Subscreen areas can be entered for a BADI. Screen enhancements can be implemented for these in the form of subscreen screens".

    hi,
    Function codes in Menu exits i.e Menu exits are the exits for adding new menu's to the standard transaction.
    when you check with any badi that provide menu exits it has function code like 'CU1', 'CU2',  and so on.
    for that particular fctcode you can add your own functionality,so that it appear for that transaction.
    reward points if useful,
    siri

  • Standard Function Modules, BAPIs, BADIs and User Exits  in OM

    How do I check what are the Standard Function Modules / BAPIs in OM or any HR sub modules like PA, Comp, TEM etc..

    use Tcode <b>BAPI</b> and navigate to relevant module.
    for FM go to se37 and search with HR* or RH*

  • Multi-functional Servlet considered bad practice?

    Hi,
    is it considered bad practice using doGet() for fetching say a blog entry and using doPost() for saving new entries or comments?
    Such as:
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
         blog.getPost(id);
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
         Post post = new Post(title, msg, category, author);
         blog.save(post);
    }I like to think that this is the reasoning or at least part of the reason why doGet and doPost are separate methods.
    Thank you.
    Regards,
    Adam

    Asham wrote:
    Hi,
    is it considered bad practice using doGet() for fetching say a blog entry and using doPost() for saving new entries or comments?Depends on current environment and requirements. In a small hobby application you can do so. In real business I wouldn't do so, it might bite in the future if you plan to extend that servlet with more logic.
    I like to think that this is the reasoning or at least part of the reason why doGet and doPost are separate methods.No, it is not. The HTTP protocol specification (1) offers several request methods, GET, POST, HEAD, PUT, DELETE, etc. The HttpServlet API (2) offers overrideable methods for each of those request methods so that you can handle it using some Java logic. A "plain vanilla" request is always GET. A form submit can be either GET or POST -generally POST is preferred as it can transfer more data and does "hide" query parameters.
    (1) http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
    (2) http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServlet.html

  • Function SO_DOCUMENT_SEND_API1   (substitution-user exit  about mails )

    Hello Forum,
    I have to make a substitution (user-exit) for this perform.
    Moderator message - Please respect the 2,500 character maximum when posting. Post only the relevant portions of code. And also use code tags.
    Edited by: Rob Burbank on Jan 18, 2010 2:48 PM

    Hello Forum,
    I have to make a substitution (user-exit) for this perform.
    Moderator message - Please respect the 2,500 character maximum when posting. Post only the relevant portions of code. And also use code tags.
    Edited by: Rob Burbank on Jan 18, 2010 2:48 PM

Maybe you are looking for