Skip to Content

Send mail / fax with ~100 lines from a BSP application


1. WebAS as of rel. 6.20

2. BSP/ICF/ICM is configured.

3. Mail / Fax sub system connected to the R/3 system.

4. Basic ABAP / BSP skills.

The goal:

The application is able to send a textual document per mail or fax. The subject, body, sender, recipient, send art are variable over a BSP UI. It is not a goal of this weblog to show all the possibilities (what and how) a document can be sent, the goal is to have a working program wich can be easily copied and modified upon own request. Some more feature /* e.g How to send attachments… */ can be found in the SAP note: #190669. The idea is: This feature is often used to send notification information, which is usually a textual document.

The application:

Create a BSP application from Tr. SE80. We will require a page with flow logic. Create this.

The page attributes:

Each UI input enabled field, has a page attribute, to hand over the data, and an extra attribute for the status. /* To see weather the document has been sent */



if me->typeSelector is initial.

me->typeSelector = ‘INT’.



In this method we realize the effective coding wich sends the document with the help of the Function Module: ‘SO_DOCUMENT_SEND_API1’. This part of the code will be examined in the last part of the blog, here you will find the complete coding, so you can copy paste it easily.


*for the htmlb event handling 

evt type ref to if_htmlb_data,

*mail elements 

bodyTable type table of char255,      “body 

receiver type somlreci1,              “reciver  

receivers type TABLE OF somlreci1,    “table containing the reciver

senderAddr like sender,               “sender 

document_data type SODOCCHGI1,        “header informations

packing_list type table of SOPCKLSTI1,”document content description

sent_to_all type boolean,              

*help variables 

len type int4, 

base type int4, 

line type char255. 

evt = cl_htmlb_manager=>get_event_ex( request ).

case evt->event_server_name. 

“check for the send button click  when ‘SendItem’.  “send item is pressed

*first we need to split the string into an internal table  

*with line length of 255 

len = strlen( body ) / 256.  

if len gt 0.  

do  len times.   

  base = ( sy-index – 1 ) * 256.   

  if sy-index = len.    

   line = body+base.   


   line = body+base(256).


  APPEND line to bodyTable.  


ELSE. “one line length.  

append body to bodyTable. 


“The text is now in the table bodytable.

if typeSelector eq ‘INT’.               “MAIL RECIPIENT

  receiver-receiver = recipient.

  receiver-rec_type = ‘U’.

  APPEND receiver to receivers.

  move sender to senderAddr.


Add the same for FAX, if required.

“Fill the document data /subject/

document_data-obj_descr = subject.

“Fill packing list

data: p_item type SOPCKLSTI1.

describe table bodyTable lines len.  ” the length of the document

p_item-doc_type = ‘RAW’.        ” text document

p_item-transf_bin = ‘ ‘.        ” non binary

p_item-obj_descr = subject.

p_item-body_start = 1.          ” first (and only) object

p_item-body_num = len.          ” set the length.

APPEND p_item to packing_list. 

**send the document call function



       document_data              = document_data

       mput_in_outbox              = ‘ ‘

       commit_work                = ‘X’

       sender_address             = senderAddr

       sender_address_type        = typeSelector


       sent_to_all                = sent_to_all


       packing_list               = packing_list

       contents_txt               = bodyTable

       *contents_hex               = contents_hex

        receivers                  = receivers


       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.  “Error handling

       when ‘0’.

        statusT = ‘Document is sent.’.

       when others.

        statusT = ‘Error during the operation’.


Usage of the application:

– the subject is a one line text.

– the body is a multiline text, the CRLF characters are kept, so this can be a preformatted text.

– the sender and the recipient are:

    -in case of mail: standard internet Mail Addresses, like ‘

    -in case of fax: Telephone number in the following format: 2 chr country code+faxnumber. E.g: ‘DE6227757575’ for SAP Germany.


The tricky things we must care of:

Now you have a working program wich sends mail / fax docuemts, it is upon you how you enhance this. Good luck 😉

You must be Logged on to comment or reply to a post.
  • Welcome to SDB weblog. A well written one.

    for converting string to table you can use FMs like

    and for email did you had a look at cl_bcs classes.


    • Hello Raja,

      I wanted to use this Function module in this case, as I found in a lot of topics (+messages), that people often have problem using this. The purpose should be: Less questions around this topic. 🙂
      Thank you for your comment!


  • hi Dezso Pap ,
       your blog looks interesting, i have copied your application and i executed it,
        it's saying document is sent. but it's not going to the speicified e-mail address  or fax number .
      as you specified i have all prerequisites but i don't know about Mail / Fax sub system connected to the R/3 system, how can i check this exists or not from client.
       Thanks in advance.
    • Hello,

      it it says the document is sent, you should find this document in the Tr. SOST /* send queue */. When the send process runs /* You can also start it manually from here: Menu->utilities->Start send process. */ The system tries to deliver this documents.
      In Tr. SCOT you can see what communication nodes you have. You should have a properly configured INT node for Mail items, and a properly configured FAX node for FAX items.
      Check these out 😉