Skip to Content
Author's profile photo Rajeev Goswami

Program to send E mail to Internet Email ID or SAP business workplace (inbox) with hyperlink more than 255 char long.

Objective:

I am using function module SO_NEW_DOCUMENT_ATT_SEND_API1 to send mail which can also send the mail with attachments.

We already have lots of program available to send the email using this FM , but sometime developer face problem while they have to send a mail which have Hyperlink with more than 255 character long.

Another problem is to open hyperlink in SAP business workplace because that hyperlink works fine in Outlook but it will not open in SAP inbox. 

My solution:

If hyperlink is more than 255 char we can break it in multiple parts using proper HTML format, and if we use variable of type cfx_hyperlink to store the hyperlink it will open properly in both Email address and SAP business workplace.

Program:

**********************************************************************************************************

* Program Name: YEMAIL_WITH_HYPER_LINK                                *

*_____________________________________________________________________*

* Description :    Program to send mail to Internet Email ID or       *

* In SAP business workplace (SAP inbox) . Mail will have Hyperlink of *

* more than 255 char in Body content.                                 *

*_____________________________________________________________________*

* Inputs:                                                             *

*  p_rec     Receiver ( Email ID or SAP User)                         *

*  r_email  Receiver Type( Email )                                    *

*  r_user   receiver type( USER  )                                    *

* Ammendments:                                                        *

*    Programmer        Date                                           *

* ================  ==========  ======  ==============================*

*  Rajeev Goswami    20/03/2012                                      

************************************************************************

REPORT  yemail_with_hyper_link.

*&———————————————————————*

*&                        SELECTION-SCREEN.

*&———————————————————————*

*Parameter to send a mail

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text001.

PARAMETERS: r_email RADIOBUTTON GROUP g1
             
DEFAULT ‘X’,             ” Email
            r_user
RADIOBUTTON GROUP g1.

*                                      ” SAP User ID

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text002.

PARAMETERS: p_rec TYPE so_text255
              OBLIGATORY
.              ” Receiver

SELECTION-SCREEN END OF BLOCK b2.

*&———————————————————————*

*&                       Data Declaration

*&———————————————————————*

* To store data about Mail containts

DATA: t_pack_list TYPE STANDARD TABLE OF sopcklsti1,
      w_pack_list
TYPE sopcklsti1.

* To store the data of mail body containt

DATA: t_mail_body  TYPE STANDARD TABLE OF solisti1,
      w_mail_body 
TYPE  solisti1.

* Receiver list

DATA: t_reclist TYPE STANDARD TABLE OF somlreci1,
      w_reclist
TYPE somlreci1.

* Mail Header Info

DATA: w_mail_header TYPE sodocchgi1.

* Variable to store the line in mail body

DATA: v_tab_lines LIKE sytabix.

* Variable to store hyperlink

DATA: v_hyperlink TYPE cfx_hyperlink.

*&———————————————————————*

*&                        START-OF-SELECTION.

*&———————————————————————*

STARTOFSELECTION.
* Create header of Mail
 
PERFORM create_mail_header.

* Create body of mail
 
PERFORM create_mail_body.

* Create packlist
 
PERFORM create_pack_list.

* Receiver list
 
PERFORM create_receiver_list.

* Call FM to send mail
 
PERFORM send_email.

*&———————————————————————*

*&      Form  CREATE_MAIL_HEADER

*&———————————————————————*

*       To create Mail Header

*———————————————————————-*

*  No parameter

*———————————————————————-*

FORM create_mail_header .

  w_mail_headerobj_name = ‘MAIL’.

*Subject in Mail
  w_mail_header
-obj_descr =
‘Mail with hyperlink developed by Rajeev Goswami’.

ENDFORM.                    ” CREATE_MAIL_HEADER

*———————————————————————-*

*&      Form  CREATE_MAIL_BODY

*———————————————————————-*

*      To fill body contents of mail (This is a HTML type document so use

*      HTML tags to format the mail body)

*———————————————————————-*

* No parameter

*———————————————————————-*

FORM create_mail_body .*create Line 1
  w_mail_body
line = ‘This mail has hyperlink of size more than 255 char’.
 
APPEND w_mail_body TO t_mail_body.

* creating URL more than 255 by dividing it into two part.

*Hyperlink part 1


  v_hyperlink
= https://www.google.co.in/#hl=en&sclient=psy-ab&q=insert+hyperlink+in+email+content+in+sap&oq=insert+hyperlink+in+email+content+in+sap&aq=f&aqi=&aql=&gs_sm=3&gs_upl=3697l7191l2l7410l9l8l1l0l0l0l234l1358l0.7.1l9l0&gs_l=hp.3…’.
 

CONCATENATE ‘<br> <a href=’ v_hyperlink INTO w_mail_bodyline.

  APPEND w_mail_body TO t_mail_body.

*Hyperlink part 2
 

CLEAR v_hyperlink.

  v_hyperlink =

‘3697l7191l2l7410l9l8l1l0l0l0l234l1358l0j7j1l9l0.&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.,cf.osb&fp=d2d3a9a0d0c68858&biw=1072&bih=535’.
 

CONCATENATE  v_hyperlink ‘> click here </a>’  INTO w_mail_bodyline.

  APPEND w_mail_body TO t_mail_body.

ENDFORM.                    ” CREATE_MAIL_BODY

*&———————————————————————*

*&      Form  CREATE_PACK_LIST

*&———————————————————————*

*       To create the pack list

*———————————————————————-*

* No parameter

*———————————————————————-*

FORM create_pack_list .

* Setting the size of mail document
 
DESCRIBE TABLE t_mail_body LINES v_tab_lines.
 
READ TABLE t_mail_body INTO w_mail_body INDEX v_tab_lines.
  w_mail_header
doc_size = ( v_tab_lines 1 ) * 255 + STRLEN( w_mail_bodyline ).
* Creating the pack listentry for the  document

  CLEAR w_pack_listtransf_bin.
  w_pack_list
head_start = 1.
  w_pack_list
head_num   = 0.
  w_pack_list
body_start = 1.
  w_pack_list
body_num   = v_tab_lines.

* Document HTML to view the Hyperlink
  w_pack_list
doc_type   = ‘HTM’.

  APPEND w_pack_list TO t_pack_list.

ENDFORM.                    ” CREATE_PACK_LIST

*&———————————————————————*

*&      Form  CREATE_RECEIVER_LIST

*&———————————————————————*

*       To list the reciever

*———————————————————————-*

* No parameter

*———————————————————————-*

FORM create_receiver_list .
* Receiver
  w_reclist
receiver = p_rec.

* Type U – Internet Email address B- SAP user
 
IF r_email = ‘X’.
    w_reclist
rec_type = ‘U’.
 
ELSE.
    w_reclist
rec_type = ‘B’.
 
ENDIF.

  APPEND w_reclist TO t_reclist.

ENDFORM.                    ” CREATE_RECEIVER_LIST

*&———————————————————————*

*&      Form  SEND_EMAIL

*&———————————————————————*

*    To send the email using FM

*———————————————————————-*

* No parameter

*———————————————————————-*

FORM send_email .

** Sending the document

CALL FUNCTION ‘SO_NEW_DOCUMENT_ATT_SEND_API1’
   
EXPORTING
      document_data             
= w_mail_header
      put_in_outbox             
= ‘X’
      commit_work               
= ‘X’
   
TABLES
      packing_list              
= t_pack_list
      contents_txt              
= t_mail_body
      receivers                 
= t_reclist
   
EXCEPTIONS
      too_many_receivers        
= 1
      document_not_sent         
= 2
      operation_no_authorization
= 4
     
OTHERS                     = 99.
 
CASE sysubrc.
   
WHEN 0.
     
WRITE: / ‘sent successfully’.
   
WHEN OTHERS.
     
WRITE: / ‘Error occurred during sending !’.

  ENDCASE.

ENDFORM.                    ” SEND_EMAIL

Program Output:

/wp-content/uploads/2012/03/output_84468.png

If user want to send email to its mail ID do the following:

1.      1.Check the internet Email Address radio button

2.      2. Enter your email ID

3.      If mail is pending in SAPconnect then Go Transaction SOST and execute it.

SAPconnect.png

And if user want to send it to SAP business workplace( TCODE – SBWP) do the following

/wp-content/uploads/2012/03/output_userid_84509.png

1.      1.Select radio button SAP user ID

2.      2.Enter SAP user name

3.      3.Go to SAP business workplace (Tcode SBWP) inboxSWBP.png

We can see the hyperlink in email body while clicking on it will open the URL properly./wp-content/uploads/2012/03/swbp_mail_84511.png

I hope this document will be helpful to beginner as well as experienced ABAP consultants.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.