Skip to end of metadata
Go to start of metadata

This page contains ABAP snippets which send emails.

The program is used to convert output of ALV/CLASSICAL reports into HTML format and mail it as attachment to the mail id’s specified in a custom distribution list.The distribution lists can be maintained using transaction SO23 or please check following link http://help.sap.com/saphelp_nw04/helpdata/en/a8/809d1dfc8711d2a2b400a0c943858e/content.htm

General program flow.

Step 1: With input values the report is executed using Submit and Return ,and exported to spool

Step 2: The spool is retrieved.

Step 3: Using Fun.Mod. Compress the table .

Step 4: Create attachment .

Step 5: Send mail using SO_NEW_DOCUMENT_ATT_SEND_API1.

Step 6: Run report "rsconn01" to release the queue and send mails.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*& Report  ZALV_MAIL
*&---------------------------------------------------------------------*
REPORT  zalv_mail.
*=======================================================================*
*PROGRAM ID           :   zalv_mail
*PROGRAM TITLE        :   Mail ALV Report
*AUTHOR               :   Harikrishnan.S
*SUPPLIER             :
*DATE                 :   10.03.2011
*DEVELOPMENT ID       :
*CHANGE REQUEST NO    :
*DESCRIPTION          :   Mail any ALV/classical report output as
*                         Attachment(HTML)
*=======================================================================*
INCLUDE zalv_mail_top.        "TOP
INCLUDE zalv_mail_performs.   "PERFORMS
INCLUDE zalv_mail_forms.      "FORMS
*&---------------------------------------------------------------------*
*&  Include           ZALV_MAIL_TOP                                    *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*                     DECLARATIONS
*&---------------------------------------------------------------------*
TABLES: tsp01,zdmail1.
DATA: docdata    LIKE sodocchgi1,
      objpack    LIKE sopcklsti1 OCCURS  1 WITH HEADER LINE,
      objhead    LIKE solisti1   OCCURS  1 WITH HEADER LINE,
      objtxt     LIKE solisti1   OCCURS 10 WITH HEADER LINE,
      objbin     LIKE solisti1   OCCURS 10 WITH HEADER LINE,
      objhex     LIKE solix      OCCURS 10 WITH HEADER LINE,
      reclist    LIKE somlreci1  OCCURS  1 WITH HEADER LINE.
DATA: tab_lines  TYPE i,
      doc_size   TYPE i,
      att_type   LIKE soodk-objtp.
DESCRIBE TABLE objbin LINES tab_lines.
DATA:t_msg_att  TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE.
DATA:mstr_print_parms LIKE pri_params,
     mc_valid(1)      TYPE c,
     mi_bytecount     TYPE i,
     mi_length        TYPE i,
     mi_rqident       LIKE tsp01-rqident.
DATA:it_zdmail TYPE TABLE OF zdmail1,
     wa_zdmail LIKE LINE  OF it_zdmail.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME.
PARAMETER: p_repid      TYPE sy-repid OBLIGATORY,
           p_varnt(25)  TYPE c ,
           p_attnam(25) TYPE c OBLIGATORY,
           p_title(25) TYPE c  OBLIGATORY,
           p_body(255)  TYPE c.
PARAMETER p_dlid TYPE zdmail1-dlid OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN END OF BLOCK b1.
*&---------------------------------------------------------------------*
*&  Include           ZALV_MAIL_PERFORMS                               *
*&---------------------------------------------------------------------*
*  EXECUTE THE REPORT AND EXPORT TO SPOOL
PERFORM call_report.
*  GET SPOOL REQUEST NO
PERFORM get_spool_number USING p_repid
                               sy-uname
                               CHANGING mi_rqident.
*  GET DATA FRM SPOOL AND SEND MAIL
PERFORM get_data_mail.
*&---------------------------------------------------------------------*
*&  Include           ZALV_MAIL_FORMS                                  *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  call_report
*&---------------------------------------------------------------------*
*       Call any ALV REPORT
*----------------------------------------------------------------------*
FORM call_report .
*SUBMIT ALV GRID REPORT  TO SPOOL AND RETURN
  SUBMIT (p_repid)  TO SAP-SPOOL
                    USING SELECTION-SET p_varnt
                    WITHOUT SPOOL DYNPRO
                    DESTINATION space
*                    COVER TEXT ''
                    NEW LIST IDENTIFICATION 'X'
                    IMMEDIATELY space
                    AND RETURN.
ENDFORM.                    " call_report
*&---------------------------------------------------------------------*
*&      Form  get_spool_number
*&---------------------------------------------------------------------*
*    GET THE SPOOL REQUEST  NO rq2name FROM TABLE TSP01
*----------------------------------------------------------------------*
FORM get_spool_number USING: f_repid
                             f_uname
                            CHANGING f_rqident.
  DATA:
    lc_rq2name LIKE tsp01-rq2name.
  CONCATENATE f_repid                                       "+0(8)
              f_uname+0(3)
    INTO lc_rq2name SEPARATED BY '_'.
  SELECT * FROM tsp01 WHERE  rq2name = lc_rq2name
  ORDER BY rqcretime DESCENDING.
    f_rqident = tsp01-rqident.
    EXIT.
  ENDSELECT.
  IF sy-subrc NE 0.
    CLEAR f_rqident.
  ENDIF.
ENDFORM." get_spool_number
*&---------------------------------------------------------------------*
*&      Form  spool_to_html
*&---------------------------------------------------------------------*
FORM spool_to_html .
ENDFORM.                    " spool_to_html
*&---------------------------------------------------------------------*
*&      Form  GET_DATA_MAIL
*&---------------------------------------------------------------------*
FORM get_data_mail .
  DATA: mem_tab LIKE abaplist OCCURS 10.
*GET DATA FRM SPOOL AND EXPORT AS LIST TO MEMORY
  SUBMIT rspolist EXPORTING LIST TO MEMORY AND RETURN
                    WITH rqident = mi_rqident
                    WITH first = '1'
                    WITH last = '0'.
  CALL FUNCTION 'LIST_FROM_MEMORY'
    TABLES
      listobject = mem_tab
    EXCEPTIONS
      not_found  = 1
      OTHERS     = 2.
*COMPRESS LIST TO TABLE
  CALL FUNCTION 'TABLE_COMPRESS'
*     IMPORTING
*       COMPRESSED_SIZE       =
    TABLES
       in                    = mem_tab
       out                   = objbin
    EXCEPTIONS
       OTHERS                = 1.
  IF sy-subrc <> 0.
    MESSAGE ID '61' TYPE 'E' NUMBER '731'
    WITH 'TABLE_COMPRESS'.
  ENDIF.
** NOTE: Creation of attachment is finished yet.
**   For your report, the attachment should be placed into table
**     objtxt for plain text or
**     objbin for binary content.
**   Now create the message and send the document.'recipients!'.
** Create Message Body
**   Title and Description
  docdata-obj_name  = 'Royal Enfield'.
  docdata-obj_descr = p_title.
**   Main Text
  objtxt = p_body.
  APPEND objtxt.
  objtxt = text-002.
  APPEND objtxt.
  objtxt = 'Have a nice day.'.
  APPEND objtxt.
*
**   Write Packing List (Main)
*
  DESCRIBE TABLE objtxt LINES tab_lines.
  READ     TABLE objtxt INDEX tab_lines.
  docdata-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).
  CLEAR objpack-transf_bin.
  objpack-head_start = 1.
  objpack-head_num   = 0.
  objpack-body_start = 1.
  objpack-body_num   = tab_lines.
  objpack-doc_type   = 'RAW'.
  APPEND objpack.
** Create Message Attachment
*
**   Write Packing List (Attachment)
*
  att_type = 'ALI'.
  DESCRIBE TABLE objbin LINES tab_lines.
  READ     TABLE objbin INDEX tab_lines.
  objpack-doc_size = ( tab_lines - 1 ) * 255 + strlen( objbin ).
  objpack-transf_bin = 'X'.
  objpack-head_start = 1.
  objpack-head_num   = 0.
  objpack-body_start = 1.
  objpack-body_num   = tab_lines.
  objpack-doc_type   = att_type.
  objpack-obj_name   = 'ATTACHMENT'.
  objpack-obj_descr  = p_attnam.
  APPEND objpack.
*
** Create receiver list
  CLEAR: it_zdmail,
         wa_zdmail.
  SELECT * INTO TABLE it_zdmail FROM zdmail1 WHERE
                                                 dlid = p_dlid.
*ADD THE EMAIL IDS TO RECLIST-RECEIVER
* loop changed 10/MAY/2011 - HKS
  LOOP AT it_zdmail INTO wa_zdmail.
    reclist-receiver = wa_zdmail-email.  "<-- change address
    reclist-rec_type = 'U'.
    APPEND reclist.
  ENDLOOP.
  reclist-receiver = sy-uname.                "<-- change internal user
  reclist-rec_type = 'B'.
  APPEND reclist.
** Send Message
*
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data = docdata
      put_in_outbox = 'X'
      commit_work   = 'X'     "used from rel.6.10
    TABLES
      packing_list  = objpack
      object_header = objhead
      contents_bin  = objbin
      receivers     = reclist.
*      ADDED BY HARIKRISHNAN-HBS:06.05.2011
*      REASON:  "reclist" IF NOT CLEARED THE MAIL WILL BE REPEATEDLY
*               SENT TO SAME  ADDRESS
  CLEAR     reclist.
*      END OF ADDITION BY HARIKRISHNAN-HBS:06.05.2011
  IF sy-subrc <> 0.
*RELEASE AND SEND MESSAGES IN QUEUE
    CALL FUNCTION 'SO_DEQUEUE_UPDATE_LOCKS'
      EXCEPTIONS
        communication_failure = 1
        system_failure        = 2
        OTHERS                = 3.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    SUBMIT rsconn01 WITH mode = 'INT'
          WITH output = ' '
          AND RETURN.
  ENDIF.
ENDFORM.                    " GET_DATA_MAIL

TABLE DETAILS (ZTABLE FOR DIST LIST)

FIELD

KEY

INITIAL

DATAELEMENT

DATA TYPE

LENGTH

DECIMAL

DESCRIPTION

MANDT

X

X

MANDT

CLNT

3

0

CLIENT

SRNR

X

X

ZSRNR

INT4

10

0

SERIAL NO

DLID

 

 

ZDLID

CHAR

20

0

DISTRIBUTION LIST ID

EMAIL

 

 

AD_SMTPADR

CHAR

241

0

EMAIL ADDRESS

Now you can maintain data by creating a parameter transaction.

the signature of CL_DOCUMENT_BCS~ADD_ATTACHMENT:

suppose we already have PDF binary source with type XSTRING, variable iv_pdf_content.
i_attachment_type: value list of attachment type could be found in value table TSOTD:

 

in PDF, we should use BIN
i_attachment_size: could be filled via xstrlen( iv_pdf_content )
i_att_content_hex: cl_document_bcs=>xstring_to_solixip_xstring iv_pdf )
i_attachment_subject: for example test.pdf
finally the PDF attachment could be found in email box.


Back to Sending Mails - Home Page

I have seen many approaches for sending mail with attachment. Here i am writing a function module to send mail with attachment using object oriented approach. The use of this approach would eliminate bulky coding.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
FUNCTION ZNPI_SEND_MAIL.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(SUBJECT) TYPE  SO_OBJ_DES
*"     VALUE(MESSAGE_BODY) TYPE  BCSY_TEXT
*"     VALUE(ATTACHMENTS) TYPE  RMPS_T_POST_CONTENT OPTIONAL
*"     VALUE(SENDER_UID) TYPE  SYUNAME OPTIONAL
*"     VALUE(RECIPIENT_UID) TYPE  SYUNAME OPTIONAL
*"     VALUE(SENDER_MAIL) TYPE  ADR6-SMTP_ADDR OPTIONAL
*"     VALUE(RECIPIENT_MAIL) TYPE  ADR6-SMTP_ADDR OPTIONAL
*"  EXPORTING
*"     VALUE(RESULT) TYPE  BOOLEAN
*"  TABLES
*"      RECIPIENTS STRUCTURE  UIYS_IUSR OPTIONAL
*"----------------------------------------------------------------------
*Data Declaration 
  DATA: lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,
          l_send type ADR6-SMTP_ADDR ,
          l_rec type  ADR6-SMTP_ADDR .
   Data : ITAB TYPE TABLE OF SVAL,
          LS_ITAB TYPE SVAL,
          i_RETURN.
     DATA:
     lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
*     DATA:
*    lt_message_body TYPE bcsy_text VALUE IS INITIAL,
     DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL,
     attachment_subject type SO_OBJ_DES.
 
   DATA: lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.
   data: ls_recipient like line of recipients,
   ls_attachment like line of attachments.
   DATA: lv_recipient_uid TYPE uname,
         lv_recipient_mail TYPE adr6-smtp_addr.

*Prepare Mail Object 
     CLASS cl_bcs DEFINITION LOAD.
     lo_send_request = cl_bcs=>create_persistent( ).
* Message body and subject
 data: lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.
     lo_document = cl_document_bcs=>create_document(
     i_type = 'RAW'
     i_text =  message_body
     i_subject = subject ).
 
 
 
*Send  attachment 
 loop at attachments into ls_attachment.
     attachment_subject = ls_attachment-subject.
     TRY.
         lo_document->add_attachment(
         EXPORTING
         i_attachment_type = ls_attachment-OBJTP
         i_attachment_subject = attachment_subject
 
         i_att_content_hex = ls_attachment-CONT_HEX ).
       CATCH cx_document_bcs INTO lx_document_bcs.
     ENDTRY.
 endloop.
 
* Pass the document to send request 
     lo_send_request->set_document( lo_document ).
 try.
     if sender_mail is not initial.
       lo_sender = cl_cam_address_bcs=>create_internet_address( sender_mail ).
           elseif sender_uid is not initial.
       lo_sender = cl_sapuser_bcs=>create( sender_uid ).
     else.
       lo_sender = cl_sapuser_bcs=>create( sy-uname ).
     endif.
* Set sender 
     lo_send_request->set_sender(
     EXPORTING
     i_sender = lo_sender ).
        catch CX_ADDRESS_BCS.
          return.
        endtry.
* Set  recipients 
 if recipients[] is initial.
 
     if recipient_mail is not initial.
       lo_recipient = cl_cam_address_bcs=>create_internet_address( recipient_mail ).
           elseif recipient_uid is not initial.
       lo_recipient = cl_sapuser_bcs=>create( recipient_uid ).
     else.
       lo_recipient = cl_sapuser_bcs=>create( sy-uname ).
     endif.
 
     lo_send_request->add_recipient(
     EXPORTING
     i_recipient = lo_recipient
     i_express = 'X' ).
 else.
 
 loop at recipients into ls_recipient.
     if ls_recipient-iusrid is not initial.
       lv_recipient_uid = ls_recipient-iusrid.
       lo_recipient = cl_sapuser_bcs=>create( lv_recipient_uid ).
     elseif ls_recipient-email is not initial.
       lv_recipient_mail = ls_recipient-email .
       lo_recipient = cl_cam_address_bcs=>create_internet_address( lv_recipient_mail ).
     endif.
 
 lo_send_request->add_recipient(
     EXPORTING
     i_recipient = lo_recipient
     i_express = 'X' ).
 
 endloop.
 endif.
 try.
** Send email 
     lo_send_request->send(
     EXPORTING
     i_with_error_screen = 'X'
     RECEIVING
     result = result ).
     COMMIT WORK.
     wait up to 1 seconds.
catch cx_send_req_bcs.
      result = ''.
endtry.

ENDFUNCTION.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA method1 LIKE sy-ucomm.
DATA g_user LIKE soudnamei1.
DATA g_user_data LIKE soudatai1.
DATA g_owner LIKE soud-usrnam.
DATA g_receipients LIKE soos1 OCCURS 0 WITH HEADER LINE.
DATA g_document LIKE sood4 .
DATA g_header LIKE sood2.
DATA g_folmam LIKE sofm2.
DATA g_objcnt LIKE soli OCCURS 0 WITH HEADER LINE.
DATA g_objhead LIKE soli OCCURS 0 WITH HEADER LINE.
DATA g_objpara  LIKE selc OCCURS 0 WITH HEADER LINE.
DATA g_objparb  LIKE soop1 OCCURS 0 WITH HEADER LINE.
DATA g_attachments LIKE sood5 OCCURS 0 WITH HEADER LINE.
DATA g_references LIKE soxrl OCCURS 0 WITH HEADER LINE.

DATA g_authority LIKE sofa-usracc.
DATA g_ref_document LIKE sood4.
DATA g_new_parent LIKE soodk.
DATA: BEGIN OF g_files OCCURS 10 ,
        text(4096) TYPE c,
      END OF g_files.

DATA : fold_number(12) TYPE c,
       fold_yr(2) TYPE c,
       fold_type(3) TYPE c.

PARAMETERS ws_file(4096) TYPE c DEFAULT 'Insert ur Document' here''.
* Can me any file fromyour pc ....either xls or word or ppt etc ...
g_user-sapname = sy-uname.
CALL FUNCTION 'SO_USER_READ_API1'
  EXPORTING
    user                            = g_user
  IMPORTING
    user_data                       = g_user_data
  EXCEPTIONS
    USER_NOT_EXIST                  = 1
    PARAMETER_ERROR                 = 2
    X_ERROR                         = 3
    OTHERS                          = 4
          .

fold_type = g_user_data-outboxfol+0(3).
fold_yr = g_user_data-outboxfol+3(2).
fold_number =  g_user_data-outboxfol+5(12).
CLEAR g_files.

REFRESH : g_objcnt,
          g_objhead,
          g_objpara,
          g_objparb,
          g_receipients,
          g_attachments,
          g_references,
          g_files.

method1 = 'SAVE'.
g_document-foltp  = fold_type.
g_document-folyr   = fold_yr.
g_document-folno   = fold_number.
g_document-objtp   = g_user_data-object_typ.
*g_document-OBJYR   = '27'.
*g_document-OBJNO   = '000000002365'.
*g_document-OBJNAM = 'MESSAGE'.
g_document-objdes   = 'sap-img.com testing by program'.
g_document-folrg   = 'O'.
*g_document-okcode   = 'CHNG'.
g_document-objlen = '0'.
g_document-file_ext = 'TXT'.

g_header-objdes =  'sap-img.com testing by program'.
g_header-file_ext = 'TXT'.

CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
  EXPORTING
    method       = method1
    office_user  = sy-uname
    ref_document = g_ref_document
    new_parent   = g_new_parent
  IMPORTING
    authority    = g_authority
  TABLES
    objcont      = g_objcnt
    objhead      = g_objhead
    objpara      = g_objpara
    objparb      = g_objparb
    recipients   = g_receipients
    attachments  = g_attachments
    references   = g_references
    files        = g_files
  CHANGING
    document     = g_document
    header_data  = g_header.

* File from the pc to send...
method1 = 'ATTCREATEFROMPC'.

g_files-text = ws_file.
APPEND g_files.

CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
  EXPORTING
    method       = method1
    office_user  = g_owner
    ref_document = g_ref_document
    new_parent   = g_new_parent
  IMPORTING
    authority    = g_authority
  TABLES
    objcont      = g_objcnt
    objhead      = g_objhead
    objpara      = g_objpara
    objparb      = g_objparb
    recipients   = g_receipients
    attachments  = g_attachments
    references   = g_references
    files        = g_files
  CHANGING
    document     = g_document
    header_data  = g_header.

method1 = 'SEND'.

g_receipients-recnam = 'MK085'.
g_receipients-recesc = 'B'.
g_receipients-sndex = 'X'.
APPEND  g_receipients.

CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
  EXPORTING
    method       = method1
    office_user  = g_owner
    ref_document = g_ref_document
    new_parent   = g_new_parent
  IMPORTING
    authority    = g_authority
  TABLES
    objcont      = g_objcnt
    objhead      = g_objhead
    objpara      = g_objpara
    objparb      = g_objparb
    recipients   = g_receipients
    attachments  = g_attachments
    references   = g_references
    files        = g_files
  CHANGING
    document     = g_document
    header_data  = g_header.

*-- End of Program

Author: Runal Singh
Submitted: 16/01/2008

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
FUNCTION z_send_email_itab_uname.
*"----------------------------------------------------------------------*"
*"Local interface:
*"  IMPORTING
*"     VALUE(APPLICATION) LIKE  SOOD1-OBJNAM
*"     VALUE(EMAILTITLE) LIKE  SOOD1-OBJDES
*"     VALUE(RECEXTNAM) LIKE  SOOS1-RECEXTNAM OPTIONAL
*"     VALUE(SENDER) LIKE  SOUD-USRNAM DEFAULT SY-UNAME
*"     VALUE(UNAME) LIKE  SOOS1-RECEXTNAM OPTIONAL
*"  EXPORTING
*"     VALUE(RETURN_CODE) LIKE  SY-SUBRC
*"  TABLES
*"     TEXTTAB STRUCTURE  SOLI
*"----------------------------------------------------------------------
* tables
  TABLES: pa0105,  "Employee detail for username and email address
          usr21,   "Login addition address data
          adr6.    "Address table for email addresses
*- local data declaration
  DATA: ohd    LIKE sood1,
        oid    LIKE soodk,
        to_all LIKE sonv-flag,
        t_uname LIKE sy-uname,
        okey   LIKE swotobjid-objkey.
  DATA: BEGIN OF receivers OCCURS 0.
          INCLUDE STRUCTURE soos1.
  DATA: END OF receivers.
*- fill odh
  CLEAR ohd.
  ohd-objla    = sy-langu.
  ohd-objnam   = application.
  ohd-objdes   = emailtitle.
  ohd-objpri   = 3.
  ohd-objsns   = 'F'.
  ohd-ownnam   = sy-uname.

  IF NOT uname IS INITIAL.
* Find personnel number of username
    CONDENSE uname NO-GAPS.
    WHILE uname CS ','.
      t_uname = uname+0(sy-fdpos).
      ADD 1 TO sy-fdpos.
      SHIFT uname LEFT BY sy-fdpos PLACES.
      PERFORM find_email_address USING t_uname
                              CHANGING recextnam.
    ENDWHILE.
*Do the last record
    IF uname <> space.
      t_uname = uname.
      PERFORM find_email_address USING t_uname
                              CHANGING recextnam.
    ENDIF.
  ENDIF.
*- send Email
  IF NOT recextnam IS INITIAL.
    CONDENSE recextnam NO-GAPS.
    CHECK recextnam CS '@'.
  ENDIF.
*- for every individual recipient send an Email*
  WHILE recextnam CS ','.
    PERFORM init_rec TABLES receivers.
    READ TABLE receivers INDEX 1.    r
    eceivers-recextnam = recextnam+0(sy-fdpos).
    ADD 1 TO sy-fdpos.
    SHIFT recextnam LEFT BY sy-fdpos PLACES.
    MODIFY receivers INDEX 1.
    PERFORM so_object_send_rec  TABLES texttab receivers
                                USING ohd sender.
  ENDWHILE.
*- check last recipient in recipient list
  IF recextnam <> space.
    PERFORM init_rec TABLES receivers.
    READ TABLE receivers INDEX 1.
    receivers-recextnam = recextnam.
    MODIFY receivers INDEX 1.
    PERFORM so_object_send_rec
    TABLES texttab receivers
    USING ohd            sender.
  ENDIF.
ENDFUNCTION.

*---------------------------------------------------------------------*
*       FORM SO_OBJECT_SEND_REC                                       *
*---------------------------------------------------------------------*
FORM  so_object_send_rec TABLES  objcont STRUCTURE soli
                                 receivers    STRUCTURE soos1
                          USING  object_hd    STRUCTURE sood1
                                 sender LIKE soud-usrnam.
  DATA:   oid     LIKE soodk,
          to_all  LIKE sonv-flag,
          okey    LIKE swotobjid-objkey.
  CALL FUNCTION 'SO_OBJECT_SEND'
    EXPORTING
      extern_address             = 'X'
      object_hd_change           = object_hd
      object_type                = 'RAW'
      outbox_flag                = 'X'
      sender                     = sender
    IMPORTING
      object_id_new              = oid
      sent_to_all                = to_all
      office_object_key          = oke
    TABLES
      objcont                    = objcont
      receivers                  = receivers
    EXCEPTIONS
      active_user_not_exist      = 1
      communication_failure      = 2
      component_not_available    = 3
      folder_not_exist           = 4
      folder_no_authorization    = 5
      forwarder_not_exist        = 6
      note_not_exist             = 7
      object_not_exist           = 8
      object_not_sent            = 9
      object_no_authorization    = 10
      object_type_not_exist      = 11
      operation_no_authorization = 12
      owner_not_exist            = 13
      parameter_error            = 14
      substitute_not_active      = 15
      substitute_not_defined     = 16
      system_failure             = 17
      too_much_receivers         = 18
      user_not_exist             = 19
      x_error                    = 20
      OTHERS                     = 21.
  IF sy-subrc <> 0.
    CASE sy-subrc.
      WHEN 1.
        MESSAGE i999(b1) WITH 'Activer user does not exist.' 'Send Mail failed!'.
      WHEN 2.
        MESSAGE i999(b1) WITH 'Communication Failure.' 'Send Mail failed!'.
      WHEN 3.
        MESSAGE i999(b1) WITH 'Component not available.'  'Send Mail failed!'.
      WHEN 4.
        MESSAGE i999(b1) WITH 'Folder does not exist.' 'Send Mail failed!'.
      WHEN 5.
        MESSAGE i999(b1) WITH 'No authorization for folder.' 'Send Mail failed!'.
      WHEN 6.
        MESSAGE i999(b1) WITH 'Forwarder does not exist.' 'Send Mail failed!'.
      WHEN 7.
        MESSAGE i999(b1) WITH 'Note does not exist.'  'Send Mail failed!'.
      WHEN 8.
        MESSAGE i999(b1) WITH 'Object does not exist.' 'Send Mail failed!'.
      WHEN 9.
        MESSAGE i999(b1) WITH 'Object not sent.' 'Send Mail failed!'.
      WHEN 10.
        MESSAGE i999(b1) WITH 'No authorization for object.'  'Send Mail failed!'.
      WHEN 11.
        MESSAGE i999(b1) WITH 'Object type does not exist.' 'Send Mail failed!'.
      WHEN 12.
        MESSAGE i999(b1) WITH 'No authorization for operation.'  'Send Mail failed!'.
      WHEN 13.
        MESSAGE i999(b1) WITH 'Owner does not exist.' 'Send Mail failed!'.
      WHEN 14.
        MESSAGE i999(b1) WITH 'Parameter Error.'   'Send Mail failed!'.
      WHEN 15.
        MESSAGE i999(b1) WITH 'Substitute not active.'  'Send Mail failed!'.
      WHEN 16.
        MESSAGE i999(b1) WITH 'Substitute not defined.'   'Send Mail failed!'.
      WHEN 17.
        MESSAGE i999(b1) WITH 'System failure.' 'Send Mail failed!'.
      WHEN 18.
        MESSAGE i999(b1) WITH 'Too many receivers.'    'Send Mail failed!'.
      WHEN 19.
        MESSAGE i999(b1) WITH 'User does not exist.' 'Send Mail failed!'.
      WHEN 20.
        MESSAGE i999(b1) WITH 'Unknown error ocurred.' 'Send Mail failed!'.
      WHEN 21.
        MESSAGE i999(b1) WITH 'Unknown error ocurred.' 'Send Mail failed!'.
    ENDCASE.
  ENDIF.
ENDFORM.                    "so_object_send_rec
*****----------------------------------------------------------------------*
*   FORM INIT_REC
**-------------------------------------------------------------------------*
FORM init_rec TABLES receivers STRUCTURE soos1.
  CLEAR receivers.
  REFRESH receivers.
  MOVE sy-datum  TO receivers-rcdat .
  MOVE sy-uzeit  TO receivers-rctim.
  MOVE '1'       TO receivers-sndpri.
  MOVE 'X'       TO receivers-sndex.
  MOVE 'U-'      TO receivers-recnam.
  MOVE 'U'       TO receivers-recesc.
  MOVE 'INT'     TO receivers-sndart.
  MOVE '5'       TO receivers-sortclass.
  APPEND receivers.
ENDFORM.                    "init_rec
*&---------------------------------------------------------------------*
*& Form  find_email_address
*&---------------------------------------------------------------------*
*       Returns the email address for a USERID whether they are an
*       employee or just a user.
*----------------------------------------------------------------------*
*      <--P_RECEXTNAM  Email address
*      -->P_UNAME      USERID
*----------------------------------------------------------------------*
FORM find_email_address USING    p_uname
                        CHANGING p_recextnam LIKE soos1-recextnam.
  DATA:   t_pernr LIKE pa0105-pernr,
          t_email LIKE pa0105-usrid_long.
* STEP 1 - Find personnel number for UNAME
  SELECT SINGLE pernr
           INTO t_pernr
           FROM pa0105
     WHERE subty = '0001'
       AND endda >= sy-datum
       AND begda <= sy-datum
       AND usrid = p_uname.
* Employee record found
  IF sy-subrc = 0.
* STEP 2 - Find email address for personnel number
    SELECT SINGLE usrid_long
             INTO t_email
             FROM pa0105
            WHERE pernr = t_pernr
              AND subty = '0022'
              AND endda >= sy-datum
              AND begda <= sy-datum.
    IF sy-subrc = 0.
      IF NOT p_recextnam IS INITIAL.
        CONCATENATE p_recextnam t_email INTO p_recextnam SEPARATED BY ','.
      ELSE.
        p_recextnam = t_email.
      ENDIF.
    ELSE.  "Never found an email address for employee
*** WHO SHOULD WE SEND TO HERE??? ***
    ENDIF.
* Employee number not found.
*Search in ADR6 table
  ELSE.
* See if user name is in the username table.
* i.e. The user is not an employee
    SELECT SINGLE addrnumber
                  persnumber
             INTO (usr21-addrnumber, usr21-persnumber)
             FROM usr21
            WHERE bname = p_uname.
    IF sy-subrc = 0.
* Found user name now let's get the email address
      SELECT SINGLE smtp_addr
               INTO t_email
               FROM adr6
              WHERE addrnumber = usr21-addrnumber
                AND persnumber = usr21-persnumber.
      IF sy-subrc <> 0 OR t_email IS INITIAL.
*** WHO SHOULD WE SEND TO HERE??? ***
      ELSE.  "Found email
        IF NOT p_recextnam IS INITIAL.
          CONCATENATE p_recextnam t_email INTO p_recextnam SEPARATED BY ','.
        ELSE.
          p_recextnam = t_email.
        ENDIF.
      ENDIF.
    ELSE.   "UNAME just does not have an email address addigned at all
*** WHO SHOULD WE SEND TO HERE??? ***
    ENDIF.
  ENDIF.
ENDFORM.                    " find_email_address

Back to Sending Mails - Home Page

Generates PDF output from pre-existing ZFHR_TRAVEL_REQUEST Adobe Form.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA : function TYPE funcname,
       ftype TYPE fpinterfacetype,
       fname TYPE funcname.
DATA : outputparams TYPE sfpoutputparams.

PARAMETER:      p_email   TYPE adr6-smtp_addr OBLIGATORY.

outputparams-nodialog = 'X'.
outputparams-preview = 'X'.
outputparams-dest = 'PDF1'.

outputparams-getpdf = 'X'.

DATA: fp_docparams TYPE sfpdocparams.
DATA: fp_formoutput TYPE fpformoutput.

CALL FUNCTION 'FP_JOB_OPEN'
  CHANGING
    ie_outputparams       = outputparams
* EXCEPTIONS
*   CANCEL                = 1
*   USAGE_ERROR           = 2
*   SYSTEM_ERROR          = 3
*   INTERNAL_ERROR        = 4
*   OTHERS                = 5
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
  EXPORTING
    i_name              = 'ZFHR_TRAVEL_REQUEST'
  IMPORTING
    e_funcname          = function
    e_interface_type    = ftype
    ev_funcname_inbound = fname.

fp_docparams-langu = 'E'.
fp_docparams-country = 'IN'.
fp_docparams-fillable = 'X'.

CALL FUNCTION function
 EXPORTING
   /1bcdwb/docparams        = fp_docparams
   employeename             = '00050104'
 IMPORTING
   /1bcdwb/formoutput       = fp_formoutput
* EXCEPTIONS
*   USAGE_ERROR              = 1
*   SYSTEM_ERROR             = 2
*   INTERNAL_ERROR           = 3
*   OTHERS                   = 4
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'FP_JOB_CLOSE'
* IMPORTING
*   E_RESULT             =
* EXCEPTIONS
*   USAGE_ERROR          = 1
*   SYSTEM_ERROR         = 2
*   INTERNAL_ERROR       = 3
*   OTHERS               = 4
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

************************************************************
*Download file

DATA: filename TYPE string,
 path TYPE string,
 fullpath TYPE string,
 default_extension TYPE string VALUE 'PDF'.
cl_gui_frontend_services=>file_save_dialog(
EXPORTING
default_extension = default_extension
CHANGING
filename = filename
path = path
fullpath = fullpath ).
CHECK fullpath IS NOT INITIAL.

DATA: data_tab TYPE TABLE OF x255.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
  EXPORTING
    buffer     = fp_formoutput-pdf
  TABLES
    binary_tab = data_tab.

*filename = 'E:\adobe\emptest.pdf'.

cl_gui_frontend_services=>gui_download(
EXPORTING
filename = filename
filetype = 'BIN'
CHANGING
data_tab = data_tab ).
cl_gui_frontend_services=>execute(
EXPORTING
document = filename ).

************************************************************
* Mail

* BCS data
DATA  send_request       TYPE REF TO cl_bcs.
DATA  text               TYPE bcsy_text.
DATA  document           TYPE REF TO cl_document_bcs.
DATA  recipient          TYPE REF TO if_recipient_bcs.
DATA: bcs_exception      TYPE REF TO cx_bcs.
DATA  sent_to_all        TYPE os_boolean.
DATA  pdf_content        TYPE solix_tab.
DATA  lp_pdf_size        TYPE so_obj_len.

TRY.
*   --------- create persistent send request ---------------------
    send_request = cl_bcs=>create_persistent( ).

*   --------- add document ---------------------------------------
*   get PDF xstring and convert it to BCS format
    lp_pdf_size = XSTRLEN( fp_formoutput-pdf ).

    pdf_content = cl_document_bcs=>xstring_to_solix(
        ip_xstring = fp_formoutput-pdf ).

    document = cl_document_bcs=>create_document(
          i_type    = 'PDF'
          i_hex     = pdf_content
          i_length  = lp_pdf_size
          i_subject = 'Travel Request form' ).              "#EC NOTEXT

*   add document to send request
    send_request->set_document( document ).

*   --------- add recipient (e-mail address) ---------------------
    recipient = cl_cam_address_bcs=>create_internet_address(
        i_address_string = p_email ).

*   add recipient to send request
    send_request->add_recipient( i_recipient = recipient ).

*   --------- send document --------------------------------------
    sent_to_all = send_request->send(
        i_with_error_screen = 'X' ).

    IF sent_to_all = 'X'.
      MESSAGE i022(so).
    ENDIF.

*   --------- explicit 'commit work' is mandatory! ---------------
    COMMIT WORK.

* ------------------------------------------------------------------
* *            exception handling
* ------------------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* ------------------------------------------------------------------
  CATCH cx_bcs INTO bcs_exception.
    WRITE: text-001.
    WRITE: text-002, bcs_exception->error_type.
    EXIT.

ENDTRY.

Hi All

I  always struggle to analyze the classes in s050 tcode, not able to debug them when triggered via a  mail ,Nevertheless I found a way of simulating it.

Here is custom built code

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT z_so50_exit.

TYPES: BEGIN OF ty_range_att_type,
  zatt TYPE c LENGTH 4,
  zdesc TYPE char50,
END OF ty_range_att_type.
DATA:
  gv_rc TYPE i,
  gv_len TYPE i,
  gv_filename TYPE string.
DATA:
  gs_x TYPE bcss_t100m,
  gs_text TYPE soli.
DATA:
  gt_rc TYPE bcsy_smtpa,
  gt_doc TYPE bcsy_sodoc,
  gt_solix TYPE solix_tab,
  gt_text TYPE bcsy_text.
DATA:
  go_pdfmail TYPE REF TO if_inbound_exit_bcs,
  go_cont TYPE REF TO cl_gui_custom_container,
  go_req TYPE REF TO cl_send_request_bcs,
  go_addr TYPE REF TO cl_cam_address_bcs,
  go_document TYPE REF TO cl_document_bcs,
  go_maint TYPE REF TO cl_ibnd_rules_maint_bcs,
  lt_range_att_type TYPE TABLE OF ty_range_att_type,
  lt_bcsy_smtp2 TYPE bcsy_smtp2,
  ls_range_att_type TYPE ty_range_att_type.

PARAMETERS:
  p_file TYPE tdlen255 LOWER CASE,
  p_file1 TYPE ad_smtpadr LOWER CASE,
  p_file2 TYPE seoclsname LOWER CASE,
  p_file3(3).

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  DATA: gt_file TYPE filetable,
        gs_file TYPE file_table,
        gv_user_action TYPE i.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      default_extension       = '*'
      file_filter             = '*'
    CHANGING
      file_table              = gt_file
      rc                      = gv_rc
      user_action             = gv_user_action
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.
  READ TABLE gt_file INTO gs_file INDEX 1.
  p_file = gs_file-filename.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file3.
  CLEAR:lt_range_att_type.
        ls_range_att_type-zatt = 'PDF'.
        ls_range_att_type-zdesc = 'PDF'.
  APPEND ls_range_att_type TO lt_range_att_type.
  ls_range_att_type-zatt = 'XLS'.
  ls_range_att_type-zdesc = 'XLS'.
  APPEND ls_range_att_type TO lt_range_att_type.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield    = 'ZDESC'
      dynpprog    = sy-repid
      dynpnr      = sy-dynnr
      dynprofield = 'P_FILE3'
      value_org   = 'S'
    TABLES
      value_tab   = lt_range_att_type.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file2.
  CLEAR:lt_bcsy_smtp2.
  CREATE OBJECT:
  go_cont
    EXPORTING container_name = 'CCONT'
  ,
  go_maint
    EXPORTING io_cont = go_cont.

  go_maint->read_smtp_entries( IMPORTING et_entries = lt_bcsy_smtp2 ).

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield    = 'CLS_NAME'
      dynpprog    = sy-repid
      dynpnr      = sy-dynnr
      dynprofield = 'P_FILE2'
      value_org   = 'S'
    TABLES
      value_tab   = lt_bcsy_smtp2.

START-OF-SELECTION.
  gv_filename = p_file.

  cl_gui_frontend_services=>gui_upload(
    EXPORTING filename = gv_filename
              filetype = 'BIN'
    IMPORTING filelength = gv_len
    CHANGING data_tab = gt_solix
    EXCEPTIONS OTHERS = 1 ).

  CHECK sy-subrc = 0.
  go_req = cl_send_request_bcs=>create( ).
  go_addr = cl_cam_address_bcs=>create_internet_address( i_address_string = p_file1 ).
  go_req->setu_sender( go_addr ).
  go_req->set_tech_sender( go_addr ).
  gs_text = 'Hello'.
  APPEND gs_text TO gt_text.

  go_document = cl_document_bcs=>create_document(
    i_type = 'RAW'
    i_text = gt_text
    i_length = '0'
    i_subject = 'Dummy text' ).

  go_document->add_attachment( i_attachment_type = p_file3
    i_attachment_subject = 'My attachment'
    i_att_content_hex = gt_solix ).

  go_req->setu_document( i_document = go_document ).
*create object reference of type class
  CALL METHOD (p_file2)=>if_inbound_exit_bcs~create_instance
    RECEIVING
      ro_ref = go_pdfmail.
*casting of object reference to interface
  go_pdfmail->process_inbound(
    EXPORTING
      io_sreq = go_req
      it_recipients = gt_rc
      it_doctypes = gt_doc
    IMPORTING
      e_retcode = gv_rc
      es_t100msg = gs_x ).

Author: Pratik Mallick
Submitted: 5th August,2008

Description

In the code gallery I have found a number of examples showing how to attach an attachment to an email.  There are examples of multi attachments too. But what the code snippets lack is proper explanation. Most of them are just codes which needs to be copy pasted without proper understanding. I have attempted to simplify the understanding by this simple, basic example of attaching an attachment. In code comments I have tried to explain the requirement of each step. Hope this is appreciated. Thank You.

*CODE*
REPORT  z_pratik_attachment          LINE-SIZE 132
                                     LINE-COUNT 65
                                     NO STANDARD PAGE HEADING.


***********************************************************************
* INTERNAL TABLES                                                                                      *
***********************************************************************

DATA:
      i_objpack   TYPE STANDARD TABLE OF sopcklsti1,
      i_objtext   TYPE STANDARD TABLE OF solisti1,
      i_objbin    TYPE STANDARD TABLE OF solisti1,
      i_receivers TYPE STANDARD TABLE OF somlreci1.




***********************************************************************
* WORK AREAS                                                                                              *
***********************************************************************
DATA: wa_email_doc TYPE sodocchgi1,
      wa_objpack   TYPE sopcklsti1,
      wa_objtext   TYPE solisti1,
      wa_receivers TYPE somlreci1.

***********************************************************************
* CONSTANTS                                                                                                 *
***********************************************************************
CONSTANTS: c_x     TYPE flag   VALUE 'X',
           c_u     TYPE char1  VALUE 'U'.


***********************************************************************
* START-OF-SELECTION                                                                               *
***********************************************************************
START-OF-SELECTION.

***********************************************************************
* END-OF-SELECTION                                                                                   *
***********************************************************************
END-OF-SELECTION.

  wa_email_doc-obj_name = 'Attachment Example'.
  "Mail Subject
  wa_email_doc-obj_descr
  = 'How to attach Multiple Attachments to an Email'.

* Main Mail body Text in itab i_objtext
  wa_objtext+0(36)  = 'We are not going to print this line.'.
  APPEND wa_objtext TO i_objtext.
  CLEAR wa_objtext.
  wa_objtext+0(46)  = 'This is the body of the email. We have skipped'.
  APPEND wa_objtext TO i_objtext.
  CLEAR wa_objtext.
  wa_objtext+0(45)  = ' the first line of the mail and printed from '.
  wa_objtext+45(12)  = 'second line.'.
  APPEND wa_objtext TO i_objtext.
  CLEAR wa_objtext.

* Text for the attachments in itab i_objbin
  wa_objtext+0(21)
  = 'This is attachment 1.'.
  APPEND wa_objtext TO i_objbin.
  CLEAR wa_objtext.
  wa_objtext+0(31) = 'We have got another attachment.'.
  APPEND wa_objtext TO i_objbin.
  CLEAR wa_objtext.
  wa_objtext+0(28) = 'This is attachment number 2.'.
  APPEND wa_objtext TO i_objbin.
  CLEAR wa_objtext.




** Creating the entry for the compressed document
*--(1): Creating entry for the Main Mail body text in itab i_objtext

  " wa_objpack-transf_bin
  " Flag for indicating an obj. to be transported in binary form.
  " If this flag is activated ('X'), the table entry describes an
  " object stored in binary format. The content of the object is in
  " the table CONTENTS_BIN. If the flag is not activated, the object
  " content is in the table CONTENTS_TXT in ASCII format.
  wa_objpack-transf_bin = ' '.
  " Starting index(row) For header information in the itab i_objpack
  wa_objpack-head_start = 1.
  " No of lines for the header information in itab i_objpack
  wa_objpack-head_num   = 1.
  " The row(index) of the itab i_objtext from where the Mail Body starts
  wa_objpack-body_start = 2.  "Skipped the first Line
  " The number of lines in the Mail body
  wa_objpack-body_num   = 2.  "We have two lines from the 2nd row
  " Document type. There are also whole lot of other options
  wa_objpack-doc_type   = 'RAW'.
  wa_objpack-obj_name   = 'MAIN BODY'.
  wa_objpack-obj_descr  = 'MAIL BODY TEXT'.
  wa_objpack-obj_langu  = ' '.
  " In this case one can skip this. Normally ist calculated as
  " no of linex * 255
  wa_objpack-doc_size = ' '.

  APPEND wa_objpack TO i_objpack.
  CLEAR wa_objpack.

*--(2): Creating entry for the Attachment text in itab i_objbin
*----Attachment 1----*
  wa_objpack-transf_bin = c_x.
  wa_objpack-head_start = 2.
  wa_objpack-head_num   = 1.
  wa_objpack-body_start = 1. "Itab i_objbin row number
  wa_objpack-body_num   = 2.
  wa_objpack-doc_size =  510 . "Approximately for 2 Lines-> 255 * 2
  wa_objpack-doc_type   = 'RAW'.
  wa_objpack-obj_name   = 'Attachment 1'.
  wa_objpack-obj_descr  = 'Attachment 1'.
  wa_objpack-obj_langu  = ' '.
  APPEND wa_objpack TO i_objpack.

*--(3): Creating entry for the Attachment text in itab i_objbin
*----Attachment 2----*
  wa_objpack-transf_bin = c_x.
  wa_objpack-head_start = 3.
  wa_objpack-head_num   = 1.
  wa_objpack-body_start = 3.     "Itab i_objbin row number
  wa_objpack-body_num   = 1.
  wa_objpack-doc_size   =  255 . "Approximately for 1 Line
  wa_objpack-doc_type   = 'RAW'.
  wa_objpack-obj_name   = 'Attachment 2'.
  wa_objpack-obj_descr  = 'Attachment 2'.
  wa_objpack-obj_langu  = ' '.
  APPEND wa_objpack TO i_objpack.


*Building the recepient list
** Receipient information
  wa_receivers-receiver = sy-uname.
  wa_receivers-rec_type = 'B'. "To SAP Inbox
  APPEND wa_receivers TO i_receivers.
  CLEAR wa_receivers.

  wa_receivers-receiver = 'abc@gmail.com'.
  wa_receivers-rec_type = c_u.
  APPEND wa_receivers TO i_receivers.
  CLEAR wa_receivers.

* Finally Send the Document
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = wa_email_doc
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = i_objpack
      contents_bin               = i_objbin
      contents_txt               = i_objtext
      receivers                  = i_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.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT ztsapmail.
DATA: x_object_type LIKE sood-objtp.
DATA: BEGIN OF x_object_hd_change.
        INCLUDE STRUCTURE sood1.
DATA: END OF x_object_hd_change.
DATA: BEGIN OF x_objcont OCCURS 10.
        INCLUDE STRUCTURE soli.
DATA: END OF x_objcont.
DATA: BEGIN OF x_objhead OCCURS 0.
        INCLUDE STRUCTURE soli.
DATA: END OF x_objhead.
DATA: BEGIN OF raw_head.
        INCLUDE STRUCTURE sorh.
DATA: END OF raw_head.
DATA: BEGIN OF x_receivers OCCURS 0.
        INCLUDE STRUCTURE soos1.
DATA: END OF x_receivers.
PARAMETERS: receiver LIKE x_receivers-recnam. " Name
*BUILD MESSAGE HEADERMOVE 'Sort field goes here' TO X_OBJECT_HD_CHANGE-OBJSRT. " Sort field
MOVE 'Name of the object goes here' TO x_object_hd_change-objnam. " Name
MOVE 'Document title goes here' TO x_object_hd_change-objdes. " Title
MOVE 'F' TO x_object_hd_change-objsns. " Functional OBJECT
MOVE 'E' TO x_object_hd_change-objla. " Language
* Object type of the new documentMOVE 'RAW' TO X_OBJECT_TYPE.
CLEAR x_objcont.
MOVE 'Contents of mail' TO x_objcont-line.
APPEND x_objcont.
CLEAR x_objcont-line.
APPEND x_objcont.
MOVE 'More contents' TO x_objcont-line.
APPEND x_objcont.
MOVE 'Still more contents'
TO x_objcont-line.
APPEND x_objcont.
MOVE ' ' TO x_objcont-line.
APPEND x_objcont.
* Specific header (Dependent on the object type, here RAW)REFRESH X_OBJHEAD.
DESCRIBE TABLE x_objcont LINES raw_head-rawsiz.
MOVE raw_head TO x_objhead.
APPEND x_objhead.
*RECEIVERS tableCLEAR X_RECEIVERS.
REFRESH x_receivers.
MOVE receiver TO x_receivers-recnam. " Name
MOVE 'B' TO x_receivers-recesc. " Receiver type
MOVE 'X' TO x_receivers-sndcp. " Send as a copy
MOVE 'X' TO x_receivers-sndex. " EXPRESS DOCUMENT
APPEND x_receivers.
CALL FUNCTION 'SO_OBJECT_SEND'
  EXPORTING
    folder_id        = 'OUTBOX'
    object_hd_change = x_object_hd_change
    object_type      = x_object_type
    outbox_flag      = 'X'
    owner            = sy-uname
    tablesobjcont    = x_objcont
    objhead          = x_objhead
    receivers        = x_receivers.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
* Sending Emails and Sap mail using ABAP
REPORT ztunixmail.

DATA : to_address LIKE sy_lisel,from_address LIKE sy-lisel,
subject LIKE sy-lisel,
attachment_name LIKE sy_lisel,
data_file_path LIKE sxpgcolist-parameters,
body_file_path LIKE sxpgcolist-parameters.
DATA : BEGIN OF int_email_attach OCCURS 0,
  txtline TYPE char255,
END OF int_email_attach.
DATA : BEGIN OF int_email_body OCCURS 0,
  txtline TYPE char255,
END OF int_email_body.
CLEAR : int_exec_protocol,int_email_attach,int_email_body.
REFRESH : int_exec_protocol,int_email_attach,int_email_body.

int_email_attach-txtline = 'Put all attachment text in this table'.
APPEND int_email_attach.
CLEAR int_email_attach.
int_email_body-txtline = 'Put all attachment text in this table'.
APPEND int_email_body.
CLEAR int_email_body.

CONCATENATE to_addressfrom_address
subject
body_file_path
data_file_path
attachment_name
INTO v_parameters.

IF NOT int_email_attach[] IS INITIAL.
  OPEN DATASET data_file_path FOR OUTPUT IN TEXT MODE.
  LOOP AT int_email_attach.
    TRANSFER int_email_attach-txtline TO data_file_path.
  ENDLOOP.
  CLOSE DATASET data_file_path.
ENDIF.

IF NOT int_email_body[] IS INITIAL.
  OPEN DATASET body_file_path FOR OUTPUT IN TEXT MODE.
  LOOP AT int_email_body.
    TRANSFER int_email_body-txtline TO body_file_path.
  ENDLOOP.
  CLOSE DATASET body_file_path.
ENDIF.

CALL FUNCTION 'SXPG_CALL_SYSTEM'
  EXPORTING
    commandname                = 'Z_EMAIL' " Command calling unix script
    parameters                 = v_parameters
    tablesexec_protocol        = int_exec_protocol
  EXCEPTIONS
    no_permission              = 1
    command_not_found          = 2
    parameters_too_long        = 3
    security_risk              = 4
    wrong_check_call_interface = 5
    program_start_error        = 6
    program_termination_error  = 7
    x_error                    = 8
    parameter_expected         = 9
    too_many_parameters        = 10
    illegal_command            = 11
    OTHERS                     = 12.

Author: Runal Singh
Submitted: 16/01/2008

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
FUNCTION z_send_email_itab_uname.
*"----------------------------------------------------------------------*"
*"Local interface:
*"  IMPORTING
*"     VALUE(APPLICATION) LIKE  SOOD1-OBJNAM
*"     VALUE(EMAILTITLE) LIKE  SOOD1-OBJDES
*"     VALUE(RECEXTNAM) LIKE  SOOS1-RECEXTNAM OPTIONAL
*"     VALUE(SENDER) LIKE  SOUD-USRNAM DEFAULT SY-UNAME
*"     VALUE(UNAME) LIKE  SOOS1-RECEXTNAM OPTIONAL
*"  EXPORTING
*"     VALUE(RETURN_CODE) LIKE  SY-SUBRC
*"  TABLES
*"     TEXTTAB STRUCTURE  SOLI
*"----------------------------------------------------------------------
* tables
  TABLES: pa0105,  "Employee detail for username and email address
          usr21,   "Login addition address data
          adr6.    "Address table for email addresses
*- local data declaration
  DATA: ohd    LIKE sood1,
        oid    LIKE soodk,
        to_all LIKE sonv-flag,
        t_uname LIKE sy-uname,
        okey   LIKE swotobjid-objkey.
  DATA: BEGIN OF receivers OCCURS 0.
          INCLUDE STRUCTURE soos1.
  DATA: END OF receivers.
*- fill odh
  CLEAR ohd.
  ohd-objla    = sy-langu.
  ohd-objnam   = application.
  ohd-objdes   = emailtitle.
  ohd-objpri   = 3.
  ohd-objsns   = 'F'.
  ohd-ownnam   = sy-uname.

  IF NOT uname IS INITIAL.
* Find personnel number of username
    CONDENSE uname NO-GAPS.
    WHILE uname CS ','.
      t_uname = uname+0(sy-fdpos).
      ADD 1 TO sy-fdpos.
      SHIFT uname LEFT BY sy-fdpos PLACES.
      PERFORM find_email_address USING t_uname
                              CHANGING recextnam.
    ENDWHILE.
*Do the last record
    IF uname <> space.
      t_uname = uname.
      PERFORM find_email_address USING t_uname
                              CHANGING recextnam.
    ENDIF.
  ENDIF.
*- send Email
  IF NOT recextnam IS INITIAL.
    CONDENSE recextnam NO-GAPS.
    CHECK recextnam CS '@'.
  ENDIF.
*- for every individual recipient send an Email*
  WHILE recextnam CS ','.
    PERFORM init_rec TABLES receivers.
    READ TABLE receivers INDEX 1.
    receivers-recextnam = recextnam+0(sy-fdpos).
    ADD 1 TO sy-fdpos.
    SHIFT recextnam LEFT BY sy-fdpos PLACES.
    MODIFY receivers INDEX 1.
    PERFORM so_object_send_rec  TABLES texttab receivers
                                USING ohd sender.
  ENDWHILE.
*- check last recipient in recipient list
  IF recextnam <> space.
    PERFORM init_rec TABLES receivers.
    READ TABLE receivers INDEX 1.
    receivers-recextnam = recextnam.
    MODIFY receivers INDEX 1.
    PERFORM so_object_send_rec
    TABLES texttab receivers
    USING ohd            sender.
  ENDIF.
ENDFUNCTION.

*---------------------------------------------------------------------*
*       FORM SO_OBJECT_SEND_REC                                       *
*---------------------------------------------------------------------*
FORM  so_object_send_rec TABLES  objcont STRUCTURE soli
                                 receivers    STRUCTURE soos1
                          USING  object_hd    STRUCTURE sood1
                                 sender LIKE soud-usrnam.
  DATA:   oid     LIKE soodk,
          to_all  LIKE sonv-flag,
          okey    LIKE swotobjid-objkey.
  CALL FUNCTION 'SO_OBJECT_SEND'
    EXPORTING
      extern_address             = 'X'
      object_hd_change           = object_hd
      object_type                = 'RAW'
      outbox_flag                = 'X'
      sender                     = sender
    IMPORTING
      object_id_new              = oid
      sent_to_all                = to_all
      office_object_key          = oke
    TABLES
      objcont                    = objcont
      receivers                  = receivers
    EXCEPTIONS
      active_user_not_exist      = 1
      communication_failure      = 2
      component_not_available    = 3
      folder_not_exist           = 4
      folder_no_authorization    = 5
      forwarder_not_exist        = 6
      note_not_exist             = 7
      object_not_exist           = 8
      object_not_sent            = 9
      object_no_authorization    = 10
      object_type_not_exist      = 11
      operation_no_authorization = 12
      owner_not_exist            = 13
      parameter_error            = 14
      substitute_not_active      = 15
      substitute_not_defined     = 16
      system_failure             = 17
      too_much_receivers         = 18
      user_not_exist             = 19
      x_error                    = 20
      OTHERS                     = 21.
  IF sy-subrc <> 0.
    CASE sy-subrc.
      WHEN 1.
        MESSAGE i999(b1) WITH 'Activer user does not exist.' 'Send Mail failed!'.
      WHEN 2.
        MESSAGE i999(b1) WITH 'Communication Failure.' 'Send Mail failed!'.
      WHEN 3.
        MESSAGE i999(b1) WITH 'Component not available.'  'Send Mail failed!'.
      WHEN 4.
        MESSAGE i999(b1) WITH 'Folder does not exist.' 'Send Mail failed!'.
      WHEN 5.
        MESSAGE i999(b1) WITH 'No authorization for folder.' 'Send Mail failed!'.
      WHEN 6.
        MESSAGE i999(b1) WITH 'Forwarder does not exist.' 'Send Mail failed!'.
      WHEN 7.
        MESSAGE i999(b1) WITH 'Note does not exist.'  'Send Mail failed!'.
      WHEN 8.
        MESSAGE i999(b1) WITH 'Object does not exist.' 'Send Mail failed!'.
      WHEN 9.
        MESSAGE i999(b1) WITH 'Object not sent.' 'Send Mail failed!'.
      WHEN 10.
        MESSAGE i999(b1) WITH 'No authorization for object.'  'Send Mail failed!'.
      WHEN 11.
        MESSAGE i999(b1) WITH 'Object type does not exist.' 'Send Mail failed!'.
      WHEN 12.
        MESSAGE i999(b1) WITH 'No authorization for operation.'  'Send Mail failed!'.
      WHEN 13.
        MESSAGE i999(b1) WITH 'Owner does not exist.' 'Send Mail failed!'.
      WHEN 14.
        MESSAGE i999(b1) WITH 'Parameter Error.'   'Send Mail failed!'.
      WHEN 15.
        MESSAGE i999(b1) WITH 'Substitute not active.'  'Send Mail failed!'.
      WHEN 16.
        MESSAGE i999(b1) WITH 'Substitute not defined.'   'Send Mail failed!'.
      WHEN 17.
        MESSAGE i999(b1) WITH 'System failure.' 'Send Mail failed!'.
      WHEN 18.
        MESSAGE i999(b1) WITH 'Too many receivers.'    'Send Mail failed!'.
      WHEN 19.
        MESSAGE i999(b1) WITH 'User does not exist.' 'Send Mail failed!'.
      WHEN 20.
        MESSAGE i999(b1) WITH 'Unknown error ocurred.' 'Send Mail failed!'.
      WHEN 21.
        MESSAGE i999(b1) WITH 'Unknown error ocurred.' 'Send Mail failed!'.
    ENDCASE.
  ENDIF.
ENDFORM.                    "so_object_send_rec
*----------------------------------------------------------------------*
*   FORM INIT_REC
*----------------------------------------------------------------------*
FORM init_rec TABLES receivers STRUCTURE soos1.
  CLEAR receivers.
  REFRESH receivers.
  MOVE sy-datum  TO receivers-rcdat .
  MOVE sy-uzeit  TO receivers-rctim.
  MOVE '1'       TO receivers-sndpri.
  MOVE 'X'       TO receivers-sndex.
  MOVE 'U-'      TO receivers-recnam.
  MOVE 'U'       TO receivers-recesc.
  MOVE 'INT'     TO receivers-sndart.
  MOVE '5'       TO receivers-sortclass.
  APPEND receivers.
ENDFORM.                    "init_rec
*&---------------------------------------------------------------------*
*& Form  find_email_address
*&---------------------------------------------------------------------*
*       Returns the email address for a USERID whether they are an
*       employee or just a user.
*----------------------------------------------------------------------*
*      <--P_RECEXTNAM  Email address
*      -->P_UNAME      USERID
*----------------------------------------------------------------------*
FORM find_email_address USING    p_uname
                        CHANGING p_recextnam LIKE soos1-recextnam.
  DATA:   t_pernr LIKE pa0105-pernr,
          t_email LIKE pa0105-usrid_long.
* STEP 1 - Find personnel number for UNAME
  SELECT SINGLE pernr
           INTO t_pernr
           FROM pa0105
     WHERE subty = '0001'
       AND endda >= sy-datum
       AND begda <= sy-datum
       AND usrid = p_uname.
* Employee record found
  IF sy-subrc = 0.
* STEP 2 - Find email address for personnel number
    SELECT SINGLE usrid_long
             INTO t_email
             FROM pa0105
            WHERE pernr = t_pernr
              AND subty = '0022'
              AND endda >= sy-datum
              AND begda <= sy-datum.
    IF sy-subrc = 0.
      IF NOT p_recextnam IS INITIAL.
        CONCATENATE p_recextnam t_email INTO p_recextnam SEPARATED BY ','.
      ELSE.
        p_recextnam = t_email.
      ENDIF.
    ELSE.  "Never found an email address for employee
*** WHO SHOULD WE SEND TO HERE??? ***
    ENDIF.
* Employee number not found.
* Search in ADR6 table
  ELSE.
* See if user name is in the username table.
* i.e. The user is not an employee
    SELECT SINGLE addrnumber
                  persnumber
             INTO (usr21-addrnumber, usr21-persnumber)
             FROM usr21
            WHERE bname = p_uname.
    IF sy-subrc = 0.
* Found user name now let's get the email address
      SELECT SINGLE smtp_addr
               INTO t_email
               FROM adr6
              WHERE addrnumber = usr21-addrnumber
                AND persnumber = usr21-persnumber.
      IF sy-subrc <> 0 OR t_email IS INITIAL.
*** WHO SHOULD WE SEND TO HERE??? ***
      ELSE.  "Found email
        IF NOT p_recextnam IS INITIAL.
          CONCATENATE p_recextnam t_email INTO p_recextnam SEPARATED BY ','.
        ELSE.
          p_recextnam = t_email.
        ENDIF.
      ENDIF.
    ELSE.   "UNAME just does not have an email address addigned at all
*** WHO SHOULD WE SEND TO HERE??? ***
    ENDIF.
  ENDIF.
ENDFORM.                    " find_email_address

  Note the code snippet for sending mails to outlook with URL

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*** Header
DATA : wa_header TYPE sodocchgi1.

*** Contents Data
DATA : it_content TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0,
       wa_content TYPE solisti1,
*** Receivers Data
       it_receivers TYPE STANDARD TABLE OF somlreci1 INITIAL SIZE 0,
       wa_receivers TYPE somlreci1,
       it_para TYPE STANDARD TABLE OF soparai1 INITIAL SIZE 0,
       wa_para TYPE soparai1.

wa_receivers-receiver = 'abc@sdn.com'.
wa_receivers-rec_type = 'U'.
wa_receivers-com_type = 'INT'.
APPEND wa_receivers TO it_receivers.
CLEAR: wa_receivers.

wa_header-obj_prio = 1.
wa_header-priority = 1.
wa_header-obj_langu = sy-langu.

wa_header-obj_descr = 'Mail with SAP SDN link'.

CONCATENATE 'Dear ' 'SDN ' INTO wa_content-line SEPARATED BY ''.
APPEND wa_content TO it_content.
CLEAR wa_content.

CONCATENATE '<a href="http://www.sdn.sap.com" " target="_blank" >'
            'SAP Developer Network (SDN) </a>'
            ' '
            INTO wa_content-line SEPARATED BY ''.
APPEND wa_content TO it_content.
CLEAR wa_content.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
  EXPORTING
    document_data  = wa_header
    document_type  = 'RAW'
    commit_work    = 'X'
  TABLES
    object_content = it_content
    object_para    = it_para
    receivers      = it_receivers.

Author: Mauricio Lauffer
Submitted: 08/03/2012
Related Links:

Send email with new class CL_BCS is very simple!

Follow a example:

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&-------------------------------------------------------------*
*& Report  ZEMAIL_CL_BCS                                       *
*&-------------------------------------------------------------*
*& Mauricio Lauffer
*&-------------------------------------------------------------*

  REPORT  zemail_cl_bcs.


  CONSTANTS:
    gc_subject TYPE so_obj_des VALUE 'ABAP Email with CL_BCS',
    gc_raw     TYPE char03 VALUE 'RAW'.

  DATA:
    gv_mlrec         TYPE so_obj_nam,
    gv_sent_to_all   TYPE os_boolean,
    gv_email         TYPE adr6-smtp_addr,
    gv_subject       TYPE so_obj_des,
    gv_text          TYPE bcsy_text,
    gr_send_request  TYPE REF TO cl_bcs,
    gr_bcs_exception TYPE REF TO cx_bcs,
    gr_recipient     TYPE REF TO if_recipient_bcs,
    gr_sender        TYPE REF TO cl_sapuser_bcs,
    gr_document      TYPE REF TO cl_document_bcs.



  TRY.
      "Create send request
      gr_send_request = cl_bcs=>create_persistent( ).


      "Email FROM...
      gr_sender = cl_sapuser_bcs=>create( sy-uname ).
      "Add sender to send request
      CALL METHOD gr_send_request->set_sender
        EXPORTING
          i_sender = gr_sender.


      "Email TO...
      gv_email = 'frodo.baggins@outlook.com'.
      gr_recipient = cl_cam_address_bcs=>create_internet_address( gv_email ).
      "Add recipient to send request
      CALL METHOD gr_send_request->add_recipient
        EXPORTING
          i_recipient = gr_recipient
          i_express   = 'X'.


      "Email BODY
      APPEND 'Hello world! My first ABAP email!' TO gv_text.
      gr_document = cl_document_bcs=>create_document(
                      i_type    = gc_raw
                      i_text    = gv_text
                      i_length  = '12'
                      i_subject = gc_subject ).
      "Add document to send request
      CALL METHOD gr_send_request->set_document( gr_document ).


      "Send email
      CALL METHOD gr_send_request->send(
        EXPORTING
          i_with_error_screen = 'X'
        RECEIVING
          result              = gv_sent_to_all ).
      IF gv_sent_to_all = 'X'.
        WRITE 'Email sent!'.
      ENDIF.

      "Commit to send email
      COMMIT WORK.


      "Exception handling
    CATCH cx_bcs INTO gr_bcs_exception.
      WRITE:
        'Error!',
        'Error type:',
        gr_bcs_exception->error_type.
  ENDTRY.

Back to Sending Mails - Home Page

* Before using following CODE, Need to Create ITS Service for SAP Trasaction thru tcode : SICF

Note : read comments for more details.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
* Data Declaration related to SAP Link Creation for TRIP
*********************************************************
DATA : wda_name     TYPE string,
       in_protocol  TYPE string,
       out_host     TYPE string,
       out_port     TYPE string,
       out_protocol TYPE string,
       val          TYPE string,
       g_url        TYPE string.

* Data Declaration related to Mail
***********************************
DATA :  send_request       TYPE REF TO cl_bcs,
   document           TYPE REF TO cl_document_bcs,
   send TYPE REF TO if_sender_bcs,
   i_text TYPE soli_tab,
   wa_text TYPE soli,
   receiver          TYPE REF TO if_recipient_bcs,
   sent_to_all        TYPE os_boolean,
   sender TYPE adr6-smtp_addr,
   recipient TYPE adr6-smtp_addr,
   subject TYPE so_obj_des.
DATA : temp_addr TYPE adr6-smtp_addr.
***********************************

*********************************************************
* -Generating URL for SAP Trasaction ( SAP GUI for HTML )
*********************************************************
CALL METHOD cl_http_server=>if_http_server~get_location
  EXPORTING
    protocol     = in_protocol
    server       = cl_wdr_task=>server
  IMPORTING
    host         = out_host
    port         = out_port
    out_protocol = out_protocol.

val = sy-mandt.
CONCATENATE out_protocol '://' out_host ':' out_port '/sap/bc/gui/sap/its/ztrip' INTO g_url.
*                                 "  /sap/bc/gui/sap/its/ path for ITS service
*                                 "  ztrip service name for TCODE - TRIP, created thru SICF
CALL METHOD cl_http_server=>append_field_url
  EXPORTING
    name  = 'sap-client'
    value = val
  CHANGING
    url   = g_url.

***************************************
* Sending mail to Outlook with SAP link
***************************************

send_request = cl_bcs=>create_persistent( ).
CONCATENATE 'Dear SDN,' '' INTO wa_text-line.
APPEND wa_text-line TO i_text.

CONCATENATE 'Please find below link for Travel Request ( TRIP ),' '' INTO wa_text-line.
APPEND wa_text-line TO i_text.

CONCATENATE '<a href="' g_url '"  > Link to Travel Request </a>' ' ' INTO wa_text-line.
APPEND wa_text-line TO i_text.

subject = 'SDN : Mail to Outlook with SAPLink'.
document = cl_document_bcs=>create_document(
                       i_type    = 'RAW'
                       i_text    = i_text
                       i_length  = '18'
                       i_subject = subject ).

* add document to send request
CALL METHOD send_request->set_document( document ).

* create internet address for the sender
send = cl_cam_address_bcs=>create_internet_address(
                                 i_address_string = 'SDN@SAP.COM'
                                 i_address_name = 'SAP SDN').

* set the sender to send_request instance
CALL METHOD send_request->set_sender
  EXPORTING
    i_sender = send.

temp_addr = 'sdn@sap.com'. " Receiving Address
receiver = cl_cam_address_bcs=>create_internet_address(
                                        temp_addr  ). " adding receipts

CALL METHOD send_request->add_recipient
  EXPORTING
    i_recipient = receiver
    i_express   = 'X'.

send_request->set_send_immediately( 'X' ).

* sending the mail
CALL METHOD send_request->send(
  EXPORTING
    i_with_error_screen = 'X'
  RECEIVING
    result              = sent_to_all ).
IF sent_to_all = 'X'.
  WRITE :/ 'Mail has sent successfully'.
ENDIF.

With this tutorial it is possible to create contact persons with the BAPI BAPI_ADDRCONTPART_SAVEREPLICA for customers and or vendors.

The example is for customers only.

One of the main problems is that the created contactperson with the BAPI BAPI_ADDRCONTPART_SAVEREPLICA didn't become available in Tcode XD02

This was due to the problem that the table KNVK was not updated trough this BAPI.

Other problem was that with function  SD_CUSTOMER_MAINTAIN_ALL not all necessary contact information could be managed like email adress.

DATA: st_sender TYPE bapi_sender,
      gs_kna1 TYPE kna1,
      h_kunnr TYPE kunnr,
      gt_knvk TYPE STANDARD TABLE OF fknvk,
      gs_knvk TYPE fknvk,
      new_contactid TYPE bapicontact_01-contact,
      new_contactid_create TYPE bapi4003_1-objkey_p,
      gt_bapiad3vl TYPE STANDARD TABLE OF bapiad3vl,
      gs_bapiad3vl TYPE bapiad3vl,
      gt_bapiadsmtp TYPE STANDARD TABLE OF bapiadsmtp,
      gs_bapiadsmtp TYPE bapiadsmtp,
      gt_bapiadtel TYPE STANDARD TABLE OF bapiadtel,
      gs_bapiadtel TYPE bapiadtel,
      objid_cust LIKE bapi4002_1-objkey,
      gs_return TYPE bapiret2,
      gt_return TYPE STANDARD TABLE OF bapiret2,
      gs_commit_return TYPE bapiret2,
      gs_addr_no TYPE bapi4003_1-addr_no,
      gs_pers_no TYPE bapi4003_1-pers_no.

h_kunnr = '1100'.  "example customer code
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input  = h_kunnr
  IMPORTING
    output = h_kunnr.

SELECT SINGLE * FROM kna1
  INTO gs_kna1
  WHERE kunnr EQ h_kunnr.

gs_knvk-kunnr = h_kunnr.
gs_knvk-name1 =  'lastname'.
gs_knvk-namev = 'firstname'.
gs_knvk-ernam = sy-uname.
gs_knvk-erdat = sy-datum.
APPEND gs_knvk TO gt_knvk.
*lastname en firstname must be the same as passed to the BAPI!
* otherwise the data of KNVK will overwrite the data entered by the BAPI
* this can be tested by entering different fpor knvk and the bapi
* if xd03 is started and double click on the contact you see the bapi details
* if xd02 is started and double click on the contact
****the lastname and firstname of the knvk overwrite the addres  data of the bapi
* other data entered with the bapi like email telephone and roomnumber maintain the values written with the BAPI

CALL FUNCTION 'SD_CUSTOMER_MAINTAIN_ALL'
  EXPORTING
    i_kna1                     = gs_kna1
    i_maintain_address_by_kna1 = ' '
    pi_postflag                = 'X'
  TABLES
    t_xknvk                    = gt_knvk
  EXCEPTIONS
    client_error               = 1
    kna1_incomplete            = 2
    knb1_incomplete            = 3
    knb5_incomplete            = 4
    knvv_incomplete            = 5
    kunnr_not_unique           = 6
    sales_area_not_unique      = 7
    sales_area_not_valid       = 8
    insert_update_conflict     = 9
    number_assignment_error    = 10
    number_not_in_range        = 11
    number_range_not_extern    = 12
    number_range_not_intern    = 13
    account_group_not_valid    = 14
    parnr_invalid              = 15
    bank_address_invalid       = 16
    tax_data_not_valid         = 17
    no_authority               = 18
    company_code_not_unique    = 19
    dunning_data_not_valid     = 20
    knb1_reference_invalid     = 21
    cam_error                  = 22
    OTHERS                     = 23.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Instead of using BAPI_PARTNEREMPLOYEE_GETINTNUM to retrieve the next number for the parnr
* I use the function  'SD_CUSTOMER_MAINTAIN_ALL' to retrieve the next number
* so the connection with KNVK is already established
READ TABLE gt_knvk INDEX 1 INTO gs_knvk.
new_contactid_create = gs_knvk-parnr.
objid_cust = h_kunnr.
gs_bapiad3vl_x-lastname = 'X'.
gs_bapiad3vl_x-firstname = 'X'.
APPEND gs_bapiad3vl_x TO gt_bapiad3vl_x.
*common data
*lastname en firstname must be the same as passed to KNVK!
gs_bapiad3vl-lastname = 'lastname'.
gs_bapiad3vl-firstname = 'firstname'.
gs_bapiad3vl-pers_group = 'BP'.
gs_bapiad3vl-namcountry = 'NL'.
gs_bapiad3vl-langu_p = 'NL'.
gs_bapiad3vl-room_no_p = 'roomnumber'.
APPEND gs_bapiad3vl TO gt_bapiad3vl.
* email
gs_bapiadsmtp-e_mail = 'youre@email.adres'.
APPEND gs_bapiadsmtp TO gt_bapiadsmtp.
* telephone nr
gs_bapiadtel-telephone = '020-11'.
gs_bapiadtel-extension = '55111'.
APPEND gs_bapiadtel TO gt_bapiadtel.
* instead of the bapi below also the bapi
* BAPI_ADDRESSCONTPART_CHANGE can be used
CALL FUNCTION 'BAPI_ADDRCONTPART_SAVEREPLICA'
  EXPORTING
    obj_type_p       = 'BUS1006001'
    obj_id_p         = new_contactid_create
    obj_type_c       = 'KNA1'
    obj_id_c         = objid_cust
    iv_check_address = 'X'
  IMPORTING
    return           = gs_return
    address_number   = gs_addr_no
    person_number    = gs_pers_no
  TABLES
    bapiad3vl        = gt_bapiad3vl
    bapiadtel        = gt_bapiadtel
    bapiadsmtp       = gt_bapiadsmtp.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    wait   = 'X'
  IMPORTING
    return = gs_commit_return.
 

This porgram send the email with multiple attachments. First all I wanted was to avoid the 255 character limit of the SEND_API function module, but I modified the program so that it is useful to every one.

First it appends all the character data to a string, then the string is converted to XSTRING in order to be compressed. And then attached to the mail.

After going through the code I hope you can alter it according to your needs.

Good Luck.

 
*&---------------------------------------------------------------------*
*& Report  ZTHILANKA_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZTHILANKA_TEST.


data: binary_content type solix_tab.
data: xl_content type xstring .

constants:
con_tab  type c value cl_abap_char_utilities=>horizontal_tab,
con_cret type c value cl_abap_char_utilities=>cr_lf.

data: xlcontent type xstring,
      conlength type i,
      conlengths type so_obj_len,
      result_content type string,
      wa_string type string, "This holds all of your data
      dummy type string.

data: send_request type ref to cl_bcs.
data: text type bcsy_text.
data: document type ref to cl_document_bcs.
data: sender type ref to if_sender_bcs.
data: recipient type ref to if_recipient_bcs.
data: recipients type bcsy_smtpa.
data: bcs_exception type ref to cx_bcs.
data: sent_to_all type os_boolean.

data: e_r_page type ref to cl_rsr_www_page.
data: content_length type w3param-cont_len ,
      content_type type w3param-cont_type,
      return_code type w3param-ret_code .
data: html type standard table of w3html .
data: server type string ,
      port type string .
data: wa_rec type ad_smtpadr .
data: bcs_message type string .

data: subject type so_obj_des.
data: sender_id type ad_smtpadr.
data: email type ad_smtpadr.

data: gv_file type string,
      gv_zipfilehex type xstring,
      go_zipper type ref to cl_abap_zip. "The zip folder object

concatenate 'Customer no.'
'CUSTOMER name'
'Subcustomer'
'Sales incoterms'
'Currency'
'Material'
'Mat long text'
'level1'
'level2'
'level3'
'Level 1 description'
'Level 2 description'
'Level 3 description'
'Data'
'Valid from'
'Valid to'
into wa_string separated by con_tab.
concatenate con_cret con_tab wa_string into wa_string.
* After this keep on appending the data to the wa_string
data: i type i,
      true type string.

clear: xl_content .
* convert the string data to xstring
call function 'SCMS_STRING_TO_XSTRING'
exporting
  text = wa_string
* MIMETYPE = ' '
* ENCODING =
importing
  buffer = xl_content.
* EXCEPTIONS
* FAILED = 1
* OTHERS = 2
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

gv_file = 'Data.xls'. "Zip file name

create OBJECT go_zipper.
go_zipper->add( name    = gv_file
                content = xl_content )."If you have other content to be added to the zip folder, do it here

gv_zipfilehex = go_zipper->save( ).


concatenate 'Data list ' 'date' into  subject .

sender_id = 'your_email@yourdomain.tld'.
email = 'customer@hisdomain.tld'.

refresh binary_content .

call function 'SCMS_XSTRING_TO_BINARY'
exporting
  buffer     = gv_zipfilehex
tables
  binary_tab = binary_content.


*refresh text .
clear result_content .
*The body message
concatenate
'<p><font color="#000080">Dear Customer,</font></p>'
'<p><font color="#000080">Attached herewith is the data list you requested.</font></p>'

into result_content .
conlength = strlen( result_content ) .
conlengths = conlength .
call function 'SCMS_STRING_TO_FTEXT'
exporting
  text      = result_content
tables
  ftext_tab = text.



try.
  clear send_request .

  send_request = cl_bcs=>create_persistent( ).

  clear document .
  document = cl_document_bcs=>create_document(
  i_type    = 'HTM'
  i_text    = text
  i_length  = conlengths
  i_subject = subject ).

  call method document->add_attachment
  exporting
    i_attachment_type    = 'zip'
    i_attachment_subject = 'Price List' "Attachment name
    i_att_content_hex    = binary_content.


*You can add multiple attachments like below

*        CALL METHOD document->add_attachment
*          EXPORTING
*            i_attachment_type    = 'zip'
*            i_attachment_subject = 'Subject testing 2' "atta_sub
*            i_att_content_hex    = binary_content.
*
*        CALL METHOD document->add_attachment
*          EXPORTING
*            i_attachment_type    = 'zip'
*            i_attachment_subject = 'Subject 3' "atta_sub
*            i_att_content_hex    = binary_content.

*     add document to send request
  call method send_request->set_document( document ).

  clear sender .
  sender = cl_cam_address_bcs=>create_internet_address( sender_id ).
  call method send_request->set_sender
  exporting
    i_sender = sender.

  clear wa_rec .



*     add recipient with its respective attributes to send request
*     you can add multiple recipients in the same mail by calling
*     this method repeatedly.

 clear recipient .
  wa_rec =  email.
  recipient = cl_cam_address_bcs=>create_internet_address(
  wa_rec ).

*  call method send_request->add_recipient
*  exporting
*    i_recipient = recipient1
*    i_express   = 'X'.

*  call method send_request->add_recipient
*  exporting
*    i_recipient = recipient2
*    i_express   = 'X'.



  call method send_request->add_recipient
  exporting
    i_recipient = recipient
    i_express   = 'X'.

  call method send_request->set_status_attributes
  exporting
    i_requested_status = 'E'
    i_status_mail      = 'E'.

  call method send_request->set_send_immediately( 'X' ).
*     ---------- send document ---------------------------------------

  call method send_request->send(
  exporting
    i_with_error_screen = 'X'
    RECEIVING
    result = sent_to_all ).
  if sent_to_all = 'X'.
*APPEND 'Mail sent successfully ' TO return .
  endif.
  commit work.
catch cx_bcs into bcs_exception.
  bcs_message = bcs_exception->get_text( ).
*APPEND bcs_message TO return .
  exit.
endtry.

Submitted: Nov 16 2007

 
TABLES: ekko.  
PARAMETERS: p_email   TYPE somlreci1-receiver
                                  DEFAULT 'test@sapdev.co.uk'.
TYPES: BEGIN OF t_ekpo,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
      wa_ekpo TYPE t_ekpo.
TYPES: BEGIN OF t_charekpo,
  ebeln(10) TYPE c,
  ebelp(5)  TYPE c,
  aedat(8)  TYPE c,
  matnr(18) TYPE c,
END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.
DATA:   it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                WITH HEADER LINE.
DATA:   it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                WITH HEADER LINE.
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,
        gd_error    TYPE sy-subrc,
        gd_reciever TYPE sy-subrc.
************************************************************************
*START_OF_SELECTION
START-OF-SELECTION.
*   Retrieve sample data from table ekpo
  PERFORM data_retrieval.
*   Populate table with detaisl to be entered into .xls file
  PERFORM build_xls_data_table.
************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
* Populate message body text
  perform populate_email_message_body.
* Send file by email as .xls speadsheet
  PERFORM send_file_as_email_attachment
                               tables it_message
                                      it_attach
                                using p_email
                                      'Example .xls documnet attachment'
                                      'XLS'
                                      'filename'
                                      ' '
                                      ' '
                                      ' '
                             changing gd_error
                                      gd_reciever.
*   Instructs mail send program for SAPCONNECT to send email(rsconn01)
  PERFORM initiate_mail_execute_program.
*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
FORM data_retrieval.
  SELECT ebeln ebelp aedat matnr
   UP TO 10 ROWS
    FROM ekpo
    INTO TABLE it_ekpo.
ENDFORM.                    " DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*&      Form  BUILD_XLS_DATA_TABLE
*&---------------------------------------------------------------------*
*       Build data table for .xls document
*----------------------------------------------------------------------*
FORM build_xls_data_table.
  CONSTANTS: con_cret TYPE x VALUE '0D',  "OK for non Unicode
             con_tab TYPE x VALUE '09'.   "OK for non Unicode
*If you have Unicode check active in program attributes thnen 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 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
         INTO it_attach SEPARATED BY con_tab.
  CONCATENATE con_cret it_attach  INTO it_attach.
  APPEND  it_attach.
  LOOP AT it_ekpo INTO wa_charekpo.
    CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
                wa_charekpo-aedat wa_charekpo-matnr
           INTO it_attach SEPARATED BY con_tab.
    CONCATENATE con_cret it_attach  INTO it_attach.
    APPEND  it_attach.
  ENDLOOP.
ENDFORM.                    " BUILD_XLS_DATA_TABLE
*&---------------------------------------------------------------------*
*&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
*&---------------------------------------------------------------------*
*       Send email
*----------------------------------------------------------------------*
FORM send_file_as_email_attachment tables pit_message
                                          pit_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: 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.
  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[] = pit_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.
  t_receivers-receiver = ld_email.
  t_receivers-rec_type = 'U'.
  t_receivers-com_type = 'INT'.
  t_receivers-notif_del = 'X'.
  t_receivers-notif_ndel = 'X'.
  APPEND t_receivers.
  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.
*&---------------------------------------------------------------------*
*&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
*&---------------------------------------------------------------------*
*       Instructs mail send program for SAPCONNECT to send email.
*----------------------------------------------------------------------*
FORM initiate_mail_execute_program.
  WAIT UP TO 2 SECONDS.
  SUBMIT rsconn01 WITH mode = 'INT'
                WITH output = 'X'
                AND RETURN.
ENDFORM.                    " INITIATE_MAIL_EXECUTE_PROGRAM
*&---------------------------------------------------------------------*
*&      Form  POPULATE_EMAIL_MESSAGE_BODY
*&---------------------------------------------------------------------*
*        Populate message body text
*----------------------------------------------------------------------*
form populate_email_message_body.
  REFRESH it_message.
  it_message = 'Please find attached a list test ekpo records'.
  APPEND it_message.
endform.                    " POPULATE_EMAIL_MESSAGE_BODY
*& Report  ZPLXX_PRO_RE_CS0_EMAIL_INTERF
*&---------------------------------------------------------------------*
*& Program:     Application Server files to Cadbury
*& Developer:   Marcin Pciak - Nearshore PL
*& Date:        05.03.2009
*&
*& Short descr: Program to be used mainly in background jobs, however
*&              may be used directly
*&              It looks for the file on Application Server generated today
*&              and sends it to given external address. Programm uses
*&              global class to populate and dispatch the message. Here data
*&              are only prepared and later encapsulated in the class
*&
*&              If PA_FULL parameter is checked then entire file name with extension must be
*&              specified, otherwise program looks for all files matching this subname
*&
*& Prerequisites: Given file (with today's date) must reside in Application Server
*&---------------------------------------------------------------------*


REPORT  zplxx_pro_re_cs0_email_interf.


"first load class definition - provided later
CLASS lcl_email_dispatcher DEFINITION DEFERRED.


*&---------------------------------------------------------------------*
*&                      SELECTION SCREEN
*&---------------------------------------------------------------------*
DATA: recip TYPE so_recname.


SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-tit.
PARAMETERS: pa_dir TYPE epsf-epsdirnam VISIBLE LENGTH 60 OBLIGATORY,  "directory
            pa_file TYPE epsf-epsfilnam VISIBLE LENGTH 40 OBLIGATORY. "file name or its part
*            pa_ext  TYPE c LENGTH 3 VISIBLE LENGTH 3 OBLIGATORY.      "extension
SELECT-OPTIONS so_recip FOR recip NO INTERVALS OBLIGATORY.
PARAMETERS: pa_full AS CHECKBOX.   "is path fully specified?
SELECTION-SCREEN END OF BLOCK blk.


SELECTION-SCREEN BEGIN OF BLOCK bl2 WITH FRAME TITLE text-mes.
PARAMETERS pa_subj TYPE so_obj_des OBLIGATORY.
SELECTION-SCREEN END OF BLOCK bl2.


*&---------------------------------------------------------------------*
*&                            TYPINGS
*&---------------------------------------------------------------------*
TYPES: tt_fdscr TYPE TABLE OF rlgrap-filename,
       tt_recip TYPE TABLE OF so_recname,
       tt_mess  TYPE TABLE OF string.


*&---------------------------------------------------------------------*
*&                          DATA OBJECTS
*&---------------------------------------------------------------------*
"tables to populate the message
DATA: it_fdscr TYPE tt_fdscr,
      it_recip TYPE tt_recip,
      it_mess  TYPE tt_mess.


DATA: gr_email_dispatcher TYPE REF TO lcl_email_dispatcher.


"full file path and name
DATA: full_path TYPE epsf-epspath.


"directory list
DATA: BEGIN OF dir_list OCCURS 0.
        INCLUDE STRUCTURE epsfili.
DATA END OF dir_list.


"file attributes
DATA: BEGIN OF file,
       mtime(6) TYPE p,     "returns time in secs from 1970
       date LIKE sy-datum,
       time(10) TYPE c,     "format 00:00:00
     END OF file.


 INCLUDE ZPLXX_PRO_IN_CS0_EMAIL_INT_C00.


*&---------------------------------------------------------------------*
*&                           GO!
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  "------------------------ get direcotry listing
  CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
    EXPORTING
      dir_name               = pa_dir
    TABLES
      dir_list               = dir_list
    EXCEPTIONS
      invalid_eps_subdir     = 1
      sapgparam_failed       = 2
      build_directory_failed = 3
      no_authorization       = 4
      read_directory_failed  = 5
      too_many_read_errors   = 6
      empty_directory_list   = 7
      OTHERS                 = 8.
  IF sy-subrc <> 0.
    MESSAGE 'No such directory' TYPE 'I' DISPLAY LIKE 'E'.
    LEAVE TO SCREEN 0.
  ENDIF.


  "------------------------ get direcotry listing
  LOOP AT dir_list.
    IF pa_full EQ space.
      CHECK dir_list-name CS pa_file.  "consider only files with this name
    ELSE.
      CHECK dir_list-name EQ pa_file.  "check exact name
    ENDIF.


    "get file attributes
    CALL FUNCTION 'EPS_GET_FILE_ATTRIBUTES'
      EXPORTING
        file_name              = dir_list-name
        dir_name               = pa_dir
      IMPORTING
        file_mtime             = file-mtime
      EXCEPTIONS
        read_directory_failed  = 1
        read_attributes_failed = 2
        OTHERS                 = 3.
    IF sy-subrc <> 0.
      CONTINUE.   "skip the file
    ENDIF.


    "get file timestamp (for this change p6 to time from 1970)
    PERFORM p6_to_date_time_tz(rstr0400)
            USING file-mtime
                  file-time
                  file-date.


    "process file generated today
    IF file-date EQ sy-datum.
      CONCATENATE pa_dir '/' dir_list-name INTO full_path.
      APPEND full_path TO it_fdscr.
    ENDIF.
  ENDLOOP.


  "------------------------ process only if any files found
  CHECK it_fdscr[] IS NOT INITIAL.


  "------------------------ set recipients
  LOOP AT so_recip.
    APPEND so_recip-low TO it_recip.
  ENDLOOP.


  "------------------------ set message
  APPEND 'This message was automatically generated in order to supply you with SAP Application Server data file(s).' TO it_mess.
  APPEND 'Check the attachment(s).' TO it_mess.
  APPEND INITIAL LINE TO it_mess.
  APPEND 'Please do not reply to this message.' TO it_mess.
  APPEND INITIAL LINE TO it_mess.
  APPEND '------------------------' TO it_mess.
  APPEND 'With Best Regards' TO it_mess.
  APPEND 'NorthgateArinso team' TO it_mess.


  "------------------------ crate and dispatch message
  CREATE OBJECT gr_email_dispatcher
    EXPORTING
      im_subject   = pa_subj
      im_tab_mess  = it_mess
      im_tab_fdscr = it_fdscr
      im_tab_recip = it_recip.


*&---------------------------------------------------------------------*
*&  Include           ZPLXX_PRO_IN_CS0_EMAIL_INT_C00
*&---------------------------------------------------------------------*


*----------------------------------------------------------------------*
*       CLASS lcl_email_dispatcher DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_email_dispatcher DEFINITION.
  PUBLIC SECTION.
    METHODS: constructor IMPORTING im_subject     TYPE so_obj_des
                                   im_tab_mess    TYPE tt_mess
                                   im_tab_fdscr   TYPE tt_fdscr
                                   im_tab_recip   TYPE tt_recip.


  PRIVATE SECTION.


    "tables
    DATA: it_recipients   TYPE TABLE OF somlreci1,
          it_packing_list TYPE TABLE OF sopcklsti1,
          it_message      TYPE TABLE OF solisti1,
          it_attachments  TYPE TABLE OF solisti1.


    "structures
    DATA: doc_attr        TYPE sodocchgi1.


    METHODS: set_doc_attributes IMPORTING f_subject TYPE so_obj_des, "50 chars
             set_recipients IMPORTING ft_recip TYPE tt_recip,
             set_automatic_message IMPORTING ft_mess TYPE tt_mess,
             initialize_packing_list IMPORTING ft_fdscr TYPE tt_fdscr,
             prepare_data_for_dispatch IMPORTING f_fdscr TYPE rlgrap-filename
                                       CHANGING f_lines TYPE i
                                                fs_packing_list TYPE sopcklsti1,
             get_file_name IMPORTING f_path TYPE rlgrap-filename
                           EXPORTING f_file TYPE so_obj_des,
             dispatch.


ENDCLASS.                    "lcl_email_dispatcher DEFINITION


*----------------------------------------------------------------------*
*       CLASS lcl_email_dispatcher IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_email_dispatcher IMPLEMENTATION.
  METHOD constructor.
    set_doc_attributes( im_subject ).
    set_recipients( im_tab_recip ).
    set_automatic_message( im_tab_mess ).
    initialize_packing_list( im_tab_fdscr ).
    dispatch( ).
  ENDMETHOD.                    "constructor


  METHOD set_doc_attributes.
    "---------------------- Document attributes
    doc_attr-obj_name = 'WAS_FILESEND'.
    doc_attr-obj_descr = f_subject.
    doc_attr-obj_langu = sy-langu.
    doc_attr-sensitivty = 'F'.      "functional message
  ENDMETHOD.                    "set_doc_attributes


  METHOD set_recipients.
    DATA: wa_recip LIKE LINE OF ft_recip,
          wa_recipient  TYPE somlreci1.


    "---------------------- Recipcients
    LOOP AT ft_recip INTO wa_recip.
      wa_recipient-receiver = wa_recip.
      wa_recipient-rec_type = 'U'.               "internet address
      wa_recipient-com_type = 'INT'.             "send via internet
      APPEND wa_recipient TO it_recipients.
    ENDLOOP.
  ENDMETHOD.                    "set_recipients


  METHOD set_automatic_message.
    DATA: wa_mess LIKE LINE OF ft_mess.


    LOOP AT ft_mess INTO wa_mess.
      APPEND wa_mess TO it_message.
    ENDLOOP.
  ENDMETHOD.                    "set_automatic_message


  METHOD initialize_packing_list.
    DATA: wa_fdscr LIKE LINE OF ft_fdscr,
          wa_packing_list TYPE sopcklsti1,
          l_line TYPE i,
          index(3) TYPE n,
          file TYPE so_obj_des.                             "char50


    "--------------------- describe message
    wa_packing_list-transf_bin = space.
    wa_packing_list-body_start = 1.
    DESCRIBE TABLE it_message.
    wa_packing_list-body_num = sy-tfill.
    wa_packing_list-doc_type = 'RAW'.
    APPEND wa_packing_list TO it_packing_list.


    "---------------------- describe attachemnts (one per line)
    l_line = 1.


    LOOP AT ft_fdscr INTO wa_fdscr.


      "------------------ construct attachement name
      get_file_name( EXPORTING f_path = wa_fdscr IMPORTING f_file = file ).


      "------------------ attachment attributes
      CLEAR wa_packing_list.
      wa_packing_list-transf_bin = 'X'.
      wa_packing_list-body_start = l_line.
      index = sy-tabix.
      CONCATENATE 'ATTACH' index INTO wa_packing_list-obj_name.
      wa_packing_list-obj_descr = file.
      wa_packing_list-obj_langu = sy-langu.
      wa_packing_list-doc_type = 'DAT'.          "send as DAT file


      "------------------- get the file form Application server
      CLEAR l_line.
      prepare_data_for_dispatch( EXPORTING f_fdscr = wa_fdscr CHANGING f_lines = l_line
                                                                       fs_packing_list = wa_packing_list ).


      "------------------- return read lines
      wa_packing_list-body_num = l_line.


      "------------------- new attachemnt starts from next line
      l_line = wa_packing_list-body_start + wa_packing_list-body_num.


      APPEND wa_packing_list TO it_packing_list.
    ENDLOOP.
  ENDMETHOD.                    "initialize_packing_list


  METHOD prepare_data_for_dispatch.
    DATA: l_len TYPE i,
          wa_attachment TYPE solisti1.


    OPEN DATASET f_fdscr FOR INPUT IN BINARY MODE.
    IF sy-subrc NE 0.
      "error log here -> can't open file from WAS
    ELSE.
      DO.
        READ DATASET f_fdscr INTO wa_attachment LENGTH l_len.
        IF sy-subrc NE 0.
          EXIT.
        ENDIF.
        APPEND wa_attachment TO it_attachments.
        ADD 1 TO f_lines.
        ADD l_len TO fs_packing_list-doc_size.
      ENDDO.


      "---------------------- all data read in one shot
      IF l_len <> 0.
        APPEND wa_attachment TO it_attachments.
        ADD 1 TO f_lines.
        ADD l_len TO fs_packing_list-doc_size.
      ENDIF.


      CLOSE DATASET  f_fdscr.
    ENDIF.


  ENDMETHOD.                    "prepare_data_for_dispatch


  METHOD get_file_name.
    DATA: off TYPE i,
          len TYPE i,
          file_tmp LIKE f_path.


    WHILE sy-subrc = 0.
      FIND '/' IN SECTION OFFSET off OF f_path
               MATCH OFFSET off
               MATCH LENGTH len.
      IF sy-subrc = 0.
        off = off + len.
      ENDIF.
    ENDWHILE.


    file_tmp = f_path.


    SHIFT file_tmp BY off PLACES LEFT.
    len = STRLEN( file_tmp ).
    SUBTRACT 4 FROM len.
    f_file = file_tmp(len).


  ENDMETHOD.                    "get_file_name


  METHOD dispatch.
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
        document_data              = doc_attr
        put_in_outbox              = 'X'
        commit_work                = 'X'
      TABLES
        packing_list               = it_packing_list
        contents_bin               = it_attachments
        contents_txt               = it_message
        receivers                  = it_recipients
      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.
      WAIT UP TO 2 SECONDS.
      SUBMIT rsconn01 WITH mode = 'INT'
*                        WITH ouput = 'X'
                      AND RETURN.
    ENDIF.
  ENDMETHOD.                    "send_mail


ENDCLASS.                    "lcl_email_sender IMPLEMENTATION

Back to Sending Mails - Home Page

Author: Martin Lang
Submitted: Aug 3rd 2009

Prerequisites: Check for these Notes and apply if required:

Sample Code:

*&---------------------------------------------------------------------*
*& Report  ZAG_CAL_ICAL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

report  z_appointment_to_outlook.

include <cntn01>.
type-pools: sccon.
data: mail type text40.

* Provide select option to enter multiple attendees
SELECTION-SCREEN: BEGIN OF BLOCK org.
select-options: email for mail no intervals default 'Joe.Doe@test.com'.
SELECTION-SCREEN: END OF BLOCK org.


data lo_appointment type ref to cl_appointment.
data ls_participant type scspart.
data lv_address type swc_object.
data ls_address_container like swcont occurs 0 with header line.
data lt_text type so_txttab.
data ls_text like line of lt_text.
data lv_location like scsappt-room.
data lo_send_request type ref to cl_bcs.
data lv_sent_to_all type os_boolean.

create object lo_appointment.

* Add multiple attendees
loop at email.
clear ls_participant.
swc_create_object lv_address 'ADDRESS' space.
swc_set_element ls_address_container 'AddressString' email-low.
swc_set_element ls_address_container 'TypeId' 'U'.
swc_call_method lv_address 'Create' ls_address_container.
check sy-subrc = 0.

* * get key and type of object
swc_get_object_key lv_address ls_participant-objkey.
check sy-subrc = 0.
swc_get_object_type lv_address ls_participant-objtype.
check sy-subrc = 0.
move sccon_part_sndmail_with_ans to ls_participant-send_mail.
ls_participant-comm_mode = 'INT'.
lo_appointment->add_participant( participant = ls_participant ).

endloop.


* Sample Apppointment for specific date/time
*lo_appointment->set_date( date_from = '20090801'
*                          time_from = '130000'
*                           date_to = '20090801'
*                           time_to = '140000'
*                           ).

* Sample Appointment for All-Day-Event
lo_appointment->set_date( date_from = '20090803'
                          date_to = '20090803'
                          ).

* Make appointment appear "busy"
lo_appointment->set_busy_value( sccon_busy_busy   ).

* Set Location
lo_appointment->set_location_string( 'Location' ).

* Set Organizer
lo_appointment->set_organizer( sy-uname ).

* "Type of Meeting" (value picked from table SCAPPTTYPE)
lo_appointment->set_type( 'ABSENT' ).

* Make this an all day event
lo_appointment->SET_VIEW_ATTRIBUTES( SHOW_ON_TOP  = 'X').

* Set Meeting body text
ls_text = 'This is the Body Text of the Appointment'.
append ls_text to lt_text.
lo_appointment->set_text( lt_text ).

* Set Meeting Subject
lo_appointment->set_title( 'This is the Appointment Subject' ).


* Important to set this one to space. Otherwise SAP will send a not user-friendly e-mail
lo_appointment->save( send_invitation = space ).

* Now that we have the appointment, we can send a good one for outlook by switching to BCS
lo_send_request = lo_appointment->create_send_request( ).

* don't request read/delivery receipts
lo_send_request->set_status_attributes( i_requested_status   = 'N'
                                        i_status_mail        = 'N'
                                         ).

* Send it to the world
lv_sent_to_all = lo_send_request->send( i_with_error_screen = 'X' ).

commit work and wait.

Email with attachements can be sent by using CL_BCS class as below :This code sample can be used as a reference :

The standard class CL_BCS is used to send the notification along with attachment .  CREATE_PERSISTENT is the method which  used to  send request object of the standard class CL_BCS.

Method CREATE_DOCUMENT of CL_DOCUMENT_BCS is used for  creating the text of the email body.Method ADD_ATTACHMENT of  CL_DOCUMENT_BCS is used to creating attachment of the email.Here lt_att_content_hex should contain data

CLASS cl_bcs DEFINITION LOAD.
DATA:  lo_send_request TYPE REF TO cl_bcs
      ,lo_document     TYPE REF TO cl_document_bcs
      ,lo_sender       TYPE REF TO if_sender_bcs
      ,lo_recipient    TYPE REF TO if_recipient_bcs      ,lt_message_body TYPE bcsy_text
      ,lx_document_bcs TYPE REF TO cx_document_bcs
      ,lv_send         TYPE ad_smtpadr VALUE 'xyz@gmail.com'
      ,lv_sent_to_all  TYPE os_boolean     .
"create send request
lo_send_request = cl_bcs=>create_persistent( ).

"create message body and subject
APPEND 'Dear Vendor,' TO lt_message_body.
APPEND INITIAL LINE to lt_message_body.
APPEND 'Please fill the attached .' TO lt_message_body.
APPEND INITIAL LINE to lt_message_body.
APPEND 'Thank You,' TO lt_message_body.

"put your text into the document
lo_document = cl_document_bcs=>create_document(
                 i_type = 'RAW'
                 i_text = lt_message_body
                 i_subject = 'Vendor Payment Form' ).


TRY.
  lo_document->add_attachment(
    EXPORTING
      i_attachment_type = 'PDF'
      i_attachment_subject = 'Form'
      i_att_content_hex = lt_att_content_hex ).

  CATCH cx_document_bcs INTO lx_document_bcs.
ENDTRY.

* Add attachment
* Pass the document to send request
lo_send_request->set_document( lo_document ).


"Create sender
lo_sender = cl_cam_address_bcs=>create_internet_address( l_send ).

"Set sender
lo_send_request->set_sender( lo_sender ).

"Create recipient
lo_recipient = cl_sapuser_bcs=>create( sy-uname ).

*Set recipient
lo_send_request->add_recipient(
     EXPORTING
       i_recipient = lo_recipient i_express = 'X' ).

lo_send_request->add_recipient( lo_recipient ).

* Send email
lo_send_request->send(
  EXPORTING
    i_with_error_screen = 'X'
  RECEIVING
    result = lv_sent_to_all ).

COMMIT WORK.

Author: kalyan Annapareddy
Submitted: 9th june 2008
Related Links:

SAP is a robust system, which gives many facilities in the form of Function Modules (FMs) for connecting to external systems or for use within the system. With a clever use of these FMs we can achieve a lot of things through ABAP code.

This article focuses on ways to send E-mails and SAP Mails using ABAP code.

Firstly SAP Mail

A SAP mail is a mail internal to the SAP system. It is a very good forum to exchange information with other users. Using a SAP mail in ABAP code facilitates exchange of automatic messages at various stages of the business process. It is easy to use and saves many hassles involved in using workflows for exchanging messages.

The ABAP code to send a sap mail is built around the FM SO_OBJECT_SEND which has the following pattern.

CALL FUNCTION 'SO_OBJECT_SEND'
* EXPORTING
*   FOLDER_ID                        = ' '
*   FORWARDER                        = ' '
*   OBJECT_FL_CHANGE                 =
*   OBJECT_HD_CHANGE                 = ' '
*   OBJECT_ID                        = ' '
*   OBJECT_TYPE                      = ' '
*   OUTBOX_FLAG                      = ' '
*   OWNER                            = ' '
*   STORE_FLAG                       = ' '
*   DELETE_FLAG                      = ' '
*   SENDER                           = ' '
*   CHECK_SEND_AUTHORITY             = ' '
*   CHECK_ALREADY_SENT               = ' '
*   GIVE_OBJECT_BACK                 =
*   ORIGINATOR                       = ' '
*   ORIGINATOR_TYPE                  = 'J'
*   LINK_FOLDER_ID                   = ' '
*   SEND_REQUEST_OID                 = ' '
*   IP_ENCRYPT                       = 'U'
*   IP_SIGN                          = 'U'
*   IP_REC_COUNT_ADD                 =
* IMPORTING
*   OBJECT_ID_NEW                    =
*   SENT_TO_ALL                      =
*   ALL_BINDING_DONE                 =
*   OFFICE_OBJECT_KEY                =
*   ORIGINATOR_ID                    =
*   E_SEND_REQUEST_OID               =
* TABLES
*   OBJCONT                          =
*   OBJHEAD                          =
*   OBJPARA                          =
*   OBJPARB                          =
*   RECEIVERS                        =
*   PACKING_LIST                     =
*   ATT_CONT                         =
*   ATT_HEAD                         =
*   NOTE_TEXT                        =
*   LINK_LIST                        =
*   APPLICATION_OBJECT               =
* EXCEPTIONS
*   ACTIVE_USER_NOT_EXIST            = 1
*   COMMUNICATION_FAILURE            = 2
*   COMPONENT_NOT_AVAILABLE          = 3
*   FOLDER_NOT_EXIST                 = 4
*   FOLDER_NO_AUTHORIZATION          = 5
*   FORWARDER_NOT_EXIST              = 6
*   NOTE_NOT_EXIST                   = 7
*   OBJECT_NOT_EXIST                 = 8
*   OBJECT_NOT_SENT                  = 9
*   OBJECT_NO_AUTHORIZATION          = 10
*   OBJECT_TYPE_NOT_EXIST            = 11
*   OPERATION_NO_AUTHORIZATION       = 12
*   OWNER_NOT_EXIST                  = 13
*   PARAMETER_ERROR                  = 14
*   SUBSTITUTE_NOT_ACTIVE            = 15
*   SUBSTITUTE_NOT_DEFINED           = 16
*   SYSTEM_FAILURE                   = 17
*   TOO_MUCH_RECEIVERS               = 18
*   USER_NOT_EXIST                   = 19
*   ORIGINATOR_NOT_EXIST             = 20
*   X_ERROR                          = 21
*   OTHERS                           = 22
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

 

Author: Saravanan M

Submitted: <06 Sep 2011>
Related Links:

Class CL_BCS: http://help.sap.com/saphelp_sm32/helpdata/en/2d/1c5d3aebba4c38e10000000a114084/content.htm

Class CL_DOCUMENT_BCS: http://help.sap.com/saphelp_NW70EHP1core/helpdata/en/8c/5bf13b68402b69e10000000a11402f/content.htm

Description

This article describes how to convert internal table value into excel and sending excel in email using class CL_BCS and CL_DOCUMENT_BCS.

Selection Screen:

Selection Screen.bmp
 

*&---------------------------------------------------------------------*
*& Report ZSDRR_DAILY_FEED
*&
*&---------------------------------------------------------------------*
*& Description : This is the report program to send email with *
*& list of new contract created daily, weekly and *
*& monthly to specified email ID in the selection *
*& screen. *
*&---------------------------------------------------------------------*
REPORT zsdrr_daily_feed.
TABLES: mara.
*/..Types Declarations
TYPES : BEGIN OF ty_vbak,
vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
auart TYPE vbak-auart,
augru TYPE vbak-augru,
vkbur TYPE vbak-vkbur,
kunnr TYPE vbak-kunnr,
END OF ty_vbak,
BEGIN OF ty_vbkd,
vbeln TYPE vbkd-vbeln,
posnr TYPE vbkd-posnr,
zzreinstate TYPE vbkd-zzreinstate,
zzexpired TYPE vbkd-zzexpired,
zzlatesale TYPE vbkd-zzlatesale,
zzrenewal TYPE vbkd-zzrenewal,
END OF ty_vbkd,
BEGIN OF ty_veda,
vbeln TYPE veda-vbeln,
vposn TYPE veda-vposn,
vbegdat TYPE veda-vbegdat,
venddat TYPE veda-venddat,
vkuegru TYPE veda-vkuegru,
vbedkue TYPE veda-vbedkue,
END OF ty_veda,
BEGIN OF ty_vbap,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
zmeng TYPE vbap-zmeng,
kzwi3 TYPE vbap-kzwi3,
kzwi5 TYPE vbap-kzwi5,
maktx TYPE makt-maktx,
mtart TYPE mara-mtart,
END OF ty_vbap,
BEGIN OF ty_vbpa,
vbeln TYPE vbpa-vbeln,
posnr TYPE vbpa-posnr,
parvw TYPE vbpa-parvw,
kunnr TYPE vbpa-kunnr,
pernr TYPE vbpa-pernr,
adrnr TYPE vbpa-adrnr,
END OF ty_vbpa,
BEGIN OF ty_vbpa_s,
sobid TYPE hrp1001-sobid,
kunnr TYPE but000-partner,
END OF ty_vbpa_s,
BEGIN OF ty_adrc,
addrnumber TYPE adrc-addrnumber,
name1 TYPE adrc-name1,
name2 TYPE adrc-name2,
street TYPE adrc-street,
city1 TYPE adrc-city1,
post_code1 TYPE adrc-post_code1,
country TYPE adrc-country,
region TYPE adrc-region,
tel_number TYPE adrc-tel_number,
END OF ty_adrc,
BEGIN OF ty_adr6,
addrnumber TYPE adrc-addrnumber,
smtp_addr TYPE adr6-smtp_addr,
END OF ty_adr6,
BEGIN OF ty_but000,
partner TYPE but000-partner,
bpkind TYPE but000-bpkind,
bu_group TYPE but000-bu_group,
name_last TYPE but000-name_last,
name_first TYPE but000-name_first,
END OF ty_but000,
BEGIN OF ty_hrp1001,
otype TYPE hrp1001-otype,
objid TYPE hrp1001-objid,
plvar TYPE hrp1001-plvar,
relat TYPE hrp1001-relat,
begda TYPE hrp1001-begda,
endda TYPE hrp1001-endda,
sclas TYPE hrp1001-sclas,
sobid TYPE hrp1001-sobid,
END OF ty_hrp1001,
BEGIN OF ty_vbfa,
vbelv TYPE vbfa-vbelv,
posnv TYPE vbfa-posnv,
vbeln TYPE vbfa-vbeln,
posnn TYPE vbfa-posnn,
vbtyp_n TYPE vbfa-vbtyp_n,
vbtyp_v TYPE vbfa-vbtyp_v,
END OF ty_vbfa,
BEGIN OF ty_vbeln,
vbeln TYPE vbak-vbeln,
posnr TYPE vbap-posnr,
END OF ty_vbeln.
TYPES: BEGIN OF ty_kna1,
kunnr TYPE kna1-kunnr,
erdat TYPE kna1-erdat,
END OF ty_kna1.
TYPES: BEGIN OF x_final,
auart TYPE vbak-auart,
erdat TYPE vbak-erdat,
augru TYPE vbak-augru,
vbeln TYPE vbak-vbeln,
posnr TYPE vbap-posnr,
kunnr TYPE vbak-kunnr,
name(60) TYPE c,
telf1 TYPE sza1_d0100-tel_number,
smtp_addr TYPE sza1_d0100-smtp_addr,
street TYPE addr1_data-street,
city1 TYPE addr1_data-city1,
region TYPE addr1_data-region,
post_code1 TYPE addr1_data-post_code1,
country TYPE addr1_data-country,
kunnr_b TYPE vbak-kunnr,
name_b(60) TYPE c,
telf1_b TYPE sza1_d0100-tel_number,
smtp_addr_b TYPE sza1_d0100-smtp_addr,
street_b TYPE addr1_data-street,
city1_b TYPE addr1_data-city1,
region_b TYPE addr1_data-region,
post_code1_b TYPE addr1_data-post_code1,
country_b TYPE addr1_data-country,
matnr TYPE vbap-matnr,
maktx TYPE makt-maktx,
zmeng TYPE vbap-zmeng,
vbegdat TYPE veda-vbegdat,
venddat TYPE veda-venddat,
kzwi3 TYPE vbap-kzwi3,
con_val TYPE vbap-kzwi3,
sales_rep TYPE vbak-kunnr,
vkbur TYPE vbak-vkbur,
END OF x_final,
BEGIN OF x_log,
message TYPE string,
END OF x_log.
*/..Workarea Declarations
DATA: w_vbak TYPE ty_vbak,
w_veda TYPE ty_veda,
w_vbkd TYPE ty_vbkd,
w_vbap TYPE ty_vbap,
w_vbpa TYPE ty_vbpa,
w_adrc TYPE ty_adrc,
w_adr6 TYPE ty_adr6,
w_vbfa TYPE ty_vbfa,
w_vbeln TYPE ty_vbeln,
w_tvarv TYPE tvarv,
w_final TYPE x_final,
w_log TYPE x_log,
w_veda_new TYPE ty_veda,
w_kna1 TYPE ty_kna1.
*/..Data Declarations
DATA : gv_datefrm TYPE sy-datum,
gv_dateto TYPE sy-datum,
gv_order TYPE string.
DATA: t_vbak TYPE STANDARD TABLE OF ty_vbak,
t_vbkd TYPE STANDARD TABLE OF ty_vbkd,
t_veda TYPE STANDARD TABLE OF ty_veda,
t_vbap TYPE STANDARD TABLE OF ty_vbap,
t_vbpa TYPE STANDARD TABLE OF ty_vbpa,
t_vbpa_s TYPE STANDARD TABLE OF ty_vbpa_s,
t_adrc TYPE STANDARD TABLE OF ty_adrc,
t_adr6 TYPE STANDARD TABLE OF ty_adr6,
t_hrp1001 TYPE STANDARD TABLE OF ty_hrp1001,
t_but000 TYPE STANDARD TABLE OF ty_but000,
t_vbfa TYPE STANDARD TABLE OF ty_vbfa,
t_vbeln TYPE STANDARD TABLE OF ty_vbeln,
t_tvarv TYPE STANDARD TABLE OF tvarv,
t_final TYPE STANDARD TABLE OF x_final,
t_log TYPE STANDARD TABLE OF x_log,
t_veda_new TYPE STANDARD TABLE OF ty_veda,
t_kna1 TYPE STANDARD TABLE OF ty_kna1.
DATA: t_cdhdr TYPE TABLE OF cdhdr,
t_cdhdr1 TYPE TABLE OF cdhdr,
t_cdpos TYPE TABLE OF cdpos.
DATA: w_cdpos TYPE cdpos,
w_cdhdr TYPE cdhdr,
w_but000 TYPE ty_but000,
w_hrp1001 TYPE ty_hrp1001,
w_vbpa_s TYPE ty_vbpa_s.
DATA: r_beg_dat TYPE RANGE OF vbak-erdat,
r_canc_dat TYPE RANGE OF veda-vbedkue,
r_parvw TYPE RANGE OF vbpa-parvw,
r_auart TYPE RANGE OF vbak-auart,
rg_auart TYPE RANGE OF vbak-auart,
r_reinst TYPE RANGE OF vbak-erdat,
r_expired TYPE RANGE OF vbak-erdat,
r_contract TYPE RANGE OF vbak-erdat,
r_vkuegru TYPE RANGE OF veda-vkuegru,
r_mtart TYPE RANGE OF mara-mtart,
r_matnr TYPE RANGE OF mara-matnr.
DATA: w_beg_dat LIKE LINE OF r_beg_dat,
w_canc_dat LIKE LINE OF r_canc_dat,
w_parvw LIKE LINE OF r_parvw,
w_auart LIKE LINE OF r_auart,
wg_auart LIKE LINE OF rg_auart,
w_reinst LIKE LINE OF r_reinst,
w_expired LIKE LINE OF r_expired,
w_contract LIKE LINE OF r_contract,
w_vkuegru LIKE LINE OF r_vkuegru,
w_mtart LIKE LINE OF r_mtart.
*/..Selection screen declaration
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_rname TYPE makt-maktx OBLIGATORY,
p_mid TYPE adr6-smtp_addr OBLIGATORY.
SELECT-OPTIONS: s_mat_i FOR mara-matnr,
s_mat_p FOR mara-matnr.
SELECTION-SCREEN END OF BLOCK b1.
* Frequency and Timing
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
PARAMETERS: p_daily RADIOBUTTON GROUP g1 DEFAULT 'X',
p_weekly RADIOBUTTON GROUP g1,
p_month RADIOBUTTON GROUP g1.
SELECTION-SCREEN END OF BLOCK b3.
*-Initialization-*
INITIALIZATION.
  PERFORM initialization.
*-Start-of-Selection-*
START-OF-SELECTION.
*/..Get the time period for which the report is run.
  PERFORM get_daterange.
*/..Get the Material types based on the selection.
  PERFORM sub_fill_material_types.
  PERFORM sub_consolidate_data.
*&---------------------------------------------------------------------*
*& Form INITIALIZATION
*&---------------------------------------------------------------------*
FORM initialization .
  wg_auart-sign = 'I'.
  wg_auart-option = 'EQ'.
  wg_auart-low = 'ZC01'.
  APPEND wg_auart TO rg_auart.
  CLEAR wg_auart.
  wg_auart-sign = 'I'.
  wg_auart-option = 'EQ'.
  wg_auart-low = 'ZC02'.
  APPEND wg_auart TO rg_auart.
  CLEAR wg_auart.
  wg_auart-sign = 'I'.
  wg_auart-option = 'EQ'.
  wg_auart-low = 'ZC03'.
  APPEND wg_auart TO rg_auart.
  CLEAR wg_auart.
  wg_auart-sign = 'I'.
  wg_auart-option = 'EQ'.
  wg_auart-low = 'ZR01'.
  APPEND wg_auart TO rg_auart.
  CLEAR wg_auart.
  wg_auart-sign = 'I'.
  wg_auart-option = 'EQ'.
  wg_auart-low = 'ZR02'.
  APPEND wg_auart TO rg_auart.
  CLEAR wg_auart.
ENDFORM. " INITIALIZATION
*&---------------------------------------------------------------------*
*& Form GET_DATERANGE
*&---------------------------------------------------------------------*
FORM get_daterange .
  DATA : lv_date TYPE sy-datum.
  CLEAR: lv_date,
  gv_datefrm,
  gv_dateto.
  IF p_daily EQ 'X'.
*/..Set current date
    gv_datefrm = sy-datum.
    gv_dateto = sy-datum.
  ELSEIF p_weekly EQ 'X'.
*/..get a date in previous week.
    CALL FUNCTION 'HR_99S_DATE_MINUS_TIME_UNIT'
      EXPORTING
        i_idate               = sy-datum
        i_time                = 7
        i_timeunit            = 'D'
      IMPORTING
        o_idate               = lv_date
      EXCEPTIONS
        invalid_period        = 1
        invalid_round_up_rule = 2
        internal_error        = 3
        OTHERS                = 4.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
*/..get the previous week's start and end date.
*/..by default monday would be the starting day and Sunday would be
* the ending day.
    CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'
    EXPORTING
    date = lv_date
    IMPORTING
* WEEK =
    monday = gv_datefrm
    sunday = gv_dateto.
  ELSEIF p_month EQ 'X'.
*/..get a date in previous month.
    CALL FUNCTION 'HR_99S_DATE_MINUS_TIME_UNIT'
      EXPORTING
        i_idate               = sy-datum
        i_time                = 1
        i_timeunit            = 'M'
      IMPORTING
        o_idate               = lv_date
      EXCEPTIONS
        invalid_period        = 1
        invalid_round_up_rule = 2
        internal_error        = 3
        OTHERS                = 4.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
* /..Get the previous month's start and End Date.
    CALL FUNCTION 'OIL_MONTH_GET_FIRST_LAST'
      EXPORTING
        i_date      = lv_date
      IMPORTING
        e_first_day = gv_datefrm
        e_last_day  = gv_dateto
      EXCEPTIONS
        wrong_date  = 1
        OTHERS      = 2.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDIF.
ENDFORM. " GET_DATERANGE
*&---------------------------------------------------------------------*
*& Form GET_CONTRACT_LIST
*&---------------------------------------------------------------------*
FORM get_contract_list .
*/.. Get the Change history value for the given selection.
*/.. Change history might be Dialy, Weekly or Monthly.
*/..Based onthe checkbox selected pick the matching contract nos.
*/..for new orders.
  REFRESH r_beg_dat.
  w_beg_dat-sign = 'I'.
  w_beg_dat-option = 'BT'.
  w_beg_dat-low = gv_datefrm.
  w_beg_dat-high = gv_dateto.
  APPEND w_beg_dat TO r_beg_dat.
  CLEAR w_beg_dat.
*/..Get the contract header details.
  SELECT vbeln erdat auart augru vkbur kunnr
  FROM vbak
  INTO TABLE t_vbak
  WHERE erdat IN r_beg_dat
  AND auart IN r_auart.
  IF t_vbak[] IS NOT INITIAL.
*/..Get the Sales Document: Business Data details.
    SELECT vbeln posnr zzreinstate zzexpired zzlatesale zzrenewal
    FROM vbkd
    INTO TABLE t_vbkd
    FOR ALL ENTRIES IN t_vbak
    WHERE vbeln = t_vbak-vbeln.
*/.. Get the Contract data details
    SELECT vbeln vposn vbegdat venddat vkuegru vbedkue
    FROM veda
    INTO TABLE t_veda
    FOR ALL ENTRIES IN t_vbak
    WHERE vbeln = t_vbak-vbeln.
* AND vbedkue IN r_canc_dat
* AND vkuegru = gv_canc_reason.
*/..get material and its desc details from VBAP and MAKT table.
    PERFORM sub_get_item_details USING t_vbak.
*/..Get partner detials from VBPA table
* for the above obtained contracts.
*build a range holding only Ship-to,
* sold-to and Bill-to partner functions
    PERFORM sub_get_partner_details USING t_vbak.
*/.. Get the Address details for Sold to & Bill to partners
    PERFORM sub_get_partner_address_det USING t_vbpa.
*/.. Get the E-mail addresses for Sold to & Bill to addresses
    PERFORM sub_get_email_address USING t_vbpa.
*/.. Get Sales Rep Details for all the Contract documents
    PERFORM sub_get_sales_rep_details USING t_vbpa_s.
  ENDIF.
ENDFORM. " GET_CONTRACT_LIST
*&---------------------------------------------------------------------*
*& Form SUB_CONSOLIDATE_DATA_NEW
*&---------------------------------------------------------------------*
FORM sub_consolidate_data_new.
  LOOP AT t_vbak INTO w_vbak WHERE auart IN r_auart.
    w_final-vbeln = w_vbak-vbeln.
    w_final-auart = w_vbak-auart.
    w_final-erdat = w_vbak-erdat.
    w_final-augru = w_vbak-augru.
    w_final-vkbur = w_vbak-vkbur.
*/.. Sold to Party addresses
    CLEAR w_vbpa.
    READ TABLE t_vbpa INTO w_vbpa WITH KEY vbeln = w_vbak-vbeln parvw = 'AG'.
    IF sy-subrc = 0.
      w_final-kunnr = w_vbpa-kunnr.
      READ TABLE t_adrc INTO w_adrc WITH KEY addrnumber = w_vbpa-adrnr.
      IF sy-subrc = 0.
        CONCATENATE w_adrc-name1 w_adrc-name2 INTO w_final-name SEPARATED BY space.
        w_final-telf1 = w_adrc-tel_number.
        w_final-street = w_adrc-street.
        w_final-city1 = w_adrc-city1.
        w_final-region = w_adrc-region.
        w_final-post_code1 = w_adrc-post_code1.
        w_final-country = w_adrc-country.
      ENDIF.
      READ TABLE t_adr6 INTO w_adr6 WITH KEY addrnumber = w_vbpa-adrnr.
      IF sy-subrc = 0.
        w_final-smtp_addr = w_adr6-smtp_addr.
      ENDIF.
    ENDIF.
*/.. Bill to party address
    CLEAR w_vbpa.
    READ TABLE t_vbpa INTO w_vbpa WITH KEY vbeln = w_vbak-vbeln parvw = 'RE'.
    IF sy-subrc = 0.
      w_final-kunnr_b = w_vbpa-kunnr.
      CLEAR w_adrc.
      READ TABLE t_adrc INTO w_adrc WITH KEY addrnumber = w_vbpa-adrnr.
      IF sy-subrc = 0.
        CONCATENATE w_adrc-name1 w_adrc-name2 INTO w_final-name_b SEPARATED BY space.
        w_final-telf1_b = w_adrc-tel_number.
        w_final-street_b = w_adrc-street.
        w_final-city1_b = w_adrc-city1.
        w_final-region_b = w_adrc-region.
        w_final-post_code1_b = w_adrc-post_code1.
        w_final-country_b = w_adrc-country.
      ENDIF.
      CLEAR w_adr6.
      READ TABLE t_adr6 INTO w_adr6 WITH KEY addrnumber = w_vbpa-adrnr.
      IF sy-subrc = 0.
        w_final-smtp_addr_b = w_adr6-smtp_addr.
      ENDIF.
    ENDIF.
* Line Item Details
    LOOP AT t_vbap INTO w_vbap WHERE vbeln = w_vbak-vbeln.
      w_final-posnr = w_vbap-posnr.
      w_final-matnr = w_vbap-matnr.
      w_final-maktx = w_vbap-maktx.
      w_final-zmeng = w_vbap-zmeng.
      w_final-kzwi3 = w_vbap-kzwi3 + w_vbap-kzwi5.
      READ TABLE t_vbpa INTO w_vbpa WITH KEY vbeln = w_vbak-vbeln posnr = w_vbap-posnr parvw = 'Z3'.
      IF sy-subrc = 0.
        CLEAR w_hrp1001.
        READ TABLE t_hrp1001 INTO w_hrp1001 WITH KEY sobid = w_vbpa-kunnr. "#EC *
        IF sy-subrc = 0.
          w_final-sales_rep = w_hrp1001-sobid.
        ENDIF.
      ELSE.
        CLEAR w_vbpa.
        READ TABLE t_vbpa INTO w_vbpa WITH KEY vbeln = w_vbak-vbeln parvw = 'Z3'.
        IF sy-subrc = 0.
          CLEAR w_hrp1001.
          READ TABLE t_hrp1001 INTO w_hrp1001 WITH KEY sobid = w_vbpa-kunnr. "#EC *
          IF sy-subrc = 0.
            w_final-sales_rep = w_hrp1001-sobid.
          ENDIF.
        ENDIF.
      ENDIF.
      CLEAR w_veda.
      READ TABLE t_veda INTO w_veda WITH KEY vbeln = w_vbap-vbeln vposn = w_vbap-posnr.
      IF sy-subrc = 0.
        w_final-vbegdat = w_veda-vbegdat.
        w_final-venddat = w_veda-venddat.
      ELSE.
        READ TABLE t_veda INTO w_veda WITH KEY vbeln = w_vbap-vbeln." vposn = w_vbap-posnr.
        IF sy-subrc = 0.
          w_final-vbegdat = w_veda-vbegdat.
          w_final-venddat = w_veda-venddat.
        ENDIF.
      ENDIF.
      APPEND w_final TO t_final.
    ENDLOOP.
    CLEAR w_final.
    CLEAR w_vbap.
    CLEAR w_vbak.
  ENDLOOP.
  REFRESH: t_vbak,
  t_veda,
  t_vbkd,
  t_vbap,
  t_vbpa,
  t_adr6,
  t_adrc.
ENDFORM. " SUB_CONSOLIDATE_DATA_NEW
*&---------------------------------------------------------------------*
*& Form SUB_SEND_MAIL
*&---------------------------------------------------------------------*
FORM sub_send_mail.
* Data Declaration for Mail Sending Options
* Receiver
  DATA: l_recipent TYPE REF TO if_recipient_bcs,
* Sender
  l_sender TYPE REF TO cl_sapuser_bcs,
  l_attcdoctype TYPE soodk-objtp,
  l_atttitle TYPE sood-objdes,
  l_freq TYPE string,
  l_from TYPE char10,
  l_to TYPE char10.
* Execptions
  DATA : l_bcs_exception TYPE REF TO cx_bcs,               "#EC NEEDED)
  l_document TYPE REF TO cl_document_bcs,
  l_send_request TYPE REF TO cl_bcs.
  DATA: t_mail_text TYPE bcsy_text,
  wa_mail_text_row TYPE soli,
  l_subject2 TYPE so_obj_des,
  l_message TYPE string,
  l_message1 TYPE string.
  DATA: l_num_rows TYPE i,
  l_text_length TYPE so_obj_len,
  l_num_line TYPE i.
  DATA: l_line TYPE string,
  l_zmeng TYPE string,
  l_kzwi3 TYPE string.
  DATA: l_venddat TYPE char10,
  l_vbegdat TYPE char10,
  l_erdat TYPE char10.
  DATA: gt_binary_content TYPE solix_tab,
  gv_size TYPE so_obj_len.
  CONSTANTS: c_tab TYPE c VALUE cl_bcs_convert=>gc_tab,
  c_cr TYPE c VALUE cl_bcs_convert=>gc_crlf,
  c_ext TYPE soodk-objtp VALUE 'XLS',
  c_x TYPE c VALUE 'X'.
  TYPES : BEGIN OF ty_tvakt,
  auart TYPE auart,
  bezei TYPE bezei20,
  END OF ty_tvakt,
  BEGIN OF ty_tvaut,
  augru TYPE augru,
  bezei TYPE bezei40,
  END OF ty_tvaut.
  DATA : lt_tvakt TYPE STANDARD TABLE OF ty_tvakt,
  wa_tvakt TYPE ty_tvakt,
  lt_tvaut TYPE STANDARD TABLE OF ty_tvaut,
  wa_tvaut TYPE ty_tvaut,
  lt_ordesc TYPE STANDARD TABLE OF x_final,
  lv_auart TYPE auart,
  lv_augru TYPE augru,
  lv_auarttxt TYPE bezei40,
  lv_augrutxt TYPE bezei40,
  c_hyp(3) TYPE c VALUE ' - '.
  IF NOT t_final IS INITIAL.
    lt_ordesc = t_final.
    SORT lt_ordesc BY auart augru.
    DELETE ADJACENT DUPLICATES FROM lt_ordesc COMPARING auart augru.
    CLEAR : lt_tvakt,
    lt_tvaut,
    lv_auart,
    lv_augru.
    SELECT auart bezei INTO TABLE lt_tvakt
    FROM tvakt
    FOR ALL ENTRIES IN lt_ordesc
    WHERE auart EQ lt_ordesc-auart
    AND spras EQ sy-langu.
    SORT lt_tvakt BY auart.
    DELETE ADJACENT DUPLICATES FROM lt_tvakt COMPARING ALL FIELDS.
    SELECT augru bezei INTO TABLE lt_tvaut
    FROM tvaut
    FOR ALL ENTRIES IN lt_ordesc
    WHERE augru EQ lt_ordesc-augru
    AND spras EQ sy-langu.
    SORT lt_tvaut BY augru.
    DELETE ADJACENT DUPLICATES FROM lt_tvaut COMPARING ALL FIELDS.
  ENDIF.
* Subject - Header
  l_subject2 = p_rname.
  CONCATENATE gv_datefrm+4(2) '/' gv_datefrm+6(2) '/' gv_datefrm+0(4) INTO l_from.
  CONCATENATE gv_dateto+4(2) '/' gv_dateto+6(2) '/' gv_dateto+0(4) INTO l_to.
  CLEAR l_freq.
  IF p_daily = c_x.
    l_freq = 'Daily'.
  ELSEIF p_weekly = c_x.
    l_freq = 'Weekly'.
  ELSEIF p_month = c_x.
    l_freq = 'Monthly'.
  ENDIF.
  DESCRIBE TABLE t_final LINES l_num_line.
  TRY.
      wa_mail_text_row = 'Data Selection Details:'.
      APPEND wa_mail_text_row TO t_mail_text. CLEAR wa_mail_text_row.
      APPEND wa_mail_text_row TO t_mail_text. CLEAR wa_mail_text_row.
      CONCATENATE 'Contract Type' ':' gv_order INTO wa_mail_text_row SEPARATED BY space.
      APPEND wa_mail_text_row TO t_mail_text.
      CLEAR wa_mail_text_row.
      CONCATENATE 'Frequency' ':' l_freq INTO wa_mail_text_row SEPARATED BY space.
      APPEND wa_mail_text_row TO t_mail_text.
      CLEAR wa_mail_text_row.
      CONCATENATE 'Date' ':' l_from 'to' l_to INTO wa_mail_text_row SEPARATED BY space.
      APPEND wa_mail_text_row TO t_mail_text. CLEAR wa_mail_text_row.
      CLEAR l_message.
      l_message = l_num_line.
      CONCATENATE 'No. of Records' ':' l_message INTO wa_mail_text_row SEPARATED BY space.
      APPEND wa_mail_text_row TO t_mail_text. CLEAR wa_mail_text_row.
      APPEND wa_mail_text_row TO t_mail_text.
      APPEND wa_mail_text_row TO t_mail_text.
      IF t_final[] IS INITIAL.
        wa_mail_text_row = 'No document exists for this selection.'.
        APPEND wa_mail_text_row TO t_mail_text.
        CLEAR wa_mail_text_row.
      ENDIF.
* Define rows and file size
      DESCRIBE TABLE t_mail_text LINES l_num_rows.
      l_num_rows = l_num_rows * 255.
      MOVE l_num_rows TO l_text_length.
      TRY.
          CALL METHOD cl_document_bcs=>create_document
            EXPORTING
              i_type    = 'RAW'
              i_subject = l_subject2
              i_length  = l_text_length
              i_text    = t_mail_text
            RECEIVING
              result    = l_document.
        CATCH cx_document_bcs .                         "#EC NO_HANDLER
      ENDTRY.
* IF t_final[] IS NOT INITIAL.
* Create Attachment
      CONCATENATE c_tab
      text-011 c_tab
      text-012 c_tab
      text-013 c_tab
      text-014 c_tab
      text-015 c_tab
      text-016 c_tab
      text-017 c_tab
      text-018 c_tab
      text-019 c_tab
      text-020 c_tab
      text-021 c_tab
      text-022 c_tab
      text-023 c_tab
      text-024 c_tab
      text-025 c_tab
      text-026 c_tab
      text-027 c_tab
      text-028 c_tab
      text-029 c_tab
      text-030 c_tab
      text-031 c_tab
      text-032 c_tab
      text-033 c_tab
      text-034 c_tab
      text-035 c_tab
      text-036 c_tab
      text-037 c_tab
      text-038 c_tab
      text-039 c_cr INTO l_line.
      CLEAR w_final.
      LOOP AT t_final INTO w_final.
        l_zmeng = w_final-zmeng.
        l_kzwi3 = w_final-kzwi3.
        CLEAR: l_vbegdat,
        l_venddat,
        l_erdat.
        CONCATENATE w_final-vbegdat+4(2) '/'
        w_final-vbegdat+6(2) '/'
        w_final-vbegdat+0(4)
        INTO l_vbegdat.
        CONCATENATE w_final-venddat+4(2) '/'
        w_final-venddat+6(2) '/'
        w_final-venddat+0(4)
        INTO l_venddat.
        CONCATENATE w_final-erdat+4(2) '/'
        w_final-erdat+6(2) '/'
        w_final-erdat+0(4)
        INTO l_erdat.
        IF w_final-auart NE lv_auart.
          READ TABLE lt_tvakt INTO wa_tvakt
          WITH KEY auart = w_final-auart.
          IF sy-subrc EQ 0.
            lv_auarttxt = wa_tvakt-bezei.
            CONCATENATE w_final-auart lv_auarttxt INTO lv_auarttxt SEPARATED BY c_hyp.
          ELSE.
            lv_auarttxt = w_final-auart.
          ENDIF.
          lv_auart = w_final-auart.
        ENDIF.
        IF w_final-augru NE lv_augru.
          READ TABLE lt_tvaut INTO wa_tvaut
          WITH KEY augru = w_final-augru.
          IF sy-subrc EQ 0.
            lv_augrutxt = wa_tvaut-bezei.
            CONCATENATE w_final-augru lv_augrutxt INTO lv_augrutxt SEPARATED BY c_hyp.
          ELSE.
            lv_augrutxt = w_final-augru.
          ENDIF.
          lv_augru = w_final-augru.
        ENDIF.
        CONCATENATE l_line
        lv_auarttxt
        l_erdat
        lv_augrutxt
        w_final-vbeln
        w_final-posnr
        w_final-kunnr
        w_final-name
        w_final-telf1
        w_final-smtp_addr
        w_final-street
        w_final-city1
        w_final-country
        w_final-post_code1
        w_final-region
        w_final-kunnr_b
        w_final-name_b
        w_final-street_b
        w_final-city1_b
        w_final-region_b
        w_final-post_code1_b
        w_final-telf1_b
        w_final-matnr
        w_final-maktx
        l_zmeng
        l_vbegdat
        l_venddat
        l_kzwi3
        w_final-sales_rep
        w_final-vkbur
        INTO l_line SEPARATED BY c_tab.
        CONCATENATE l_line c_cr INTO l_line.
        CLEAR w_final.
      ENDLOOP.
      TRY.
          cl_bcs_convert=>string_to_solix(
          EXPORTING
          iv_string = l_line
          iv_codepage = '4103' "suitable for MS Excel, leave empty
          iv_add_bom = 'X' "for other doc types
          IMPORTING
          et_solix = gt_binary_content
          ev_size = gv_size ).
        CATCH cx_bcs.
          MESSAGE e445(so).
      ENDTRY.
* ENDIF.
* Define File Name
      l_attcdoctype = c_ext.
      l_atttitle = p_rname.
* Create Document
      CALL METHOD l_document->add_attachment(
        i_attachment_type = l_attcdoctype
        i_attachment_subject = l_atttitle
        i_attachment_size = gv_size
        i_att_content_hex = gt_binary_content ).
      l_send_request = cl_bcs=>create_persistent( ).
      l_send_request->set_document( l_document ).
* Define Sender
      l_sender = cl_sapuser_bcs=>create( sy-uname ).
      TRY.
          CALL METHOD l_send_request->set_sender
            EXPORTING
              i_sender = l_sender.
        CATCH cx_send_req_bcs .                         "#EC NO_HANDLER
      ENDTRY.
* Define Recipient
      l_recipent = cl_cam_address_bcs=>create_internet_address( p_mid ).
      l_send_request->add_recipient( EXPORTING i_recipient = l_recipent ).
* Schedule
      l_send_request->set_send_immediately( 'X' ).
      l_send_request->send( ).
      COMMIT WORK AND WAIT.
* Catch Execptions
    CATCH cx_bcs INTO l_bcs_exception.                  "#EC NO_HANDLER
  ENDTRY.
  IF sy-subrc = 0.
    CONCATENATE gv_order '-' l_message INTO l_message1 SEPARATED BY space.
    w_log-message = l_message1.
    APPEND w_log TO t_log.
    CLEAR w_log.
  ENDIF.
  REFRESH t_final.
  CLEAR w_final.
ENDFORM. " SUB_SEND_MAIL
*&---------------------------------------------------------------------*
*& Form SUB_CONSOLIDATE_DATA
*&---------------------------------------------------------------------*
FORM sub_consolidate_data.
*/.. Consolidate and send the New Orders
  CLEAR gv_order.
  gv_order = 'New Contracts'.
*/..Get the list of document types to fetch the contracts.
  PERFORM get_document_types_new.
*/..Based on the selected check boxes, pick the required details.
  PERFORM get_contract_list.
*/.. Consolidate New orders
  PERFORM sub_consolidate_data_new.
*/.. Send New orders
  PERFORM sub_send_mail.
* Display final Log
  PERFORM sub_display_log.
ENDFORM. " SUB_CONSOLIDATE_DATA
*&---------------------------------------------------------------------*
*& Form SUB_GET_ITEM_DETAILS
*&---------------------------------------------------------------------*
FORM sub_get_item_details USING t_vbak LIKE t_vbak.
  REFRESH t_vbap.
*/..get material and its desc details from VBAP and MAKT table.
  IF NOT t_vbak[] IS INITIAL.
    SELECT a~vbeln a~posnr a~matnr a~zmeng a~kzwi3 a~kzwi5
    b~maktx c~mtart
    FROM vbap AS a INNER JOIN
    makt AS b ON a~matnr = b~matnr
    INNER JOIN mara AS c ON c~matnr = b~matnr
    INTO TABLE t_vbap
    FOR ALL ENTRIES IN t_vbak
    WHERE a~vbeln = t_vbak-vbeln
    AND c~matnr IN r_matnr
    AND c~mtart IN r_mtart.
  ENDIF.
ENDFORM. " SUB_GET_ITEM_DETAILS
*&---------------------------------------------------------------------*
*& Form SUB_GET_PARTNER_DETAILS
*&---------------------------------------------------------------------*
FORM sub_get_partner_details USING t_vbak LIKE t_vbak.
  REFRESH: r_parvw,
  t_vbpa,
  t_vbpa_s.
  w_parvw-sign = 'I'.
  w_parvw-option = 'EQ'.
  w_parvw-low = 'AG'.
  APPEND w_parvw TO r_parvw.
  CLEAR w_parvw.
  w_parvw-sign = 'I'.
  w_parvw-option = 'EQ'.
  w_parvw-low = 'RE'.
  APPEND w_parvw TO r_parvw.
  CLEAR w_parvw.
  w_parvw-sign = 'I'.
  w_parvw-option = 'EQ'.
  w_parvw-low = 'SH'.
  APPEND w_parvw TO r_parvw.
  CLEAR w_parvw.
  w_parvw-sign = 'I'.
  w_parvw-option = 'EQ'.
  w_parvw-low = 'Z3'.
  APPEND w_parvw TO r_parvw.
  CLEAR w_parvw.
  SELECT vbeln posnr parvw kunnr pernr adrnr
  FROM vbpa INTO TABLE t_vbpa
  FOR ALL ENTRIES IN t_vbak
  WHERE vbeln = t_vbak-vbeln
  AND parvw IN r_parvw.
  LOOP AT t_vbpa INTO w_vbpa WHERE parvw = 'Z3'.
    w_vbpa_s-sobid = w_vbpa-kunnr.
    w_vbpa_s-kunnr = w_vbpa-kunnr.
    APPEND w_vbpa_s TO t_vbpa_s.
    CLEAR w_vbpa_s.
  ENDLOOP.
ENDFORM. " SUB_GET_PARTNER_DETAILS
*&---------------------------------------------------------------------*
*& Form SUB_GET_PARTNER_ADDRESS_DET
*&---------------------------------------------------------------------*
FORM sub_get_partner_address_det USING t_vbpa LIKE t_vbpa.
  REFRESH t_adrc.
  IF t_vbpa[] IS NOT INITIAL.
    SELECT addrnumber name1 name2 street city1 post_code1 region country tel_number
    FROM adrc
    INTO TABLE t_adrc
    FOR ALL ENTRIES IN t_vbpa
    WHERE addrnumber = t_vbpa-adrnr.
  ENDIF.
ENDFORM. " SUB_GET_PARTNER_ADDRESS_DET
*&---------------------------------------------------------------------*
*& Form SUB_GET_EMAIL_ADDRESS
*&---------------------------------------------------------------------*
FORM sub_get_email_address USING t_vbpa LIKE t_vbpa.
  REFRESH t_adr6.
  IF t_vbpa[] IS NOT INITIAL.
    SELECT addrnumber smtp_addr
    FROM adr6
    INTO TABLE t_adr6
    FOR ALL ENTRIES IN t_vbpa
    WHERE addrnumber = t_vbpa-adrnr.
  ENDIF.
ENDFORM. " SUB_GET_EMAIL_ADDRESS
*&---------------------------------------------------------------------*
*& Form SUB_GET_SALES_REP_DETAILS
*&---------------------------------------------------------------------*
FORM sub_get_sales_rep_details USING t_vbpa_s LIKE t_vbpa_s.
  REFRESH: t_but000,
  t_hrp1001.
  SELECT otype objid plvar relat begda endda sclas sobid
  FROM hrp1001
  INTO TABLE t_hrp1001
  FOR ALL ENTRIES IN t_vbpa_s
  WHERE sobid = t_vbpa_s-sobid
  AND otype = 'S'
  AND plvar = '01'
  AND relat = '008'
  AND sclas = 'BP'
  AND begda < sy-datum
  AND endda >= sy-datum.
  SELECT partner bpkind bu_group name_last name_first
  FROM but000 INTO TABLE t_but000
  FOR ALL ENTRIES IN t_hrp1001
  WHERE partner = t_hrp1001-sobid+0(10)
  AND bpkind = '9002'.
ENDFORM. " SUB_GET_SALES_REP_DETAILS
*&---------------------------------------------------------------------*
*& Form SUB_FILL_MATERIAL_TYPES
*&---------------------------------------------------------------------*
FORM sub_fill_material_types .
  REFRESH r_mtart.
  REFRESH r_matnr.
  IF s_mat_i IS NOT INITIAL.
    APPEND LINES OF s_mat_i TO r_matnr.
  ENDIF.
  IF s_mat_p IS NOT INITIAL.
    APPEND LINES OF s_mat_p TO r_matnr.
  ENDIF.
ENDFORM. " SUB_FILL_MATERIAL_TYPES
*&---------------------------------------------------------------------*
*& Form GET_DOCUMENT_TYPES_NEW
*&---------------------------------------------------------------------*
FORM get_document_types_new .
  REFRESH r_auart.
  w_auart-sign = 'I'.
  w_auart-option = 'EQ'.
  w_auart-low = 'ZC01'.
  APPEND w_auart TO r_auart.
  CLEAR w_auart.
  w_auart-sign = 'I'.
  w_auart-option = 'EQ'.
  w_auart-low = 'ZC02'.
  APPEND w_auart TO r_auart.
  CLEAR w_auart.
  w_auart-sign = 'I'.
  w_auart-option = 'EQ'.
  w_auart-low = 'ZC03'.
  APPEND w_auart TO r_auart.
  CLEAR w_auart.
ENDFORM. " GET_DOCUMENT_TYPES_NEW
*&---------------------------------------------------------------------*
*& Form GET_DOCUMENT_TYPES_RENEW
*&---------------------------------------------------------------------*
FORM get_document_types_renew .
  REFRESH r_auart.
  w_auart-sign = 'I'.
  w_auart-option = 'EQ'.
  w_auart-low = 'ZR01'.
  APPEND w_auart TO r_auart.
  CLEAR w_auart.
  w_auart-sign = 'I'.
  w_auart-option = 'EQ'.
  w_auart-low = 'ZR02'.
  APPEND w_auart TO r_auart.
  CLEAR w_auart.
ENDFORM. " GET_DOCUMENT_TYPES_RENEW
*&---------------------------------------------------------------------*
*& Form SUB_DISPLAY_LOG
*&---------------------------------------------------------------------*
FORM sub_display_log .
  DATA: l_mesg TYPE string.
  IF t_log IS NOT INITIAL.
    CONCATENATE 'Email sent to' p_mid 'successfully' INTO l_mesg SEPARATED BY space.
  ELSE.
    CONCATENATE 'Email failed to sent -' p_mid INTO l_mesg SEPARATED BY space.
  ENDIF.
  WRITE / l_mesg.
  LOOP AT t_log INTO w_log.
    WRITE: / w_log-message.
    CLEAR w_log.
  ENDLOOP.
ENDFORM. " SUB_DISPLAY_LOG
*&---------------------------------------------------------------------*
*& Form SUB_VALIDATE_PARTNER_DATA
*&---------------------------------------------------------------------*
FORM sub_validate_partner_data .
  REFRESH t_cdhdr1[].
  SORT t_cdhdr BY objectid.
  t_cdhdr1[] = t_cdhdr[].
  LOOP AT t_cdhdr1 INTO w_cdhdr WHERE change_ind = 'I'.
    READ TABLE t_cdhdr1 TRANSPORTING NO FIELDS WITH KEY objectid = w_cdhdr-objectid
    udate = w_cdhdr-udate
    change_ind = 'U'.
    IF sy-subrc = 0.
      DELETE t_cdhdr WHERE objectid = w_cdhdr-objectid.
    ENDIF.
    CLEAR w_cdhdr.
  ENDLOOP.
ENDFORM. " SUB_VALIDATE_PARTNER_DATA
*&---------------------------------------------------------------------*
*& Form SUB_GET_DOCUMENT_TYPE_ADD
*&---------------------------------------------------------------------*
FORM sub_get_document_type_add .
  REFRESH r_auart.
  w_auart-sign = 'I'.
  w_auart-option = 'EQ'.
  w_auart-low = 'ZC01'.
  APPEND w_auart TO r_auart.
  CLEAR w_auart.
  w_auart-sign = 'I'.
  w_auart-option = 'EQ'.
  w_auart-low = 'ZC02'.
  APPEND w_auart TO r_auart.
  CLEAR w_auart.
  w_auart-sign = 'I'.
  w_auart-option = 'EQ'.
  w_auart-low = 'ZC03'.
  APPEND w_auart TO r_auart.
  CLEAR w_auart.
  w_auart-sign = 'I'.
  w_auart-option = 'EQ'.
  w_auart-low = 'ZC04'.
  APPEND w_auart TO r_auart.
  CLEAR w_auart.
  w_auart-sign = 'I'.
  w_auart-option = 'EQ'.
  w_auart-low = 'ZC05'.
  APPEND w_auart TO r_auart.
  CLEAR w_auart.
  w_auart-sign = 'I'.
  w_auart-option = 'EQ'.
  w_auart-low = 'ZC06'.
  APPEND w_auart TO r_auart.
  CLEAR w_auart.
  w_auart-sign = 'I'.
  w_auart-option = 'EQ'.
  w_auart-low = 'ZR01'.
  APPEND w_auart TO r_auart.
  CLEAR w_auart.
  w_auart-sign = 'I'.
  w_auart-option = 'EQ'.
  w_auart-low = 'ZR02'.
  APPEND w_auart TO r_auart.
  CLEAR w_auart.
ENDFORM. " SUB_GET_DOCUMENT_TYPE_ADD
 
REPORT zabap_send_mail.
PARAMETERS: psubject(40) TYPE c DEFAULT 'Hello',
            p_email(40) TYPE c DEFAULT 'write email address' .
DATA: it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
      it_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
      it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      gd_cnt TYPE i,
      gd_sent_all(1) TYPE c,
      gd_doc_data LIKE sodocchgi1,
      gd_error TYPE sy-subrc.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                  WITH HEADER LINE.
************************************************************************
START-OF-SELECTION.
  PERFORM populate_message_table.
*Send email message, although is not sent from SAP until mail send
*program has been executed(rsconn01)
  PERFORM send_email_message.
*Instructs mail send program for SAPCONNECT to send email(rsconn01)
  PERFORM initiate_mail_execute_program.
*&---------------------------------------------------------------------
*& Form POPULATE_MESSAGE_TABLE
*&---------------------------------------------------------------------
*Adds text to email text table
*----------------------------------------------------------------------
FORM populate_message_table.
  APPEND 'Email line 1' TO it_message.
  APPEND 'Email line 2' TO it_message.
  APPEND 'Email line 3' TO it_message.
  APPEND 'Email line 4' TO it_message.
ENDFORM. " POPULATE_MESSAGE_TABLE
*&---------------------------------------------------------------------
*& Form SEND_EMAIL_MESSAGE
*&---------------------------------------------------------------------
*Send email message
*----------------------------------------------------------------------
FORM send_email_message.
*Fill the document data.
  gd_doc_data-doc_size = 1.

*Populate the subject/generic message attributes
  gd_doc_data-obj_langu = sy-langu.
  gd_doc_data-obj_name = 'SAPRPT'.
  gd_doc_data-obj_descr = psubject.
  gd_doc_data-sensitivty = 'F'.

*Describe the body of the message
  CLEAR it_packing_list.
  REFRESH it_packing_list.
  it_packing_list-transf_bin = space.
  it_packing_list-head_start = 1.
  it_packing_list-head_num = 0.
  it_packing_list-body_start = 1.
  DESCRIBE TABLE it_message LINES it_packing_list-body_num.
  it_packing_list-doc_type = 'RAW'.
  APPEND it_packing_list.

*Add the recipients email address
  CLEAR it_receivers.
  REFRESH it_receivers.
  it_receivers-receiver = p_email.
  it_receivers-rec_type = 'U'.
  it_receivers-com_type = 'INT'.
  it_receivers-notif_del = 'X'.
  it_receivers-notif_ndel = 'X'.
  APPEND it_receivers.

*Call the FM to post the message to SAPMAIL
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = gd_doc_data
      put_in_outbox              = 'X'
    IMPORTING
      sent_to_all                = gd_sent_all
    TABLES
      packing_list               = it_packing_list
      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.

*Store function module return code
  gd_error = sy-subrc.

*Get it_receivers return code
  LOOP AT it_receivers.
  ENDLOOP.
ENDFORM. " SEND_EMAIL_MESSAGE
*&---------------------------------------------------------------------
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
*&---------------------------------------------------------------------
*Instructs mail send program for SAPCONNECT to send email.
*----------------------------------------------------------------------
FORM initiate_mail_execute_program.
  WAIT UP TO 2 SECONDS.
  IF gd_error EQ 0.
    SUBMIT rsconn01 WITH mode = 'INT'
    WITH output = 'X'
    AND RETURN.
  ENDIF.
ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM
 

SAP mail is a very robust method of interacting with users within SAP system, it is always good to receive email in Microsoft inbox. This also works like an additional notification to users in case they do not check SAP mail regularly.

Sending an email to the Microsoft Inbox is a way of interacting with a non SAP system through ABAP code and hence is very interesting. A fair knowledge of UNIX shell scripting is assumed here.

The ABAP code to send an email to Microsoft inbox revolves around following UNIX script

Echo "From:" "<"$1">" > <unix file path name>

Echo "To:" "<"$2">" >> <unix file path name>

Echo "Subject:" "<"$3">" >> <unix file path name>

Cat $4 >> <unix file path name>

Uuencode $5 $6 >> <unix file path name>

Cat <unix file path name> | /usr/sbin/sendmail -f $fraddr $toaddr

(Note : the commands in the above script can be case sensitive. Check the actual case on the unix installation in question)

Let us understand the various parts of the above script.

$1 = Sender email address

$2 = Recipient email address

$3 = Subject of the email

$4 = Path of unix server file having email body

Form email body as an internal table in ABAP program, download it to a unix server file

$5 = Path of unix server file to be sent as email attachment

$6 = Name to be given to the attachment (like test1.doc, test1.xls). The corresponding Microsoft icon will be shown in the email for the type of file attached ( Word document, excel document etc)

The script builds a temporary file and pipes the file to the sendmail command to achieve the mission.

This script can be invoked from SAP to send the mail to the intended recipient. Store this small script on the unix server. (Assume script name is sndmail )

To do this we should define a link in the SAP system between a customized command and this unix script.

The FM to define a customized command in SAP system has the following pattern.

CALL FUNCTION 'SXPG_CALL_SYSTEM'
  EXPORTING
    commandname                = 
    parameters                 = ' '
  IMPORTING
    status                     = 
  TABLES
    exec_protocol              = 
  EXCEPTIONS
    no_permission              = 1
    command_not_found          = 2
    parameters_too_long        = 3
    security_risk              = 4
    wrong_check_call_interface = 5
    program_start_error        = 6
    program_termination_error  = 7
    x_error                    = 8
    parameter_expected         = 9
    too_many_parameters        = 10
    illegal_command            = 11
    OTHERS                     = 12.
 

The parameters of Function Module are explained below:

Import Parameters Name and Description

Field name

Field function

Commandname
Name of unix shell script or command to be executed by SAP

 

Name of unix shell script to be invoked

Parameters

 

The parameters to be sent to unix shell script ($1, $2 etc). Send parameters as a concatenated string separated by space and length not exceeding 128 characters
For eg in UNIX environment the above shell script would be executed as
Sndmail sender@a.com receiver@b.com Trial /home/test.doc testmail.
We will be simulating this command using the FM from SAP system

Table Parameters Name and Description

Field Name

Field function

Exec_protocol (structure)
Table to get messages from unix server after shell script is executed

Length

Length of the message from external program i.e unix

 

Message

Log message from external program i.e unix

Export Parameters Name and Description

Field Name

Field function

Status
Contains the status of execution of external program

 

Scheduling status of external program i.e unix

 

Once the above FM is invoked with the necessary parameters the unix program sendmail will send a mail to the inbox of the recipient in Microsoft.

The restriction on the parameter string length of 128 characters can be removed to make way for very long email addresses and subjects. Build the parameters into an internal table and download it as a file on the unix server. Instead of passing each parameter individually, pass the unix server path of this file as the parameter to the unix shell script (sndmail mentioned above). Modify the shell script to read every line of this parameter file as variables to be used in the shell script.

REPORT ztsapmail.
DATA: x_object_type LIKE sood-objtp.
DATA: BEGIN OF x_object_hd_change.
        INCLUDE STRUCTURE sood1.
DATA: END OF x_object_hd_change.
DATA: BEGIN OF x_objcont OCCURS 10.
        INCLUDE STRUCTURE soli.
DATA: END OF x_objcont.
DATA: BEGIN OF x_objhead OCCURS 0.
        INCLUDE STRUCTURE soli.
DATA: END OF x_objhead.
DATA: BEGIN OF raw_head.
        INCLUDE STRUCTURE sorh.
DATA: END OF raw_head.
DATA: BEGIN OF x_receivers OCCURS 0.
        INCLUDE STRUCTURE soos1.
DATA: END OF x_receivers.
PARAMETERS: receiver LIKE x_receivers-recnam. " Name
*BUILD MESSAGE HEADER
MOVE 'Sort field goes here' TO x_object_hd_change-objsrt. " Sort field
MOVE 'Name of the object goes here' TO x_object_hd_change-objnam. " Name
MOVE 'Document title goes here' TO x_object_hd_change-objdes. " Title
MOVE 'F' TO x_object_hd_change-objsns. " Functional OBJECT
MOVE 'E' TO x_object_hd_change-objla. " Language
* Object type of the new document
MOVE 'RAW' TO x_object_type.
CLEAR x_objcont.
MOVE 'Contents of mail' TO x_objcont-line.
APPEND x_objcont.
CLEAR x_objcont-line. APPEND x_objcont.
MOVE 'More contents' TO x_objcont-line.
APPEND x_objcont.
MOVE 'Still more contents'
TO x_objcont-line.
APPEND x_objcont.
MOVE ' ' TO x_objcont-line.
APPEND x_objcont.
* Specific header (Dependent on the object type, here RAW)
REFRESH x_objhead.
DESCRIBE TABLE x_objcont LINES raw_head-rawsiz.
MOVE raw_head TO x_objhead.
APPEND x_objhead.
*RECEIVERS table
CLEAR x_receivers.
REFRESH x_receivers.
MOVE receiver TO x_receivers-recnam. " Name
MOVE 'B' TO x_receivers-recesc. " Receiver type
MOVE 'X' TO x_receivers-sndcp. " Send as a copy
MOVE 'X' TO x_receivers-sndex. " EXPRESS DOCUMENT
APPEND x_receivers.
CALL FUNCTION 'SO_OBJECT_SEND'
  EXPORTING
    object_hd_change = x_object_hd_change
    object_type      = x_object_type
    outbox_flag      = 'X'
    owner            = sy-uname
  TABLES
    objcont          = x_objcont
    objhead          = x_objhead
    receivers        = x_receivers.
*
DATA: to_address LIKE sy_lisel,
      from_address LIKE sy-lisel,
      subject LIKE sy-lisel,
      attachment_name LIKE sy_lisel,
      data_file_path LIKE sxpgcolist-parameters,
      body_file_path LIKE sxpgcolist-parameters.
DATA : BEGIN OF int_email_attach OCCURS 0,
txtline(255),
END OF int_email_attach.
DATA : BEGIN OF int_email_body OCCURS 0,
txtline(255),
END OF int_email_body.
CLEAR : int_exec_protocol,int_email_attach,int_email_body.
REFRESH : int_exec_protocol,int_email_attach,int_email_body.
*
int_email_attach-txtline = 'Put all attachment text in this table'.
APPEND int_email_attach. CLEAR int_email_attach.
int_email_body-txtline = 'Put all attachment text in this table'.
APPEND int_email_body. CLEAR int_email_body.
*
CONCATENATE to_address
from_address
subject
body_file_path
data_file_path
attachment_name
INTO v_parameters.
*
IF NOT int_email_attach[] IS INITIAL.
  OPEN DATASET data_file_path FOR OUTPUT IN TEXT MODE.
  LOOP AT int_email_attach.
    TRANSFER int_email_attach-txtline TO data_file_path.
  ENDLOOP.
  CLOSE DATASET data_file_path.
ENDIF.
*
IF NOT int_email_body[] IS INITIAL.
  OPEN DATASET body_file_path FOR OUTPUT IN TEXT MODE.
  LOOP AT int_email_body.
    TRANSFER int_email_body-txtline TO body_file_path.
  ENDLOOP.
  CLOSE DATASET body_file_path.
ENDIF.
*
CALL FUNCTION 'SXPG_CALL_SYSTEM'
  EXPORTING
    commandname                = 'Z_EMAIL' " - Command calling unix script
    PARAMETERS                 = v_parameters
  TABLES
    exec_protocol              = int_exec_protocol
  EXCEPTIONS
    no_permission              = 1
    command_not_found          = 2
    parameters_too_long        = 3
    security_risk              = 4
    wrong_check_call_interface = 5
    program_start_error        = 6
    program_termination_error  = 7
    x_error                    = 8
    parameter_expected         = 9
    too_many_parameters        = 10
    illegal_command            = 11
    OTHERS                     = 12.
 

With the Help of this code u are able to send a mail to the Non SAP system.

 

Author: Gunda Ravi Kumar
Submitted: 22/05/2007

Sending a mail with file attachment  

Description:
I have seen many people asking queries regarding sending mail, and also while attaching the file to a mail. There are standard Function Modules provided by SAP to achieve this task, even then there might be problems while populating the file to be attached or while populating the Function Module parameters. The following code clearly explains the process of sending mail with file attachment.  

**Data Declarations
**Internal Table
DATA : BEGIN OF it_spfli OCCURS 0,
          carrid LIKE spfli-carrid,
          connid LIKE spfli-connid,
       END OF it_spfli.
DATA:   it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
        it_contents     LIKE solisti1 OCCURS 0 WITH HEADER LINE,
** storing receivers       
        it_receivers    LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
**storing file attachment data
        it_attachment   LIKE solisti1 OCCURS 0 WITH HEADER LINE,                    gd_doc_data     LIKE sodocchgi1,
        gd_error        TYPE sy-subrc,
        l_gntxt         LIKE t357g_t-gntxt,
        lv_message(100) TYPE c.
DATA:   it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                WITH HEADER LINE. "storing mail body
DATA : psubject(30) TYPE c VALUE 'Sample Mail'. "subject of the mail
DATA : ld_format TYPE so_obj_tp , "file format
       ld_attfilename TYPE so_obj_des, "file name
       w_cnt TYPE i.
**Selecting the data
SELECT carrid connid INTO TABLE it_spfli FROM spfli WHERE carrid EQ 'AA'.
**Perform for populating mail body
PERFORM populate_message.
**Perform for populating file attachment
PERFORM populate_attachment.
**Perform for populating mail characteristic info
PERFORM populate_pack.
**Perform for populating receivers
PERFORM populate_receivers.
**Perform to send mail
PERFORM send_mail.
*&---------------------------------------------------------------------*
*&      Form  populate_message
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM populate_message .
**Populating the body
  lv_message = 'Sample mail for testing purpose.'.
  APPEND lv_message TO it_message.
ENDFORM.                    " populate_message
*&---------------------------------------------------------------------*
*&      Form  populate_attachment
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM populate_attachment .
**Populating the attachment file with the data from final intenal table
  CONCATENATE 'CARRIER ID'
              'CONNECTION ID'
              INTO it_attachment SEPARATED BY
              cl_abap_char_utilities=>horizontal_tab.
  CONCATENATE cl_abap_char_utilities=>cr_lf it_attachment INTO
  it_attachment.
  APPEND it_attachment.
  LOOP AT it_spfli.
    CONCATENATE it_spfli-carrid it_spfli-connid INTO it_attachment SEPARATED BY
             cl_abap_char_utilities=>horizontal_tab.
    CONCATENATE cl_abap_char_utilities=>cr_lf it_attachment INTO
    it_attachment.
    APPEND it_attachment.
  ENDLOOP.
ENDFORM.                    " populate_attachment
*&---------------------------------------------------------------------*
*&      Form  populate_receivers
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM populate_receivers .
**Populating Mail Recepients
**If there are more than one mail recepient then loop and append them to it_receivers
  it_receivers-receiver = Mail-id of the receiver. (eg : 'abc@xyz.com')
  it_receivers-rec_type = 'U'.
  it_receivers-com_type = 'INT'.
  it_receivers-notif_del = 'X'.
  it_receivers-notif_ndel = 'X'.
  it_receivers-express = 'X'.
  APPEND it_receivers.
ENDFORM.                    " populate_receivers
*&---------------------------------------------------------------------*
*&      Form  populate_pack
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM populate_pack .
**File Type
  ld_format = 'XLS'.
**File Name
  ld_attfilename = 'File1'.
* Fill the document data.
  gd_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
  gd_doc_data-obj_langu = sy-langu.
  gd_doc_data-obj_name = 'SAPRPT'.
  gd_doc_data-obj_descr = psubject .
  gd_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
  CLEAR gd_doc_data.
* Populate the subject/generic message attributes
  gd_doc_data-obj_langu = sy-langu.
  READ TABLE it_attachment INDEX w_cnt.
  gd_doc_data-doc_size = ( w_cnt - 1 ) * 255 + STRLEN( it_attachment ).
  gd_doc_data-obj_name  = 'SAPRPT'.
  gd_doc_data-obj_descr = psubject.
  gd_doc_data-sensitivty = 'F'.
* Describe the body of the message
  CLEAR it_packing_list.
  REFRESH it_packing_list.
  it_packing_list-transf_bin = space.
  it_packing_list-head_start = 1.
  it_packing_list-head_num = 0.
  it_packing_list-body_start = 1.
  DESCRIBE TABLE it_message LINES it_packing_list-body_num.
  it_packing_list-doc_type = 'RAW'.
  APPEND it_packing_list.
**Describe the attachment info
  it_packing_list-transf_bin = 'X'.
  it_packing_list-head_start = 1.
  it_packing_list-head_num = 1.
  it_packing_list-body_start = 1.
  DESCRIBE TABLE it_attachment LINES  it_packing_list-body_num.
  it_packing_list-doc_type = ld_format.
  it_packing_list-obj_name = ld_attfilename.
  it_packing_list-obj_descr = ld_attfilename.
  it_packing_list-doc_size = it_packing_list-body_num * 255.
  APPEND it_packing_list.
ENDFORM.                    " populate_pack
*&---------------------------------------------------------------------*
*&      Form  send_mail
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM send_mail .
**Function Module to send mail
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = gd_doc_data
      put_in_outbox              = 'X'
      commit_work                = 'X'
    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.
ENDFORM.                    " send_mail

Back to Sending Mails - Home Page

Author:  Pratik Mallick
Submitted: 3rd April 2009

Introduction

Send notification is becoming important from business point of view. It adds extra reliability to the process and enables business person to react quickly to customer's requirement. If any error occurred to a process some group of people in the top management will get a notification and react based on the details specified in the notification.

Business Requirements

In some situation we had to send a notification to a group people. Some cases we had to only send the text in the mail body and some cases we had to send the detail records as attachments. Suppose one user ran a program to update the material master and the top management wants to get the success records as one attachment and error records as another attachment in the email.   

Methodology

Using the below object oriented technique it can easily obtained. 

Create object

The standard class CL_BCS is used to send the notification along with attachment to a group of people. Method CREATE_PERSISTENT is used to create an send request object of the standard class CL_BCS.

Create body of the email

Method CREATE_DOCUMENT of standard class CL_DOCUMENT_BCS is used to create the text of the email body.

Create attachments of the email

Method ADD_ATTACHMENT of standard class CL_DOCUMENT_BCS is used to create attachment of the email. If we want to create the multiple attachment we have call this method multiple times.
Method SET_DOCUMENT of the standard class CL_BCS is used to add the document (email body and attachments) to be send request object.

Create sender

Method CREATE of the standard class CL_SAPUSER_BCS is used to create the sender address.
Method SET_SENDER of standard class CL_BCS is used add the sender address to the send request object.

Create recipient

Method CREATE_INTERNET_ADDRESS of standard class CL_CAM_ADDRESS_BCS is used to create recipient email address.

Method ADD_RECIPIENT of standard class CL_BCS is used to add the recipient email address to the send request object.

Send email

Method SEND of standard class CL_BCS is used to send the send request object to a group of people added in the recipient list.
Sending is done in a queued way; immediate sending can be triggered for very urgent alerts.

Code

data: l_send_request type ref to cl_bcs,         " Send request
      l_body      type bcsy_text,                " Mail body
      l_success   type bcsy_text,                " Atchmnt for success
      l_error     type bcsy_text,                " Atchmnt for error
      wa_text     type soli,                     " Work area for attach
      l_document  type ref to cl_document_bcs,   " Mail body
      l_sender    type ref to if_sender_bcs,     " Sender address
      l_recipient type ref to if_recipient_bcs,  " Recipient
      l_size      type sood-objlen,              " Size of Attachment
      l_lines     type i,                        " Lines count
      l_email     type ad_smtpadr,               " Email ID
      l_extension type soodk-objtp value 'RAW'.  " TXT format
* Prepare mail bidy
append 'Send multiple file as attachment of a Email.'  to l_body.
append space to l_body.
* Preparing contents of attachment with Change Log
* Header line
wa_text-line+0   = 'First column'.
wa_text-line+20  = 'Second column'.
wa_text-line+40  = 'Third column'.
wa_text-line+60  = 'Fourth column'.
wa_text-line+80  = 'Fifth column'.
wa_text-line+100 = 'Sixth column'.
wa_text-line+120 = 'Seventh column'.
wa_text-line+140 = 'Eighth column'.
append wa_text to l_success.
append wa_text to l_error.
clear : wa_text.
* Populate the data part
wa_text-line+0   = '111111111'.
wa_text-line+20  = '222222222'.
wa_text-line+40  = '333333333'.
wa_text-line+60  = '333333333'.
wa_text-line+80  = '444444444'.
wa_text-line+100 = '555555555'.
wa_text-line+120 = '666666666'.
wa_text-line+140 = '777777777'.
append wa_text to l_success.
clear : wa_text.
wa_text-line+0   = 'aaaaaaaaa'.
wa_text-line+20  = 'bbbbbbbbb'.
wa_text-line+40  = 'ccccccccc'.
wa_text-line+60  = 'ddddddddd'.
wa_text-line+80  = 'eeeeeeeee'.
wa_text-line+100 = 'fffffffff'.
wa_text-line+120 = 'ggggggggg'.
wa_text-line+140 = 'hhhhhhhhh'.
append wa_text to l_error.
clear : wa_text.
* Creates persistent send request
l_send_request = cl_bcs=>create_persistent( ).
* Craete document for mail body
l_document = cl_document_bcs=>create_document(
             i_type    = 'RAW'
             i_text    = l_body  " Mail body
             i_subject = 'Mail send as attachment' ).
* Attachment for success records
l_lines = lines( l_success ).
l_size = l_lines * 255.
* Add attchment
call method l_document->add_attachment
  exporting
    i_attachment_type    = l_extension
    i_attachment_subject = 'Success'
    i_attachment_size    = l_size
    i_att_content_text   = l_success. " Attachment for success record
* Attachment for error records
l_lines = lines( l_error ).
l_size = l_lines * 255.
* Add attchment
call method l_document->add_attachment
  exporting
    i_attachment_type    = l_extension
    i_attachment_subject = 'Error'
    i_attachment_size    = l_size
    i_att_content_text   = l_error. " Attachment for error record
* Add the document to send request
call method l_send_request->set_document( l_document ).
* Sender addess
l_sender = cl_sapuser_bcs=>create( sy-uname ).
call method l_send_request->set_sender
  exporting
    i_sender = l_sender.
* Recipient address
l_email = 'myname@in.ibm.com'.
l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ).
* Add recipient address to send request
call method l_send_request->add_recipient
  exporting
    i_recipient  = l_recipient
    i_express    = 'X'
    i_copy       = ' '
    i_blind_copy = ' '
    i_no_forward = ' '.
l_email = 'myname@gmail.com'.
l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ).
* Add recipient address to send request
call method l_send_request->add_recipient
  exporting
    i_recipient  = l_recipient
    i_express    = 'X'
    i_copy       = ' '
    i_blind_copy = ' '
    i_no_forward = ' '.
* E-Mail is placed into queue for sending. In case of very important alerts
* use the following parameter to initiate an 'immediate sending'; but notice that
* this will trigger a dedicated send process for every single message - which is
* very costly for system performance
* l_send_request->set_send_immediately( 'X' ). "uncomment for immediate sending
* Send mail
call method l_send_request->send( ).
commit work. */

                                                                 
Mail via SAP ABAP Coding.........                                                                     
                      *******************Send mail in SAP ABAP**************************

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
* Data Declarations
DATA: LT_MAILSUBJECT     TYPE SODOCCHGI1.
DATA: LT_MAILRECIPIENTS  TYPE STANDARD TABLE OF SOMLREC90 WITH HEADER LINE.
DATA: LT_MAILTXT         TYPE STANDARD TABLE OF SOLI      WITH HEADER LINE.
* Recipients
LT_MAILRECIPIENTS-REC_TYPE  = 'U'.
LT_MAILRECIPIENTS-RECEIVER = 'sheetal@gmail.com'.
APPEND LT_MAILRECIPIENTS .
CLEAR LT_MAILRECIPIENTS .
* Subject.
LT_MAILSUBJECT-OBJ_NAME = 'TEST'.
LT_MAILSUBJECT-OBJ_LANGU = SY-LANGU.
LT_MAILSUBJECT-OBJ_DESCR = 'Mail Subject'.
* Mail Contents
LT_MAILTXT = 'This is a test mail'.
APPEND LT_MAILTXT. CLEAR LT_MAILTXT.
* Send Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
  EXPORTING
    DOCUMENT_DATA              = LT_MAILSUBJECT
  TABLES
    OBJECT_CONTENT             = LT_MAILTXT
    RECEIVERS                  = LT_MAILRECIPIENTS
  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 EQ 0.
  COMMIT WORK.
*   Push mail out from SAP outbox
  SUBMIT RSCONN01 WITH MODE = 'INT' AND RETURN.
ENDIF.

 

****************End ************************************************
(thumbs up)  Sheetal Gulati

sap.miniarora@gmail.com

Author: Vinod Reddy Vemuru
Submitted: 25/01/2009
This sample code can be used to send Email with HTML attachment.

REPORT z756942.
PARAMETERS: po_email TYPE ad_smtpadr LOWER CASE.
DATA: li_objcont TYPE STANDARD TABLE OF solisti1,
      li_reclist TYPE STANDARD TABLE OF somlreci1,
      li_objpack TYPE STANDARD TABLE OF sopcklsti1,
      li_objhead TYPE STANDARD TABLE OF solisti1,
      li_content TYPE STANDARD TABLE OF solisti1,
      lwa_objcont TYPE solisti1,
      lwa_reclist TYPE somlreci1,
      lwa_objpack TYPE sopcklsti1,
      lwa_objhead TYPE solisti1,
      lwa_content TYPE solisti1,
      lwa_doc TYPE sodocchgi1,
      l_lines TYPE i.
REFRESH: li_objcont[], li_reclist[],
          li_objpack[], li_objhead[],
          li_content[].
CLEAR: lwa_objcont, lwa_reclist,
        lwa_objpack, lwa_objhead,
        lwa_content, lwa_doc.
MOVE '<body>' TO lwa_objcont.
APPEND lwa_objcont TO li_objcont.
MOVE '<p>' TO lwa_objcont.
APPEND lwa_objcont TO li_objcont.
MOVE 'This is a sample HTML content from test program' TO lwa_objcont.
APPEND lwa_objcont TO li_objcont.
MOVE '</p>' TO lwa_objcont.
APPEND lwa_objcont TO li_objcont.
MOVE '</body>' TO lwa_objcont.
APPEND lwa_objcont TO li_objcont.

lwa_reclist-receiver = po_email.
lwa_reclist-rec_type = 'U'.
APPEND lwa_reclist TO li_reclist.
lwa_objhead = 'test.htm'.
APPEND lwa_objhead TO li_objhead.
lwa_content = 'Please find attached document for more details'.
APPEND lwa_content TO li_content.
CLEAR l_lines.
DESCRIBE TABLE li_content LINES l_lines.
READ TABLE li_content INTO lwa_content INDEX l_lines.
lwa_doc-doc_size = ( l_lines - 1 ) * 255 + STRLEN( lwa_content ).
lwa_doc-obj_langu = 'E'.
lwa_doc-obj_name = 'Test HTML file'.
lwa_doc-obj_descr = 'Test HTML file'.
CLEAR lwa_objpack-transf_bin.
lwa_objpack-head_start = 1.
lwa_objpack-head_num = 0.
lwa_objpack-body_start = 1.
lwa_objpack-body_num = l_lines.
lwa_objpack-doc_type = 'RAW'.
APPEND lwa_objpack TO li_objpack.
CLEAR: lwa_objpack, l_lines.
DESCRIBE TABLE li_objcont LINES l_lines.
READ TABLE li_objcont INTO lwa_objcont INDEX l_lines.
lwa_objpack-doc_size = ( l_lines - 1 ) * 255 + STRLEN( lwa_objcont ).
lwa_objpack-transf_bin = 'X'.
lwa_objpack-head_start = 1.
lwa_objpack-head_num = 0.
lwa_objpack-body_start = 1.
lwa_objpack-body_num = l_lines.
lwa_objpack-doc_type = 'HTM' .
lwa_objpack-obj_name = 'Test HTML file'.
lwa_objpack-obj_descr = 'Test HTML file'.
APPEND lwa_objpack TO li_objpack.
*Sending the mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    document_data              = lwa_doc
    put_in_outbox              = 'X'
  TABLES
    packing_list               = li_objpack
    object_header              = li_objhead
    contents_bin               = li_objcont
    contents_txt               = li_content
    receivers                  = li_reclist
  EXCEPTIONS
    too_many_receivers         = 1
    document_not_sent          = 2
    operation_no_authorization = 4
    OTHERS                     = 99.
IF sy-subrc NE 0.
  WRITE:/ 'Document sending failed'.
ELSE.
  WRITE:/ 'Document successfully sent'.
  COMMIT WORK.
ENDIF.
 

In some scenario where we have to send error records or some impotent documents to a group of people as attachments via Email.

REPORT  ztest_subha_mail.

DATA: l_send_request TYPE REF TO cl_bcs,         " Send request
      l_body      TYPE bcsy_text,                " Mail body
      l_attach    TYPE bcsy_text,                " Attachment
      wa_text     TYPE soli,                     " Work area for attach
      l_document  TYPE REF TO cl_document_bcs,   " Mail body
      l_sender    TYPE REF TO if_sender_bcs,     " Sender address
      l_recipient TYPE REF TO if_recipient_bcs,  " Recipient
      l_size      TYPE sood-objlen,              " Size of Attachment
      c_tab       TYPE abap_char1  VALUE
                       cl_abap_char_utilities=>horizontal_tab,
      l_lines     TYPE i,                        " Lines count
      l_email     TYPE ad_smtpadr,               " Email ID
      l_extension TYPE soodk-objtp VALUE 'RAW'.  " TXT format

* Prepare mail bidy
APPEND 'Test Mail by Subhankar' TO l_body.

* Preparing contents of attachment with Change Log
* Header line
wa_text-line+0   = 'First column'.
wa_text-line+20  = 'Second column'.
wa_text-line+40  = 'Third column'.
wa_text-line+60  = 'Fourth column'.
wa_text-line+80  = 'Fifth column'.
wa_text-line+100 = 'Sixth column'.
wa_text-line+120 = 'Seventh column'.
wa_text-line+140 = 'Eighth column'.

APPEND wa_text TO l_attach.
CLEAR : wa_text.
* Populate the data part
wa_text-line+0   = '111111111'.
wa_text-line+20  = '222222222'.
wa_text-line+40  = '333333333'.
wa_text-line+60  = '333333333'.
wa_text-line+80  = '444444444'.
wa_text-line+100 = '555555555'.
wa_text-line+120 = '666666666'.
wa_text-line+140 = '777777777'.
APPEND wa_text TO l_attach.
CLEAR : wa_text.

wa_text-line+0   = 'aaaaaaaaa'.
wa_text-line+20  = 'bbbbbbbbb'.
wa_text-line+40  = 'ccccccccc'.
wa_text-line+60  = 'ddddddddd'.
wa_text-line+80  = 'eeeeeeeee'.
wa_text-line+100 = 'fffffffff'.
wa_text-line+120 = 'ggggggggg'.
wa_text-line+140 = 'hhhhhhhhh'.
APPEND wa_text TO l_attach.
CLEAR : wa_text.
l_lines = LINES( l_attach ).
l_size = l_lines * 255.

* Creates persistent send request
l_send_request = cl_bcs=>create_persistent( ).

* Craete document for mail body
l_document = cl_document_bcs=>create_document(
             i_type    = 'RAW'
             i_text    = l_body
             i_subject = 'Mail send as attachment' ).

* Add attchment
CALL METHOD l_document->add_attachment
  EXPORTING
    i_attachment_type    = l_extension
    i_attachment_subject = 'My attachment'
    i_attachment_size    = l_size
    i_att_content_text   = l_attach.

* Add the document to send request
CALL METHOD l_send_request->set_document( l_document ).

* Sender addess
l_sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD l_send_request->set_sender
  EXPORTING
    i_sender = l_sender.

* Recipient address
l_email = 'sugarani@in.ibm.com'.
l_recipient = cl_cam_address_bcs=>create_internet_address( l_email ).

* Add recipient address to send request
CALL METHOD l_send_request->add_recipient
  EXPORTING
    i_recipient  = l_recipient
    i_express    = 'X'
    i_copy       = ' '
    i_blind_copy = ' '
    i_no_forward = ' '.

* Trigger E-Mail immediately
l_send_request->set_send_immediately( 'X' ).

* Send mail
CALL METHOD l_send_request->send( ).

COMMIT WORK.
 

Author: Suresh Maryala
Submitted: 03/24/2008

Purpose of this document is to capture sending multiple attachments of Spool using SAP E-mail. Spool is converted to HTML format before sent as e-mail. There is no limit on how many attachments can be sent.

This is an example of a code sample:

TABLES: sos04,
        rspotype,
        soli.

PARAMETERS: p_des         LIKE sood1-objdes.
SELECT-OPTIONS: s_spool   FOR rspotype-rqnumber NO INTERVALS,
                s_emails  FOR sos04-l_adr_name NO INTERVALS,
                s_text    FOR soli-line NO INTERVALS.

************************************************************************
* DATA DEFINITION
************************************************************************
*TYPES
TYPES: BEGIN OF ty_tbtcp.
        INCLUDE STRUCTURE tsp01.
TYPES: END OF ty_tbtcp.
TYPES: BEGIN OF ty_objpack,
        rqnumber   TYPE rspotype-rqnumber,
        head_start TYPE sopcklsti1-head_start,
        head_num   TYPE sopcklsti1-head_num,
        body_start TYPE sopcklsti1-body_start,
        body_num   TYPE sopcklsti1-body_num,
        no_lines   TYPE i,
       END OF ty_objpack.
*INTERNAL TABLES
DATA: lt_tbtcp       TYPE STANDARD TABLE OF ty_tbtcp,
      lt_objpack     TYPE STANDARD TABLE OF ty_objpack,
      lt_mess_bod    LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      lt_mess_att    LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      lt_mess_2      LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      lt_spool_list  TYPE STANDARD TABLE OF bapixmspoo WITH HEADER LINE,
      lt_spool_2     TYPE STANDARD TABLE OF bapixmspoo WITH HEADER LINE,
      l_spool_id     LIKE tsp01-rqident.
DATA: ls_tbtcp       TYPE ty_tbtcp,
      ls_objpack     TYPE ty_objpack.
DATA  so_ali LIKE soli OCCURS 0 WITH HEADER LINE.
DATA: it_lines LIKE tline OCCURS 0 WITH HEADER LINE.
DATA: p_template LIKE wwwdataid-objid.
DATA listtab LIKE abaplist OCCURS 1.
DATA p_html LIKE bapihtml OCCURS 10 WITH HEADER LINE.
DATA lt_html LIKE bapihtml OCCURS 10 WITH HEADER LINE.
*STRUCTURES
*VARIABLES
*VARIABLES
DATA: l_spool_nr             LIKE tsp01-rqident,
      l_bytecount            LIKE tst01-dsize,
      l_buffer               TYPE string,
      l_spool_cnt            TYPE i,
      l_cnt                  TYPE i,
      l_line_no              TYPE i,
      l_total_cnt            TYPE i,
      p_cnt(3)               TYPE c,
      p_spool_nr(10)         TYPE c.
DATA: l_subject              LIKE sodocchgi1-obj_descr,
      l_sender_type          LIKE soextreci1-adr_typ,
      l_recsize              TYPE i,
      l_receiver             TYPE sy-subrc.
DATA: ld_sender_address      LIKE soextreci1-receiver,
      ld_sender_address_type LIKE soextreci1-adr_typ,
      ld_error               TYPE sy-subrc.
DATA: t_packing_list         LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
      t_receivers            LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
      t_attachment           LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      w_sent_all(1)          TYPE c,
      w_doc_data             LIKE sodocchgi1.
DATA: tab_lines              LIKE sy-tabix.
************************************************************************
* INITIALIZATION
************************************************************************
INITIALIZATION.
************************************************************************
* START-OF-SELECTION
************************************************************************
START-OF-SELECTION.
* Read Spool Number
  PERFORM f_obtain_spool_id.
* HTML Logic
  PERFORM f_convert_spool_to_htm.
* E-mail need to be sent as HTML
  PERFORM f_process_email.
* End process
  IF sy-subrc <> 0.
    WRITE:/ 'Error Sending Document',
          / 'Return Code:', sy-subrc.
  ELSE.
    WRITE:/ 'Document successfully sent'.
  ENDIF.
************************************************************************
*END-OF-SELECTON
************************************************************************
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  f_obtain_spool_id
*&---------------------------------------------------------------------*
FORM f_obtain_spool_id .
* Capture all Spool Numbers into a internal table
  REFRESH lt_tbtcp.
  CLEAR   ls_tbtcp.
  SELECT *
  INTO TABLE lt_tbtcp
  FROM tsp01
  WHERE rqident IN s_spool.
* Sort by Spool Number
  SORT lt_tbtcp BY rqident.
* Capture the number of spool numbers entered
  CLEAR l_total_cnt.
  DESCRIBE TABLE lt_tbtcp LINES l_total_cnt.
ENDFORM.                    " f_obtain_spool_id
*&---------------------------------------------------------------------*
*&      Form  f_process_email
*&---------------------------------------------------------------------*
FORM f_process_email .
* HTML E-mail
  DESCRIBE TABLE lt_html LINES l_recsize.
  CHECK l_recsize > 0.
  PERFORM f_send_email.
ENDFORM.                    " f_process_email
*&---------------------------------------------------------------------*
*&      Form  f_send_email
*&---------------------------------------------------------------------*
FORM f_send_email .
  CHECK NOT ( s_emails-low IS INITIAL ).
  REFRESH lt_mess_bod.
* Default subject matter
  l_subject         = p_des.
  IF NOT s_text-low IS INITIAL.
    LOOP AT s_text.
      MOVE s_text-low TO lt_mess_bod.
      APPEND lt_mess_bod.
      CLEAR  lt_mess_bod.
    ENDLOOP.
  ENDIF.
* HTML Attachment logic
  PERFORM f_send_email_html_attachment.
ENDFORM.                    " f_send_email
*&---------------------------------------------------------------------*
*&      Form  f_convert_spool_to_htm
*&---------------------------------------------------------------------*
FORM f_convert_spool_to_htm .
  LOOP AT lt_tbtcp INTO ls_tbtcp.
    CLEAR p_html.
    REFRESH p_html.
    ADD 1 TO l_cnt.
    l_spool_id = ls_tbtcp-rqident.
    SUBMIT rspolst2 EXPORTING LIST TO MEMORY AND RETURN
    WITH rqident = l_spool_id.
    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        listobject = listtab
      EXCEPTIONS
        not_found  = 1
        OTHERS     = 2.
    IF sy-subrc <> 0.
*      message e418 raising read_error.
    ENDIF.
    IF p_template IS INITIAL.
      p_template = 'WEBREPORTING_REPORT'.
    ENDIF.
    CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
      EXPORTING
        template_name = p_template
      TABLES
        html          = p_html
        listobject    = listtab
      EXCEPTIONS
        OTHERS        = 1.
    LOOP AT p_html.
      MOVE-CORRESPONDING p_html TO lt_html.
      APPEND lt_html.
    ENDLOOP.
* Building table lt_objpack internal table for creating attachments
    MOVE l_spool_id TO ls_objpack-rqnumber.
    IF l_cnt = 1.
      MOVE 1 TO ls_objpack-head_start.
      MOVE 0 TO ls_objpack-head_num.
      MOVE 1 TO ls_objpack-body_start.
      DESCRIBE TABLE lt_html LINES ls_objpack-no_lines.
      MOVE ls_objpack-no_lines TO ls_objpack-body_num.
      APPEND ls_objpack TO lt_objpack.
    ENDIF.
    IF l_cnt > 1.
      ls_objpack-head_start = ls_objpack-no_lines + 1.
      ls_objpack-head_num = ls_objpack-no_lines + 1.
      ls_objpack-body_start = ls_objpack-no_lines + 1.
      DESCRIBE TABLE p_html LINES ls_objpack-no_lines.
      MOVE ls_objpack-no_lines TO ls_objpack-body_num.
      APPEND ls_objpack TO lt_objpack.
* Overwrite total number of lines
      DESCRIBE TABLE lt_html LINES ls_objpack-no_lines.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " f_convert_spool_to_htm
*&---------------------------------------------------------------------*
*&      Form  f_send_email_html_attachment
*&---------------------------------------------------------------------*
FORM f_send_email_html_attachment .
* Fill the document data.
  w_doc_data-doc_size = 1.
* Fill the document data and get size of attachment
  CLEAR w_doc_data.
  w_doc_data-obj_langu = sy-langu.
  w_doc_data-obj_name  = 'SAPRPT'.
  w_doc_data-obj_descr = p_des .
  w_doc_data-sensitivty = 'F'.
  CLEAR t_attachment.
  REFRESH t_attachment.
  t_attachment[] = lt_html[].
* Describe the body of the message
  CLEAR t_packing_list.
  REFRESH t_packing_list.
  DESCRIBE TABLE lt_mess_bod LINES tab_lines.
  READ TABLE lt_mess_bod INDEX tab_lines.
  w_doc_data-doc_size = ( tab_lines - 1 ) * 255 + strlen( lt_mess_bod ).
  CLEAR t_packing_list-transf_bin.
  t_packing_list-head_start = 1.
  t_packing_list-head_num = 0.
  t_packing_list-body_start = 1.
  t_packing_list-body_num = tab_lines.
  t_packing_list-doc_type = 'RAW'.
  APPEND t_packing_list.
* Create attachment notification
  CLEAR: l_line_no.
  LOOP AT lt_objpack INTO ls_objpack.
    ADD 1 TO l_line_no.
    t_packing_list-transf_bin = 'X'.
    t_packing_list-head_start = ls_objpack-head_start.
    t_packing_list-head_num = ls_objpack-head_num.
    t_packing_list-body_start = ls_objpack-body_start.
    t_packing_list-doc_type = 'HTM'.
    p_cnt = l_line_no.
    CONDENSE p_cnt.
    p_spool_nr = ls_objpack-rqnumber.
    CONCATENATE 'Attachment' p_cnt INTO t_packing_list-obj_name SEPARATED BY space.
* Format Attachment Name.
    PERFORM get_attachment_name USING    p_spool_nr
                                CHANGING t_packing_list-obj_descr.
    t_packing_list-body_num = ls_objpack-body_num.
    t_packing_list-doc_size = t_packing_list-body_num * 255.
    APPEND t_packing_list.
  ENDLOOP.
* Add the recipients email address
  CLEAR t_receivers.
  REFRESH t_receivers.
  LOOP AT s_emails.
    t_receivers-receiver = s_emails-low.
    t_receivers-rec_type = 'U'.
    t_receivers-com_type = 'INT'.
    t_receivers-notif_del = 'X'.
    t_receivers-notif_ndel = 'X'.
* E-mail Delivery is selected
    IF NOT p_del IS INITIAL.
      t_receivers-notif_del = 'X'.
    ELSE.
      CLEAR t_receivers-notif_del.
    ENDIF.
* E-mail Read receipt is checked
    IF NOT p_read IS INITIAL.
      t_receivers-notif_read = 'X'.
    ELSE.
      CLEAR t_receivers-notif_read.
    ENDIF.
    APPEND t_receivers.
  ENDLOOP.
  ld_sender_address = sy-uname.
  ld_sender_address_type = 'B'.
  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               = lt_mess_att
      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 error return code
  ld_error = sy-subrc.
* Populate zreceiver return code
  LOOP AT t_receivers.
    l_receiver = t_receivers-retrn_code.
  ENDLOOP.
ENDFORM.                    " f_send_email_html_attachment
*&---------------------------------------------------------------------*
*&      Form  GET_ATTACHMENT_NAME
*&---------------------------------------------------------------------*
FORM get_attachment_name  USING    p_spool_nr
                          CHANGING t_packing_list_obj_descr.
  CLEAR ls_tbtcp.
  READ TABLE lt_tbtcp INTO ls_tbtcp
             WITH KEY rqident = p_spool_nr
             BINARY SEARCH.
  IF sy-subrc EQ 0.
    IF ls_tbtcp-rqtitle IS INITIAL.
      ls_tbtcp-rqtitle = ls_tbtcp-rq2name.
    ENDIF.
    CONCATENATE p_spool_nr '-' ls_tbtcp-rqtitle INTO t_packing_list_obj_descr SEPARATED BY space.
  ELSE.
    CONCATENATE p_spool_nr '- Spool'  INTO t_packing_list_obj_descr SEPARATED BY space.
  ENDIF.
  CONDENSE t_packing_list_obj_descr.
ENDFORM.                    " GET_ATTACHMENT_NAME
 

Description: In the Business Process Modeling Group I have seen alot of request regarding how to send mail notifications by using ABAP Code.
I have used the below mentioned code in several cases like
Info Letter to all Vendors, Sending PO Via Email, Reminder mails to the Agents in Workflow and also escalation mails to Process Owners when the task is not performed by the agents in the given time.

Prerequisite : SAP Enterprise Edition and above
SAP Connect needs to be configured
Mail Rely should be available

DATA reciever TYPE TABLE OF adr6-smtp_addr.
DATA subject TYPE so_obj_des.
DATA text TYPE bcsy_text.
DATA line TYPE soli-line.
DATA send_request TYPE REF TO cl_bcs.
DATA document TYPE REF TO cl_document_bcs.
DATA recipient TYPE REF TO if_recipient_bcs.
DATA bcs_exception TYPE REF TO cx_bcs.
DATA sent_to_all TYPE os_boolean.
DATA adresse TYPE adr6-smtp_addr.
DATA mailflag(1) VALUE space.

DATA dat(10).
DATA time(10).
DATA tfree(12).

WRITE sy-datum TO dat.
WRITE sy-uzeit TO time.

subject = 'This is my Subject '.
line = ' I am the body of the message '.

APPEND line TO text.

*mail send mail out to external mail server .

TRY.

*    create the send request
    send_request = cl_bcs=>create_persistent( ).

    document = cl_document_bcs=>create_document(
    i_type = 'RAW'
    i_text = text
    i_subject = betreff ).

*    add document to send request
    send_request->set_document( document ).

*    create recipient and add to send request

    adresse = 'reciever@xyz.com'.

    recipient = cl_cam_address_bcs=>create_internet_address(
    adresse ).
    send_request->add_recipient( i_recipient = recipient ).

*    send mail now
    sent_to_all = send_request->send( i_with_error_screen = 'X' ).

    IF sent_to_all = 'X'.
      MESSAGE s022(so).
    ENDIF.

  CATCH cx_bcs INTO bcs_exception.
    MESSAGE e865(so) WITH bcs_exception->error_type.
ENDTRY.

*Close Transaction.
COMMIT WORK.
 

Many a time our customers ask us if we can send an outlook meeting notice from ABAP. Until now, We did not realize that it was possible, But now we do.

Here is the code snippet of what we had done to achieve this.

The first step was look at a Microsoft outlook meeting invitation as a flat file. For that, we created a meeting notice and downloaded it as a *VCS file. For this please create a dummy invite, invite attendees and save is as a .VCS file. ( File->Save as). Your flat file should look like this.

BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
VERSION:1.0
BEGIN:VEVENT
DTSTART:20070804T183000Z
DTEND:20070804T190000Z
LOCATION;ENCODING=QUOTED-PRINTABLE:Dennys
UID:040000008200E00074C5B7101A82E0080000000070011ADA9FD6C7010000000000000000100
 00000F29C2A2ACE5F284382D1B7CC8BA82B8B
DESCRIPTION;ENCODING=QUOTED-PRINTABLE:=09  =0D=0A
SUMMARY;ENCODING=QUOTED-PRINTABLE:Test Meeting for Code Gallery
PRIORITY:3
END:VEVENT
END:VCALENDAR
 

Now , We all know that the function module  SO_NEW_DOCUMENT_ATT_SEND_API1 can be used send an e-mail with a file as an attachment.  There are tons of messages already on this topic and hence to avoid redundancy, I am skipping that part. for eg please refer

http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

I am only showing the lines that are used to fill and create the calendar file. Please note this is a sample code and hence hardcoded. Please use text elements for constants and work areas to append to internal tables without directly appending them.

* These are the parameters for the attachment file name and the contents of the attachment itself.
DATA: t_objhead LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA: t_objbin LIKE solisti1 OCCURS 20 WITH HEADER LINE.
CONSTANTS:  c_cr(2) VALUE '0D'.
t_objhead = 'testappointment.vcs'.
APPEND t_objhead.
*hence the file will be sent as a vcs file. now for the details.
CONCATENATE 'BEGIN:VCALENDAR' c_cr INTO t_objbin.
APPEND t_objbin.
 

Please add all the other lines in the file in a similar manner.

You can also try to send an e-mail from SBWP to an external address with a VCS attachment and the results would be similar. Please note that the number UID:040000008200E00074C5B7101A82E0080000000070011ADA9FD6C7010000000000000000100
 00000F29C2A2ACE5F284382D1B7CC8BA82B8B might vary for diffewrent versions. Also, they can save it into their calendar and you might get a receipt acknowlegement if you are in the same smtp server as them in case you set the flag in SO_NEW_DOCUMENT_ATT_SEND_API1. Please try using this snippet and let me know any problems you  face or any questions that you may have. Happy reading.

Any comments to improve this snippet are more than welcome.

Thanks

Ganesh.S

"The following code is used to send automatic email.
"define tables
DATA: gt_receivers        TYPE soos1_tab,
      gt_obj_cont         TYPE soli_tab,
      gs_object_hd_change TYPE sood1.
"define structures and work areas
DATA: gs_receivers        TYPE soos1,      gs_obj_cont         TYPE soli,
      gs_object_hd_change TYPE sood1.
"fill two lines of email body
gs_obj_cont-line = 'first line of email body'.
APPEND gs_obj_cont TO  gt_obj_cont.
gs_obj_cont-line = 'second line of email body'.
APPEND gs_obj_cont TO  gt_obj_cont."set receiver
gs_receivers-recextnam  = 'name.last@email.com'.
gs_receivers-recesc     = 'E'.
gs_receivers-sndart     = 'INT'.
gs_receivers-sndpri     = 1.
gs_receivers-mailstatus = 'E'.
gs_receivers-rcdat      = sy-datum.
gs_receivers-rctim      = sy-uzeit .
gs_receivers-deliver    = 'X'.
gs_receivers-mailstatus = 'X'.
gs_receivers-not_deli   = 'X'.
APPEND gs_receivers TO gt_receivers.

gs_object_hd_change-objla  = sy-langu.
gs_object_hd_change-objnam = 'Immediate mail'.

CALL FUNCTION 'SO_OBJECT_SEND'
     EXPORTING
       object_hd_change           = gs_object_hd_change
       object_type                = 'RAW'
       outbox_flag                = 'X'
     TABLES
       objcont                    = gt_obj_cont
       receivers                  = gt_receivers
     EXCEPTIONS
       active_user_not_exist      = 1
       communication_failure      = 2
       component_not_available    = 3
       folder_not_exist           = 4
       folder_no_authorization    = 5
       forwarder_not_exist        = 6
       note_not_exist             = 7
       object_not_exist           = 8
       object_not_sent            = 9
       object_no_authorization    = 10
       object_type_not_exist      = 11
       operation_no_authorization = 12
       owner_not_exist            = 13
       parameter_error            = 14
       substitute_not_active      = 15
       substitute_not_defined     = 16
       system_failure             = 17
       too_much_receivers         = 18
       user_not_exist             = 19
       originator_not_exist       = 20
       x_error                    = 21
       others                     = 22.

 COMMIT WORK.

The following is the sample program for Creating OLE Application and in turn which sends the an email by storing a copy in your presentation server.
You can customize according to your requirement. 

 

*&---------------------------------------------------------------------*
*& Report  YG_ABR20640
*&
*&---------------------------------------------------------------------*
* Program Name        : YGH_ABR20640                                   *
* Program Description : Detail Activity Report                         *
* Developer           : Raghavendra.D.S (LZ1162)                    *
* Business Analyst    : Vivek Pandey
* Transaction code    : YG_ABR20640                                    *
*&---------------------------------------------------------------------*
REPORT ygh_abr20640 MESSAGE-ID ygf_abr20640
                    LINE-COUNT 5000
                    LINE-SIZE 179.
*----------------------------------------------------------------------*
* TABLES DECLERATIONS                                                  *
*----------------------------------------------------------------------*
TABLES:     dpr_project, cgpl_entity, but000.
TYPE-POOLS: slis.
*----------------------------------------------------------------------*
* TYPES DECLERATIONS                                                   *
*----------------------------------------------------------------------*
TYPES : BEGIN OF t_cats_0315,
         pernr  TYPE pernr_d,
         begda  TYPE begda,
         endda  TYPE endda,
         kostl  TYPE skostl,
         lstar  TYPE lstar,
         plsta  TYPE plsta,
         werks  TYPE werks_d,
         lifnr  TYPE elifn,
         ebeln  TYPE sebeln,
         ebelp  TYPE sebelp,
         lstnr  TYPE asnum,
         sprznr TYPE co_prznr,
         accnt  TYPE c,
        END OF t_cats_0315,
        BEGIN OF t_project_id,
         project_id TYPE dpr_tv_project_id,
        END OF t_project_id,
        BEGIN OF t_final,
         participant_guid TYPE dpr_tv_participant_guid,
         bupa_guid        TYPE bu_partner_guid,
         comp_code        TYPE bukrs,
         plant            TYPE werks_d,
         pernr            TYPE personid,
         lifnr            TYPE lifnr,
         name             TYPE name1_gp,
         proj_name        TYPE dpr_tv_name,
         name_first       TYPE bu_namep_f,
         name_last        TYPE bu_namep_l,
         text1            TYPE cgpl_text1,
         role_text        TYPE dpr_tv_participant_role_text,
         staff_action     TYPE dpr_bupa_link-staff_action,
         task_type        TYPE dpr_tv_tsk_type,
         work_effort      TYPE dpr_tv_effort,
         work_unit        TYPE dpr_tv_unit,
         beg_tmstmp_eng   TYPE sy-datum,
         end_tmstmp_eng   TYPE sy-datum,
         location_text    TYPE dpr_tv_location_text,
         task_desc(1000)  TYPE c,                 "tdline,
         task_name        TYPE dpr_tv_name,
         proj_desc(1000)  TYPE c,                 "tdline,
         project_id       TYPE project_id,
         object_key(132)  TYPE c,
         actualstart      TYPE dpr_tv_bapi_ext_date,
         actualfinish     TYPE dpr_tv_bapi_ext_date,
         task_number      TYPE dpr_tv_task_id,
         name_pm(40)      TYPE c,
         bpkind(9)        TYPE c,
         flag             TYPE c,
         days_total       TYPE dpr_tv_effort,
        END OF t_final.
TYPES : BEGIN OF t_taskassignment,
         guid             TYPE dpr_tv_guid,
         created_by       TYPE dpr_tv_created_by,
         created_on       TYPE dpr_tv_timestamp,
         changed_by       TYPE dpr_tv_changed_by,
         changed_on       TYPE dpr_tv_timestamp,
         sort_number      TYPE dpr_tv_sort_number,
         participant_guid TYPE dpr_tv_guid,
         entity_type      TYPE cgpl_object_type,
         entity_guid      TYPE dpr_tv_guid,
         beg_tmstmp       TYPE dpr_tv_timestamp,
         end_tmstmp       TYPE dpr_tv_timestamp,
         work_effort      TYPE dpr_tv_assigned_work,
         work_unit        TYPE dpr_tv_unit,
         responsible      TYPE dpr_tv_responsibility,
         concrete_role    TYPE dpr_tv_concrete_role,
         ea_dummy         TYPE dpr_tv_ea_dummy,
         commentary       TYPE dpr_tv_commentary,
        END OF t_taskassignment,
        BEGIN OF t_taskdetail,
         participant_guid TYPE dpr_tv_participant_guid,
         entity_guid      TYPE dpr_tv_guid,
         task_type        TYPE dpr_tv_tsk_type,
         task_name        TYPE dpr_tv_name,
         task_type_text   TYPE dpr_tv_tsk_type_text,
         task_number      TYPE dpr_tv_task_id,
         task_desc(1000)  TYPE c,                         "tdline,
        END OF t_taskdetail,
        BEGIN OF t_output,
         bpartner    TYPE bu_partner,
         mail(125)   TYPE c,
         status(50)  TYPE c,
        END OF t_output.
TYPES : BEGIN OF t_message.
        INCLUDE STRUCTURE bapiret2.
TYPES : END OF t_message.
TYPES : BEGIN OF t_bdcdata,
         program TYPE bdc_prog,
         dynpro TYPE bdc_dynr,
         dynbegin TYPE bdc_start,
         fnam TYPE char140,
         fval TYPE string,
        END OF t_bdcdata.
*----------------------------------------------------------------------*
* DATA DECLERATIONS                                                    *
*----------------------------------------------------------------------*
DATA: v_guid             TYPE cgpl_guid16,
      v_pernr            TYPE personid,
      v_location         TYPE dpr_tv_location,
      v_begdate          TYPE sy-datum,
      v_beg_tmstmp       TYPE timestamp,
      v_enddate          TYPE sy-datum,
      v_end_tmstmp       TYPE timestamp,
      v_location_text    TYPE dpr_tv_location_text,
      v_task_guid        TYPE dpr_tv_entity_guid,
      v_tsk_type         TYPE dpr_tv_tsk_type,
      v_type_text        TYPE dpr_tv_type_text,
      v_project_guid     TYPE dpr_tt_guids,
      v_staff_action     TYPE prp_action_id,
      v_project_guid_s   TYPE LINE OF dpr_tt_guids,
      v_project_guid_1   TYPE dpr_tv_guid,
      v_text1            TYPE cgpl_text1,
      v_participant_role TYPE dpr_tv_participant_role,
      v_role_text        TYPE dpr_tv_participant_role_text,
      v_ltext(1000)      TYPE c,
      v_name(70)         TYPE c,
      v_save_name(70)    TYPE c,
      v_name_sub(100)    TYPE c,
      v_number           TYPE dpr_tv_number,
      v_role_guid        TYPE dpr_tv_bapi_guid_role,
      v_guid_x16         TYPE sysuuid-x,
      v_guid_c32         TYPE sysuuid-c,
      v_sucess(4)        TYPE c VALUE 0,
      v_failure(4)       TYPE c VALUE 0,
      v_int_order        TYPE project_id,
      v_name_first_pm    TYPE bu_namep_f,
      v_name_last_pm     TYPE bu_namep_l,
      v_name_pm(40)      TYPE c,
      v_skipflag         TYPE c VALUE '0',
      datediff           TYPE tfmatage,
      v_datediff(4)      TYPE n,
      v_bpkind           TYPE bu_bpkind,
      v_bpkind1          TYPE catsvarian,
      v_bpkind2          TYPE catsvarian,
      v_days_total       TYPE dpr_tv_assigned_work.   "i.
DATA : v_vis TYPE i.
*----------------------------------------------------------------------*
* INTERNAL TABLE DECLERATIONS                                          *
*----------------------------------------------------------------------*
DATA:  i_dpr_bupa_link_final  TYPE STANDARD TABLE OF t_final          WITH HEADER LINE,
       i_dpr_bupa_link_final1 TYPE STANDARD TABLE OF t_final          WITH HEADER LINE,
       i_dpr_bupa_link_final2 TYPE STANDARD TABLE OF t_final          WITH HEADER LINE,
       i_dpr_bupa_link_final3 TYPE STANDARD TABLE OF t_final          WITH HEADER LINE,
       i_batchoutput          TYPE STANDARD TABLE OF t_final          WITH HEADER LINE,
       i_tline                TYPE STANDARD TABLE OF tline            WITH HEADER LINE,
       i_project_id           TYPE STANDARD TABLE OF t_project_id     WITH HEADER LINE,
       i_dpr_bupa_link        TYPE STANDARD TABLE OF dpr_bupa_link    WITH HEADER LINE,
       i_proj_guid            TYPE STANDARD TABLE OF dpr_part         WITH HEADER LINE,
       i_objlink              TYPE STANDARD TABLE OF dpr_objlink      WITH HEADER LINE,
       i_taskassignment       TYPE STANDARD TABLE OF dpr_entity_link  WITH HEADER LINE,
       i_taskdetail           TYPE STANDARD TABLE OF t_taskdetail     WITH HEADER LINE,
       i_taskassignment1      TYPE STANDARD TABLE OF t_taskassignment WITH HEADER LINE,
       i_output               TYPE STANDARD TABLE OF t_output         WITH HEADER LINE,
       i_et_description       TYPE STANDARD TABLE OF
                                                  bapi_ts_description WITH HEADER LINE,
       i_bapi_ts_description  TYPE STANDARD TABLE OF
                                                  bapi_ts_description WITH HEADER LINE,
       i_bapi_task_desc       TYPE STANDARD TABLE OF
                                                  bapi_ts_description WITH HEADER LINE,
       i_et_staffing          TYPE STANDARD TABLE OF
                                                  bapi_ts_prp_staffing_det WITH HEADER LINE,
       i_et_subject           TYPE STANDARD TABLE OF
                                                  bapi_ts_subobject WITH HEADER LINE,
       i_months_name          TYPE STANDARD TABLE OF
                                                  t247 WITH HEADER LINE,
       i_bapi_ts_name         TYPE STANDARD TABLE OF
                                                  bapi_ts_name WITH HEADER LINE,
       i_message              TYPE STANDARD TABLE OF t_message WITH HEADER LINE.
*----------------------------------------------------------------------*
* WORKAREA DECLERATIONS                                                *
*----------------------------------------------------------------------*
DATA : wa_0315                       TYPE STANDARD TABLE OF t_cats_0315 WITH HEADER LINE,
       wa_bapi2075_2                 TYPE bapi2075_2,
       wa_participant_guid           TYPE bapi_ts_guid,
       wa_es_projectrole             TYPE bapi_ts_prp_projectrole_det,
       wa_es_projectrole_pm          TYPE bapi_ts_prp_projectrole_det,
       wa_task_guid                  TYPE bapi_ts_guid,
       wa_es_task_detail             TYPE bapi_ts_task_detail,
       wa_generaldetail              TYPE bapivendor_04,
       wa_bapi_ts_guid               TYPE bapi_ts_guid,
       wa_bapi_ts_project_def_detail TYPE bapi_ts_project_def_detail,
       wa_bapi_ts_name               TYPE STANDARD TABLE OF bapi_ts_name WITH HEADER LINE.
*----------------------------------------------------------------------*
* BATCH JOB DECLERATIONS                                               *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* TYPES DECLERATIONS                                                   *
*----------------------------------------------------------------------*
TYPES: t_document_data  TYPE  sodocchgi1,
       t_packing_list   TYPE  sopcklsti1,
       t_attachment     TYPE  solisti1,
       t_body_msg       TYPE  solisti1,
       t_receivers      TYPE  somlreci1.
*----------------------------------------------------------------------*
* INTERNALTABLE DECLERATIONS                                           *
*----------------------------------------------------------------------*
DATA : i_document_data  TYPE STANDARD TABLE OF t_document_data,
       i_packing_list   TYPE STANDARD TABLE OF t_packing_list,
       i_attachment     TYPE STANDARD TABLE OF t_attachment,
       i_body_msg       TYPE STANDARD TABLE OF t_body_msg,
       i_receivers      TYPE STANDARD TABLE OF t_receivers.
*----------------------------------------------------------------------*
* WORK AREA DECLERATIONS                                               *
*----------------------------------------------------------------------*
DATA : w_document_data  TYPE  t_document_data,
       w_packing_list   TYPE  t_packing_list,
       w_attachment     TYPE  t_attachment,
       w_body_msg       TYPE  t_body_msg,
       w_receivers      TYPE  t_receivers.
*----------------------------------------------------------------------*
* DATA DECLERATIONS                                                    *
*----------------------------------------------------------------------*
DATA : v_work_effort(9)      TYPE c,
       v_beg_tmstmp_eng      TYPE sy-datum,
       v_end_tmstmp_eng      TYPE sy-datum,
       v_beg_tmstmp_eng1(11) TYPE c,
       v_end_tmstmp_eng1(11) TYPE c,
       v_date(2)             TYPE c,
       v_month(2)            TYPE c,
       v_year(4)             TYPE c,
       v_start_date          TYPE sy-datum,
       v_end_date            TYPE sy-datum,
       v_email(128)          TYPE c,
       v_recp(128)           TYPE c,
       g_sent_to_all         TYPE sonv-flag,
       g_tab_lines           TYPE i.
*----------------------------------------------------------------------*
* CLASS DECLERATIONS                                                   *
*----------------------------------------------------------------------*
CLASS cl_abap_char_utilities DEFINITION LOAD.
*----------------------------------------------------------------------*
* CONSTANT DECLERATIONS                                                *
*----------------------------------------------------------------------*
CONSTANTS : con_tab  TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
            con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
CONSTANTS : c_gdd(6) TYPE c VALUE 'GDD590',
            c_gb2(6) TYPE c VALUE 'GB2590',
            c_gp1(6) TYPE c VALUE 'GP1590'.
*----------------------------------------------------------------------*
* RANGES DECLERATION                                                   *
*----------------------------------------------------------------------*
RANGES : r_date  FOR sy-datum,
         r_bpnum FOR but000-partner.
*----------------------------------------------------------------------*
* ALV Data Declerations                                                *
*----------------------------------------------------------------------*
DATA: fieldcatalog  TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      gd_tab_group  TYPE slis_t_sp_group_alv,
      gd_layout     TYPE slis_layout_alv,
      gd_repid      LIKE sy-repid,
      gt_events     TYPE slis_t_event,
      gd_prntparams TYPE slis_print_alv,
      v_dest        LIKE edipoa-logdes,
      v_handle      LIKE sy-tabix,
      v_spool_id    LIKE tsp01-rqident,
      v_rc          TYPE c,
      v_errmessage(100) TYPE c,
      v_text(1000) TYPE c.
*----------------------------------------------------------------------*
* OLE DATA DECLERATION                                                 *
*----------------------------------------------------------------------*
TYPES: BEGIN OF t_catsw,
        mark TYPE catsmark,
        skostl TYPE skostl,
        lstar TYPE lstar,
        sebeln TYPE sebeln,                   "PO
        sebelp TYPE sebelp,                   "ITEM NUMBER
        sprznr TYPE sprznr,
        lstnr TYPE asnum,                     "ACTIVITY NUMBER
        rkostl TYPE ekostl,
        rproj TYPE num8,
        raufnr TYPE eaufnr,
        rnplnr TYPE nw_aufnr,
        raufpl TYPE co_aufpl,
        raplzl TYPE num8,
        rkdauf TYPE ekdau,
        rkdpos TYPE ekdpo,
        rkstr TYPE ekstr,
        rprznr TYPE eprznr,
        paobjnr TYPE rkeobjnr,
        sumdayw TYPE catswsum,
        day1 TYPE catshours,
        day2 TYPE catshours,
        day3 TYPE catshours,
        day4 TYPE catshours,
        day5 TYPE catshours,
        day6 TYPE catshours,
        day7 TYPE catshours,
        day8 TYPE catshours,
        day9 TYPE catshours,
        day10 TYPE catshours,
        day11 TYPE catshours,
        day12 TYPE catshours,
        day13 TYPE catshours,
        day14 TYPE catshours,
        day15 TYPE catshours,
        day16 TYPE catshours,
        day17 TYPE catshours,
        day18 TYPE catshours,
        day19 TYPE catshours,
        day20 TYPE catshours,
        day21 TYPE catshours,
        day22 TYPE catshours,
        day23 TYPE catshours,
        day24 TYPE catshours,
        day25 TYPE catshours,
        day26 TYPE catshours,
        day27 TYPE catshours,
        day28 TYPE catshours,
        day29 TYPE catshours,
        day30 TYPE catshours,
        day31 TYPE catshours,
        vornr TYPE vornr,
        uvorn TYPE uvorn,
        bedid TYPE num12,
        kapar TYPE kapart,
        arbpl TYPE arbpl,
        posid TYPE ps_posid,
        zcpr_guid TYPE char32,
        zcpr_extid TYPE char24,          "TASK NAME
        zcpr_objguid TYPE char32,
        zcpr_objgextid TYPE char24,
        zcpr_objtype TYPE char3,
        zzcpr_guid TYPE char32,
        zzcpr_extid TYPE char24,         "PROJECT ID
        zzcpr_objguid TYPE char32,
        zzcpr_objgextid TYPE char24,     "TASK ID
        zzcpr_objtype TYPE char3,
        participant_role TYPE char15,    "PARTICIPANT ROLE
        arbid TYPE objektid,
        werks TYPE werks_d,
        split TYPE cats_split,
        ltxa1 TYPE ltxa1,
        fstad TYPE dats,
        sstad TYPE dats,
        fendd TYPE dats,
        sendd TYPE dats,
        kbearest TYPE fltp_value,
        vertl TYPE cr_vertn,
        autyp TYPE auftyp,
        kalid TYPE wfcid,
        rproj_ext TYPE ps_posid,
        disptextw1 TYPE text40,
        disptextw2 TYPE text40,
        kper_single TYPE catsmark,
        kper_collect TYPE catsmark,
       END OF t_catsw.
INCLUDE ole2incl.
DATA: gs_excel        TYPE ole2_object,
      gs_wbooklist    TYPE ole2_object,
      gs_application  TYPE ole2_object,
      gs_wbook        TYPE ole2_object,
      gs_activesheet  TYPE ole2_object,
      gs_sheets       TYPE ole2_object,
      gs_newsheet     TYPE ole2_object,
      gs_cell1        TYPE ole2_object,
      gs_cell2        TYPE ole2_object,
      gs_cells        TYPE ole2_object,
      gs_range        TYPE ole2_object,
      gs_font         TYPE ole2_object,
      gs_interior     TYPE ole2_object,
      gs_columns      TYPE ole2_object,
      gs_autofit      TYPE ole2_object,
      gs_table_border TYPE ole2_object,
      gs_table        TYPE ole2_object,
      gs_save         TYPE ole2_object,
      gs_wactbooklist TYPE ole2_object,
      gs_comment      TYPE ole2_object,
      g_workbook      TYPE ole2_object.
DATA: gv_index(2) TYPE c,
      gv_outer_index LIKE sy-index,
      gv_sheet_name(26) TYPE c,
      gv_line_cntr TYPE i,
      gv_line_cntr_1 TYPE i,
      v_flag TYPE c VALUE '0'.
DATA: i_etworklist TYPE STANDARD TABLE OF t_catsw WITH HEADER LINE.
*----------------------------------------------------------------------*
* EMAIL DATA DECLERATION                                               *
*----------------------------------------------------------------------*
DATA : method1 LIKE sy-ucomm,
       g_user LIKE soudnamei1,
       g_user_data LIKE soudatai1,
       g_owner LIKE soud-usrnam,
       g_receipients LIKE soos1 OCCURS 0 WITH HEADER LINE,
       g_document LIKE sood4,
       g_header LIKE sood2,
       g_folmam LIKE sofm2,
       g_objcnt LIKE soli OCCURS 0 WITH HEADER LINE,
       g_objhead LIKE soli OCCURS 0 WITH HEADER LINE,
       g_objpara  LIKE selc OCCURS 0 WITH HEADER LINE,
       g_objparb  LIKE soop1 OCCURS 0 WITH HEADER LINE,
       g_attachments LIKE sood5 OCCURS 0 WITH HEADER LINE,
       g_references LIKE soxrl OCCURS 0 WITH HEADER LINE,
       g_authority LIKE sofa-usracc,
       g_ref_document LIKE sood4,
       g_new_parent LIKE soodk.

DATA: BEGIN OF g_files OCCURS 10,
       text(4096) TYPE c,
      END OF g_files.
DATA : fold_number(12) TYPE c,
       fold_yr(2)      TYPE c,
       fold_type(3)    TYPE c.
DATA : ws_file         TYPE string, "DEFAULT 'C:\Documents and Settings\rd76685\Desktop\test.xls'.
       ws_email(128)   TYPE c,
       ws_pernr        TYPE pernr_d,
       ws_proid        TYPE project_id,
       ws_begdt(10)    TYPE c,
       ws_enddt(10)    TYPE c,
       w_pernr         TYPE pernr_d,
       w_proid         TYPE project_id,
       w_begdt(10)     TYPE c,
       w_enddt(10)     TYPE c,
       v_begday(2)     TYPE c,
       v_begmnt(2)     TYPE c,
       v_begyear(4)    TYPE c,
       v_endday(2)     TYPE c,
       v_endmnt(2)     TYPE c,
       v_endyear(4)    TYPE c,
       v_begday1(2)    TYPE c,
       v_begmnt1(2)    TYPE c,
       v_begyear1(4)   TYPE c,
       v_endday1(2)    TYPE c,
       v_endmnt1(2)    TYPE c,
       v_endyear1(4)   TYPE c,
       v_datebeg(11)   TYPE c,
       v_datebeg1(10)  TYPE c,
       v_dateend(11)   TYPE c,
       v_dateend1(10)  TYPE c,
       v_begindate(11) TYPE c,
       v_enddate1(11)  TYPE c,
       v_month_name    TYPE fcktx,
       v_temp_value    TYPE dpr_tv_effort,
       v_status1       TYPE c VALUE '0',
       v_status2       TYPE c VALUE '0',
       v_tag1(3)       TYPE c VALUE '<(>',
       v_tag2(3)       TYPE c VALUE '<)>',
       v_ldescription(1000) TYPE c,
       v_beg_date1     TYPE sy-datum,
       v_end_date1     TYPE sy-datum.
DATA : v_bpnumlow(8)   TYPE c,
       v_bpnumhigh(8)  TYPE c.
*DATA : bdcdata TYPE STANDARD TABLE OF t_bdcdata WITH HEADER LINE.
DATA : bdcdata TYPE STANDARD TABLE OF bdcdata WITH HEADER LINE.
DATA : wa_bapibus1006_head TYPE bapibus1006_head,
       wa_bapiadsmtp       TYPE STANDARD TABLE OF bapiadsmtp WITH HEADER LINE.
DATA : v_businesspartner   TYPE bu_partner.
*----------------------------------------------------------------------*
* S E L E C T I O N    S C R E E N                                     *
*----------------------------------------------------------------------*
* Selection Parameters/Select Options.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_projid FOR dpr_project-project_id OBLIGATORY
                              MATCHCODE OBJECT ygi_abr20663_projectid,
                 s_bpnum  FOR but000-partner.
PARAMETERS:      p_begdt LIKE sy-datum DEFAULT sy-datum,
                 p_enddt LIKE sy-datum.
PARAMETERS :     p_trig TYPE xfeld,
                 p_recp(125) TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
* INITIALAZITION                                                       *
*----------------------------------------------------------------------*
INITIALIZATION.
  PERFORM f_initialaze_rfcdest.
*----------------------------------------------------------------------*
* AT SELECTION SCREEN                                                  *
*----------------------------------------------------------------------*
**Validating Selection Screen File Type
AT SELECTION-SCREEN.
  IF s_projid[] IS INITIAL AND
     p_begdt IS INITIAL AND
     p_enddt IS NOT INITIAL.
    MESSAGE e000.
  ELSEIF s_projid[] IS INITIAL AND
     p_begdt IS NOT INITIAL AND
     p_enddt IS INITIAL.
    MESSAGE e001.
  ELSEIF NOT s_projid[] IS INITIAL AND
     p_begdt IS INITIAL AND
     p_enddt IS INITIAL.
    MESSAGE e003.
  ELSEIF NOT s_projid[] IS INITIAL AND
     p_begdt IS INITIAL AND
     p_enddt IS NOT INITIAL.
    MESSAGE e000.
  ELSEIF NOT s_projid[] IS INITIAL AND
     p_begdt IS NOT INITIAL AND
     p_enddt IS INITIAL.
    MESSAGE e001.
  ELSEIF NOT s_projid[] IS INITIAL AND
     p_enddt < p_begdt.
    MESSAGE e004.
  ELSEIF s_projid[] IS INITIAL AND
     p_enddt < p_begdt.
    MESSAGE e004.
  ELSEIF s_projid[] IS INITIAL AND
     p_begdt IS INITIAL AND
     p_enddt IS INITIAL.
    MESSAGE e003.
  ENDIF.
*----------------------------------------------------------------------*
* S T A R T   O F   S E L E C T I O N                                  *
*----------------------------------------------------------------------*
START-OF-SELECTION.
  IF NOT s_bpnum[] IS INITIAL.
    LOOP AT s_bpnum.
      v_bpnumlow  = s_bpnum-low+2(8).
      v_bpnumhigh = s_bpnum-high+2(8).
      r_bpnum-option  = s_bpnum-option.
      r_bpnum-sign    = s_bpnum-sign.
      r_bpnum-low     = v_bpnumlow.
      r_bpnum-high    = v_bpnumhigh.
      APPEND r_bpnum.
      CLEAR : r_bpnum, v_bpnumlow, v_bpnumhigh.
    ENDLOOP.
  ENDIF.

  r_date-option = 'BT'.
  r_date-sign   = 'I'.
  r_date-low    = p_begdt.
  r_date-high   = p_enddt.
  APPEND r_date.
  CLEAR : r_date.

  CALL FUNCTION 'MONTH_NAMES_GET'
    EXPORTING
      language              = sy-langu
    TABLES
      month_names           = i_months_name
    EXCEPTIONS
      month_names_not_found = 1
      OTHERS                = 2.

  CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
    EXPORTING
      i_date_from = p_begdt
      i_date_to   = p_enddt
    IMPORTING
      e_days      = datediff.

  v_datediff = datediff.
  v_datediff = v_datediff + 1.
  SHIFT v_datediff LEFT DELETING LEADING space.
  IF v_datediff = '0'.
    v_datediff = 1.
    SHIFT v_datediff LEFT DELETING LEADING space.
  ENDIF.
  v_begdate = p_begdt.
  v_enddate = p_enddt.
  v_begyear = p_begdt+0(4).
  v_begmnt  = p_begdt+4(2).
  v_begday  = p_begdt+6(2).
  LOOP AT i_months_name WHERE mnr EQ v_begmnt.
    v_month_name = i_months_name-ktx.
  ENDLOOP.
  CONCATENATE v_begday v_month_name v_begyear INTO v_datebeg SEPARATED BY '-'.
  CONCATENATE v_begday v_begmnt v_begyear INTO v_datebeg1 SEPARATED BY '.'.
  v_endyear = p_enddt+0(4).
  v_endmnt  = p_enddt+4(2).
  v_endday  = p_enddt+6(2).
  LOOP AT i_months_name WHERE mnr EQ v_endmnt.
    v_month_name = i_months_name-ktx.
  ENDLOOP.
  CONCATENATE v_endday v_month_name v_endyear INTO v_dateend SEPARATED BY '-'.
  CONCATENATE v_endday v_endmnt v_endyear INTO v_dateend1 SEPARATED BY '.'.
  CONVERT DATE       v_begdate INTO
          TIME STAMP v_beg_tmstmp
          TIME ZONE cl_cgpl_scheduling=>m_tzone.
  CONVERT DATE       v_enddate INTO
          TIME STAMP v_end_tmstmp
          TIME ZONE cl_cgpl_scheduling=>m_tzone.

  PERFORM data_retrieval.
  PERFORM fetch_records.
  PERFORM filter_records.
  IF sy-batch NE 'X'.
    IF p_trig NE 'X' AND
       i_dpr_bupa_link_final1[] IS NOT INITIAL.
      PERFORM filter_output_display_alv.
      IF NOT i_dpr_bupa_link_final1[] IS INITIAL.
        PERFORM build_fieldcatalog.
        PERFORM build_layout.
        PERFORM display_alv_report.
      ENDIF.
    ELSEIF p_trig EQ 'X' AND
           p_recp IS INITIAL AND
           i_dpr_bupa_link_final1[] IS NOT INITIAL.
      PERFORM excel_sheet_application.
    ELSEIF p_trig EQ 'X' AND
           p_recp IS NOT INITIAL AND
           i_dpr_bupa_link_final1[] IS NOT INITIAL.
      PERFORM excel_sheet_mail_recipient USING p_recp.
    ENDIF.
  ELSE.
    PERFORM batch_process_email USING p_recp.
  ENDIF.
  CLEAR : v_begday,  v_begmnt,  v_begyear,  v_endday,  v_endmnt,  v_endyear,
          v_datebeg, v_dateend, v_datediff, datediff,  v_month_name, v_datebeg1, v_dateend1,
          v_begday1, v_begmnt1, v_begyear1, v_endday1, v_endmnt1, v_endyear1.
  REFRESH : i_months_name.
  IF i_dpr_bupa_link_final1[] IS INITIAL.
    MESSAGE ID 'YGF_ABR20640' TYPE 'I' NUMBER '005'.
  ENDIF.
*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
FORM data_retrieval .
  IF NOT s_projid[] IS INITIAL.   "AND
*         p_begdt IS INITIAL AND
*         p_enddt IS INITIAL.
    SELECT guid project_id
           FROM dpr_project
           INTO CORRESPONDING FIELDS OF TABLE i_project_id
           WHERE project_id IN s_projid AND
                 version_number EQ space.

    LOOP AT i_project_id.
      CALL FUNCTION 'DPR_GET_GUID_BY_ID_FROM_DB'
        EXPORTING
          iv_number            = i_project_id-project_id
          iv_version_number    = ' '
          iv_object_type       = 'DPO'
        IMPORTING
          et_guid              = v_project_guid
        EXCEPTIONS
          no_rfc_authorization = 1
          not_found            = 2
          invalid_object_type  = 3
          OTHERS               = 4.
      IF sy-subrc = 0.
        READ TABLE v_project_guid INTO v_project_guid_s INDEX 1.
        SELECT *
               FROM cgpl_entity
               INTO CORRESPONDING FIELDS OF TABLE i_proj_guid
               WHERE project_guid EQ v_project_guid_s AND
                     object_type  EQ 'MTG'.
        IF sy-subrc = 0.
          IF NOT i_proj_guid[] IS INITIAL.
            SELECT *
                   APPENDING CORRESPONDING FIELDS OF TABLE i_dpr_bupa_link
                   FROM dpr_bupa_link
                   FOR ALL ENTRIES IN i_proj_guid
                   WHERE participant_guid EQ i_proj_guid-guid AND
                         end_tmstmp >= v_beg_tmstmp AND
                         beg_tmstmp <= v_end_tmstmp.
*                         staff_action = 'CRTD' AND
          ENDIF.
        ENDIF.
      ENDIF.
      CLEAR : v_project_guid, v_project_guid_s, v_guid.
      REFRESH : i_proj_guid.
    ENDLOOP.
  ELSEIF s_projid[] IS INITIAL.    "AND
*         p_begdt IS NOT INITIAL AND
*         p_enddt IS NOT INITIAL.
    SELECT *
           INTO CORRESPONDING FIELDS OF TABLE i_dpr_bupa_link
           FROM dpr_bupa_link
           WHERE end_tmstmp >= v_beg_tmstmp AND
                 beg_tmstmp <= v_end_tmstmp.
*               staff_action = 'CRTD' AND

*  ELSEIF NOT s_projid[] IS INITIAL AND
*         ( p_begdt IS NOT INITIAL OR p_enddt IS NOT INITIAL ).
*    SELECT guid project_id
*           FROM dpr_project
*           INTO CORRESPONDING FIELDS OF TABLE i_project_id
*           WHERE project_id IN s_projid.
*
*    LOOP AT i_project_id.
*      CALL FUNCTION 'DPR_GET_GUID_BY_ID_FROM_DB'
*        EXPORTING
*          iv_number            = i_project_id-project_id
*          iv_version_number    = ' '
*          iv_object_type       = 'DPO'
*        IMPORTING
*          et_guid              = v_project_guid
*        EXCEPTIONS
*          no_rfc_authorization = 1
*          not_found            = 2
*          invalid_object_type  = 3
*          OTHERS               = 4.
*      IF sy-subrc = 0.
*        READ TABLE v_project_guid INTO v_project_guid_s INDEX 1.
*        SELECT *
*               FROM cgpl_entity
*               INTO CORRESPONDING FIELDS OF TABLE i_proj_guid
*               WHERE project_guid EQ v_project_guid_s AND
*                     object_type  EQ 'MTG'.
*        IF sy-subrc = 0.
*          IF NOT i_proj_guid[] IS INITIAL.
*            SELECT *
*                   APPENDING CORRESPONDING FIELDS OF TABLE i_dpr_bupa_link
*                   FROM dpr_bupa_link
*                   FOR ALL ENTRIES IN i_proj_guid
*                   WHERE participant_guid EQ i_proj_guid-guid AND
*                         staff_action = 'CRTD'.
*          ENDIF.
*        ENDIF.
*      ENDIF.
*      CLEAR : v_project_guid, v_project_guid_s, v_guid.
*      REFRESH : i_proj_guid.
*    ENDLOOP.
*  ELSEIF s_projid[] IS INITIAL AND
*        p_begdt IS INITIAL AND
*        p_enddt IS INITIAL.
*    SELECT *
*           INTO CORRESPONDING FIELDS OF TABLE i_dpr_bupa_link
*           FROM dpr_bupa_link
*           WHERE staff_action = 'CRTD'.
  ENDIF.
ENDFORM.                    " DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*&      Form  FETCH_RECORS
*&---------------------------------------------------------------------*
FORM fetch_records .
  DATA : v_length(3) TYPE n.
  LOOP AT i_dpr_bupa_link.
    i_dpr_bupa_link_final-bupa_guid = i_dpr_bupa_link-bupa_guid.
    i_dpr_bupa_link_final-participant_guid = i_dpr_bupa_link-participant_guid.
** to get Personal Number(PERNR) for each BUPA_GUID
    CALL FUNCTION 'BP_CENTRALPERSON_GET'
      EXPORTING
        iv_bu_partner_guid = i_dpr_bupa_link-bupa_guid
      IMPORTING
        ev_person_id       = v_pernr.

    i_dpr_bupa_link_final-pernr = v_pernr.

    DATA : v_name_last  TYPE bu_namep_l,
           v_name_first TYPE bu_namep_f.
    SELECT SINGLE name_last name_first
           FROM but000
           INTO (v_name_last , v_name_first)
           WHERE partner_guid = i_dpr_bupa_link-bupa_guid.

    i_dpr_bupa_link_final-name_first = v_name_first.
    i_dpr_bupa_link_final-name_last  = v_name_last.

**To Get LIFNR
    CALL FUNCTION 'CATS_GET_INFOTYPE_0315' DESTINATION v_dest
      EXPORTING
        pernr           = v_pernr
        date            = sy-datum
      IMPORTING
        i0315           = wa_0315
      EXCEPTIONS
        pernr_not_found = 1
        no_record       = 2
        no_authority    = 3
        OTHERS          = 4.
**For ICDR's only
*    IF sy-subrc NE 0.
*      CONTINUE.
*    ENDIF.
**For ICDR's only
    i_dpr_bupa_link_final-lifnr = wa_0315-lifnr.
    i_dpr_bupa_link_final-pernr = v_pernr.

    CALL FUNCTION 'BAPI_VENDOR_GETDETAIL' DESTINATION v_dest
      EXPORTING
        vendorno      = wa_0315-lifnr
      IMPORTING
        generaldetail = wa_generaldetail.
    i_dpr_bupa_link_final-name = wa_generaldetail-name.

**Project Name
    SELECT SINGLE project_guid
           FROM cgpl_entity
           INTO v_project_guid_1
           WHERE guid = i_dpr_bupa_link-participant_guid AND
                 object_type EQ 'MTG'.

    SELECT SINGLE text1
           FROM cgpl_text
           INTO v_text1
           WHERE guid = v_project_guid_1.

    i_dpr_bupa_link_final-text1 = v_text1.
**Purchase Order Details
    wa_participant_guid-role_guid = i_dpr_bupa_link-participant_guid.
    CALL FUNCTION 'BAPI_BUS2177_GET_DETAIL'
      EXPORTING
        projectrole_guid = wa_participant_guid-role_guid
      IMPORTING
        es_projectrole   = wa_es_projectrole.

**To get PM Name
    CALL FUNCTION 'BAPI_BUS2172_GET_SUBOBJECTS'
      EXPORTING
        project_definition_guid = wa_es_projectrole-project_guid
      TABLES
        et_subobject            = i_et_subject.

    LOOP AT i_et_subject WHERE object_type EQ 'MTG'.
      CALL FUNCTION 'BAPI_BUS2177_GET_DETAIL'
        EXPORTING
          projectrole_guid = i_et_subject-guid
        IMPORTING
          es_projectrole   = wa_es_projectrole_pm
        TABLES
          et_staffing      = i_et_staffing.

      IF wa_es_projectrole_pm-role_type = 'DSRB-PM'.
        READ TABLE i_et_staffing INDEX 1.
        IF sy-subrc = 0.
          SELECT SINGLE name_first name_last
                 FROM but000
                 INTO (v_name_first_pm, v_name_last_pm)
                 WHERE partner_guid = i_et_staffing-partner_guid.
          IF sy-subrc = 0.
            CONCATENATE v_name_first_pm
                        v_name_last_pm
                        INTO v_name_pm SEPARATED BY space.
            i_dpr_bupa_link_final-name_pm = v_name_pm.
            CLEAR : v_name_first_pm, v_name_last_pm, v_name_pm.
          ENDIF.
        ENDIF.
      ENDIF.
      REFRESH : i_et_staffing.
      CLEAR   : wa_es_projectrole_pm.
    ENDLOOP.
    REFRESH : i_et_subject.

    SELECT *
           FROM dpr_objlink
           INTO CORRESPONDING FIELDS OF TABLE i_objlink
           WHERE task_guid = wa_es_projectrole-role_guid AND
                 object_type = '0PURCHORDITEM'.
    IF sy-subrc = 0.
      LOOP AT i_objlink.
        WRITE i_objlink-description TO v_ldescription NO-GAP.
        CONCATENATE v_ltext i_objlink-object_key+0(10) '/' '(' v_ldescription ')' ',' INTO v_ltext.
        CONCATENATE v_ltext '/' INTO v_ltext.
        CLEAR : v_ldescription.
      ENDLOOP.
      TRANSLATE v_ltext USING '/ '.
      SEARCH v_ltext FOR ','.
      IF sy-subrc = 0.
        v_length =  strlen( v_ltext ).
        v_length = v_length - 1.
        v_ltext = v_ltext+0(v_length).
      ENDIF.
*      v_ltext = v_ltext+1(131).
      i_dpr_bupa_link_final-object_key = v_ltext.
      CLEAR : v_ltext, v_ldescription.
    ENDIF.
    CLEAR : wa_participant_guid, wa_es_projectrole, v_length.
**Internal Order Number
    SELECT SINGLE project_guid
              FROM cgpl_entity
              INTO v_project_guid_1
              WHERE guid = i_dpr_bupa_link-participant_guid AND
                    object_type EQ 'MTG'.

    CALL FUNCTION 'DPR_GET_ID_BY_GUID_FROM_DB'
      EXPORTING
        iv_guid              = v_project_guid_1
      IMPORTING
        ev_number            = v_number
      EXCEPTIONS
        no_rfc_authorization = 1
        not_found            = 2
        invalid_object_type  = 3
        OTHERS               = 4.

    i_dpr_bupa_link_final-project_id = v_number.
**Role Type Text / Role Description
    wa_participant_guid-role_guid = i_dpr_bupa_link-participant_guid.
    CALL FUNCTION 'BAPI_BUS2177_GET_DETAIL'
      EXPORTING
        projectrole_guid = wa_participant_guid-role_guid
      IMPORTING
        es_projectrole   = wa_es_projectrole
      TABLES
        et_description   = i_et_description.

    IF sy-subrc = 0.
      CLEAR : v_name.
      LOOP AT i_et_description.
        CONCATENATE v_ltext i_et_description-description_line INTO v_ltext SEPARATED BY ','.
        REPLACE ALL OCCURRENCES OF v_tag1 IN v_ltext WITH ' '.
        REPLACE ALL OCCURRENCES OF v_tag2 IN v_ltext WITH ' '.
      ENDLOOP.
      v_ltext = v_ltext+1(999).
      i_dpr_bupa_link_final-task_desc = v_ltext.
      CLEAR : v_ltext.
      i_dpr_bupa_link_final-role_text = wa_es_projectrole-role_type_text.
    ENDIF.
    CLEAR : wa_participant_guid, wa_es_projectrole.
**Project Dates
    wa_bapi_ts_guid-project_definition_guid = v_project_guid_1.

    CALL FUNCTION 'BAPI_BUS2172_GET_DETAIL'
      EXPORTING
        project_definition_guid      = wa_bapi_ts_guid-project_definition_guid
      IMPORTING
        es_project_definition_detail = wa_bapi_ts_project_def_detail
      TABLES
        et_name                      = i_bapi_ts_name
        et_description               = i_bapi_ts_description.

    IF sy-subrc = 0.
      CLEAR : v_ltext.
      LOOP AT i_bapi_ts_description.
        CONCATENATE v_ltext i_bapi_ts_description-description_line INTO v_ltext SEPARATED BY ','.
        REPLACE ALL OCCURRENCES OF v_tag1 IN v_ltext WITH ' '.
        REPLACE ALL OCCURRENCES OF v_tag2 IN v_ltext WITH ' '.
      ENDLOOP.
      v_ltext = v_ltext+1(999).
      i_dpr_bupa_link_final-proj_desc = v_ltext.
      CLEAR : v_ltext.
    ENDIF.
    LOOP AT i_bapi_ts_name WHERE language = 'EN'.
      i_dpr_bupa_link_final-proj_name = i_bapi_ts_name-name.
    ENDLOOP.
    i_dpr_bupa_link_final-actualstart = wa_bapi_ts_project_def_detail-fixed_start_date.
    i_dpr_bupa_link_final-actualfinish = wa_bapi_ts_project_def_detail-fixed_finish_date.
**Task Type
    SELECT *
            FROM dpr_entity_link
            APPENDING CORRESPONDING FIELDS OF TABLE i_taskassignment
            WHERE participant_guid EQ i_dpr_bupa_link-participant_guid AND
                  entity_type EQ 'TTO' AND
                  responsible NE 'X'.
    APPEND : i_dpr_bupa_link_final.
    CLEAR  : v_pernr, wa_0315, v_project_guid, v_number, wa_bapi2075_2, v_text1,
             v_participant_role,v_guid_x16, v_guid_c32, v_role_text, v_name,
             v_location, v_location_text,  wa_participant_guid, i_dpr_bupa_link_final,
             v_role_guid, wa_es_projectrole, wa_generaldetail, wa_bapi_ts_project_def_detail,
             wa_bapi_ts_guid, v_project_guid_1.
    REFRESH : i_tline, i_objlink, i_et_description, i_bapi_ts_name.
  ENDLOOP.

  LOOP AT i_taskassignment.
    wa_task_guid-task_guid = i_taskassignment-entity_guid.

    i_bapi_task_desc-language = 'EN'.
    APPEND i_bapi_task_desc.

    CALL FUNCTION 'BAPI_BUS2175_GET_DETAIL'
      EXPORTING
        task_guid      = wa_task_guid-task_guid
      IMPORTING
        es_task_detail = wa_es_task_detail
      TABLES
        et_name        = wa_bapi_ts_name
        et_description = i_bapi_task_desc.

    i_taskdetail-participant_guid = i_taskassignment-participant_guid.
    i_taskdetail-entity_guid      = i_taskassignment-entity_guid.
    i_taskdetail-task_type        = wa_es_task_detail-task_type.
    i_taskdetail-task_type_text   = wa_es_task_detail-task_type_text.
    i_taskdetail-task_number      = wa_es_task_detail-task_number.
    READ TABLE wa_bapi_ts_name INDEX 1.
    IF sy-subrc = 0.
      i_taskdetail-task_name      = wa_bapi_ts_name-name.
    ENDIF.
    READ TABLE i_bapi_task_desc INDEX 1.
    IF sy-subrc EQ 0.
      CLEAR : v_ltext.
      v_ltext = i_bapi_task_desc-description_line.
      REPLACE ALL OCCURRENCES OF v_tag1 IN v_ltext WITH ' '.
      REPLACE ALL OCCURRENCES OF v_tag2 IN v_ltext WITH ' '.
      i_taskdetail-task_desc   = v_ltext.             "i_bapi_task_desc-description_line.
    ENDIF.
    APPEND : i_taskdetail.
    CLEAR : i_taskdetail, wa_es_task_detail, wa_task_guid, wa_bapi_ts_name, v_ltext.
  ENDLOOP.
ENDFORM.                    " FETCH_RECORdS
*&---------------------------------------------------------------------*
*&      Form  FILTER_RECORDS
*&---------------------------------------------------------------------*
FORM filter_records .
  DATA : v_beg_date      TYPE sy-datum,
         v_end_date      TYPE sy-datum,
         v_beg_timestamp TYPE timestamp,
         v_end_timestamp TYPE timestamp,
         v_effortvalue(11) TYPE c,
         v_effortvalue1(4) TYPE n,
         v_length(4)       TYPE c.

  LOOP AT i_taskassignment.
    v_beg_timestamp = i_taskassignment-beg_tmstmp.
    v_end_timestamp = i_taskassignment-end_tmstmp.
    READ TABLE i_dpr_bupa_link_final WITH KEY
                 participant_guid = i_taskassignment-participant_guid.
    IF sy-subrc = 0.
      MOVE-CORRESPONDING i_dpr_bupa_link_final TO i_dpr_bupa_link_final1.
      CONVERT TIME STAMP v_beg_timestamp
              TIME ZONE cl_cgpl_scheduling=>m_tzone
              INTO DATE v_beg_date.
      CONVERT TIME STAMP v_end_timestamp
              TIME ZONE cl_cgpl_scheduling=>m_tzone
              INTO DATE v_end_date.
      i_dpr_bupa_link_final1-work_effort    = i_taskassignment-work_effort.
      i_dpr_bupa_link_final1-work_unit      = i_taskassignment-work_unit.
      i_dpr_bupa_link_final1-beg_tmstmp_eng = v_beg_date.   "I_taskassignment-beg_tmstmp.
      i_dpr_bupa_link_final1-end_tmstmp_eng = v_end_date.   "I_taskassignment-end_tmstmp.

**For Checking the work effort days with the
**Task Start/End Dates with Report Start /End Dates
**For Validating the dates by comparing
**Dates selection with Task Start Dates and Task End Dates
      v_temp_value = i_taskassignment-work_effort.
      IF i_dpr_bupa_link_final1-beg_tmstmp_eng > p_begdt.
        IF i_dpr_bupa_link_final1-beg_tmstmp_eng > p_enddt.
          CONTINUE.
        ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng > p_enddt.
          v_days_total = p_enddt - i_dpr_bupa_link_final1-beg_tmstmp_eng.
          v_days_total = v_days_total + 1 .
          IF v_days_total EQ '0.00'.
            v_days_total = '1.00'.
          ENDIF.
          IF v_temp_value LE v_days_total.
            i_dpr_bupa_link_final1-days_total = v_temp_value.
          ELSE.
            i_dpr_bupa_link_final1-days_total = v_days_total.
          ENDIF.
          i_dpr_bupa_link_final1-flag = 'X'.
        ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng < p_enddt.
          v_days_total = i_dpr_bupa_link_final1-end_tmstmp_eng - i_dpr_bupa_link_final1-beg_tmstmp_eng.
          v_days_total = v_days_total + 1 .
          IF v_days_total EQ '0.00'.
            v_days_total = '1.00'.
          ENDIF.
          IF v_temp_value LE v_days_total.
            i_dpr_bupa_link_final1-days_total = v_temp_value.
          ELSE.
            i_dpr_bupa_link_final1-days_total = v_days_total.
          ENDIF.
          i_dpr_bupa_link_final1-flag = 'X'.
        ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng = p_enddt.
          v_days_total = i_dpr_bupa_link_final1-end_tmstmp_eng - i_dpr_bupa_link_final1-beg_tmstmp_eng.
          v_days_total = v_days_total + 1 .
          IF v_days_total EQ '0.00'.
            v_days_total = '1.00'.
          ENDIF.
          IF v_temp_value LE v_days_total.
            i_dpr_bupa_link_final1-days_total = v_temp_value.
          ELSE.
            i_dpr_bupa_link_final1-days_total = v_days_total.
          ENDIF.
          i_dpr_bupa_link_final1-flag = 'X'.
        ENDIF.
      ELSEIF i_dpr_bupa_link_final1-beg_tmstmp_eng < p_begdt.
        IF i_dpr_bupa_link_final1-end_tmstmp_eng < p_begdt.
          CONTINUE.
        ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng > p_enddt.
          v_days_total = p_enddt - p_begdt.
          v_days_total = v_days_total + 1 .
          IF v_days_total EQ '0.00'.
            v_days_total = '1.00'.
          ENDIF.
          IF v_temp_value LE v_days_total.
            i_dpr_bupa_link_final1-days_total = v_temp_value.
          ELSE.
            i_dpr_bupa_link_final1-days_total = v_days_total.
          ENDIF.
          i_dpr_bupa_link_final1-flag = 'X'.
        ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng < p_enddt.
          v_days_total = i_dpr_bupa_link_final1-end_tmstmp_eng - p_begdt.
          v_days_total = v_days_total + 1 .
          IF v_days_total EQ '0.00'.
            v_days_total = '1.00'.
          ENDIF.
          IF v_temp_value LE v_days_total.
            i_dpr_bupa_link_final1-days_total = v_temp_value.
          ELSE.
            i_dpr_bupa_link_final1-days_total = v_days_total.
          ENDIF.
          i_dpr_bupa_link_final1-flag = 'X'.
        ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng = p_enddt.
          v_days_total = p_enddt - p_begdt.
          v_days_total = v_days_total + 1 .
          IF v_days_total EQ '0.00'.
            v_days_total = '1.00'.
          ENDIF.
          IF v_temp_value LE v_days_total.
            i_dpr_bupa_link_final1-days_total = v_temp_value.
          ELSE.
            i_dpr_bupa_link_final1-days_total = v_days_total.
          ENDIF.
          i_dpr_bupa_link_final1-flag = 'X'.
        ENDIF.
      ELSEIF i_dpr_bupa_link_final1-beg_tmstmp_eng = p_begdt.
        IF i_dpr_bupa_link_final1-end_tmstmp_eng > p_enddt.
          v_days_total = p_enddt - i_dpr_bupa_link_final1-beg_tmstmp_eng.
          v_days_total = v_days_total + 1 .
          IF v_days_total EQ '0.00'.
            v_days_total = '1.00'.
          ENDIF.
          IF v_temp_value LE v_days_total.
            i_dpr_bupa_link_final1-days_total = v_temp_value.
          ELSE.
            i_dpr_bupa_link_final1-days_total = v_days_total.
          ENDIF.
          i_dpr_bupa_link_final1-flag = 'X'.
        ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng < p_enddt.
          v_days_total = i_dpr_bupa_link_final1-end_tmstmp_eng - i_dpr_bupa_link_final1-beg_tmstmp_eng.
          v_days_total = v_days_total + 1 .
          IF v_days_total EQ '0.00'.
            v_days_total = '1.00'.
          ENDIF.
          IF v_temp_value LE v_days_total.
            i_dpr_bupa_link_final1-days_total = v_temp_value.
          ELSE.
            i_dpr_bupa_link_final1-days_total = v_days_total.
          ENDIF.
          i_dpr_bupa_link_final1-flag = 'X'.
        ELSEIF i_dpr_bupa_link_final1-end_tmstmp_eng = p_enddt.
          v_days_total = p_enddt - p_begdt.
          v_days_total = v_days_total + 1 .
          IF v_days_total EQ '0.00'.
            v_days_total = '1.00'.
          ENDIF.
          IF v_temp_value LE v_days_total.
            i_dpr_bupa_link_final1-days_total = v_temp_value.
          ELSE.
            i_dpr_bupa_link_final1-days_total = v_days_total.
          ENDIF.
          i_dpr_bupa_link_final1-flag = 'X'.
        ENDIF.
      ENDIF.
      READ TABLE i_taskdetail WITH KEY
                 participant_guid = i_taskassignment-participant_guid
                 entity_guid      = i_taskassignment-entity_guid.
      IF sy-subrc = 0.
        i_dpr_bupa_link_final1-task_type   = i_taskdetail-task_type_text.
        i_dpr_bupa_link_final1-task_name   = i_taskdetail-task_name.
        i_dpr_bupa_link_final1-task_number = i_taskdetail-task_number.
        i_dpr_bupa_link_final1-task_desc   = i_taskdetail-task_desc.
      ENDIF.
      APPEND i_dpr_bupa_link_final1.
      CLEAR : i_dpr_bupa_link_final1.
    ELSE.
      MOVE-CORRESPONDING i_dpr_bupa_link_final TO i_dpr_bupa_link_final1.
      APPEND i_dpr_bupa_link_final1.
      CLEAR : i_dpr_bupa_link_final1, v_beg_date, v_end_date, v_beg_timestamp, v_end_timestamp.
    ENDIF.
    CLEAR : v_beg_date, v_end_date, v_beg_timestamp, v_end_timestamp.
    CLEAR : v_temp_value, v_days_total.
  ENDLOOP.
  CLEAR : i_dpr_bupa_link_final1.
  SORT i_dpr_bupa_link_final1 BY pernr.
  IF NOT r_bpnum[] IS INITIAL.
    LOOP AT i_dpr_bupa_link_final1.
      IF i_dpr_bupa_link_final1-pernr IN r_bpnum.
        CONTINUE.
      ELSE.
        DELETE i_dpr_bupa_link_final1 INDEX sy-tabix.
      ENDIF.
    ENDLOOP.
    CLEAR : i_dpr_bupa_link_final1.
  ENDIF.
ENDFORM.                    " FILTER_RECORDS
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
FORM build_fieldcatalog .
  fieldcatalog-fieldname   = 'DUMMY'.
  fieldcatalog-col_pos     = 1.
  fieldcatalog-edit        = 'X'.
  fieldcatalog-no_out      = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'NAME_FIRST'.
  fieldcatalog-seltext_m   = 'First Name'.
  fieldcatalog-col_pos     = 2.
  fieldcatalog-emphasize   = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'NAME_LAST'.
  fieldcatalog-seltext_m   = 'Last Name'.
  fieldcatalog-col_pos     = 3.
  fieldcatalog-emphasize   = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'LIFNR'.
  fieldcatalog-seltext_m   = 'Vendor Number'.
  fieldcatalog-col_pos     = 4.
  fieldcatalog-emphasize   = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'OBJECT_KEY'.
  fieldcatalog-seltext_m   = 'Purchase Order'.
  fieldcatalog-col_pos     = 5.
  fieldcatalog-emphasize   = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'TEXT1'.
  fieldcatalog-seltext_m   = 'Project Name'.
  fieldcatalog-col_pos     = 6.
  fieldcatalog-emphasize   = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'WORK_EFFORT'.
  fieldcatalog-seltext_m   = 'Task Work Effort'.
  fieldcatalog-col_pos     = 7.
  fieldcatalog-emphasize   = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'WORK_UNIT'.
  fieldcatalog-seltext_m   = 'Task Work Unit'.
  fieldcatalog-col_pos     = 8.
  fieldcatalog-emphasize   = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'BEG_TMSTMP_ENG'.
  fieldcatalog-seltext_m   = 'Task Begin Date'.
  fieldcatalog-col_pos     = 9.
  fieldcatalog-emphasize   = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'END_TMSTMP_ENG'.
  fieldcatalog-seltext_m   = 'Task End Date'.
  fieldcatalog-col_pos     = 10.
  fieldcatalog-emphasize   = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'PROJECT_ID'.
  fieldcatalog-seltext_m   = 'Internal Order'.
  fieldcatalog-col_pos     = 11.
  fieldcatalog-emphasize   = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'ACTUALSTART'.
  fieldcatalog-seltext_l   = 'Project Actual Start Date'.
  fieldcatalog-col_pos     = 12.
  fieldcatalog-emphasize   = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'ACTUALFINISH'.
  fieldcatalog-seltext_l   = 'Project Actual Finish Date'.
  fieldcatalog-col_pos     = 13.
  fieldcatalog-emphasize   = 'X'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
ENDFORM.                    " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
FORM build_layout .
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-zebra             = 'X'.
  gd_layout-header_text       = 'DETAIL ACTIVITY REPORT'.
ENDFORM.                    " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
FORM display_alv_report .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      is_layout          = gd_layout
      it_fieldcat        = fieldcatalog[]
      i_save             = 'X'
    TABLES
      t_outtab           = i_dpr_bupa_link_final1
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.                    " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*&      Form  EXCEL_SHEET_APPLICATION
*&---------------------------------------------------------------------*
FORM excel_sheet_application .
  DATA : v_name TYPE char80,
         v_participant_guid TYPE dpr_tv_participant_guid,
         v_index TYPE sy-tabix,
         v_times TYPE i,
         v_effortvalue(11) TYPE c,
         v_effortvalue1(4) TYPE n,
         v_pernr_old       TYPE personid,
         v_pernr_new       TYPE personid,
         v_length(4)  TYPE c.
  DATA : return(255)  TYPE c,
         return1(128) TYPE c,
         type         TYPE i,
         return_file  TYPE string,
         v_email(128) TYPE c.
  DATA : p_file       TYPE localfile.

**TO DETERMINE THE CURRENT USERNAME DESKTOP
**PATH FOR CREATING FOLDER IN HIS SYSTEM.
  LOOP AT i_dpr_bupa_link_final1.
    v_pernr            = i_dpr_bupa_link_final1-pernr.
    CONCATENATE 'E0' v_pernr INTO v_businesspartner.
    SELECT SINGLE bpkind
           FROM but000
           INTO v_bpkind
           WHERE partner = v_businesspartner.
    CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1.
    IF NOT v_bpkind IS INITIAL.
      i_dpr_bupa_link_final1-bpkind = v_bpkind1.
      MODIFY i_dpr_bupa_link_final1
             INDEX sy-tabix
             TRANSPORTING bpkind.
    ELSE.
      DELETE i_dpr_bupa_link_final1 INDEX sy-tabix.
    ENDIF.
    CLEAR : v_bpkind, v_bpkind1, v_businesspartner, v_pernr.
  ENDLOOP.
  i_dpr_bupa_link_final2[] =  i_dpr_bupa_link_final1[].
  SORT i_dpr_bupa_link_final2 BY participant_guid.
  DELETE ADJACENT DUPLICATES FROM i_dpr_bupa_link_final2 COMPARING participant_guid.
  type = '00000000012'.
  CALL FUNCTION 'GUI_GET_DESKTOP_INFO'
    EXPORTING
      type   = type
    CHANGING
      return = return.

  CONCATENATE return '\DAR_' sy-datum '_' sy-uzeit INTO return.
  return1 = return.
  CALL FUNCTION 'GUI_CREATE_DIRECTORY'
    EXPORTING
      dirname = return1
    EXCEPTIONS
      failed  = 1
      OTHERS  = 2.

  return = return1.

  LOOP AT i_dpr_bupa_link_final2.
    v_skipflag = 0.
    v_index = sy-tabix.
    v_pernr            = i_dpr_bupa_link_final2-pernr.
    v_participant_guid = i_dpr_bupa_link_final2-participant_guid.
    v_int_order        = i_dpr_bupa_link_final2-project_id.
    v_bpkind2          = i_dpr_bupa_link_final2-bpkind.
*--Forming sheet name
    gv_index = sy-index .
    gv_outer_index = sy-index .
    gv_sheet_name = 'Detail Activity Report'.
***For email checking for individual PERNR
    CONCATENATE 'E0' v_pernr INTO v_businesspartner.
    wa_bapibus1006_head-bpartner = v_businesspartner.
    REFRESH : wa_bapiadsmtp.
    CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL'
      EXPORTING
        businesspartner = wa_bapibus1006_head-bpartner
        valid_date      = sy-datum
      TABLES
        bapiadsmtp      = wa_bapiadsmtp.
    IF wa_bapiadsmtp[] IS INITIAL.
      v_skipflag = 1.
    ELSE.
      REFRESH : wa_bapiadsmtp.
    ENDIF.

    LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid.
      IF
*         i_dpr_bupa_link_final1-lifnr      IS INITIAL OR
*         i_dpr_bupa_link_final1-name       IS INITIAL OR
         i_dpr_bupa_link_final1-pernr      IS INITIAL OR
         i_dpr_bupa_link_final1-project_id IS INITIAL OR
         i_dpr_bupa_link_final1-proj_name  IS INITIAL OR
         i_dpr_bupa_link_final1-name_pm    IS INITIAL OR
*         i_dpr_bupa_link_final1-object_key IS INITIAL OR
         i_dpr_bupa_link_final1-proj_desc  IS INITIAL.
        v_skipflag = 1.
      ENDIF.
      CONCATENATE i_dpr_bupa_link_final1-name_first i_dpr_bupa_link_final1-name_last INTO v_name SEPARATED BY space.
      IF v_name IS INITIAL.
        v_skipflag = 1.
      ENDIF.
      IF i_dpr_bupa_link_final1-object_key IS INITIAL AND
         i_dpr_bupa_link_final1-bpkind EQ 'DSR_ICDR'.
        v_skipflag = 1.
      ENDIF.
      IF i_dpr_bupa_link_final1-task_name      IS INITIAL OR
         i_dpr_bupa_link_final1-task_desc      IS INITIAL OR
         i_dpr_bupa_link_final1-task_type      IS INITIAL OR
         i_dpr_bupa_link_final1-role_text      IS INITIAL OR
         i_dpr_bupa_link_final1-beg_tmstmp_eng IS INITIAL OR
         i_dpr_bupa_link_final1-end_tmstmp_eng IS INITIAL OR
         i_dpr_bupa_link_final1-work_effort    IS INITIAL.
        v_skipflag = 1.
      ENDIF.
      CLEAR : v_name.
    ENDLOOP.
    CONCATENATE 'E0' v_pernr INTO v_businesspartner.
    SELECT SINGLE bpkind
           FROM but000
           INTO v_bpkind
           WHERE partner = v_businesspartner.
    CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1.
    IF NOT v_bpkind IS INITIAL.
      CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest
        EXPORTING
          sap_variant = v_bpkind1
          sap_pernr   = v_pernr
          beg_date    = p_begdt
          end_date    = p_enddt
        TABLES
          sap_icatsw  = i_etworklist.
    ENDIF.
    DELETE i_etworklist WHERE zzcpr_extid NE v_int_order.
    CLEAR : v_bpkind, v_bpkind1.
    IF i_etworklist[] IS INITIAL.
      v_skipflag = 1.
    ENDIF.

    IF v_skipflag = 0.
*--For the first loop, Excel is initiated and one new sheet is added
      CREATE OBJECT gs_excel 'EXCEL.APPLICATION' .
      GET PROPERTY OF gs_excel 'Visible' = v_vis.
* Set this property to open excel in background
      SET PROPERTY OF gs_excel 'Visible' = 'False' .
      GET PROPERTY OF gs_excel 'Workbooks' = gs_wbooklist .
      GET PROPERTY OF gs_wbooklist 'Application' = gs_application .
      SET PROPERTY OF gs_application 'SheetsInNewWorkbook' = 1 .
      CALL METHOD OF
          gs_wbooklist
          'Add'        = gs_wbook.
      GET PROPERTY OF gs_application 'ActiveSheet' = gs_activesheet .
      GET PROPERTY OF gs_excel 'ActiveWorkbook' = g_workbook.
      SET PROPERTY OF gs_activesheet 'Name' = gv_sheet_name .
      GET PROPERTY OF gs_activesheet 'Cells' = gs_cells.
      GET PROPERTY OF gs_cells 'Font' = gs_font .
      SET PROPERTY OF gs_font 'Name' = 'Arial' .
      SET PROPERTY OF gs_font 'Size' = '10' .
      gv_line_cntr = 1 . "line counter
*--Title
*--Selecting cell area to be merged.
      CALL METHOD OF
          gs_excel
          'Cells'  = gs_cell1
        EXPORTING
          #1       = 1
          #2       = 1.
      CALL METHOD OF
          gs_excel
          'Cells'  = gs_cell2
        EXPORTING
          #1       = 1
          #2       = 15.
      CALL METHOD OF
          gs_excel
          'Range'  = gs_cells
        EXPORTING
          #1       = gs_cell1
          #2       = gs_cell2.
      CALL METHOD OF
          gs_cells
          'Select'.
*--Merging
      CALL METHOD OF
          gs_cells
          'Merge'.
*--Setting title data
      CALL METHOD OF
          gs_excel
          'Cells'  = gs_cell1
        EXPORTING
          #1       = gv_line_cntr
          #2       = 1.
      SET PROPERTY OF gs_cells 'Value' = 'DETAIL ACTIVITY REPORT' .
*--Formatting the title
      GET PROPERTY OF gs_cells 'Font' = gs_font .
      SET PROPERTY OF gs_font 'Name' = 'Arial' .
      SET PROPERTY OF gs_font 'Size' = '12' .
      SET PROPERTY OF gs_font 'Underline' = 2 .
      SET PROPERTY OF gs_font 'Bold' = 1 .
      SET PROPERTY OF gs_cells 'HorizontalAlignment' = -4108 .
      GET PROPERTY OF gs_cells 'Interior' = gs_interior .
      SET PROPERTY OF gs_interior 'Color' = '10092543' .
      CALL METHOD OF
          gs_cells
          'BorderAround'

        EXPORTING
          #1             = 1 "continuous line
          #2             = 2. "thick
      SET PROPERTY OF gs_cells 'Locked' = 1.
      gv_line_cntr = gv_line_cntr + 2 .
      LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid.
        ON CHANGE OF i_dpr_bupa_link_final1-participant_guid.
          PERFORM header_data_display.
          PERFORM line_title_display.
          w_proid = i_dpr_bupa_link_final1-project_id.
          v_flag = 1.
        ENDON.
        IF v_flag = 1.
          v_flag = 0.
          CONTINUE.
        ENDIF.
        PERFORM line_item_display.
      ENDLOOP.
**Code Closed by LZ16662
**FOR DISPLAYING CATSWORKLIST DETAILS
**IN EXCEL SHEET
**CONSTANTS VALUE FOR ACTIVITY NUMBER BASED ON SYSTEM
*      CONCATENATE 'E0' v_pernr INTO v_businesspartner.
*      SELECT SINGLE bpkind
*             FROM but000
*             INTO v_bpkind
*             WHERE partner = v_businesspartner.
*      CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1.
*      IF NOT v_bpkind IS INITIAL.
*        CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest
*          EXPORTING
*            sap_variant = v_bpkind1
*            sap_pernr   = v_pernr
*            beg_date    = p_begdt
*            end_date    = p_enddt
*          TABLES
*            sap_icatsw  = i_etworklist.
*      ENDIF.
*      DELETE i_etworklist WHERE zzcpr_extid NE v_int_order.
*      CLEAR : v_int_order, v_bpkind.
**Code Closed by LZ16662
      gv_line_cntr = gv_line_cntr_1.
      gv_line_cntr = gv_line_cntr + 2 .

**FOR DISPLAYING COLOMN NAMES FOR CATSWORKLIST
      PERFORM cats_header_data.
**FOR DISPLAYING LINE ITEM DETAILS FOR CATSWORKLIST
      LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid
                                       AND flag EQ 'X'.
*        v_times = i_dpr_bupa_link_final1-days_total.
        v_temp_value = i_dpr_bupa_link_final1-days_total.          "work_effort.
        v_temp_value = ceil( v_temp_value ).
        v_effortvalue = v_temp_value.
        v_length = strlen( v_effortvalue ).
        v_length = v_length - 3.
        v_effortvalue = v_effortvalue+0(v_length).
        SHIFT v_effortvalue LEFT DELETING LEADING space.
        MOVE v_effortvalue TO v_effortvalue1.
        IF  v_effortvalue1 LE v_datediff.
          v_times = v_effortvalue1.
        ELSEIF v_effortvalue1 GT v_datediff.
          v_times = v_datediff.
        ENDIF.
        READ TABLE i_etworklist WITH KEY zzcpr_objgextid = i_dpr_bupa_link_final1-task_number.
        IF sy-subrc = 0.
          DO v_times TIMES.
            gv_line_cntr = gv_line_cntr + 1.
            PERFORM cats_line_data.
          ENDDO.
        ENDIF.
        CLEAR : v_effortvalue, v_length, v_times, v_effortvalue1, v_temp_value.
      ENDLOOP.
      CLEAR : v_bpkind2.
      PERFORM note_condition.
*      LOOP AT i_etworklist WHERE sebeln NE space.
*        gv_line_cntr = gv_line_cntr + 1.
*        PERFORM cats_line_data.
*      ENDLOOP.
*      SET PROPERTY OF gs_activesheet 'PROTECT' = 1.
      CALL METHOD OF
          gs_activesheet
          'PROTECT'

        EXPORTING
          #1             = 'dsr123##$'.
      CALL METHOD OF
          g_workbook
          'PROTECT'

        EXPORTING
          #1         = 'dsr123##$'.
      REFRESH : i_etworklist.
*    SET PROPERTY OF gs_activesheet 'PROTECT' = 1. "Protect sheet
**TO STORE THE EXCEL FILE FOR DIFFERENT PERSONNEL NUMBER
**TO STORE THE SAME IN CREATED DIRECTORY
*      CONCATENATE i_dpr_bupa_link_final2-name_first i_dpr_bupa_link_final2-name_last INTO v_save_name SEPARATED BY space.
      CONCATENATE i_dpr_bupa_link_final2-role_text '-' INTO v_save_name.
      return_file = return.
      CONCATENATE return '\'  i_dpr_bupa_link_final2-project_id '' v_pernr ''
                  v_save_name  sy-datum '-' sy-uzeit '.xls' INTO return_file.
      CALL METHOD OF
          gs_wbook
          'SaveAs'

        EXPORTING
          #1       = return_file.
*    SET PROPERTY OF gs_excel 'DisplayAlerts' = 0.
      PERFORM free_objects.
      CONCATENATE 'E0' v_pernr INTO v_businesspartner.
      wa_bapibus1006_head-bpartner = v_businesspartner.

      CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL'
        EXPORTING
          businesspartner = wa_bapibus1006_head-bpartner
          valid_date      = sy-datum
        TABLES
          bapiadsmtp      = wa_bapiadsmtp.
      IF NOT wa_bapiadsmtp[] IS INITIAL.
        READ TABLE wa_bapiadsmtp INDEX 1.

        IF sy-subrc = 0.
          v_email = wa_bapiadsmtp-e_mail.
          w_pernr = v_pernr.
          w_begdt = v_datebeg1.
          w_enddt = v_dateend1.
**EMAILING AN ATTACHMENT TO SAPUSER INBOX
          PERFORM emailing_document USING return_file
                                          v_email
                                          w_pernr
                                          w_proid
                                          w_begdt
                                          w_enddt.
          i_output-bpartner = v_businesspartner.
          i_output-mail     = v_email.
          i_output-status   = 'Sucessfully Mailed the Document'.
          APPEND i_output.
          CLEAR : i_output.
          v_sucess = v_sucess + 1.
        ELSE.
          i_output-bpartner = v_businesspartner.
          i_output-status   = 'Email Address not Maintained'.
          APPEND i_output.
          CLEAR : i_output.
          v_failure = v_failure + 1.
        ENDIF.
      ENDIF.
    ENDIF.
    CLEAR : v_participant_guid, v_pernr, return_file,
            v_businesspartner, wa_bapiadsmtp, wa_bapibus1006_head, v_email, w_proid, w_pernr, w_begdt, w_enddt,
            ws_pernr, ws_proid, ws_begdt, ws_enddt, v_times, v_save_name, return1.
    REFRESH : i_etworklist.
  ENDLOOP.

  LOOP AT i_output WHERE mail NE space.
    v_status1 = 1.
  ENDLOOP.
  LOOP AT i_output WHERE mail EQ space.
    v_status2 = 1.
  ENDLOOP.
  IF v_status1 = 1.
    WRITE : / 'Date   :', sy-datum.
    WRITE : / 'Time   :', sy-uzeit.
    WRITE : / 'Result :', v_sucess , 'Record''s mailed sucessfully'.
    WRITE : / sy-uline.
    WRITE : / sy-vline , AT 2 'BUSINESS PARTNER' CENTERED INTENSIFIED COLOR 4, AT 20 sy-vline,
            AT 30 'EMAIL-ID' CENTERED INTENSIFIED COLOR 4 , AT 125 sy-vline,
            AT 126 'STATUS' CENTERED INTENSIFIED COLOR 4, AT 179 sy-vline.
    WRITE : / sy-uline.
    LOOP AT i_output WHERE mail NE space.
      WRITE : / sy-vline, i_output-bpartner CENTERED INTENSIFIED COLOR 2, AT 20 sy-vline,
                AT 21  i_output-mail LEFT-JUSTIFIED INTENSIFIED COLOR 2, AT 125 sy-vline,
                AT 126 i_output-status LEFT-JUSTIFIED INTENSIFIED COLOR 5, AT 179 sy-vline.
      WRITE : / sy-uline.
    ENDLOOP.
  ENDIF.
  IF v_status2 = 1.

    WRITE : / 'Result :', v_failure , 'Record''s mailed unsucessfully'.
    WRITE : / sy-uline.
    WRITE : / sy-vline , AT 2 'BUSINESS PARTNER' CENTERED INTENSIFIED COLOR 4, sy-vline,
            AT 30 'EMAIL-ID' CENTERED INTENSIFIED COLOR 4 , AT 125 sy-vline,
            AT 126 'STATUS' CENTERED INTENSIFIED COLOR 4, AT 179 sy-vline.
    WRITE : / sy-uline.
    LOOP AT i_output WHERE mail EQ space.
      WRITE : / sy-vline, i_output-bpartner CENTERED INTENSIFIED COLOR 2, AT 20 sy-vline,
                AT 21 i_output-mail LEFT-JUSTIFIED INTENSIFIED COLOR 2, AT 125 sy-vline,
                AT 126 i_output-status LEFT-JUSTIFIED INTENSIFIED COLOR 6, AT 179 sy-vline.
      WRITE : / sy-uline.
    ENDLOOP.
  ENDIF.
*  MESSAGE ID 'YGF_ABR20640' TYPE 'I' NUMBER '002'
*              WITH v_index.
ENDFORM.                    " EXCEL_SHEET_APPLICATION
*&---------------------------------------------------------------------*
*&      Form  HEADER_DATA_DISPLAY
*&---------------------------------------------------------------------*
FORM header_data_display.
**To Fill LIFNR Vendor Title and Number
*--Writing data
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell2
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Range'  = gs_cells
    EXPORTING
      #1       = gs_cell1
      #2       = gs_cell2.
  CALL METHOD OF
      gs_cells
      'Select'.
**--Merging
  CALL METHOD OF
      gs_cells
      'Merge'.
  SET PROPERTY OF gs_cells 'Value' = 'Vendor Number'.
  SET PROPERTY OF gs_cells 'Locked' = 1.
*--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 2.

  IF NOT i_dpr_bupa_link_final1-lifnr IS INITIAL.
    SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-lifnr.
  ELSE.
    SET PROPERTY OF gs_cell1 'Value' = 'Not Applicable for FSEs'.
  ENDIF.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
**To Fill NAME Vendor Title and Name
  gv_line_cntr = gv_line_cntr + 1 .     "Header Counter
*--Writing data
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell2
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Range'  = gs_cells
    EXPORTING
      #1       = gs_cell1
      #2       = gs_cell2.
  CALL METHOD OF
      gs_cells
      'Select'.
*--Merging
  CALL METHOD OF
      gs_cells
      'Merge'.
  SET PROPERTY OF gs_cells 'Value' = 'Vendor Name'.
  SET PROPERTY OF gs_cells 'Locked' = 1.
  GET PROPERTY OF gs_cells 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 2.
  IF NOT i_dpr_bupa_link_final1-name IS INITIAL.
    SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-name.
  ELSE.
    SET PROPERTY OF gs_cell1 'Value' = 'Not Applicable for FSEs'.
  ENDIF.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
**To Fill PERNR Title and Number
  gv_line_cntr = gv_line_cntr + 1 .     "Header Counter
*--Writing data
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell2
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Range'  = gs_cells
    EXPORTING
      #1       = gs_cell1
      #2       = gs_cell2.
  CALL METHOD OF
      gs_cells
      'Select'.
*--Merging
  CALL METHOD OF
      gs_cells
      'Merge'.
  SET PROPERTY OF gs_cells 'Value' = 'Personnel Number'.
  SET PROPERTY OF gs_cells 'Locked' = 1.
  GET PROPERTY OF gs_cells 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 2.
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-pernr.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
**To Fill project_id Title and Number
  gv_line_cntr = gv_line_cntr + 1 .
*--Writing data
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell2
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Range'  = gs_cells
    EXPORTING
      #1       = gs_cell1
      #2       = gs_cell2.
  CALL METHOD OF
      gs_cells
      'Select'.
*--Merging
  CALL METHOD OF
      gs_cells
      'Merge'.
  SET PROPERTY OF gs_cells 'Value' = 'Internal Order'.
  SET PROPERTY OF gs_cells 'Locked' = 1.
  GET PROPERTY OF gs_cells 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 2.
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-project_id.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
**To Fill Project Name
  gv_line_cntr = gv_line_cntr + 1 .
*--Writing data
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell2
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Range'  = gs_cells
    EXPORTING
      #1       = gs_cell1
      #2       = gs_cell2.
  CALL METHOD OF
      gs_cells
      'Select'.
*--Merging
  CALL METHOD OF
      gs_cells
      'Merge'.
  SET PROPERTY OF gs_cells 'Value' = 'Project Name'.
  SET PROPERTY OF gs_cells 'Locked' = 1.
  GET PROPERTY OF gs_cells 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 2.
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-proj_name.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
**To Fill Project Manager Name
  gv_line_cntr = gv_line_cntr + 1 .
*--Writing data
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell2
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Range'  = gs_cells
    EXPORTING
      #1       = gs_cell1
      #2       = gs_cell2.
  CALL METHOD OF
      gs_cells
      'Select'.
*--Merging
  CALL METHOD OF
      gs_cells
      'Merge'.
  SET PROPERTY OF gs_cells 'Value' = 'Project Manager'.
  SET PROPERTY OF gs_cells 'Locked' = 1.
  GET PROPERTY OF gs_cells 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 2.
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-name_pm.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
**To Fill Firstname and Lastename
  gv_line_cntr = gv_line_cntr + 1 .
*--Writing data
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell2
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Range'  = gs_cells
    EXPORTING
      #1       = gs_cell1
      #2       = gs_cell2.
  CALL METHOD OF
      gs_cells
      'Select'.
*--Merging
  CALL METHOD OF
      gs_cells
      'Merge'.
  SET PROPERTY OF gs_cells 'Value' = 'Resource Name'.
  SET PROPERTY OF gs_cells 'Locked' = 1.
  GET PROPERTY OF gs_cells 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 2.
  CONCATENATE i_dpr_bupa_link_final1-name_first i_dpr_bupa_link_final1-name_last INTO v_name SEPARATED BY space.
  SET PROPERTY OF gs_cell1 'Value' = v_name.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CLEAR : v_name.
**To Fill Purchase Order
  gv_line_cntr = gv_line_cntr + 1 .
*--Writing data
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell2
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Range'  = gs_cells
    EXPORTING
      #1       = gs_cell1
      #2       = gs_cell2.
  CALL METHOD OF
      gs_cells
      'Select'.
*--Merging
  CALL METHOD OF
      gs_cells
      'Merge'.
  SET PROPERTY OF gs_cells 'Value' = 'Purchase Order'.
  SET PROPERTY OF gs_cells 'Locked' = 1.
  GET PROPERTY OF gs_cells 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 2.
  IF NOT i_dpr_bupa_link_final1-object_key IS INITIAL.
    SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-object_key .
  ELSE.
    SET PROPERTY OF gs_cell1 'Value' = 'Not Applicable for FSEs'.
  ENDIF.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  SET PROPERTY OF gs_cell1 'WrapText' = 1.
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
**Project Description
  gv_line_cntr = gv_line_cntr + 1 .
*--Writing data
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell2
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Range'  = gs_cells
    EXPORTING
      #1       = gs_cell1
      #2       = gs_cell2.
  CALL METHOD OF
      gs_cells
      'Select'.
*--Merging
  CALL METHOD OF
      gs_cells
      'Merge'.
  SET PROPERTY OF gs_cells 'Value' = 'Project Description'.
  SET PROPERTY OF gs_cells 'Locked' = 1.
  GET PROPERTY OF gs_cells 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '20' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 2.
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-proj_desc .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  SET PROPERTY OF gs_cell1 'WrapText' = 1.
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
**Report Start Date
  v_begyear1 = p_begdt+0(4).
  v_begmnt1  = p_begdt+4(2).
  v_begday1  = p_begdt+6(2).
  LOOP AT i_months_name WHERE mnr EQ v_begmnt1.
    v_month_name = i_months_name-ktx.
  ENDLOOP.
  CONCATENATE v_begday1 v_month_name v_begyear1 INTO v_begindate SEPARATED BY '-'.
  gv_line_cntr = gv_line_cntr + 1 .
*--Writing data
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell2
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Range'  = gs_cells
    EXPORTING
      #1       = gs_cell1
      #2       = gs_cell2.
  CALL METHOD OF
      gs_cells
      'Select'.
*--Merging
  CALL METHOD OF
      gs_cells
      'Merge'.
  SET PROPERTY OF gs_cells 'Value' = 'Report Start Date'.
  SET PROPERTY OF gs_cells 'Locked' = 1.
  GET PROPERTY OF gs_cells 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '20' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 2.
  SET PROPERTY OF gs_cell1 'NumberFormat' = '[$-409]d-mmm-yyyy;@'.
  SET PROPERTY OF gs_cell1 'Value' = v_begindate.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
**Report End Date
  v_endyear1 = p_enddt+0(4).
  v_endmnt1  = p_enddt+4(2).
  v_endday1  = p_enddt+6(2).
  LOOP AT i_months_name WHERE mnr EQ v_endmnt1.
    v_month_name = i_months_name-ktx.
  ENDLOOP.
  CONCATENATE v_endday1 v_month_name v_endyear1 INTO v_enddate1 SEPARATED BY '-'.
  gv_line_cntr = gv_line_cntr + 1 .
*--Writing data
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell2
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Range'  = gs_cells
    EXPORTING
      #1       = gs_cell1
      #2       = gs_cell2.
  CALL METHOD OF
      gs_cells
      'Select'.
*--Merging
  CALL METHOD OF
      gs_cells
      'Merge'.
  SET PROPERTY OF gs_cells 'Value' = 'Report End Date'.
  SET PROPERTY OF gs_cells 'Locked' = 1.
  GET PROPERTY OF gs_cells 'Font' = gs_font .
  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
*  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '20' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 2.
  SET PROPERTY OF gs_cell1 'NumberFormat' = '[$-409]d-mmm-yyyy;@'.
  SET PROPERTY OF gs_cell1 'Value' = v_enddate1.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  gv_line_cntr = gv_line_cntr + 2.         "Line Item Counter
ENDFORM.                    " HEADER_DATA_DISPLAY
*&---------------------------------------------------------------------*
*&      Form  line_title_DISPLAY
*&---------------------------------------------------------------------*
FORM line_title_display.
*----------------------------------------------------------------------*
*    TASK NAME                                                         *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 2.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'TASK NAME' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  gv_line_cntr_1 = gv_line_cntr.
  gv_line_cntr_1 = gv_line_cntr_1 + 1.
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr_1
      #2       = 1.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr_1
*    #2 = 2.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-task_name .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick

*----------------------------------------------------------------------*
*    TASK DESCRIPTION                                                  *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 2.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 4.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'TASK DESCRIPTION' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr_1
      #2       = 2.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr_1
*    #2 = 4.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-task_desc .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '30' .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  SET PROPERTY OF gs_cell1 'WrapText' = 1.
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*    TASK TYPE                                                         *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 3.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 6.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'TASK TYPE' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*1ST LINE OF TASK TYPE-SATYAJIT
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr_1
      #2       = 3.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr_1
*    #2 = 6.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-task_type .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*    ROLE TYPE                                                         *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 4.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 8.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'ROLE TYPE' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr_1
      #2       = 4.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr_1
*    #2 = 8.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-role_text .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '15' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*    ASSIGNMENT START DATE                                             *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 5.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 11.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'ASSIGNMENT START DATE' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '23' .
  SET PROPERTY OF gs_cell1 'WrapText' = 1.
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CLEAR : v_begyear1, v_begmnt1, v_begday1, v_begindate.
  v_begyear1 = i_dpr_bupa_link_final1-beg_tmstmp_eng+0(4).
  v_begmnt1  = i_dpr_bupa_link_final1-beg_tmstmp_eng+4(2).
  v_begday1  = i_dpr_bupa_link_final1-beg_tmstmp_eng+6(2).
  LOOP AT i_months_name WHERE mnr EQ v_begmnt1.
    v_month_name = i_months_name-ktx.
  ENDLOOP.
  CONCATENATE v_begday1 v_month_name v_begyear1 INTO v_begindate SEPARATED BY '-'.
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr_1
      #2       = 5.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr_1
*    #2 = 11.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'NumberFormat' = '[$-409]d-mmm-yyyy;@'.
  SET PROPERTY OF gs_cell1 'Value' = v_begindate .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '23' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*    ASSIGNMENT END DATE                                               *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 6.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 13.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'ASSIGNMENT END DATE' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '23' .
  SET PROPERTY OF gs_cell1 'WrapText' = 1.
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CLEAR : v_endyear1, v_endmnt1, v_endday1, v_enddate1.
  v_endyear1 = i_dpr_bupa_link_final1-end_tmstmp_eng+0(4).
  v_endmnt1  = i_dpr_bupa_link_final1-end_tmstmp_eng+4(2).
  v_endday1  = i_dpr_bupa_link_final1-end_tmstmp_eng+6(2).
  LOOP AT i_months_name WHERE mnr EQ v_endmnt1.
    v_month_name = i_months_name-ktx.
  ENDLOOP.
  CONCATENATE v_endday1 v_month_name v_endyear1 INTO v_enddate1 SEPARATED BY '-'.
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr_1
      #2       = 6.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr_1
*    #2 = 13.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'NumberFormat' = '[$-409]d-mmm-yyyy;@'.
  SET PROPERTY OF gs_cell1 'Value' = v_enddate1 .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '23' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*    ALLOCATED WORK EFFORTS                                            *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 7.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 16.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'ALLOCATED DAYS' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr_1
      #2       = 7.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr_1
*    #2 = 16.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-work_effort .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
ENDFORM.                                 "line_title_DISPLAY
*&---------------------------------------------------------------------*
*&      Form  LINE_ITEM_DISPLAY
*&---------------------------------------------------------------------*
FORM line_item_display.
  gv_line_cntr_1 = gv_line_cntr_1 + 1.
*----------------------------------------------------------------------*
*    TASK NAME                                                         *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr_1
      #2       = 1.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr_1
*    #2 = 2.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-task_name .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*    TASK DESCRIPTION                                                  *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr_1
      #2       = 2.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr_1
*    #2 = 4.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-task_desc .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '30' .
  SET PROPERTY OF gs_cell1 'WrapText' = 1.
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*    TASK TYPE                                                         *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr_1
      #2       = 3.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr_1
*    #2 = 6.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-task_type .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '15' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*    ROLE TYPE                                                         *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr_1
      #2       = 4.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr_1
*    #2 = 8.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-role_text .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4131 .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '15' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*    ASSIGNMENT START DATE                                             *
*----------------------------------------------------------------------*
  CLEAR : v_begyear1, v_begmnt1, v_begday1, v_begindate.
  v_begyear1 = i_dpr_bupa_link_final1-beg_tmstmp_eng+0(4).
  v_begmnt1  = i_dpr_bupa_link_final1-beg_tmstmp_eng+4(2).
  v_begday1  = i_dpr_bupa_link_final1-beg_tmstmp_eng+6(2).
  LOOP AT i_months_name WHERE mnr EQ v_begmnt1.
    v_month_name = i_months_name-ktx.
  ENDLOOP.
  CONCATENATE v_begday1 v_month_name v_begyear1 INTO v_begindate SEPARATED BY '-'.
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr_1
      #2       = 5.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr_1
*    #2 = 11.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'NumberFormat' = '[$-409]d-mmm-yyyy;@'.
  SET PROPERTY OF gs_cell1 'Value' = v_begindate .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '19' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*    ASSIGNMENT END DATE                                               *
*----------------------------------------------------------------------*
  CLEAR : v_endyear1, v_endmnt1, v_endday1, v_enddate1.
  v_endyear1 = i_dpr_bupa_link_final1-end_tmstmp_eng+0(4).
  v_endmnt1  = i_dpr_bupa_link_final1-end_tmstmp_eng+4(2).
  v_endday1  = i_dpr_bupa_link_final1-end_tmstmp_eng+6(2).
  LOOP AT i_months_name WHERE mnr EQ v_endmnt1.
    v_month_name = i_months_name-ktx.
  ENDLOOP.
  CONCATENATE v_endday1 v_month_name v_endyear1 INTO v_enddate1 SEPARATED BY '-'.
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr_1
      #2       = 6.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr_1
*    #2 = 13.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'NumberFormat' = '[$-409]d-mmm-yyyy;@'.
  SET PROPERTY OF gs_cell1 'Value' = v_enddate1 .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '19' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*    ALLOCATED WORK EFFORTS                                            *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr_1
      #2       = 7.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr_1
*    #2 = 16.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final1-work_effort .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
ENDFORM.                         "LINE_ITEM_DISPLAY
*&---------------------------------------------------------------------*
*&      Form  CATS_HEADER_DATA
*&---------------------------------------------------------------------*
FORM cats_header_data .
*----------------------------------------------------------------------*
* TASK ID                                                              *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 2.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'TASK ID' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
* TASK NAME                                                            *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 2.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 4.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'TASK NAME' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  WORK DATE                                                           *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 3.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 6.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'WORK DATE' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  DAYS                                                                *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 4.
  SET PROPERTY OF gs_cell1 'Value' = 'DAYS' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  ROLE TYPE                                                           *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 5.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 9.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'ROLE TYPE' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  UOM                                                                 *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 6.
  SET PROPERTY OF gs_cell1 'Value' = 'UOM' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  DATA ENTRY PROFILE                                                  *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 7.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 13.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'DATA ENTRY PROFILE' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '24' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  PERSONNEL NUMBER                                                    *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 8.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 16.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'PERSONNEL NUMBER' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '20' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  INTERNAL ORDER                                                      *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 9.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 18.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'INTERNAL ORDER' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '20' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  ACTIVITY TYPE                                                       *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 10.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 20.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'ACTIVITY TYPE' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '20' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  SENDER COST CENTER                                                  *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 11.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 23.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'SENDER COST CENTRE' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '29' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  PURCHASE ORDER                                                      *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 12.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 25.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'PURCHASE ORDER' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '20' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  LINE ITEM                                                           *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 13.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 27.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'LINE ITEM' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '14' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  PROJECT ID                                                          *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 14.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 29.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'PROJECT ID' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '16' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  ACTIVITY NUMBER (Service Master)                                    *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 15.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 32.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = 'ACTIVITY NUMBER (Service Master)' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 1 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '10092543' .
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '45'.
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
ENDFORM.                    " CATS_HEADER_DATA
*&---------------------------------------------------------------------*
*&      Form  CATS_LINE_DATA
*&---------------------------------------------------------------------*
FORM cats_line_data .
  DATA : v_task_id    TYPE char25,
         v_lstnr1(18) TYPE c,
         v_lstnr(19)  TYPE c.
*----------------------------------------------------------------------*
*  TASK ID                                                             *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 2.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  v_task_id = i_etworklist-zzcpr_objgextid.
  CONCATENATE '''' v_task_id INTO v_task_id.
  SET PROPERTY OF gs_cell1 'Value' = v_task_id.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
  SET PROPERTY OF gs_cell1 'ColumnWidth' = '22' .
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CLEAR : v_task_id.
*----------------------------------------------------------------------*
*  TASK NAME                                                           *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 2.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 4.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  READ TABLE i_dpr_bupa_link_final1 WITH KEY task_number = i_etworklist-zzcpr_objgextid.
  SET PROPERTY OF gs_cell1 'Value' =  i_dpr_bupa_link_final1-task_name.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  WORK DATE                                                           *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 3.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 6.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'NumberFormat' = '[$-409]d-mmm-yyyy;@'.
  SET PROPERTY OF gs_cell1 'Value' = ' ' .
  GET PROPERTY OF gs_cell1 'AddComment' = gs_comment .
  CALL METHOD OF
      gs_comment
      'Text'

    EXPORTING
      #1         = 'Enter Date Format in DD-MMM-YYYY'.
  SET PROPERTY OF gs_cell1 'Locked' = 0 .
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '65280' .
  SET PROPERTY OF gs_cell1 'WrapText' = 1.
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  DAYS                                                                *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 4.
  SET PROPERTY OF gs_cell1 'NumberFormat' = '0.000'.
  SET PROPERTY OF gs_cell1 'Value' = '0.000' .
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  GET PROPERTY OF gs_cell1 'Interior' = gs_interior .
  SET PROPERTY OF gs_interior 'Color' = '65280' .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  SET PROPERTY OF gs_cell1 'Locked' = 0 .
*----------------------------------------------------------------------*
*  ROLE TYPE                                                           *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 5.
**--Merging
  SET PROPERTY OF gs_cell1 'Value' = i_dpr_bupa_link_final2-role_text .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  UNIT OF MEASUREMENT                                                 *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 6.
  SET PROPERTY OF gs_cell1 'Value' = 'DA' .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
* DATA ENTRY PROFILE                                                   *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 7.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 13.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  IF v_bpkind2 EQ 'DSR_ICDR'.
    SET PROPERTY OF gs_cell1 'Value' = 'DSR_BICD' .
  ELSEIF v_bpkind2 EQ 'DSR_FSE'.
    SET PROPERTY OF gs_cell1 'Value' = 'DSR_BFSE' .
  ENDIF.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
* PERSONNAL NUMBER                                                     *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 8.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 16.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = v_pernr .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  INTERNAL ORDER                                                      *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 9.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 18.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  IF i_etworklist-raufnr IS INITIAL.
    SET PROPERTY OF gs_cell1 'Value' = ' ' .
  ELSE.
    SET PROPERTY OF gs_cell1 'Value' = i_etworklist-raufnr .
  ENDIF.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  ACTIVITY TYPE                                                       *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 10.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 20.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  IF i_etworklist-lstar IS INITIAL.
    SET PROPERTY OF gs_cell1 'Value' = ' ' .
  ELSE.
    SET PROPERTY OF gs_cell1 'Value' = i_etworklist-lstar .
  ENDIF.
  SET PROPERTY OF gs_cell1 'Locked' = 1 .
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  SENDER COST CENTRE                                                  *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 11.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 23.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  IF i_etworklist-skostl IS INITIAL.
    SET PROPERTY OF gs_cell1 'Value' = ' ' .
  ELSE.
    SET PROPERTY OF gs_cell1 'Value' = i_etworklist-skostl .
  ENDIF.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  PURCHASE ORDER                                                      *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 12.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 25.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
*  read table i_dpr_bupa_link_final1 key
  SET PROPERTY OF gs_cell1 'Value' = i_etworklist-sebeln.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  LINE ITEM                                                           *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 13.
* CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 27.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = i_etworklist-sebelp.
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  PROJECT ID                                                          *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 14.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 29.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  SET PROPERTY OF gs_cell1 'Value' = i_etworklist-zzcpr_extid .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
*----------------------------------------------------------------------*
*  ACTIVITY NUMBER                                                     *
*----------------------------------------------------------------------*
*--Title
*--Selecting cell area to be merged.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 15.
*  CALL METHOD OF gs_excel 'Cells' = gs_cell2
*    EXPORTING
*    #1 = gv_line_cntr
*    #2 = 32.
*  CALL METHOD OF gs_excel 'Range' = gs_cells
*    EXPORTING
*    #1 = gs_cell1
*    #2 = gs_cell2.
*  CALL METHOD OF gs_cells 'Select' .
**--Merging
*  CALL METHOD OF gs_cells 'Merge' .
  v_lstnr1 = i_etworklist-lstnr.
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = v_lstnr1
    IMPORTING
      output = v_lstnr1.
  CONCATENATE '''' v_lstnr1 INTO v_lstnr.
  SET PROPERTY OF gs_cell1 'Value' = v_lstnr .
  SET PROPERTY OF gs_cell1 'Locked' = 1.
**--Formatting the title
  GET PROPERTY OF gs_cell1 'Font' = gs_font .
*  SET PROPERTY OF gs_font 'Name' = 'Arial' .
*  SET PROPERTY OF gs_font 'Size' = '10' .
  SET PROPERTY OF gs_font 'Bold' = 0 .
  SET PROPERTY OF gs_cell1 'HorizontalAlignment' = -4108 .
  CALL METHOD OF
      gs_cell1
      'BorderAround'

    EXPORTING
      #1             = 1 "continuous line
      #2             = 2. "thick
  CLEAR : v_lstnr, v_lstnr1.
ENDFORM.                    " CATS_LINE_DATA
*&---------------------------------------------------------------------*
*&      Form  EMAILING_DOCUMENT
*&---------------------------------------------------------------------*
FORM emailing_document USING return_file
                             v_email
                             w_pernr
                             w_proid
                             w_begdt
                             w_enddt.

  ws_file  = return_file.
  ws_email = v_email.
  ws_pernr = w_pernr.
  ws_proid = w_proid.
  ws_begdt = w_begdt.
  ws_enddt = w_enddt.

  PERFORM bdc_dynpro      USING 'YGS_SEND_EXTERNAL_MAIL' '1000'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'WS_FILE'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=ONLI'.
  PERFORM bdc_field       USING 'WS_FILE'
                                 ws_file.
  PERFORM bdc_field       USING 'WS_EMAIL'
                                 ws_email.
  PERFORM bdc_field       USING 'WS_PERNR'
                                 ws_pernr.
  PERFORM bdc_field       USING 'WS_PROID'
                                 ws_proid.
  PERFORM bdc_field       USING 'WS_BEGDT'
                                 ws_begdt.
  PERFORM bdc_field       USING 'WS_ENDDT'
                                 ws_enddt.
  PERFORM bdc_dynpro      USING 'SAPLSO04' '1000'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=ENTR'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'SOS04-L_ADR_NAME(01)'.
  PERFORM bdc_field       USING 'SOS04-L_ADR_NAME(01)'
                                 v_email.
  PERFORM bdc_dynpro      USING 'SAPLSO04' '1000'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=SEND'.
  PERFORM bdc_field       USING 'BDC_CURSOR'
                                'SOS04-L_ADR_NAME(01)'.
  CALL TRANSACTION 'YG_EMAIL' USING bdcdata
                              MODE   'N'
                              UPDATE 'S'.
  REFRESH : bdcdata.
ENDFORM.                    " EMAILING_DOCUMENT
*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
  CLEAR bdcdata.
  bdcdata-program  = program.
  bdcdata-dynpro   = dynpro.
  bdcdata-dynbegin = 'X'.
  APPEND bdcdata.
ENDFORM.                    "BDC_DYNPRO
*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
  CLEAR bdcdata.
  bdcdata-fnam = fnam.
  bdcdata-fval = fval.
  APPEND bdcdata.
ENDFORM.                    "BDC_FIELD
*&---------------------------------------------------------------------*
*&      Form  EXCEL_SHEET_MAIL_RECIPIENT
*&---------------------------------------------------------------------*
FORM excel_sheet_mail_recipient USING p_recp.
  DATA : v_name TYPE char80,
         v_participant_guid TYPE dpr_tv_participant_guid,
         v_index TYPE sy-tabix,
         v_times(4) TYPE c,
         v_effortvalue(11) TYPE c,
         v_effortvalue1(4) TYPE n,
         v_length(4)  TYPE c,
         v_mail(3)    TYPE c VALUE 0.
  DATA : return(255)  TYPE c,
         return1(128) TYPE c,
         type         TYPE i,
         return_file  TYPE string,
         v_email(128) TYPE c,
         v_recp(128)  TYPE c.
  DATA : p_file       TYPE localfile.

**TO DETERMINE THE CURRENT USERNAME DESKTOP
**PATH FOR CREATING FOLDER IN HIS SYSTEM.
  LOOP AT i_dpr_bupa_link_final1.
    v_pernr            = i_dpr_bupa_link_final1-pernr.
    CONCATENATE 'E0' v_pernr INTO v_businesspartner.
    SELECT SINGLE bpkind
           FROM but000
           INTO v_bpkind
           WHERE partner = v_businesspartner.
    CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1.
    IF NOT v_bpkind IS INITIAL.
      i_dpr_bupa_link_final1-bpkind = v_bpkind1.
      MODIFY i_dpr_bupa_link_final1
             INDEX sy-tabix
             TRANSPORTING bpkind.
    ELSE.
      DELETE i_dpr_bupa_link_final1 INDEX sy-tabix.
    ENDIF.
    CLEAR : v_bpkind, v_bpkind1, v_businesspartner, v_pernr.
  ENDLOOP.
  i_dpr_bupa_link_final2[] =  i_dpr_bupa_link_final1[].
  SORT i_dpr_bupa_link_final2 BY participant_guid.
  DELETE ADJACENT DUPLICATES FROM i_dpr_bupa_link_final2 COMPARING participant_guid.
  type = '00000000012'.
  CALL FUNCTION 'GUI_GET_DESKTOP_INFO'
    EXPORTING
      type   = type
    CHANGING
      return = return.

  CONCATENATE return '\DAR_' sy-datum '_' sy-uzeit INTO return.
  return1 = return.
  CALL FUNCTION 'GUI_CREATE_DIRECTORY'
    EXPORTING
      dirname = return1
    EXCEPTIONS
      failed  = 1
      OTHERS  = 2.
  return = return1.
  LOOP AT i_dpr_bupa_link_final2.
    v_skipflag = 0.
    v_index = sy-tabix.
    v_pernr            = i_dpr_bupa_link_final2-pernr.
    v_participant_guid = i_dpr_bupa_link_final2-participant_guid.
    v_int_order        = i_dpr_bupa_link_final2-project_id.
    v_bpkind2          = i_dpr_bupa_link_final2-bpkind.
*--Forming sheet name
    gv_index = sy-index .
    gv_outer_index = sy-index .
    gv_sheet_name = 'Detail Activity Report'.

***For email checking for individual PERNR
    CONCATENATE 'E0' v_pernr INTO v_businesspartner.
    wa_bapibus1006_head-bpartner = v_businesspartner.
    REFRESH : wa_bapiadsmtp.
    CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL'
      EXPORTING
        businesspartner = wa_bapibus1006_head-bpartner
        valid_date      = sy-datum
      TABLES
        bapiadsmtp      = wa_bapiadsmtp.
    IF wa_bapiadsmtp[] IS INITIAL.
      v_skipflag = 1.
    ELSE.
      REFRESH : wa_bapiadsmtp.
    ENDIF.

    LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid.
      IF
*         i_dpr_bupa_link_final1-lifnr      IS INITIAL OR
*         i_dpr_bupa_link_final1-name       IS INITIAL OR
         i_dpr_bupa_link_final1-pernr      IS INITIAL OR
         i_dpr_bupa_link_final1-project_id IS INITIAL OR
         i_dpr_bupa_link_final1-proj_name  IS INITIAL OR
         i_dpr_bupa_link_final1-name_pm    IS INITIAL OR
*         i_dpr_bupa_link_final1-object_key IS INITIAL OR
         i_dpr_bupa_link_final1-proj_desc  IS INITIAL.
        v_skipflag = 1.
      ENDIF.
      CONCATENATE i_dpr_bupa_link_final1-name_first i_dpr_bupa_link_final1-name_last INTO v_name SEPARATED BY space.
      IF v_name IS INITIAL.
        v_skipflag = 1.
      ENDIF.
      IF i_dpr_bupa_link_final1-object_key IS INITIAL AND
        i_dpr_bupa_link_final1-bpkind EQ 'DSR_ICDR'.
        v_skipflag = 1.
      ENDIF.
      IF i_dpr_bupa_link_final1-task_name      IS INITIAL OR
         i_dpr_bupa_link_final1-task_desc      IS INITIAL OR
         i_dpr_bupa_link_final1-task_type      IS INITIAL OR
         i_dpr_bupa_link_final1-role_text      IS INITIAL OR
         i_dpr_bupa_link_final1-beg_tmstmp_eng IS INITIAL OR
         i_dpr_bupa_link_final1-end_tmstmp_eng IS INITIAL OR
         i_dpr_bupa_link_final1-work_effort    IS INITIAL.
        v_skipflag = 1.
      ENDIF.
      CLEAR : v_name.
    ENDLOOP.
    CONCATENATE 'E0' v_pernr INTO v_businesspartner.
    SELECT SINGLE bpkind
           FROM but000
           INTO v_bpkind
           WHERE partner = v_businesspartner.
    CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1.
    IF NOT v_bpkind IS INITIAL.
      CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest
        EXPORTING
          sap_variant = v_bpkind1
          sap_pernr   = v_pernr
          beg_date    = p_begdt
          end_date    = p_enddt
        TABLES
          sap_icatsw  = i_etworklist.
    ENDIF.
    DELETE i_etworklist WHERE zzcpr_extid NE v_int_order.
    CLEAR : v_bpkind, v_bpkind1.
    IF i_etworklist[] IS INITIAL.
      v_skipflag = 1.
    ENDIF.

    IF v_skipflag = 0.
*--For the first loop, Excel is initiated and one new sheet is added
      CREATE OBJECT gs_excel 'EXCEL.APPLICATION' .
      GET PROPERTY OF gs_excel 'Visible' = v_vis.
*set this property to open excel in background
      SET PROPERTY OF gs_excel 'Visible' = 'False' .
      GET PROPERTY OF gs_excel 'Workbooks' = gs_wbooklist .
      GET PROPERTY OF gs_wbooklist 'Application' = gs_application .
      SET PROPERTY OF gs_application 'SheetsInNewWorkbook' = 1 .
      CALL METHOD OF
          gs_wbooklist
          'Add'        = gs_wbook.
      GET PROPERTY OF gs_application 'ActiveSheet' = gs_activesheet .
      GET PROPERTY OF gs_excel 'ActiveWorkbook' = g_workbook.
      SET PROPERTY OF gs_activesheet 'Name' = gv_sheet_name .
      GET PROPERTY OF gs_activesheet 'Cells' = gs_cells.
      GET PROPERTY OF gs_cells 'Font' = gs_font .
      SET PROPERTY OF gs_font 'Name' = 'Arial' .
      SET PROPERTY OF gs_font 'Size' = '10' .
      gv_line_cntr = 1 . "line counter
*--Title
*--Selecting cell area to be merged.
      CALL METHOD OF
          gs_excel
          'Cells'  = gs_cell1
        EXPORTING
          #1       = 1
          #2       = 1.
      CALL METHOD OF
          gs_excel
          'Cells'  = gs_cell2
        EXPORTING
          #1       = 1
          #2       = 15.
      CALL METHOD OF
          gs_excel
          'Range'  = gs_cells
        EXPORTING
          #1       = gs_cell1
          #2       = gs_cell2.
      CALL METHOD OF
          gs_cells
          'Select'.
*--Merging
      CALL METHOD OF
          gs_cells
          'Merge'.
*--Setting title data
      CALL METHOD OF
          gs_excel
          'Cells'  = gs_cell1
        EXPORTING
          #1       = gv_line_cntr
          #2       = 1.
      SET PROPERTY OF gs_cells 'Value' = 'DETAIL ACTIVITY REPORT' .
      SET PROPERTY OF gs_cells 'Locked' = 1.
      GET PROPERTY OF gs_cells 'Font' = gs_font .
      SET PROPERTY OF gs_font 'Name' = 'Arial' .
      SET PROPERTY OF gs_font 'Size' = '12' .
      SET PROPERTY OF gs_font 'Underline' = 2 .
      SET PROPERTY OF gs_font 'Bold' = 1 .
      SET PROPERTY OF gs_cells 'HorizontalAlignment' = -4108 .
      GET PROPERTY OF gs_cells 'Interior' = gs_interior .
      SET PROPERTY OF gs_interior 'Color' = '10092543' .
      CALL METHOD OF
          gs_cells
          'BorderAround'

        EXPORTING
          #1             = 1 "continuous line
          #2             = 2. "thick
**--Formatting the title
      gv_line_cntr = gv_line_cntr + 2 .
      LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid.
        ON CHANGE OF i_dpr_bupa_link_final1-participant_guid.
          PERFORM header_data_display.
          PERFORM line_title_display.
          w_proid = i_dpr_bupa_link_final1-project_id.
          v_flag = 1.
        ENDON.
        IF v_flag = 1.
          v_flag = 0.
          CONTINUE.
        ENDIF.
        PERFORM line_item_display.
      ENDLOOP.
**Code Closed by LZ16662
**FOR DISPLAYING CATSWORKLIST DETAILS
**IN EXCEL SHEET
**CONSTANTS VALUE FOR ACTIVITY NUMBER BASED ON SYSTEM
*      CONCATENATE 'E0' v_pernr INTO v_businesspartner.
*      SELECT SINGLE bpkind
*             FROM but000
*             INTO v_bpkind
*             WHERE partner = v_businesspartner.
*      CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1.
*      IF NOT v_bpkind IS INITIAL.
*        CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest
*          EXPORTING
*            sap_variant = v_bpkind1
*            sap_pernr   = v_pernr
*            beg_date    = p_begdt
*            end_date    = p_enddt
*          TABLES
*            sap_icatsw  = i_etworklist.
*      ENDIF.
*      DELETE i_etworklist WHERE zzcpr_extid NE v_int_order.
*      CLEAR : v_int_order, v_bpkind.
**Code Closed by LZ16662
      gv_line_cntr = gv_line_cntr_1.
      gv_line_cntr = gv_line_cntr + 2 .
**FOR DISPLAYING COLOMN NAMES FOR CATSWORKLIST
      PERFORM cats_header_data.
**FOR DISPLAYING LINE ITEM DETAILS FOR CATSWORKLIST
      LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid
                                     AND flag EQ 'X'.
*        v_times = i_dpr_bupa_link_final1-days_total.
        v_temp_value = i_dpr_bupa_link_final1-days_total.      "work_effort.
        v_temp_value = ceil( v_temp_value ).
        v_effortvalue = v_temp_value.
        v_length = strlen( v_effortvalue ).
        v_length = v_length - 3.
        v_effortvalue = v_effortvalue+0(v_length).
        SHIFT v_effortvalue LEFT DELETING LEADING space.
        MOVE v_effortvalue TO v_effortvalue1.
        IF  v_effortvalue1 LE v_datediff.
          v_times = v_effortvalue1.
        ELSEIF v_effortvalue1 GT v_datediff.
          v_times = v_datediff.
        ENDIF.
        READ TABLE i_etworklist WITH KEY zzcpr_objgextid = i_dpr_bupa_link_final1-task_number.
        IF sy-subrc = 0.
          DO v_times TIMES.
            gv_line_cntr = gv_line_cntr + 1.
            PERFORM cats_line_data.
          ENDDO.
        ENDIF.
        CLEAR : v_effortvalue, v_length, v_times, v_effortvalue1, v_temp_value.
      ENDLOOP.
      CLEAR : v_bpkind2.
*    LOOP AT i_etworklist WHERE sebeln NE space.
*      gv_line_cntr = gv_line_cntr + 1.
*      PERFORM cats_line_data.
*    ENDLOOP.
      PERFORM note_condition.
*      SET PROPERTY OF gs_activesheet 'PROTECT' = 1.
      CALL METHOD OF
          gs_activesheet
          'PROTECT'

        EXPORTING
          #1             = 'dsr123##$'.
      CALL METHOD OF
          g_workbook
          'PROTECT'

        EXPORTING
          #1         = 'dsr123##$'.
      REFRESH : i_etworklist.
**TO STORE THE EXCEL FILE FOR DIFFERENT PERSONNEL NUMBER
**TO STORE THE SAME IN CREATED DIRECTORY
*      CONCATENATE i_dpr_bupa_link_final2-name_first i_dpr_bupa_link_final1-name_last INTO v_save_name SEPARATED BY space.
      CONCATENATE i_dpr_bupa_link_final2-role_text '-' INTO v_save_name.
      return_file = return.
      CONCATENATE return '\'  i_dpr_bupa_link_final2-project_id '' v_pernr ''
                  v_save_name sy-datum '-' sy-uzeit '.xls' INTO return_file.
      CALL METHOD OF
          gs_wbook
          'SaveAs'

        EXPORTING
          #1       = return_file.
*    SET PROPERTY OF gs_excel 'DisplayAlerts' = 0.
      PERFORM free_objects.

      CONCATENATE 'E0' v_pernr INTO v_businesspartner.
      wa_bapibus1006_head-bpartner = v_businesspartner.

      CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL'
        EXPORTING
          businesspartner = wa_bapibus1006_head-bpartner
          valid_date      = sy-datum
        TABLES
          bapiadsmtp      = wa_bapiadsmtp.
      IF NOT wa_bapiadsmtp[] IS INITIAL.
        READ TABLE wa_bapiadsmtp INDEX 1.
        IF sy-subrc = 0.
**EMAILING AN ATTACHMENT TO RECIPIENT ADDRESS SPECIFIED
          v_email = wa_bapiadsmtp-e_mail.
          w_pernr = v_pernr.
          w_begdt = v_datebeg1.
          w_enddt = v_dateend1.
          PERFORM emailing_document USING return_file
                                          v_email
                                          w_pernr
                                          w_proid
                                          w_begdt
                                          w_enddt.
          i_output-bpartner = v_businesspartner.
          i_output-mail     = v_email.
          i_output-status   = 'Sucessfully Mailed the Document'.
          APPEND i_output.
          CLEAR : i_output.
          v_sucess = v_sucess + 1.
        ELSE.
          i_output-bpartner = v_businesspartner.
          i_output-status   = 'Email Address not Maintained'.
          APPEND i_output.
          CLEAR : i_output.
          v_failure = v_failure + 1.
        ENDIF.
      ENDIF.
**EMAILING AN ATTACHMENT COPY TO RECIPIENT ADDRESS SPECIFIED
      v_email = p_recp.
      w_pernr = v_pernr.
      w_begdt = v_datebeg1.
      w_enddt = v_dateend1.
      PERFORM emailing_document USING return_file
                                      v_email
                                      w_pernr
                                      w_proid
                                      w_begdt
                                      w_enddt.
      v_mail = v_mail + 1.
    ENDIF.
    CLEAR : v_participant_guid, v_pernr, return_file,
        v_businesspartner, wa_bapiadsmtp, wa_bapibus1006_head, v_email, w_proid, w_pernr, w_begdt, w_enddt,
        ws_pernr, ws_proid, ws_begdt, ws_enddt, v_times, v_save_name, return1.
    REFRESH : i_etworklist.
  ENDLOOP.
  LOOP AT i_output WHERE mail NE space.
    v_status1 = 1.
  ENDLOOP.
  LOOP AT i_output WHERE mail EQ space.
    v_status2 = 1.
  ENDLOOP.

  IF v_status1 = 1.
    WRITE : / 'Date   :', sy-datum.
    WRITE : / 'Time   :', sy-uzeit.
    WRITE : / 'Result :', v_sucess , 'Record''s mailed sucessfully'.
    WRITE : / sy-uline.
    WRITE : / sy-vline , AT 2 'BUSINESS PARTNER' CENTERED INTENSIFIED COLOR 4, AT 20 sy-vline,
            AT 30 'EMAIL-ID' CENTERED INTENSIFIED COLOR 4 , AT 125 sy-vline,
            AT 126 'STATUS' CENTERED INTENSIFIED COLOR 4, AT 179 sy-vline.
    WRITE : / sy-uline.
    LOOP AT i_output WHERE mail NE space.
      WRITE : / sy-vline, i_output-bpartner CENTERED INTENSIFIED COLOR 2, AT 20 sy-vline,
                AT 21  i_output-mail LEFT-JUSTIFIED INTENSIFIED COLOR 2, AT 125 sy-vline,
                AT 126 i_output-status LEFT-JUSTIFIED INTENSIFIED COLOR 5, AT 179 sy-vline.
      WRITE : / sy-uline.
    ENDLOOP.
  ENDIF.
  IF v_status2  = 1.
    WRITE : / 'Result :', v_failure , 'Record''s mailed unsucessfully'.
    WRITE : / sy-uline.
    WRITE : / sy-vline , AT 2 'BUSINESS PARTNER' CENTERED INTENSIFIED COLOR 4, sy-vline,
            AT 30 'EMAIL-ID' CENTERED INTENSIFIED COLOR 4 , AT 125 sy-vline,
            AT 126 'STATUS' CENTERED INTENSIFIED COLOR 4, AT 179 sy-vline.
    WRITE : / sy-uline.
    LOOP AT i_output WHERE mail EQ space.
      WRITE : / sy-vline, i_output-bpartner CENTERED INTENSIFIED COLOR 2, AT 20 sy-vline,
                AT 21 i_output-mail LEFT-JUSTIFIED INTENSIFIED COLOR 2, AT 125 sy-vline,
                AT 126 i_output-status LEFT-JUSTIFIED INTENSIFIED COLOR 6, AT 179 sy-vline.
      WRITE : / sy-uline.
    ENDLOOP.
  ENDIF.
  IF v_mail NE 0.
    WRITE : / 'Result :', 'Record''s mailed sucessfully to -' INTENSIFIED COLOR 5 , p_recp INTENSIFIED COLOR 5.
  ELSE.
    WRITE : / 'Result :', 'Record''s mailed unsucessfully to -' INTENSIFIED COLOR 6 , p_recp INTENSIFIED COLOR 6.
  ENDIF.
ENDFORM.                    " EXCEL_SHEET_MAIL_RECIPIENT
*&---------------------------------------------------------------------*
*&      Form  BATCH_PROCESS_EMAIL
*&---------------------------------------------------------------------*
FORM batch_process_email USING p_recp .
  DATA : v_participant_guid TYPE dpr_tv_participant_guid,
         v_name TYPE char80,
         v_index TYPE sy-tabix,
         v_times(4) TYPE c,
         v_effortvalue(11) TYPE c,
         v_effortvalue1(4) TYPE n,
         v_length(4) TYPE c.

  v_recp = p_recp.
  LOOP AT i_dpr_bupa_link_final1.
    v_pernr            = i_dpr_bupa_link_final1-pernr.
    CONCATENATE 'E0' v_pernr INTO v_businesspartner.
    SELECT SINGLE bpkind
           FROM but000
           INTO v_bpkind
           WHERE partner = v_businesspartner.
    CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1.
    IF NOT v_bpkind IS INITIAL.
      i_dpr_bupa_link_final1-bpkind = v_bpkind1.
      MODIFY i_dpr_bupa_link_final1
             INDEX sy-tabix
             TRANSPORTING bpkind.
    ELSE.
      DELETE i_dpr_bupa_link_final1 INDEX sy-tabix.
    ENDIF.
    CLEAR : v_bpkind, v_bpkind1, v_businesspartner, v_pernr.
  ENDLOOP.
  i_dpr_bupa_link_final2[] =  i_dpr_bupa_link_final1[].
  SORT i_dpr_bupa_link_final2 BY participant_guid.
  DELETE ADJACENT DUPLICATES FROM i_dpr_bupa_link_final2 COMPARING participant_guid.
  LOOP AT i_dpr_bupa_link_final2.
    v_skipflag = 0.
    v_pernr            = i_dpr_bupa_link_final2-pernr.
    v_participant_guid = i_dpr_bupa_link_final2-participant_guid.
    v_int_order        = i_dpr_bupa_link_final2-project_id.
    v_bpkind2          = i_dpr_bupa_link_final2-bpkind.

    LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid.
      IF
*         i_dpr_bupa_link_final1-lifnr      IS INITIAL OR
*         i_dpr_bupa_link_final1-name       IS INITIAL OR
       i_dpr_bupa_link_final1-pernr      IS INITIAL OR
       i_dpr_bupa_link_final1-project_id IS INITIAL OR
       i_dpr_bupa_link_final1-proj_name  IS INITIAL OR
       i_dpr_bupa_link_final1-name_pm    IS INITIAL OR
*         i_dpr_bupa_link_final1-object_key IS INITIAL OR
       i_dpr_bupa_link_final1-proj_desc  IS INITIAL.
        v_skipflag = 1.
      ENDIF.
      CONCATENATE i_dpr_bupa_link_final1-name_first i_dpr_bupa_link_final1-name_last INTO v_name SEPARATED BY space.
      IF v_name IS INITIAL.
        v_skipflag = 1.
      ENDIF.
      IF i_dpr_bupa_link_final1-object_key IS INITIAL AND
        i_dpr_bupa_link_final1-bpkind EQ 'DSR_ICDR'.
        v_skipflag = 1.
      ENDIF.
      IF i_dpr_bupa_link_final1-task_name      IS INITIAL OR
         i_dpr_bupa_link_final1-task_desc      IS INITIAL OR
         i_dpr_bupa_link_final1-task_type      IS INITIAL OR
         i_dpr_bupa_link_final1-role_text      IS INITIAL OR
         i_dpr_bupa_link_final1-beg_tmstmp_eng IS INITIAL OR
         i_dpr_bupa_link_final1-end_tmstmp_eng IS INITIAL OR
         i_dpr_bupa_link_final1-work_effort    IS INITIAL.
        v_skipflag = 1.
      ENDIF.
      CLEAR : v_name.
    ENDLOOP.
    CONCATENATE 'E0' v_pernr INTO v_businesspartner.
    SELECT SINGLE bpkind
           FROM but000
           INTO v_bpkind
           WHERE partner = v_businesspartner.
    CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1.
    IF NOT v_bpkind IS INITIAL.
      CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest
        EXPORTING
          sap_variant = v_bpkind1
          sap_pernr   = v_pernr
          beg_date    = p_begdt
          end_date    = p_enddt
        TABLES
          sap_icatsw  = i_etworklist.
    ENDIF.
    DELETE i_etworklist WHERE zzcpr_extid NE v_int_order.
    CLEAR : v_bpkind, v_bpkind1.
    IF i_etworklist[] IS INITIAL.
      v_skipflag = 1.
    ENDIF.

    IF v_skipflag = 0.
      LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid.
        ON CHANGE OF i_dpr_bupa_link_final1-participant_guid.
          IF NOT i_dpr_bupa_link_final1-lifnr IS INITIAL.
            CONCATENATE 'Vendor Number :'
                               i_dpr_bupa_link_final1-lifnr
                               INTO w_attachment
                               SEPARATED BY con_tab.
            PERFORM load_data_to_attachment.
          ELSE.
            CONCATENATE 'Vendor Number :'
                                 'Not Applicable for FSEs'
                                 INTO w_attachment
                                 SEPARATED BY con_tab.
            PERFORM load_data_to_attachment.
          ENDIF.
          IF NOT i_dpr_bupa_link_final1-name IS INITIAL.
            CONCATENATE 'Vendor Name :'
                        i_dpr_bupa_link_final1-name
                        INTO w_attachment
                        SEPARATED BY con_tab.
            PERFORM load_data_to_attachment.
          ELSE.
            CONCATENATE 'Vendor Name :'
                       'Not Applicable for FSEs'
                       INTO w_attachment
                       SEPARATED BY con_tab.
            PERFORM load_data_to_attachment.
          ENDIF.
          CONCATENATE 'Personnel Number :'
                      i_dpr_bupa_link_final1-pernr
                      INTO w_attachment
                      SEPARATED BY con_tab.
          PERFORM load_data_to_attachment.
          CONCATENATE 'Internal Order :'
                      i_dpr_bupa_link_final1-project_id
                      INTO w_attachment
                      SEPARATED BY con_tab.
          PERFORM load_data_to_attachment.
          CONCATENATE 'Project Name :'
                      i_dpr_bupa_link_final1-proj_name
                      INTO w_attachment
                      SEPARATED BY con_tab.
          PERFORM load_data_to_attachment.
          CONCATENATE 'Project Manager'
                      i_dpr_bupa_link_final1-name_pm
                      INTO w_attachment
                      SEPARATED BY con_tab.
          PERFORM load_data_to_attachment.
          CONCATENATE i_dpr_bupa_link_final1-name_first i_dpr_bupa_link_final1-name_last  INTO v_name  SEPARATED BY space.
          CONCATENATE v_pernr i_dpr_bupa_link_final1-project_id INTO v_name_sub SEPARATED BY '-'.
          CONCATENATE 'Resource Name :'
                      v_name
                      INTO w_attachment
                      SEPARATED BY con_tab.
          PERFORM load_data_to_attachment.
          IF NOT i_dpr_bupa_link_final1-object_key IS INITIAL.
            CONCATENATE 'Purchase Order :'
                        i_dpr_bupa_link_final1-object_key
                        INTO w_attachment
                        SEPARATED BY con_tab.
            PERFORM load_data_to_attachment.
          ELSE.
            CONCATENATE 'Purchase Order :'
                        'Not Applicable for FSEs'
                        INTO w_attachment
                        SEPARATED BY con_tab.
            PERFORM load_data_to_attachment.
          ENDIF.
          CONCATENATE 'Project Description :'
                      i_dpr_bupa_link_final1-proj_desc
                      INTO w_attachment
                      SEPARATED BY con_tab.
          PERFORM load_data_to_attachment.
          CONCATENATE 'Report Start Date :'
                      v_datebeg
                      INTO w_attachment
                      SEPARATED BY con_tab.
          PERFORM load_data_to_attachment.
          CONCATENATE 'Report End Date :'
                      v_dateend
                      INTO w_attachment
                      SEPARATED BY con_tab.
          PERFORM load_data_to_attachment.
          CLEAR : v_name.
**Appending Extra Lines for Seperating
          PERFORM load_data_to_attachment.      "Appending Blank Lines
          PERFORM load_data_to_attachment.      "Appending Blank Lines
**2nd Stage
          CONCATENATE 'TASK NAME'
                      'TASK DESCRIPTION'
                      'TASK TYPE'
                      'ROLE TYPE'
                      'ASSIGNMENT START DATE'
                      'ASSIGNMENT END DATE'
                      'ALLOCATED DAYS'
                      '         '
                      '         '
                      '         '
                      '         '
                      '         '
                      INTO w_attachment
                      SEPARATED BY con_tab.
          PERFORM load_data_to_attachment.
**2nd stage 1st line item.
          PERFORM line_item_project_details.
          v_flag = 1.
        ENDON.
        IF v_flag = 1.
          v_flag = 0.
          CONTINUE.
        ENDIF.
        PERFORM line_item_project_details.
      ENDLOOP.
**Code Closed by LZ16662
**FOR DISPLAYING CATSWORKLIST DETAILS
**IN EXCEL SHEET
**CONSTANTS VALUE FOR ACTIVITY NUMBER BASED ON SYSTEM
*      CONCATENATE 'E0' v_pernr INTO v_businesspartner.
*      SELECT SINGLE bpkind
*             FROM but000
*             INTO v_bpkind
*             WHERE partner = v_businesspartner.
*      CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1.
*      IF NOT v_bpkind IS INITIAL.
*        CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest
*          EXPORTING
*            sap_variant   = v_bpkind1
*            sap_pernr     = v_pernr
*            beg_date      = p_begdt
*            end_date      = p_enddt
*          IMPORTING
*            sap_startdate = v_start_date
*            sap_enddate   = v_end_date
*          TABLES
*            sap_icatsw    = i_etworklist.
*      ENDIF.
*      DELETE i_etworklist WHERE zzcpr_extid NE v_int_order.
*      CLEAR : v_int_order, v_bpkind.
**Code Closed by LZ16662
**Appending Extra Lines for Seperating
      PERFORM load_data_to_attachment.      "Appending Blank Lines
**FOR DISPLAYING COLOMN NAMES FOR CATSWORKLIST
**3rd Stage
      CONCATENATE 'TASK ID'
                  'TASK NAME'
                  'WORK DATE'
                  'DAYS'
                  'ROLE TYPE'
                  'UOM'
                  'DATA ENTRY PROFILE'
                  'PERSONNEL NUMBER'
                  'INTERNAL ORDER'
                  'ACTIVITY TYPE'
                  'SENDER COST CENTRE'
                  'PURCHASE ORDER'
                  'LINE ITEM'
                  'PROJECT ID'
                  'ACTIVITY NUMBER (Service Master)'
                  '   '
                  INTO w_attachment
                  SEPARATED BY con_tab.
      PERFORM load_data_to_attachment.
**FOR DISPLAYING LINE ITEM DETAILS FOR CATSWORKLIST
      LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid.
        v_temp_value = i_dpr_bupa_link_final1-work_effort.
        v_temp_value = ceil( v_temp_value ).
        v_effortvalue = v_temp_value.
        v_length = strlen( v_effortvalue ).
        v_length = v_length - 3.
        v_effortvalue = v_effortvalue+0(v_length).
        SHIFT v_effortvalue LEFT DELETING LEADING space.
        MOVE v_effortvalue TO v_effortvalue1.
        IF  v_effortvalue1 LE v_datediff.
          v_times = v_effortvalue1.
        ELSEIF v_effortvalue1 GT v_datediff.
          v_times = v_datediff.
        ENDIF.
        READ TABLE i_etworklist WITH KEY zzcpr_objgextid = i_dpr_bupa_link_final1-task_number.
        IF sy-subrc = 0.
          DO v_times TIMES.
            PERFORM cats_line_data_output.
          ENDDO.
        ENDIF.
        CLEAR : v_effortvalue, v_length, v_times, v_effortvalue1, v_temp_value.
      ENDLOOP.
      CLEAR : v_bpkind2.
      PERFORM load_data_to_attachment.      "Appending Blank Lines
      PERFORM load_data_to_attachment.      "Appending Blank Lines
      CONCATENATE 'Note : Task Name is repeated No.'
                  'of days the task has been allocated'
                  'within the Report Period.'
                  INTO w_attachment.
*                  SEPARATED BY con_tab.
      PERFORM load_data_to_attachment.
*    LOOP AT i_etworklist WHERE sebeln NE space.
*      PERFORM cats_line_data_output.
*    ENDLOOP.
      REFRESH : i_etworklist.
**Determine the Business Partner Address
      CONCATENATE 'E0' v_pernr INTO v_businesspartner.
      wa_bapibus1006_head-bpartner = v_businesspartner.

      CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL'
        EXPORTING
          businesspartner = wa_bapibus1006_head-bpartner
          valid_date      = sy-datum
        TABLES
          bapiadsmtp      = wa_bapiadsmtp.
      IF NOT wa_bapiadsmtp[] IS INITIAL.
        READ TABLE wa_bapiadsmtp INDEX 1.
        IF sy-subrc = 0.
          v_email = wa_bapiadsmtp-e_mail.
          PERFORM send_mail USING v_email
                                  v_recp
                                  v_name_sub
                                  v_start_date
                                  v_end_date.
        ELSE.
          CLEAR   : w_document_data.
          REFRESH : i_packing_list, i_attachment, i_body_msg, i_receivers.
        ENDIF.
      ENDIF.
    ENDIF.
    REFRESH : i_packing_list, i_attachment, i_body_msg, i_receivers, i_etworklist.
    CLEAR : v_pernr, v_participant_guid, v_businesspartner, wa_bapiadsmtp, wa_bapibus1006_head, v_email,
            v_start_date, v_end_date, v_name_sub.
  ENDLOOP.
ENDFORM.                    " BATCH_PROCESS_EMAIL
*&---------------------------------------------------------------------*
*&      Form  LOAD_DATA_TO_ATTACHMENT
*&---------------------------------------------------------------------*
FORM load_data_to_attachment .
  CONCATENATE con_cret w_attachment
                      INTO w_attachment.
  APPEND w_attachment TO i_attachment.
  CLEAR  w_attachment.
ENDFORM.                    " LOAD_DATA_TO_ATTACHMENT
*&---------------------------------------------------------------------*
*&      Form  LINE_ITEM_PROJECT_DETAILS
*&---------------------------------------------------------------------*
FORM line_item_project_details .
  WRITE i_dpr_bupa_link_final1-beg_tmstmp_eng TO v_beg_tmstmp_eng.
  WRITE i_dpr_bupa_link_final1-end_tmstmp_eng TO v_end_tmstmp_eng.
  CLEAR : v_date, v_month, v_year.
  v_date  = v_beg_tmstmp_eng+0(2).
  v_month = v_beg_tmstmp_eng+2(2).
  v_year  = v_beg_tmstmp_eng+4(4).
  LOOP AT i_months_name WHERE mnr EQ v_month.
    v_month_name = i_months_name-ktx.
  ENDLOOP.
  CONCATENATE v_date v_month_name v_year INTO v_beg_tmstmp_eng1 SEPARATED BY '-'.
  CLEAR : v_date, v_month, v_year.
  v_date  = v_end_tmstmp_eng+0(2).
  v_month = v_end_tmstmp_eng+2(2).
  v_year  = v_end_tmstmp_eng+4(4).
  LOOP AT i_months_name WHERE mnr EQ v_month.
    v_month_name = i_months_name-ktx.
  ENDLOOP.
  CONCATENATE v_date v_month_name v_year INTO v_end_tmstmp_eng1 SEPARATED BY '-'.
  CLEAR : v_date, v_month, v_year.
  v_work_effort = i_dpr_bupa_link_final1-work_effort.
  CONCATENATE  i_dpr_bupa_link_final1-task_name
               i_dpr_bupa_link_final1-task_desc
               i_dpr_bupa_link_final1-task_type
               i_dpr_bupa_link_final1-role_text
               v_beg_tmstmp_eng1
               v_end_tmstmp_eng1
               v_work_effort
               '      '
               '      '
               '      '
               '      '
               '      '
               INTO w_attachment
               SEPARATED BY con_tab.
  PERFORM load_data_to_attachment.
  CLEAR : v_work_effort, v_beg_tmstmp_eng1, v_end_tmstmp_eng1, v_beg_tmstmp_eng, v_end_tmstmp_eng.
ENDFORM.                    " LINE_ITEM_PROJECT_DETAILS
*&---------------------------------------------------------------------*
*&      Form  CATS_LINE_DATA_OUTPUT
*&---------------------------------------------------------------------*
FORM cats_line_data_output .
  DATA : v_task_id   TYPE char25,
         v_task_name TYPE dpr_tv_name,
         v_lstnr(19) TYPE c,
         v_bpkind3(8) TYPE c.

  READ TABLE i_dpr_bupa_link_final1 WITH KEY task_number = i_etworklist-zzcpr_objgextid.
  IF sy-subrc = 0.
    v_task_name = i_dpr_bupa_link_final1-task_name.
  ENDIF.
  v_task_id = i_etworklist-zzcpr_objgextid.
  CONCATENATE '''' v_task_id INTO v_task_id.
  v_lstnr = i_etworklist-lstnr.
  CONCATENATE '''' v_lstnr INTO v_lstnr.

  IF v_bpkind2 = 'DSR_ICDR'.
    v_bpkind3 = v_bpkind2.
  ELSEIF v_bpkind2 EQ 'DSR_FSE'.
    v_bpkind3 = v_bpkind2.
  ENDIF.

  IF i_etworklist-skostl IS INITIAL AND
     i_etworklist-lstar  IS INITIAL AND
     i_etworklist-raufnr IS INITIAL .
    CONCATENATE v_task_id
                v_task_name
                ' '
                ' '
                i_dpr_bupa_link_final2-role_text
                'DA'
                v_bpkind3
                v_pernr
                ' '
                ' '
                ' '
                i_etworklist-sebeln
                i_etworklist-sebelp
                i_etworklist-zzcpr_extid
                v_lstnr
                '  '
                INTO w_attachment
                SEPARATED BY con_tab.
    PERFORM load_data_to_attachment.
  ELSE.
    CONCATENATE v_task_id
               v_task_name
               ' '
               ' '
               i_dpr_bupa_link_final2-role_text
               'DA'
               v_bpkind3
               v_pernr
               i_etworklist-raufnr
               i_etworklist-lstar
               i_etworklist-skostl
               i_etworklist-sebeln
               i_etworklist-sebelp
               i_etworklist-zzcpr_extid
               v_lstnr
               '  '
               INTO w_attachment
               SEPARATED BY con_tab.
  ENDIF.
  CLEAR : v_task_id, v_task_name, v_bpkind3.
ENDFORM.                    " CATS_LINE_DATA_OUTPUT
*&---------------------------------------------------------------------*
*&      Form  SEND_MAIL
*&---------------------------------------------------------------------*
FORM send_mail USING v_email
                     v_recp
                     v_name_sub
                     v_start_date
                     v_end_date.

  DATA : v_objdescr(70)  TYPE c,
         v_begindate(11) TYPE c,
         v_enddate(11)   TYPE c,
         v_temp(30)      TYPE c,
         v_month_name    TYPE fcktx.
  DATA : i_months_name   TYPE STANDARD TABLE OF
                         t247 WITH HEADER LINE.   "For getting months name in Subject line

  CALL FUNCTION 'MONTH_NAMES_GET'
    EXPORTING
      language              = sy-langu
    TABLES
      month_names           = i_months_name
    EXCEPTIONS
      month_names_not_found = 1
      OTHERS                = 2.

  "Subject of the mail.
  w_document_data-obj_name  = 'MAIL_TO_HEAD'.
  CLEAR : v_objdescr.
  v_year  = v_start_date+0(4).
  v_month = v_start_date+4(2).
  v_date  = v_start_date+6(2).
  LOOP AT i_months_name WHERE mnr EQ v_month.
    v_month_name = i_months_name-ktx.
  ENDLOOP.
  CONCATENATE v_date v_month_name v_year INTO v_begindate SEPARATED BY '.'.
  CLEAR : v_year, v_month, v_date, v_month_name.
  v_year  = v_end_date+0(4).
  v_month = v_end_date+4(2).
  v_date  = v_end_date+6(2).
  LOOP AT i_months_name WHERE mnr EQ v_month.
    v_month_name = i_months_name-ktx.
  ENDLOOP.
  CONCATENATE v_date v_month_name v_year INTO v_enddate SEPARATED BY '.'.
  CLEAR : v_year, v_month, v_date, v_month_name.
  CONCATENATE v_begindate '-' v_enddate INTO v_temp SEPARATED BY space.
  CONCATENATE 'DAR' v_name_sub v_temp INTO v_objdescr SEPARATED BY '-'.
  w_document_data-obj_descr = v_objdescr.
  CLEAR : v_objdescr, v_temp, v_begindate, v_enddate.

  "Write Packing List for Body
  DESCRIBE TABLE i_body_msg LINES g_tab_lines.
  w_packing_list-head_start = 1.
  w_packing_list-head_num   = 0.
  w_packing_list-body_start = 1.
  w_packing_list-body_num   = g_tab_lines.
  w_packing_list-doc_type   = 'RAW'.
  APPEND w_packing_list TO i_packing_list.
  CLEAR  w_packing_list.

  "Write Packing List for Attachment
  w_packing_list-transf_bin = 'X'.
  w_packing_list-head_start = 1.
  w_packing_list-head_num   = 1.
  w_packing_list-body_start = 1.
  DESCRIBE TABLE i_attachment LINES w_packing_list-body_num.
  w_packing_list-doc_type   = 'XLS'.
  CONCATENATE v_pernr 'DETAIL ACTIVITY REPORT' INTO v_objdescr SEPARATED BY '-'.
  w_packing_list-obj_descr  = v_objdescr.
  CLEAR : v_objdescr.
  w_packing_list-obj_name   = 'XLS_ATTACHMENT'.
  w_packing_list-doc_size   = w_packing_list-body_num * 255.
  APPEND w_packing_list TO i_packing_list.
  CLEAR  w_packing_list.

  "Fill the document data and get size of attachment
  w_document_data-obj_langu  = sy-langu.
  READ TABLE i_attachment INTO w_attachment INDEX g_tab_lines.
  w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + strlen( w_attachment ).

  "Receivers List.
  w_receivers-rec_type   = 'U'.  " U Internet address
  w_receivers-receiver   = v_email.  "MAIL ADDRESS
  APPEND w_receivers TO i_receivers .
  CLEAR:w_receivers.
  IF NOT v_recp IS INITIAL.
    w_receivers-rec_type   = 'U'.  " U Internet address
    w_receivers-receiver   = v_recp.  "MAIL ADDRESS
    w_receivers-copy       = 'X'.
    APPEND w_receivers TO i_receivers .
    CLEAR:w_receivers.
  ENDIF.

  "Function module to send mail to Recipients
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = w_document_data
      put_in_outbox              = 'X'
      commit_work                = 'X'
    IMPORTING
      sent_to_all                = g_sent_to_all
    TABLES
      packing_list               = i_packing_list
      contents_bin               = i_attachment
      contents_txt               = i_body_msg
      receivers                  = i_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.

*  IF sy-subrc = 0 .
*    MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'.
*  ELSE.
*    WAIT UP TO 2 SECONDS.
*    "This program starts the SAPconnect send process.
*    SUBMIT rsconn01 WITH mode = 'INT'
*                 WITH output = 'X'
*                 AND RETURN.
*  ENDIF.
  CLEAR : v_email, v_month_name.
  REFRESH : i_months_name.
ENDFORM.                    " SEND_MAIL
*&---------------------------------------------------------------------*
*&      Form  F_INITIALAZE_RFCDEST
*&---------------------------------------------------------------------*
FORM f_initialaze_rfcdest .
  DATA : v_datum TYPE sy-datum.
  CLEAR v_dest.
  CASE sy-sysid.
    WHEN 'NRD'.
      MOVE c_gdd TO v_dest.
    WHEN 'NRB'.
      MOVE c_gb2 TO v_dest.
    WHEN 'NRP'.
      MOVE c_gp1 TO v_dest.
  ENDCASE.
  v_datum = sy-datum + 15.
  p_enddt = v_datum.
  CLEAR : v_datum.
ENDFORM.                    " F_INITIALAZE_RFCDEST
*&---------------------------------------------------------------------*
*&      Form  FREE_OBJECTS
*&---------------------------------------------------------------------*
FORM free_objects .
  CALL METHOD OF
      gs_wbook
      'Close'.
  CALL METHOD OF
      gs_excel
      'Quit'.
  FREE OBJECT gs_cell1.
  FREE OBJECT gs_cell2.
  FREE OBJECT gs_cells.
  FREE OBJECT gs_activesheet.
  FREE OBJECT gs_wbook.
  FREE OBJECT gs_application.
  FREE OBJECT gs_wbooklist.
  FREE OBJECT gs_excel.
ENDFORM.                    " FREE_OBJECTS
*&---------------------------------------------------------------------*
*&      Form  NOTE_CONDITION
*&---------------------------------------------------------------------*
FORM note_condition .
  gv_line_cntr = gv_line_cntr + 2.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell1
    EXPORTING
      #1       = gv_line_cntr
      #2       = 1.
  CALL METHOD OF
      gs_excel
      'Cells'  = gs_cell2
    EXPORTING
      #1       = gv_line_cntr
      #2       = 5.
  CALL METHOD OF
      gs_excel
      'Range'  = gs_cells
    EXPORTING
      #1       = gs_cell1
      #2       = gs_cell2.
  CALL METHOD OF
      gs_cells
      'Select'.
*--Merging
  CALL METHOD OF
      gs_cells
      'Merge'.
  SET PROPERTY OF gs_cells 'Value' = 'Note: Task Name is repeated No. of days the task has been allocated within the Report Period.' .
**--Formatting the title
  GET PROPERTY OF gs_cells 'Font' = gs_font .
  SET PROPERTY OF gs_font  'Name' = 'Arial' .
  SET PROPERTY OF gs_font  'Size' = '10' .
  SET PROPERTY OF gs_font  'Bold' = 1 .
  SET PROPERTY OF gs_font  'Italic' = 1 .
  SET PROPERTY OF gs_cells 'HorizontalAlignment' = -4131 .
  SET PROPERTY OF gs_cells 'Locked' = 1.
ENDFORM.                    " NOTE_CONDITION
*&---------------------------------------------------------------------*
*&      Form  FILTER_OUTPUT_DISPLAY_ALV
*&---------------------------------------------------------------------*
FORM filter_output_display_alv .
  DATA : v_name TYPE char80,
         v_participant_guid TYPE dpr_tv_participant_guid,
         v_index TYPE sy-tabix,
         v_flag  TYPE c VALUE '0'.
**TO DETERMINE THE CURRENT USERNAME DESKTOP
**PATH FOR CREATING FOLDER IN HIS SYSTEM.
  LOOP AT i_dpr_bupa_link_final1.
    v_index = sy-tabix.
    v_pernr            = i_dpr_bupa_link_final1-pernr.
    CONCATENATE 'E0' v_pernr INTO v_businesspartner.
    SELECT SINGLE bpkind
           FROM but000
           INTO v_bpkind
           WHERE partner = v_businesspartner.
    CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1.
    IF NOT v_bpkind IS INITIAL.
      i_dpr_bupa_link_final1-bpkind = v_bpkind1.
      MODIFY i_dpr_bupa_link_final1
             INDEX sy-tabix
             TRANSPORTING bpkind.
    ELSE.
      DELETE i_dpr_bupa_link_final1 INDEX v_index.
    ENDIF.
    CLEAR : v_bpkind, v_bpkind1, v_businesspartner, v_pernr, v_index.
  ENDLOOP.

  i_dpr_bupa_link_final2[] =  i_dpr_bupa_link_final1[].
  SORT i_dpr_bupa_link_final2 BY participant_guid.
  DELETE ADJACENT DUPLICATES FROM i_dpr_bupa_link_final2 COMPARING participant_guid.

  LOOP AT i_dpr_bupa_link_final2.
    v_skipflag = 0.
    v_index = sy-tabix.
    v_pernr            = i_dpr_bupa_link_final2-pernr.
    v_participant_guid = i_dpr_bupa_link_final2-participant_guid.
    v_int_order        = i_dpr_bupa_link_final2-project_id.
    LOOP AT i_dpr_bupa_link_final1 WHERE participant_guid = v_participant_guid.
      IF
*         i_dpr_bupa_link_final1-lifnr      IS INITIAL OR
*         i_dpr_bupa_link_final1-name       IS INITIAL OR
         i_dpr_bupa_link_final1-pernr      IS INITIAL OR
         i_dpr_bupa_link_final1-project_id IS INITIAL OR
         i_dpr_bupa_link_final1-proj_name  IS INITIAL OR
         i_dpr_bupa_link_final1-name_pm    IS INITIAL OR
*         i_dpr_bupa_link_final1-object_key IS INITIAL OR
         i_dpr_bupa_link_final1-proj_desc  IS INITIAL.
        v_flag = 1.
      ENDIF.
      CONCATENATE i_dpr_bupa_link_final1-name_first i_dpr_bupa_link_final1-name_last INTO v_name SEPARATED BY space.
      IF v_name IS INITIAL.
        v_flag = 1.
      ENDIF.
      IF i_dpr_bupa_link_final1-object_key IS INITIAL AND
         i_dpr_bupa_link_final1-bpkind EQ 'DSR_ICDR'.
        v_flag = 1.
      ENDIF.
      IF i_dpr_bupa_link_final1-task_name      IS INITIAL OR
         i_dpr_bupa_link_final1-task_desc      IS INITIAL OR
         i_dpr_bupa_link_final1-task_type      IS INITIAL OR
         i_dpr_bupa_link_final1-role_text      IS INITIAL OR
         i_dpr_bupa_link_final1-beg_tmstmp_eng IS INITIAL OR
         i_dpr_bupa_link_final1-end_tmstmp_eng IS INITIAL OR
         i_dpr_bupa_link_final1-work_effort    IS INITIAL.
        v_flag = 1.
      ENDIF.
      CLEAR : v_name.
      IF v_flag = 1.
        DELETE i_dpr_bupa_link_final1 INDEX sy-tabix.
        v_flag = 0.
      ENDIF.
    ENDLOOP.
    CONCATENATE 'E0' v_pernr INTO v_businesspartner.
    SELECT SINGLE bpkind
           FROM but000
           INTO v_bpkind
           WHERE partner = v_businesspartner.
    CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1.
    IF NOT v_bpkind IS INITIAL.
      CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest
        EXPORTING
          sap_variant = v_bpkind1
          sap_pernr   = v_pernr
          beg_date    = p_begdt
          end_date    = p_enddt
        TABLES
          sap_icatsw  = i_etworklist.
    ENDIF.
    DELETE i_etworklist WHERE zzcpr_extid NE v_int_order.
    CLEAR : v_bpkind, v_bpkind1.
    IF i_etworklist[] IS INITIAL.
      DELETE i_dpr_bupa_link_final1 WHERE pernr EQ v_pernr.
    ENDIF.
**To check BP Email Address
    CONCATENATE 'E0' v_pernr INTO v_businesspartner.
    wa_bapibus1006_head-bpartner = v_businesspartner.
    REFRESH : wa_bapiadsmtp.
    CALL FUNCTION 'BAPI_BUPA_ADDRESS_GETDETAIL'
      EXPORTING
        businesspartner = wa_bapibus1006_head-bpartner
        valid_date      = sy-datum
      TABLES
        bapiadsmtp      = wa_bapiadsmtp.
    IF wa_bapiadsmtp[] IS INITIAL.
      DELETE i_dpr_bupa_link_final1 WHERE pernr EQ v_pernr.
    ELSE.
      REFRESH : wa_bapiadsmtp.
    ENDIF.
    CLEAR : v_participant_guid, v_pernr, v_businesspartner, v_int_order, wa_bapiadsmtp, wa_bapibus1006_head.
    REFRESH : i_etworklist.
  ENDLOOP.
ENDFORM.                    " FILTER_OUTPUT_DISPLAY_ALV

*PROGRAM for sending MAIL. transaction code  yg_email
*&---------------------------------------------------------------------*
*& Report  YGS_SEND_EXTERNAL_MAIL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT  ygs_send_external_mail.
*----------------------------------------------------------------------*
* DATA DECLERATIONS                                                    *
*----------------------------------------------------------------------*
DATA : method1         LIKE sy-ucomm,
       g_user          LIKE soudnamei1,
       g_user_data     LIKE soudatai1,
       g_owner         LIKE soud-usrnam,
       g_document      LIKE sood4 ,
       g_header        LIKE sood2,
       g_folmam        LIKE sofm2,
       g_authority     LIKE sofa-usracc,
       g_ref_document  LIKE sood4,
       g_new_parent    LIKE soodk,
       fold_number(12) TYPE c,
       fold_yr(2)      TYPE c,
       fold_type(3)    TYPE c.
*----------------------------------------------------------------------*
* INTERNAL TABLE DECLERATIONS                                          *
*----------------------------------------------------------------------*
DATA g_objcnt       LIKE soli  OCCURS 0 WITH HEADER LINE.
DATA g_objhead      LIKE soli  OCCURS 0 WITH HEADER LINE.
DATA g_objpara      LIKE selc  OCCURS 0 WITH HEADER LINE.
DATA g_objparb      LIKE soop1 OCCURS 0 WITH HEADER LINE.
DATA g_attachments  LIKE sood5 OCCURS 0 WITH HEADER LINE.
DATA g_references   LIKE soxrl OCCURS 0 WITH HEADER LINE.
DATA g_receipients  LIKE soos1 OCCURS 0 WITH HEADER LINE.
DATA i_months_name  TYPE STANDARD TABLE OF t247 WITH HEADER LINE. "For getting months
"name in Subject line
DATA: BEGIN OF g_files OCCURS 10 ,
       text(4096) TYPE c,
      END OF g_files.
DATA : v_objdescr(50)    TYPE c,
       v_begindate(11)   TYPE c,
       v_enddate(11)     TYPE c,
       v_temp(30)        TYPE c,
       v_dest            LIKE edipoa-logdes,
       v_start_date      TYPE sy-datum,
       v_end_date        TYPE sy-datum,
       v_date(2)         TYPE c,
       v_month(2)        TYPE c,
       v_year(4)         TYPE c,
       v_businesspartner TYPE bu_partner,
       v_bpkind          TYPE bu_bpkind,
       v_bpkind1(8)      TYPE c,
       v_month_name      TYPE fcktx,
       v_name_sub(100)   TYPE c.
*----------------------------------------------------------------------*
* CONSTANT DECLERATIONS                                                *
*----------------------------------------------------------------------*
CONSTANTS : c_gdd(6) TYPE c VALUE 'GDD590',
            c_gb2(6) TYPE c VALUE 'GB2590',
            c_gp1(6) TYPE c VALUE 'GP1590'.
*----------------------------------------------------------------------*
* PARAMETER DECLERATIONS                                               *
*----------------------------------------------------------------------*
PARAMETER : ws_file       TYPE string,
            ws_email(128) TYPE c,
            ws_pernr      TYPE pernr_d,
            ws_proid      TYPE project_id,
            ws_begdt      TYPE sy-datum,
            ws_enddt      TYPE sy-datum.

CLEAR v_dest.
CASE sy-sysid.
  WHEN 'NRD'.
    MOVE c_gdd TO v_dest.
  WHEN 'NRB'.
    MOVE c_gb2 TO v_dest.
  WHEN 'NRP'.
    MOVE c_gp1 TO v_dest.
ENDCASE.

CONCATENATE ws_pernr  ws_proid INTO v_name_sub SEPARATED BY '-'.
CALL FUNCTION 'MONTH_NAMES_GET'
  EXPORTING
    language              = sy-langu
  TABLES
    month_names           = i_months_name
  EXCEPTIONS
    month_names_not_found = 1
    OTHERS                = 2.

* Can me any file fromyour pc ....either xls or word or ppt etc ...
CLEAR : g_user_data, g_document.
g_user-sapname = sy-uname.
ws_file = ws_file.
CALL FUNCTION 'SO_USER_READ_API1'
  EXPORTING
    user      = g_user
  IMPORTING
    user_data = g_user_data.

fold_type = g_user_data-outboxfol+0(3).
fold_yr = g_user_data-outboxfol+3(2).
fold_number =  g_user_data-outboxfol+5(12).
CLEAR g_files.
REFRESH : g_objcnt,  g_objhead,  g_objpara,  g_objparb,  g_receipients,
          g_attachments,  g_references,  g_files.

method1 = 'SAVE'.
g_document-foltp    = fold_type.
g_document-folyr    = fold_yr.
g_document-folno    = fold_number.
g_document-objtp    = g_user_data-object_typ.
g_document-objdes   = 'Detail Activity Report'.
g_document-folrg    = 'O'.
g_document-objlen   = '0'.
g_document-file_ext = 'XLS'.

CONCATENATE 'E0' ws_pernr INTO v_businesspartner.
SELECT SINGLE bpkind
       FROM but000
       INTO v_bpkind
       WHERE partner = v_businesspartner.
CONCATENATE 'DSR_' v_bpkind INTO v_bpkind1.

CALL FUNCTION 'Y_CATS_WORKLIST_DEATILS' DESTINATION v_dest
  EXPORTING
    sap_variant   = v_bpkind1
    sap_pernr     = ws_pernr
    beg_date      = ws_begdt
    end_date      = ws_enddt
  IMPORTING
    sap_startdate = v_start_date
    sap_enddate   = v_end_date.

CLEAR : v_bpkind1, v_bpkind.
v_year  = v_start_date+0(4).
v_month = v_start_date+4(2).
v_date  = v_start_date+6(2).
LOOP AT i_months_name WHERE mnr EQ v_month.
  v_month_name = i_months_name-ktx.
ENDLOOP.
CONCATENATE v_date v_month_name v_year INTO v_begindate SEPARATED BY '.'.
CLEAR : v_date, v_month, v_year, v_month_name.
v_year  = v_end_date+0(4).
v_month = v_end_date+4(2).
v_date  = v_end_date+6(2).
LOOP AT i_months_name WHERE mnr EQ v_month.
  v_month_name = i_months_name-ktx.
ENDLOOP.
CONCATENATE v_date v_month_name v_year INTO v_enddate SEPARATED BY '.'.
CLEAR : v_date, v_month, v_year, v_month_name.
CONCATENATE v_begindate '-' v_enddate INTO v_temp.
CONCATENATE 'DAR' v_name_sub v_temp INTO v_objdescr  SEPARATED BY '-'.
g_header-objdes     = v_objdescr.
CLEAR : v_objdescr, v_temp, v_begindate, v_enddate, v_start_date, v_end_date.

CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
  EXPORTING
    method       = method1
    office_user  = sy-uname
    ref_document = g_ref_document
    new_parent   = g_new_parent
  IMPORTING
    authority    = g_authority
  TABLES
    objcont      = g_objcnt
    objhead      = g_objhead
    objpara      = g_objpara
    objparb      = g_objparb
    recipients   = g_receipients
    attachments  = g_attachments
    references   = g_references
    files        = g_files
  CHANGING
    document     = g_document
    header_data  = g_header.

* File from the pc to send...
method1 = 'ATTCREATEFROMPC'.

g_files-text = ws_file.
APPEND g_files.
CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
  EXPORTING
    method       = method1
    office_user  = g_owner
    ref_document = g_ref_document
    new_parent   = g_new_parent
  IMPORTING
    authority    = g_authority
  TABLES
    objcont      = g_objcnt
    objhead      = g_objhead
    objpara      = g_objpara
    objparb      = g_objparb
    recipients   = g_receipients
    attachments  = g_attachments
    references   = g_references
    files        = g_files
  CHANGING
    document     = g_document
    header_data  = g_header.

method1 = 'SEND'.
g_receipients-recextnam = ws_email.
g_receipients-recesc    = 'A'.
g_receipients-sndex     = 'X'.
APPEND  g_receipients.
CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
  EXPORTING
    method       = method1
    office_user  = g_owner
    ref_document = g_ref_document
    new_parent   = g_new_parent
  IMPORTING
    authority    = g_authority
  TABLES
    objcont      = g_objcnt
    objhead      = g_objhead
    objpara      = g_objpara
    objparb      = g_objparb
    recipients   = g_receipients
    attachments  = g_attachments
    references   = g_references
    files        = g_files
  CHANGING
    document     = g_document
    header_data  = g_header.

* SUBMIT rsconn01 WITH mode = 'INT'
*                 WITH output = 'X'
*                 AND RETURN.
REFRESH : g_objcnt,   g_objhead,   g_objpara,   g_objparb,   g_receipients,
          g_attachments,   g_references,   g_files.
 
REPORT ztsapmail.
DATA: x_object_type LIKE sood-objtp.
DATA: BEGIN OF x_object_hd_change.
        INCLUDE STRUCTURE sood1.
DATA: END OF x_object_hd_change.
DATA: BEGIN OF x_objcont OCCURS 10.
        INCLUDE STRUCTURE soli.
DATA: END OF x_objcont.
DATA: BEGIN OF x_objhead OCCURS 0.
        INCLUDE STRUCTURE soli.
DATA: END OF x_objhead.
DATA: BEGIN OF raw_head.
        INCLUDE STRUCTURE sorh.
DATA: END OF raw_head.
DATA: BEGIN OF x_receivers OCCURS 0.
        INCLUDE STRUCTURE soos1.
DATA: END OF x_receivers.
PARAMETERS: receiver LIKE x_receivers-recnam. " Name
*BUILD MESSAGE HEADER
MOVE 'Sort field goes here' TO x_object_hd_change-objsrt. " Sort field
MOVE 'Name of the object goes here' TO x_object_hd_change-objnam. " Name
MOVE 'Document title goes here' TO x_object_hd_change-objdes. " Title
MOVE 'F' TO x_object_hd_change-objsns. " Functional OBJECT
MOVE 'E' TO x_object_hd_change-objla. " Language
* Object type of the new document
MOVE 'RAW' TO x_object_type.
CLEAR x_objcont.
MOVE 'Contents of mail' TO x_objcont-line.
APPEND x_objcont.
CLEAR x_objcont-line. APPEND x_objcont.
MOVE 'More contents' TO x_objcont-line.
APPEND x_objcont.
MOVE 'Still more contents'
TO x_objcont-line.
APPEND x_objcont.
MOVE ' ' TO x_objcont-line.
APPEND x_objcont.
* Specific header (Dependent on the object type, here RAW)
REFRESH x_objhead.
DESCRIBE TABLE x_objcont LINES raw_head-rawsiz.
MOVE raw_head TO x_objhead.
APPEND x_objhead.
*RECEIVERS table
CLEAR x_receivers.
REFRESH x_receivers.
MOVE receiver TO x_receivers-recnam. " Name
MOVE 'B' TO x_receivers-recesc. " Receiver type
MOVE 'X' TO x_receivers-sndcp. " Send as a copy
MOVE 'X' TO x_receivers-sndex. " EXPRESS DOCUMENT
APPEND x_receivers.
CALL FUNCTION 'SO_OBJECT_SEND'
  EXPORTING
    object_hd_change = x_object_hd_change
    object_type      = x_object_type
    outbox_flag      = 'X'
    owner            = sy-uname
    tablesobjcont    = x_objcont
    objhead          = x_objhead
    receivers        = x_receivers.
 

Author: Jatra Riwayanto
Submitted: 26.09.2007
Related Links:

Description:
My previous snippet is a program that will display Inbox folder content. Now I am adding some code that will display mail content. User can select specific mail and will see the content of this mail.

Report Line-Size
Because length of SOLI-LINE is 255 character, we need to change report line size.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT  ZSapInbox NO STANDARD PAGE HEADING
                  LINE-COUNT 65
                  LINE-SIZE 260.

Class Definition
Adding Display_Mail method and several data variable.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
CLASS LCL_MAIN DEFINITION.
  PUBLIC SECTION.
    METHODS: DISPLAY_INBOX,
             DISPLAY_MAIL IMPORTING IM_MAILID TYPE STRING.  " -- added code --
    EVENTS:  MESSAGE EXPORTING VALUE(MSG1) TYPE STRING
                               VALUE(MSG2) TYPE STRING OPTIONAL
                               VALUE(MSG3) TYPE STRING OPTIONAL
                               VALUE(MSG4) TYPE STRING OPTIONAL.
  PRIVATE SECTION.
    METHODS: CLEAR_DATA,
             GET_INBOX_CONTENT.
*---------------------------------
* L.O.C.A.L  D.A.T.A.
*---------------------------------
    DATA: USER      TYPE SOUDNAMEI1,
          UDAT      TYPE SOUDATAI1,
          FDAT      TYPE SOFOLDATI1,
          IT_FDAT   TYPE TABLE OF SOFOLENTI1,
          WA_FDAT   TYPE SOFOLENTI1.

    DATA: MSG1      TYPE STRING,
          MSG2      TYPE STRING,
          MSG3      TYPE STRING,
          MSG4      TYPE STRING.

    DATA: FOLD_ID   TYPE SOODK,
          MAIL_ID   TYPE SOODK.          " -- added code --

    DATA: WA_OBJCONT TYPE SOLI,          " -- added code --
          IT_OBJCONT TYPE TABLE OF SOLI, " -- added code --
          OBJECT_HD_DISPLAY  TYPE SOOD2. " -- added code --

ENDCLASS.                    "lcl_main DEFINITION

Display_Mail Implementation

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
METHOD DISPLAY_MAIL.
    MOVE IM_MAILID TO MAIL_ID.

    CALL FUNCTION 'SO_OBJECT_READ'
         EXPORTING
              folder_id                  = FOLD_ID
              object_id                  = MAIL_ID
              owner                      = P_UNAME
         IMPORTING
              object_hd_display          = object_hd_display
         TABLES
              objcont                    = IT_objcont
         EXCEPTIONS
              active_user_not_exist      = 35
              communication_failure      = 71
              component_not_available    = 01
              folder_not_exist           = 06
              folder_no_authorization    = 05
              object_not_exist           = 14
              object_no_authorization    = 13
              operation_no_authorization = 21
              owner_not_exist            = 22
              parameter_error            = 23
              substitute_not_active      = 31
              substitute_not_defined     = 32
              system_failure             = 72
              x_error                    = 1000.

    IF SY-SUBRC NE 0.
     RAISE EVENT MESSAGE EXPORTING MSG1 = 'Error reading mail content'.
    ELSE.
      FORMAT COLOR COL_HEADING.
      ULINE (259).
      WRITE: / '|',(255) object_hd_display-OBJDES LEFT-JUSTIFIED, '|'.
      ULINE (259).
      FORMAT COLOR OFF.

      LOOP AT IT_OBJCONT INTO WA_OBJCONT.
        WRITE: / '|', WA_OBJCONT-LINE, '|'.
      ENDLOOP.
      ULINE (259).
    ENDIF.

  ENDMETHOD.                    "DISPLAY_MAIL

Hotspot
We need add Hotspot on Object ID column.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
METHOD DISPLAY_INBOX.
    CALL METHOD CLEAR_DATA( ).
    CALL METHOD GET_INBOX_CONTENT( ).
    IF IT_FDAT[] IS INITIAL.
      RAISE EVENT MESSAGE EXPORTING MSG1 = 'No emails in this inbox'.
    ENDIF.

    ULINE AT (114).
    FORMAT COLOR COL_HEADING.
    WRITE: / '|' NO-GAP, (020) 'Object ID'        LEFT-JUSTIFIED,
             '|' NO-GAP, (030) 'Subject'          LEFT-JUSTIFIED,
             '|' NO-GAP, (015) 'Date Recieved'    LEFT-JUSTIFIED,
             '|' NO-GAP, (040) 'Sender '          LEFT-JUSTIFIED,
             '|'.
    ULINE AT /(114).
    FORMAT COLOR OFF.

    LOOP AT IT_FDAT INTO WA_FDAT.
      FORMAT COLOR COL_NORMAL INTENSIFIED ON.
      WRITE: / '|' NO-GAP, (020) WA_FDAT-OBJECT_ID  UNDER 'Email ID'
                   HOTSPOT ON COLOR 5,  " -- added code --
               '|' NO-GAP, (030) WA_FDAT-OBJ_DESCR   LEFT-JUSTIFIED,
               '|' NO-GAP, (015) WA_FDAT-REC_DATE    LEFT-JUSTIFIED,
               '|' NO-GAP, (040) WA_FDAT-SEND_FNAM   LEFT-JUSTIFIED,
               '|'.
    ENDLOOP.
    ULINE AT /(114).
  ENDMETHOD.                    "DISPLAY_INBOX

AT LINE SELECTION
To make user enable display mail we need add AT-LINE-SELECTION code after START-OF-SELECTION.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
START-OF-SELECTION.
  DATA: O_MAIN           TYPE REF TO LCL_MAIN,
        O_HANDLER        TYPE REF TO LCL_HANDLER.

  CREATE OBJECT: O_MAIN, O_HANDLER.
  SET HANDLER O_HANDLER->HANDLE_MESSAGE FOR ALL INSTANCES.

  CALL METHOD O_MAIN->DISPLAY_INBOX.

AT LINE-SELECTION.
  DATA MAIL_ID TYPE STRING.

  MAIL_ID = SY-LISEL+1(17).
  CALL METHOD O_MAIN->DISPLAY_MAIL( MAIL_ID ).

Select Object ID.

Display mail content.

Business Scenarios:

In ETL, many times we have to use the ABAP programs to do processing so that we can implement various business scenarios. Some times users or Support teams need to be notified when something goes wrong in program while dealing with incorrect data. In those cases program goes under infinite loop and program times out. Support team then have to look into dumps and invest lot of time in analyzing the issue to find out where the program went wrong. To avoid all these manual steps we can rite a general program which can be called in different programs to generate the mails with the incorrect values. This automation will help in saving lot of manual effort.

Solution:

The ABAP developer can use the below program to generate the mails to the users and support team.
Step 1. Create a separate program as mentioned.
Go to Transaction SE38 and create program as:

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------
*& FORM  ZEMAIL_GENERATION
*&---------------------------------------------------------------------
*&  This program receives a table containing Data issue list and
*&  generate mail.
*&---------------------------------------------------------------------
FORM zemail_generation TABLES rc.
  DATA: it_objcont          LIKE solisti1 OCCURS 5 WITH HEADER LINE,
        it_reclist          LIKE somlreci1 OCCURS 5 WITH HEADER LINE,
        itab_objhead        LIKE soli OCCURS 0 WITH HEADER LINE,
        itab_receiver       LIKE soos1 OCCURS 0 WITH HEADER LINE,
        t_email_content     LIKE soli OCCURS 0 WITH HEADER LINE,
        lw_originator       LIKE soos1-recextnam,
        lw_originator_type  LIKE soos1-recesc,
        w_mail_header       LIKE sood1,
        it_document         TYPE hrhap,
        it_doc_chng         LIKE sodocchgi1,
        lin                 LIKE sy-tabix,
        v_content1          LIKE solisti1,
        v_content2          LIKE solisti1,
        v_content3          LIKE solisti1,
        v_content4          LIKE solisti1,
        v_content5          LIKE solisti1,
        header              LIKE sodocchgi1-obj_descr,
        wa_subject          TYPE char100,
        wa_content1         TYPE char100,
        wa_content2         TYPE solisti1-line,
        wa_receiver         TYPE char20,
        wa_event_id         TYPE char50,
        wa_stxh_tdname      TYPE stxh-tdname,
        status              LIKE hrhap-ap_status,
        sub_status          LIKE hrhap-ap_status_sub,
        wa_appraisal_id     LIKE hrhap-appraisal_id,
        plan_version        TYPE hap_plan_version,
        email_address       TYPE comm_id_long,
        designate_add       TYPE comm_id_long,
        l_stxh_tdname       TYPE stxh-tdname,
        lw_sender_name      TYPE soud-usrnam,
        lw_send_request_oid TYPE os_guid,
        sender_pernr        TYPE /bi0/oiemployee,
        sup_pernr           TYPE /bi0/oiemployee,
        appee_pernr         TYPE /bi0/oiemployee.
  DATA  objcont            LIKE soli OCCURS  5 WITH HEADER LINE. "Mail cont
  DATA: rc_tbl_new LIKE solisti1 OCCURS 5 WITH HEADER LINE,
        wa_rc_tbl TYPE solisti1.
  DATA: BEGIN OF w_ws,
          count TYPE i,
          smtp TYPE /bi0/oiemail_addr,
          err_num LIKE sy-msgno,
        END OF w_ws.

***End of declarations.
  CLEAR: wa_receiver, wa_subject , wa_content1, wa_content2, it_document.
  wa_receiver = 'BW-PRODSUPPORT@XYZ.com'.
  wa_subject = header =  'EMPLOYEE Hierarchy Going in Infinite Loop'.
  wa_content1 = 'The Supervisor going in Infinite loop are:'.

*Append Receiverlist table.
  it_reclist-rec_type = 'U'.                       "Internet-adress
  it_reclist-receiver = 'BW-PRODSUPPORT@XYZ.com'.           " 'BW tier 3'.
  it_reclist-express = 'X'.
  APPEND it_reclist.
*Set general email message header/subject information
  w_mail_header-objnam = ''.
  w_mail_header-objsns = 'C'.
  w_mail_header-objla  = sy-langu.
  w_mail_header-objdes = header.
*Set message header to RAW
  itab_objhead-line = 'RAW'.
  APPEND itab_objhead.
*Set receiver information
  itab_receiver-sel        = 'X'.
  itab_receiver-rcdat      = sy-datum.
  itab_receiver-recesc     = 'U'.
  itab_receiver-recnam     = '  '.
  itab_receiver-mailstatus = 'E'.
  itab_receiver-sortclass  = '5'.
  itab_receiver-sndart     = 'INT'.
  itab_receiver-sndpri     = '1'.
  itab_receiver-sndspo     = '0'.
  itab_receiver-deliver    = 'X'.
  itab_receiver-read       = 'X'.
  itab_receiver-recextnam  = w_ws-smtp.
  APPEND itab_receiver.
*Send email
*Process the EMAIL using SO_NEW_DOCUMENT_SEND_API1
*Fill the document header
  it_doc_chng-obj_name   = 'URGENT'.
  it_doc_chng-obj_descr  = header.
  IF sy-sysid = 'HRP'.
    it_doc_chng-sensitivty = 'P'.
  ELSE.
    it_doc_chng-sensitivty = 'O'.
  ENDIF.
  it_doc_chng-obj_langu  = sy-langu.
* fill the text of the mail
  it_objcont = wa_content1.
  APPEND it_objcont.
*** Append the RCs to the Text of the mail.
*RC is an internal table containing incorrect data having issues.
  APPEND LINES OF rc TO it_objcont.
* Read table and get the document size.
  DESCRIBE TABLE it_objcont LINES lin.
  READ TABLE it_objcont INDEX lin.
  it_doc_chng-doc_size = ( lin - 1 ) * 255 + strlen( it_objcont ).
  IF it_doc_chng-doc_size LT 0.
    it_doc_chng-doc_size = 0.
  ENDIF.
* Send the email
  CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
    EXPORTING
      document_data     = it_doc_chng
      document_type     = 'RAW'
      put_in_outbox     = 'X'
      commit_work       = 'X'
    TABLES
      object_content    = it_objcont
      receivers         = it_reclist
    EXCEPTIONS
      document_not_sent = 2.

ENDFORM.                    "ZEMAIL_GENERATION

Step 2. In your main program where you are doing functional processing, create an internal table and keep on filling the same with the values having data issue.
"RC" is an internal table with the values having data issues.
Call program to generate mail by using the below mention code snippet in your main program.
Table "RC" is populated with list of Corrupted RCs.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
rc[] = corr_rc_table[].
DESCRIBE TABLE rc LINES lin.
IF lin <> 0.
*** Call PERFORM to send Email for Corrupted values from RCs.
  PERFORM zemail_generation TABLES  rc .
ENDIF.
  • Step 3: For testing the functionality of the program:
     Got to Transaction SCOT and goto Utilities as shown in screen shot:"

In the "OVERVIEW OF SEND ORDERS", you will see screen as shown below:

"
Select any request to check the body of the mail. Do execute to release the mail from outbox.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT  zemail_attach                   .
TABLES: ekko.

PARAMETERS: p_email   TYPE somlreci1-receiver
                                  DEFAULT 'test@sapdev.co.uk'.

TYPES: BEGIN OF t_ekpo,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
 END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
      wa_ekpo TYPE t_ekpo.

TYPES: BEGIN OF t_charekpo,
  ebeln(10) TYPE c,
  ebelp(5)  TYPE c,
  aedat(8)  TYPE c,
  matnr(18) TYPE c,
 END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.

DATA:   it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                WITH HEADER LINE.
DATA:   it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                WITH HEADER LINE.

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,
        gd_error    TYPE sy-subrc,
        gd_reciever TYPE sy-subrc.

************************************************************************
*START_OF_SELECTION
START-OF-SELECTION.
*   Retrieve sample data from table ekpo
  PERFORM data_retrieval.

*   Populate table with details to be entered into .xls file
  PERFORM build_xls_data_table.

************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
* Populate message body text
  PERFORM populate_email_message_body.

* Send file by email as .xls speadsheet
  PERFORM send_file_as_email_attachment
                               TABLES it_message
                                      it_attach
                                USING p_email
                                      'Example .xls document attachment'
                                      'XLS'
                                      'filename'
                                      ' '
                                      ' '
                                      ' '
                             CHANGING gd_error
                                      gd_reciever.

*   Instructs mail send program for SAPCONNECT to send email(rsconn01)
  PERFORM initiate_mail_execute_program.

*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
FORM data_retrieval.
  SELECT ebeln ebelp aedat matnr
   UP TO 10 ROWS
    FROM ekpo
    INTO TABLE it_ekpo.
ENDFORM.                    " DATA_RETRIEVAL

*&---------------------------------------------------------------------*
*&      Form  BUILD_XLS_DATA_TABLE
*&---------------------------------------------------------------------*
*       Build data table for .xls document
*----------------------------------------------------------------------*
FORM build_xls_data_table.
  CONSTANTS: con_cret TYPE x VALUE '0D',  "OK for non Unicode
             con_tab TYPE x 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 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
         INTO it_attach SEPARATED BY con_tab.
  CONCATENATE con_cret it_attach  INTO it_attach.
  APPEND  it_attach.

  LOOP AT it_ekpo INTO wa_charekpo.
    CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
                wa_charekpo-aedat wa_charekpo-matnr
           INTO it_attach SEPARATED BY con_tab.
    CONCATENATE con_cret it_attach  INTO it_attach.
    APPEND  it_attach.
  ENDLOOP.
ENDFORM.                    " BUILD_XLS_DATA_TABLE

*&---------------------------------------------------------------------*
*&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
*&---------------------------------------------------------------------*
*       Send email
*----------------------------------------------------------------------*
FORM send_file_as_email_attachment TABLES pit_message
                                          pit_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: 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.

  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[] = pit_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.
  t_receivers-receiver = ld_email.
  t_receivers-rec_type = 'U'.
  t_receivers-com_type = 'INT'.
  t_receivers-notif_del = 'X'.
  t_receivers-notif_ndel = 'X'.
  APPEND t_receivers.

  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

*&---------------------------------------------------------------------*
*&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
*&---------------------------------------------------------------------*
*       Instructs mail send program for SAPCONNECT to send email.
*----------------------------------------------------------------------*
FORM initiate_mail_execute_program.
  WAIT UP TO 2 SECONDS.
  SUBMIT rsconn01 WITH mode = 'INT'
                WITH output = 'X'
                AND RETURN.
ENDFORM.                    " INITIATE_MAIL_EXECUTE_PROGRAM

*&---------------------------------------------------------------------*
*&      Form  POPULATE_EMAIL_MESSAGE_BODY
*&---------------------------------------------------------------------*
*        Populate message body text
*----------------------------------------------------------------------*
FORM populate_email_message_body.
  REFRESH it_message.
  it_message = 'Please find attached a list test ekpo records'.
  APPEND it_message.
ENDFORM.                    " POPULATE_EMAIL_MESSAGE_BODY

Sending Mails - Home Page

Hi,

https://forums.sdn.sap.com/thread.jspa?messageID=3065528&#30655283065528

https://forums.sdn.sap.com/thread.jspa?messageID=2959234&#29592342959234

https://forums.sdn.sap.com/thread.jspa?messageID=2571717&#25717172571717

https://forums.sdn.sap.com/thread.jspa?messageID=2989716&#29897162989716

https://forums.sdn.sap.com/thread.jspa?messageID=2933362&#29333622933362

 There are many threads like this to send external and internal emails from SAP. I thought to consolidate them. So, here is the code to send email from SAP with and with out attachments.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT zemail.

DATA: itcpo LIKE itcpo,
      tab_lines LIKE sy-tabix.

* Variables for EMAIL functionality
DATA: maildata   LIKE sodocchgi1.
DATA: mailpack   LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: mailhead   LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: mailbin    LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: mailtxt    LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: mailrec    LIKE somlrec90 OCCURS 0  WITH HEADER LINE.
DATA: solisti1   LIKE solisti1 OCCURS 0 WITH HEADER LINE.


PERFORM send_form_via_email.


************************************************************************
*       FORM  SEND_FORM_VIA_EMAIL                                      *
************************************************************************
FORM  send_form_via_email.

  CLEAR:    maildata, mailtxt, mailbin, mailpack, mailhead, mailrec.
  REFRESH:  mailtxt, mailbin, mailpack, mailhead, mailrec.

* Creation of the document to be sent File Name
  maildata-obj_name = 'TEST'.
* Mail Subject
  maildata-obj_descr = 'Subject'.

* Mail Contents
  mailtxt-line = 'Here is your file'.
  APPEND mailtxt.

* Prepare Packing List
  PERFORM prepare_packing_list.

* Set recipient - email address here!!!
  mailrec-receiver = 'you@yourcompany.com'.
  mailrec-rec_type  = 'U'.
  APPEND mailrec.

* Sending the document
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = maildata
      put_in_outbox              = ' '
    TABLES
      packing_list               = mailpack
      object_header              = mailhead
      contents_bin               = mailbin
      contents_txt               = mailtxt
      receivers                  = mailrec
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      operation_no_authorization = 4
      OTHERS                     = 99.

  IF sy-subrc = 0.
    SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
  ENDIF.

ENDFORM.                    "send_form_via_email

************************************************************************
*      Form  PREPARE_PACKING_LIST
************************************************************************
FORM prepare_packing_list.

  CLEAR:    mailpack, mailbin, mailhead.
  REFRESH:  mailpack, mailbin, mailhead.

  DESCRIBE TABLE mailtxt LINES tab_lines.
  READ TABLE mailtxt INDEX tab_lines.
  maildata-doc_size = ( tab_lines - 1 ) * 255 + strlen( mailtxt ).

* Creation of the entry for the compressed document
  CLEAR mailpack-transf_bin.
  mailpack-head_start = 1.
  mailpack-head_num = 0.
  mailpack-body_start = 1.
  mailpack-body_num = tab_lines.
  mailpack-doc_type = 'RAW'.
  APPEND mailpack.

  mailhead = 'TEST.TXT'.
  APPEND mailhead.



* File 1
  mailbin = 'This is file 1'.
  APPEND mailbin.

  DESCRIBE TABLE mailbin LINES tab_lines.

  mailpack-transf_bin = 'X'.
  mailpack-head_start = 1.
  mailpack-head_num = 1.
  mailpack-body_start = 1.
  mailpack-body_num = tab_lines.
  mailpack-doc_type = 'TXT'.
  mailpack-obj_name = 'TEST1'.
  mailpack-obj_descr = 'Subject'.
  mailpack-doc_size = tab_lines * 255.
  APPEND mailpack.



*File 2
  mailbin = 'This is file 2'.
  APPEND mailbin.

  DATA: start TYPE i.
  DATA: end TYPE i.

  start = tab_lines + 1.

  DESCRIBE TABLE mailbin LINES end.

  mailpack-transf_bin = 'X'.
  mailpack-head_start = 1.
  mailpack-head_num = 1.
  mailpack-body_start = start.
  mailpack-body_num = end.
  mailpack-doc_type = 'TXT'.
  mailpack-obj_name = 'TEST2'.
  mailpack-obj_descr = 'Subject'.
  mailpack-doc_size = tab_lines * 255.
  APPEND mailpack.


ENDFORM.                    "prepare_packing_list

*With PDF Attachment:*
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  EXPORTING
    formname = 'Z_TEST'
  IMPORTING
    fm_name  = v_fname.

CALL FUNCTION v_fname
  EXPORTING
    control_parameters = x_ctrl_p
  IMPORTING
    job_output_info    = x_output_data.

CALL FUNCTION 'CONVERT_OTF'
  EXPORTING
    format                = 'PDF'
    max_linewidth         = 134
  IMPORTING
    bin_filesize          = v_size
  TABLES
    otf                   = x_output_data-otfdata
    lines                 = it_lines
  EXCEPTIONS
    err_max_linewidth     = 1
    err_format            = 2
    err_conv_not_possible = 3
    OTHERS                = 4.

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
  EXPORTING
    line_width_dst              = 255
  TABLES
    content_in                  = it_lines
    content_out                 = it_soli
  EXCEPTIONS
    err_line_width_src_too_long = 1
    err_line_width_dst_too_long = 2
    err_conv_failed             = 3
    OTHERS                      = 4.

CALL FUNCTION 'FUNC_CONVERT_DATA_ODC01'
  EXPORTING
    iv_byte_mode = 'X'
  TABLES
    it_data      = it_lines
    et_data      = it_table.

*-----To caluculate total number of lines of internal table
DESCRIBE TABLE it_table LINES v_lines.

*-----Create Message Body and Title and Description
it_mess = 'successfully converted smartform from otf format to pdf' .
APPEND it_mess.

wa_doc_data-obj_name = 'smartform'.
wa_doc_data-expiry_dat = sy-datum + 10.
wa_doc_data-obj_descr = 'smartform'.
wa_doc_data-sensitivty = 'F'.
wa_doc_data-doc_size = v_lines * 255.
APPEND it_pcklist.

*-----PDF Attachment
it_pcklist-transf_bin = 'X'.
it_pcklist-head_start = 1.
it_pcklist-head_num = 0.
it_pcklist-body_start = 1.
it_pcklist-doc_size = v_lines_bin * 255 .
it_pcklist-body_num = v_lines.
it_pcklist-doc_type = 'PDF'.
it_pcklist-obj_name = 'smartform'.
it_pcklist-obj_descr = 'smart_desc'.
it_pcklist-obj_langu = 'E'.
it_pcklist-doc_size = v_lines * 255.
APPEND it_pcklist.

*-----Giving the receiver email-id
CLEAR it_receivers.
it_receivers-receiver = 'abcd@yahoo.com'.
it_receivers-rec_type = 'U'.
APPEND it_receivers.

*-----Calling the function module to sending email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    document_data              = wa_doc_data
    put_in_outbox              = 'X'
    commit_work                = 'X'
  TABLES
    packing_list               = it_pcklist
    contents_txt               = it_mess
    contents_hex               = it_table
    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.

Here is the sample code for Emailing reports in HTML format

Code listing for: ZEMAIL
Description: Email Reports in HTML Format

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT zemail.

DATA: send_request TYPE REF TO cl_bcs.
DATA: text TYPE bcsy_text.
DATA: document TYPE REF TO cl_document_bcs.
DATA: sender_id TYPE REF TO if_sender_bcs.
DATA: recipient TYPE REF TO if_recipient_bcs.
DATA: bcs_exception TYPE REF TO cx_bcs.
DATA: sent_to_all TYPE os_boolean.
DATA: conlength TYPE i ,
      conlengths TYPE so_obj_len ,
      result_content TYPE string .
DATA: content_length TYPE w3param-cont_len ,
      content_type TYPE w3param-cont_type,
      return_code TYPE w3param-ret_code .
DATA: listobject TYPE TABLE OF abaplist.
DATA: html_wa TYPE w3html.
DATA: html TYPE STANDARD TABLE OF w3html .
DATA: wa_rec TYPE ad_smtpadr .
DATA: bcs_message TYPE string .
DATA: tmp_str TYPE string .
DATA: prog TYPE programm ,
      var TYPE raldb_vari .

DATA: recepients TYPE bcsy_smtpa WITH HEADER LINE,
      return TYPE table_of_strings.
DATA : v_rec(40).


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: report TYPE program,
            variant TYPE raldb_vari,
            sender TYPE ad_smtpadr,
            subject TYPE so_obj_des.
SELECT-OPTIONS: s_rec FOR v_rec NO INTERVALS LOWER CASE.
SELECTION-SCREEN END OF BLOCK b1.

LOOP AT s_rec.
  TRANSLATE s_rec-low TO LOWER CASE.
  recepients = s_rec-low.

  APPEND recepients.
  CLEAR recepients .
ENDLOOP.
*recepients = 'seckharmc@gmail.com'.
*append recepients.

IF NOT recepients[] IS INITIAL .
  CLEAR: var, prog .
  MOVE: report TO prog ,
        variant TO var .
  TRANSLATE prog TO UPPER CASE .
  TRANSLATE var TO UPPER CASE .

  SUBMIT (prog) USING SELECTION-SET var EXPORTING LIST TO MEMORY AND RETURN.
  CLEAR: listobject , html .
  REFRESH : listobject, html .
  CALL FUNCTION 'LIST_FROM_MEMORY'
    TABLES
      listobject = listobject.
  CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
    EXPORTING
      report_name = prog
    TABLES
      html        = html
      listobject  = listobject.
  CLEAR tmp_str .
  CLEAR : html_wa .

  LOOP AT html INTO html_wa .
    CONCATENATE tmp_str html_wa INTO tmp_str.
  ENDLOOP .
  CLEAR: conlength,conlengths .
  conlength = strlen( tmp_str ) .
  conlengths = conlength .
  TRY.
      CLEAR send_request .
      send_request = cl_bcs=>create_persistent( ).
      CLEAR document .
      document = cl_document_bcs=>create_document(
                    i_type = 'HTM'
                    i_text = html
                    i_length = conlengths
                    i_subject = subject ).

* add document to send request
      CALL METHOD send_request->set_document( document ).
      CLEAR sender_id .
      sender_id = cl_cam_address_bcs=>create_internet_address( sender ).
      CALL METHOD send_request->set_sender
        EXPORTING
          i_sender = sender_id.
      CLEAR wa_rec .
      LOOP AT recepients INTO wa_rec .
        CLEAR recipient .
        recipient = cl_cam_address_bcs=>create_internet_address( wa_rec ).
* add recipient with its respective attributes to send request
        CALL METHOD send_request->add_recipient
          EXPORTING
            i_recipient = recipient
            i_express   = 'X'.

      ENDLOOP .
      CALL METHOD send_request->set_status_attributes
        EXPORTING
          i_requested_status = 'E'
          i_status_mail      = 'E'.
      CALL METHOD send_request->set_send_immediately( 'X' ).

* ---------- send document ---------------------------------------
      CALL METHOD send_request->send(
        EXPORTING
          i_with_error_screen = 'X'
        RECEIVING
          result              = sent_to_all ).
      IF sent_to_all = 'X'.
        APPEND 'Mail sent successfully ' TO return .
        WRITE:/ 'Mail sent successfully '.
      ENDIF.
      COMMIT WORK.
    CATCH cx_bcs INTO bcs_exception.
      bcs_message = bcs_exception->get_text( ).
      APPEND bcs_message TO return .
      EXIT.
  ENDTRY.
ELSE .
  APPEND 'Specify email address for sending' TO return .
ENDIF .

*Selection texts
*--------------------------------------------------------------------*
* REPORT Program Name
* SENDER Sender's E-Mail ID
* SUBJECT D .
* S_REC Receiver Email IDs
* VARIANT D .
*--------------------------------------------------------------------*
REPORT z_demo_mail.

*&---------------------------------------------------------------------*
*& Global data declaration
*&---------------------------------------------------------------------*

DATA:
w_document_data LIKE sodocchgi1.

DATA:
i_object_header TYPE STANDARD TABLE OF solisti1,
w_object_header TYPE solisti1,

i_object_content TYPE STANDARD TABLE OF solisti1,
w_object_content TYPE solisti1,

i_contents_hex TYPE STANDARD TABLE OF solix,
w_contents_hex TYPE solix,

i_object_para TYPE STANDARD TABLE OF soparai1,
w_object_para TYPE soparai1,

i_object_parb TYPE STANDARD TABLE OF soparbi1,
w_object_parb TYPE soparbi1,

i_receivers TYPE STANDARD TABLE OF somlreci1,
w_receivers TYPE somlreci1.

*&---------------------------------------------------------------------*
*& Selection screen
*&---------------------------------------------------------------------*
PARAMETER : uname TYPE syuname DEFAULT sy-uname.

*&---------------------------------------------------------------------*
*& Start-of-selection event
*&---------------------------------------------------------------------*
START-OF-SELECTION.

* Populate receiver info
  CLEAR: w_receivers.
  w_receivers-receiver = uname.
  w_receivers-rec_type = 'B'.
  APPEND w_receivers TO i_receivers.

* Populate header data
  w_document_data-obj_name = 'Your action required'.
  w_document_data-obj_descr = 'Pl. press execute button'.
  w_document_data-sensitivty = 'O'.
  w_document_data-proc_type = 'R'.
  w_document_data-proc_name = 'RSINCL00'.


* Populate mail content
  CLEAR: w_object_content.
  CONCATENATE 'Please execute report: '
  w_document_data-proc_name
  INTO w_object_content-line SEPARATED BY space.
  APPEND w_object_content TO i_object_content.


  CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
    EXPORTING
      document_data              = w_document_data
      document_type              = 'RAW'
    TABLES
      object_content             = i_object_content
      object_para                = i_object_para
      receivers                  = i_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.
  IF sy-subrc = 0.
    MESSAGE s000(z_zzz_ca_messages)
    WITH 'Mail send successfully'(001).
  ENDIF.
 

 

 

Author: Himanshu Kanekar
Submitted: 14-Oct-2010
Related Links:


A very common requirement by the user is to export data to a Formatted Microsoft Excel Spreadsheet and send it to an Email or post it on a FTP Server.  If the report is a simple ALV grid then the ALV control can do it automatically, but it would be a simple Excel Spreadsheet without any formatting. In order to create a Formatted Excel Sheet we can either use the OLE (Object Linking & Enabling) Concept or the XML method.

The OLE method involves opening an instance of Microsoft Excel and then preparing the sheet. The major disadvantage of this method is that it can be executed in Foreground only.

An ABAP Program can create an XML file and it can be opened directly into Excel.  The advantages and possibilities are endless:

  • An xml file is plain text so can be created on the Presentation Server or Application Server;
  • It can be sent as an Attachment to an Email;
  • Colours, Fonts, Number Formats and so on can be specified;
  • Formatting can be applied to Rows, Columns or Single Cells;
  • Column Heights and Widths can be specified, or Auto-Formatted;
  • Multiple Worksheets can be created;
  • Formulas can be entered in cells;

This is a Sample Code for fetching the User Login Details and sending it as an XLS attachment to an Email using the XML method -

REPORT  sy-repid.

TYPE-POOLS: ixml.

*------------------------------------------------------------------------*
*                           Data Declarations                            *
*------------------------------------------------------------------------*

* Structure for Final Internal Table
TYPES: BEGIN OF ty_final,
        srno(3) TYPE n,
        user_id TYPE usr02-bname,
        full_name TYPE bapiaddr3-fullname,
        dept TYPE bapiaddr3-department,
        login(3) TYPE c,
       END OF ty_final.

* Structure for USR02
TYPES: BEGIN OF ty_usr02,
        bname TYPE usr02-bname,
        trdat TYPE usr02-trdat,
       END OF ty_usr02.

* Internal Table & Work Area for Final Internal Table
DATA: it_final TYPE TABLE OF ty_final,
      wa_final TYPE ty_final.

* Internal Table & Work Area for USR02 Internal Table
DATA: it_usr02 TYPE TABLE OF ty_usr02,
      wa_usr02 TYPE ty_usr02.

* Work Area for ADD3_DATA Structre
DATA: wa_addr TYPE bapiaddr3.
DATA: it_return TYPE TABLE OF bapiret2.

DATA: lv_date TYPE d.
DATA: lv_filename TYPE string.

TYPES: BEGIN OF xml_line,
        data(255) TYPE x,
       END OF xml_line.

DATA: l_ixml            TYPE REF TO if_ixml,
      l_streamfactory   TYPE REF TO if_ixml_stream_factory,
      l_ostream         TYPE REF TO if_ixml_ostream,
      l_renderer        TYPE REF TO if_ixml_renderer,
      l_document        TYPE REF TO if_ixml_document.

DATA: l_element_root        TYPE REF TO if_ixml_element,
      ns_attribute          TYPE REF TO if_ixml_attribute,
      r_element_properties  TYPE REF TO if_ixml_element,
      r_element             TYPE REF TO if_ixml_element,
      r_worksheet           TYPE REF TO if_ixml_element,
      r_table               TYPE REF TO if_ixml_element,
      r_column              TYPE REF TO if_ixml_element,
      r_row                 TYPE REF TO if_ixml_element,
      r_cell                TYPE REF TO if_ixml_element,
      r_data                TYPE REF TO if_ixml_element,
      l_value               TYPE string,
      l_type                TYPE string,
      l_text(100)           TYPE c,
      r_styles              TYPE REF TO if_ixml_element,
      r_style               TYPE REF TO if_ixml_element,
      r_style1              TYPE REF TO if_ixml_element,
      r_format              TYPE REF TO if_ixml_element,
      r_border              TYPE REF TO if_ixml_element,
      num_rows              TYPE i.

DATA: l_xml_table       TYPE TABLE OF xml_line,
      wa_xml            TYPE xml_line,
      l_xml_size        TYPE i,
      l_rc              TYPE i.


*------------------------------------------------------------------------*
*                             Initialization                             *
*------------------------------------------------------------------------*

INITIALIZATION.
  lv_date = sy-datum - 1.


*------------------------------------------------------------------------*
*                           Start of Selection                           *
*------------------------------------------------------------------------*

START-OF-SELECTION.

  PERFORM get_user_data.
  PERFORM process_xml_data.
  PERFORM send_mail.


*&---------------------------------------------------------------------*
*&      Form  get_user_data
*&---------------------------------------------------------------------*
*       Fetch User details from USR02
*----------------------------------------------------------------------*

FORM get_user_data.

  REFRESH it_final.
  SELECT DISTINCT bname trdat FROM usr02 INTO TABLE it_usr02.
  SORT it_usr02 BY bname.

  IF NOT it_usr02[] IS INITIAL.

    LOOP AT it_usr02 INTO wa_usr02.

      CLEAR wa_final.
      wa_final-srno = sy-tabix.                   " Serial No.
      wa_final-user_id = wa_usr02-bname.          " User ID

      CALL FUNCTION 'BAPI_USER_GET_DETAIL'
        EXPORTING
          username = wa_usr02-bname
        IMPORTING
          address  = wa_addr
        TABLES
          return   = it_return.

      IF sy-subrc EQ 0.
        wa_final-full_name = wa_addr-fullname.    " Full Name
        wa_final-dept = wa_addr-department.       " Department
      ENDIF.

      IF wa_usr02-trdat EQ lv_date.
        wa_final-login = 'YES'.                   " Login on Previous Day
      ELSE.
        wa_final-login = 'NO'.
      ENDIF.

      APPEND wa_final TO it_final.

    ENDLOOP.

  ENDIF.

ENDFORM.                    " get_user_data


*&---------------------------------------------------------------------*
*&      Form  SEND_MAIL
*&---------------------------------------------------------------------*
*       Send Email
*----------------------------------------------------------------------*

FORM send_mail.

  DATA: objpack   LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
  DATA: objhead   LIKE solisti1 OCCURS 1 WITH HEADER LINE.
  DATA: objbin    LIKE solix OCCURS 10 WITH HEADER LINE.
  DATA: objtxt    LIKE solisti1 OCCURS 10 WITH HEADER LINE.
  DATA: reclist   LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
  DATA: doc_chng  LIKE sodocchgi1.
  DATA: tab_lines LIKE sy-tabix.
  DATA: l_num(3).
  DATA: subj_date(10) TYPE c.

* Mail Subject
  CONCATENATE lv_date+6(2) '-' lv_date+4(2) '-' lv_date+0(4) INTO subj_date.
  CONCATENATE 'SAP Application Usage Report ' subj_date INTO doc_chng-obj_descr SEPARATED BY space.

* Mail Contents
  objtxt = 'Dear User,'.
  APPEND objtxt.

  CLEAR objtxt.
  APPEND objtxt.

  CONCATENATE 'Please find the attached SAP Application Usage Report for ' subj_date INTO objtxt SEPARATED BY space.              " Mail Contents
  APPEND objtxt.

  CLEAR objtxt.
  APPEND objtxt.

  objtxt = 'Thanks & Regards,'.
  APPEND objtxt.

  objtxt = 'Himanshu Kanekar'.
  APPEND objtxt.

  DESCRIBE TABLE objtxt LINES tab_lines.
  READ TABLE objtxt INDEX tab_lines.
  doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

* Packing List For the E-mail Body
  objpack-head_start = 1.
  objpack-head_num   = 0.
  objpack-body_start = 1.
  objpack-body_num   = tab_lines.
  objpack-doc_type   = 'RAW'.
  APPEND objpack.

* Creation of the Document Attachment
  LOOP AT l_xml_table INTO wa_xml.
    CLEAR objbin.
    objbin-line = wa_xml-data.
    APPEND objbin.
  ENDLOOP.

  DESCRIBE TABLE objbin LINES tab_lines.
  objhead = 'SAP Login Details'.
  APPEND objhead.

* Packing List For the E-mail Attachment
  objpack-transf_bin = 'X'.
  objpack-head_start = 1.
  objpack-head_num   = 0.
  objpack-body_start = 1.
  objpack-body_num = tab_lines.
  CONCATENATE 'SAP_Login_Details' subj_date INTO objpack-obj_descr SEPARATED BY space.
  objpack-doc_type = 'XLS'.
  objpack-doc_size = tab_lines * 255.
  APPEND objpack.

* Target Recipent
  CLEAR reclist.
  reclist-receiver = 'user@company.com'.
  reclist-rec_type = 'U'.
  APPEND reclist.

* Sending the document
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = doc_chng
      put_in_outbox              = 'X'
    TABLES
      packing_list               = objpack
      object_header              = objhead
      contents_txt               = objtxt
      contents_hex               = objbin
      receivers                  = reclist
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      operation_no_authorization = 4
      OTHERS                     = 99.

ENDFORM.                    " SEND_MAIL



*&---------------------------------------------------------------------*
*&      Form  process_xml_data
*&---------------------------------------------------------------------*
*       Process XML Data
*----------------------------------------------------------------------*

FORM process_xml_data .

* Creating a ixml Factory
  l_ixml = cl_ixml=>create( ).

* Creating the DOM Object Model
  l_document = l_ixml->create_document( ).

* Create Root Node 'Workbook'
  l_element_root  = l_document->create_simple_element( name = 'Workbook'  parent = l_document ).
  l_element_root->set_attribute( name = 'xmlns'  value = 'urn:schemas-microsoft-com:office:spreadsheet' ).

  ns_attribute = l_document->create_namespace_decl( name = 'ss'  prefix = 'xmlns'  uri = 'urn:schemas-microsoft-com:office:spreadsheet' ).
  l_element_root->set_attribute_node( ns_attribute ).

  ns_attribute = l_document->create_namespace_decl( name = 'x'  prefix = 'xmlns'  uri = 'urn:schemas-microsoft-com:office:excel' ).
  l_element_root->set_attribute_node( ns_attribute ).

* Create node for document properties.
  r_element_properties = l_document->create_simple_element( name = 'TEST_REPORT'  parent = l_element_root ).
  l_value = sy-uname.
  l_document->create_simple_element( name = 'Author'  value = l_value  parent = r_element_properties  ).

* Styles
  r_styles = l_document->create_simple_element( name = 'Styles'  parent = l_element_root  ).

* Style for Header
  r_style  = l_document->create_simple_element( name = 'Style'   parent = r_styles  ).
  r_style->set_attribute_ns( name = 'ID'  prefix = 'ss'  value = 'Header' ).

  r_format  = l_document->create_simple_element( name = 'Font'  parent = r_style  ).
  r_format->set_attribute_ns( name = 'Bold'  prefix = 'ss'  value = '1' ).

  r_format  = l_document->create_simple_element( name = 'Interior' parent = r_style  ).
  r_format->set_attribute_ns( name = 'Color'   prefix = 'ss'  value = '#92D050' ).
  r_format->set_attribute_ns( name = 'Pattern' prefix = 'ss'  value = 'Solid' ).

  r_format  = l_document->create_simple_element( name = 'Alignment'  parent = r_style  ).
  r_format->set_attribute_ns( name = 'Vertical'  prefix = 'ss'  value = 'Center' ).
  r_format->set_attribute_ns( name = 'WrapText'  prefix = 'ss'  value = '1' ).

  r_border  = l_document->create_simple_element( name = 'Borders'  parent = r_style ).
  r_format  = l_document->create_simple_element( name = 'Border'   parent = r_border  ).
  r_format->set_attribute_ns( name = 'Position'  prefix = 'ss'  value = 'Bottom' ).
  r_format->set_attribute_ns( name = 'LineStyle'  prefix = 'ss'  value = 'Continuous' ).
  r_format->set_attribute_ns( name = 'Weight'  prefix = 'ss'  value = '1' ).

  r_format  = l_document->create_simple_element( name = 'Border'   parent = r_border  ).
  r_format->set_attribute_ns( name = 'Position'  prefix = 'ss'  value = 'Left' ).
  r_format->set_attribute_ns( name = 'LineStyle'  prefix = 'ss'  value = 'Continuous' ).
  r_format->set_attribute_ns( name = 'Weight'  prefix = 'ss'  value = '1' ).

  r_format  = l_document->create_simple_element( name = 'Border'   parent = r_border  ).
  r_format->set_attribute_ns( name = 'Position'  prefix = 'ss'  value = 'Top' ).
  r_format->set_attribute_ns( name = 'LineStyle'  prefix = 'ss'  value = 'Continuous' ).
  r_format->set_attribute_ns( name = 'Weight'  prefix = 'ss'  value = '1' ).

  r_format  = l_document->create_simple_element( name = 'Border'   parent = r_border  ).
  r_format->set_attribute_ns( name = 'Position'  prefix = 'ss'  value = 'Right' ).
  r_format->set_attribute_ns( name = 'LineStyle'  prefix = 'ss'  value = 'Continuous' ).
  r_format->set_attribute_ns( name = 'Weight'  prefix = 'ss'  value = '1' ).

* Style for Data
  r_style1  = l_document->create_simple_element( name = 'Style'   parent = r_styles  ).
  r_style1->set_attribute_ns( name = 'ID'  prefix = 'ss'  value = 'Data' ).

  r_border  = l_document->create_simple_element( name = 'Borders'  parent = r_style1 ).
  r_format  = l_document->create_simple_element( name = 'Border'   parent = r_border  ).
  r_format->set_attribute_ns( name = 'Position'  prefix = 'ss'  value = 'Bottom' ).
  r_format->set_attribute_ns( name = 'LineStyle'  prefix = 'ss'  value = 'Continuous' ).
  r_format->set_attribute_ns( name = 'Weight'  prefix = 'ss'  value = '1' ).

  r_format  = l_document->create_simple_element( name = 'Border'   parent = r_border  ).
  r_format->set_attribute_ns( name = 'Position'  prefix = 'ss'  value = 'Left' ).
  r_format->set_attribute_ns( name = 'LineStyle'  prefix = 'ss'  value = 'Continuous' ).
  r_format->set_attribute_ns( name = 'Weight'  prefix = 'ss'  value = '1' ).

  r_format  = l_document->create_simple_element( name = 'Border'   parent = r_border  ).
  r_format->set_attribute_ns( name = 'Position'  prefix = 'ss'  value = 'Top' ).
  r_format->set_attribute_ns( name = 'LineStyle'  prefix = 'ss'  value = 'Continuous' ).
  r_format->set_attribute_ns( name = 'Weight'  prefix = 'ss'  value = '1' ).

  r_format  = l_document->create_simple_element( name = 'Border'   parent = r_border  ).
  r_format->set_attribute_ns( name = 'Position'  prefix = 'ss'  value = 'Right' ).
  r_format->set_attribute_ns( name = 'LineStyle'  prefix = 'ss'  value = 'Continuous' ).
  r_format->set_attribute_ns( name = 'Weight'  prefix = 'ss'  value = '1' ).


* Worksheet
  r_worksheet = l_document->create_simple_element( name = 'Worksheet'  parent = l_element_root ).
  r_worksheet->set_attribute_ns( name = 'Name'  prefix = 'ss'  value = 'Sheet1' ).

* Table
  r_table = l_document->create_simple_element( name = 'Table'  parent = r_worksheet ).
  r_table->set_attribute_ns( name = 'FullColumns'  prefix = 'x'  value = '1' ).
  r_table->set_attribute_ns( name = 'FullRows'     prefix = 'x'  value = '1' ).

* Column Formatting
  r_column = l_document->create_simple_element( name = 'Column'  parent = r_table ).
  r_column->set_attribute_ns( name = 'Width'  prefix = 'ss'  value = '40' ).

  r_column = l_document->create_simple_element( name = 'Column'  parent = r_table ).
  r_column->set_attribute_ns( name = 'Width'  prefix = 'ss'  value = '90' ).

  r_column = l_document->create_simple_element( name = 'Column'  parent = r_table ).
  r_column->set_attribute_ns( name = 'Width'  prefix = 'ss'  value = '140' ).

  r_column = l_document->create_simple_element( name = 'Column'  parent = r_table ).
  r_column->set_attribute_ns( name = 'Width'  prefix = 'ss'  value = '150' ).

  r_column = l_document->create_simple_element( name = 'Column'  parent = r_table ).
  r_column->set_attribute_ns( name = 'Width'  prefix = 'ss'  value = '90' ).

* Blank Row
  r_row = l_document->create_simple_element( name = 'Row'  parent = r_table ).

* Column Headers Row
  r_row = l_document->create_simple_element( name = 'Row'  parent = r_table ).
  r_row->set_attribute_ns( name = 'AutoFitHeight'  prefix = 'ss'  value = '1' ).

* Sr. No.
  r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
  r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Header' ).
  r_data = l_document->create_simple_element( name = 'Data'  value = 'Sr. No.'  parent = r_cell ).
  r_data->set_attribute_ns( name = 'Type'  prefix = 'ss' value = 'String' ).

* User Name
  r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
  r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Header' ).
  r_data = l_document->create_simple_element( name = 'Data'  value = 'User Name'  parent = r_cell ).
  r_data->set_attribute_ns( name = 'Type'  prefix = 'ss' value = 'String' ).

* Full Name
  r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
  r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Header' ).
  r_data = l_document->create_simple_element( name = 'Data'  value = 'Full Name'  parent = r_cell ).
  r_data->set_attribute_ns( name = 'Type'  prefix = 'ss' value = 'String' ).

* Department
  r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
  r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Header' ).
  r_data = l_document->create_simple_element( name = 'Data'  value = 'Department'  parent = r_cell ).
  r_data->set_attribute_ns( name = 'Type'  prefix = 'ss' value = 'String' ).

* Login
  r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
  r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Header' ).
  CONCATENATE 'Login - ' lv_date+6(2) '/' lv_date+4(2) '/' lv_date+0(4) INTO l_value.
  r_data = l_document->create_simple_element( name = 'Data'  value = l_value  parent = r_cell ).
  r_data->set_attribute_ns( name = 'Type'  prefix = 'ss' value = 'String' ).

* Blank Row after Column Headers
  r_row = l_document->create_simple_element( name = 'Row'  parent = r_table ).
  r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
  r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Data' ).

  r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
  r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Data' ).

  r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
  r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Data' ).

  r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
  r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Data' ).

  r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
  r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Data' ).

* Data Table
  LOOP AT it_final INTO wa_final.

    r_row = l_document->create_simple_element( name = 'Row'  parent = r_table ).

* Sr. No.
    r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
    r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Data' ).
    l_value = sy-tabix.
    CONDENSE l_value NO-GAPS.
    r_data = l_document->create_simple_element( name = 'Data'  value = l_value   parent = r_cell ).           " Data
    r_data->set_attribute_ns( name = 'Type'  prefix = 'ss'  value = 'Number' ).                               " Cell format

* User Name
    r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
    r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Data' ).
    l_value = wa_final-user_id.
    r_data = l_document->create_simple_element( name = 'Data'  value = l_value   parent = r_cell ).           " Data
    r_data->set_attribute_ns( name = 'Type'  prefix = 'ss'  value = 'String' ).                               " Cell format

* Full Name
    r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
    r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Data' ).
    l_value = wa_final-full_name.
    r_data = l_document->create_simple_element( name = 'Data'  value = l_value   parent = r_cell ).           " Data
    r_data->set_attribute_ns( name = 'Type'  prefix = 'ss'  value = 'String' ).                               " Cell format

* Department
    r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
    r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Data' ).
    l_value = wa_final-dept.
    r_data = l_document->create_simple_element( name = 'Data'  value = l_value   parent = r_cell ).           " Data
    r_data->set_attribute_ns( name = 'Type'  prefix = 'ss'  value = 'String' ).                               " Cell format

* Login
    r_cell = l_document->create_simple_element( name = 'Cell'  parent = r_row ).
    r_cell->set_attribute_ns( name = 'StyleID'  prefix = 'ss'  value = 'Data' ).
    l_value = wa_final-login.
    r_data = l_document->create_simple_element( name = 'Data'  value = l_value   parent = r_cell ).          " Data
    r_data->set_attribute_ns( name = 'Type'  prefix = 'ss'  value = 'String' ).                              " Cell format

  ENDLOOP.

* Creating a Stream Factory
  l_streamfactory = l_ixml->create_stream_factory( ).

* Connect Internal XML Table to Stream Factory
  l_ostream = l_streamfactory->create_ostream_itable( table = l_xml_table ).

* Rendering the Document
  l_renderer = l_ixml->create_renderer( ostream  = l_ostream  document = l_document ).
  l_rc = l_renderer->render( ).

* Saving the XML Document
  l_xml_size = l_ostream->get_num_written_raw( ).

ENDFORM.                    " process_xml_data

The output of the Report is a Formatted Excel Sheet as an email attachment.

END-OF-SELECTION.
  IF getfile EQ 'X'.
    IF NOT t_app_letr[] IS INITIAL.
      PERFORM mail_merge_data_to_ms_word.
    ELSE.
      WRITE: / 'NO DATA AVAILABLE FOR THIS SELECTION!'.
    ENDIF.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  MAIL_MERGE_DATA_TO_MS_WORD
*&---------------------------------------------------------------------*
* Enclosing the other sub modules for the easy maintenance
*----------------------------------------------------------------------*
* No Parameters for this subroutine
*----------------------------------------------------------------------*
FORM mail_merge_data_to_ms_word .
  PERFORM clear_existing_data_file.
  PERFORM download_employee_data_to_pc.
  PERFORM start_ms_word.
  PERFORM fill_ms_word_with_data.
ENDFORM.                    " MAIL_MERGE_DATA_TO_MS_WORD
*&---------------------------------------------------------------------*
*&      FORM  CLEAR_EXISTING_DATA_FILE
*&---------------------------------------------------------------------*
*  Clearing the existing DATA file used for Merge
*----------------------------------------------------------------------*
* No Parameters for this subroutine
*----------------------------------------------------------------------*
FORM clear_existing_data_file .
  DATA: file_name TYPE string.
  DATA: result TYPE abap_bool.
  DATA: rc TYPE i.
  file_name = twrkfile.

  CALL METHOD cl_gui_frontend_services=>file_exist
    EXPORTING
      file            = file_name
    RECEIVING
      result          = result
    EXCEPTIONS
      cntl_error      = 1
      error_no_gui    = 2
      wrong_parameter = 3
      OTHERS          = 4.

  CALL METHOD cl_gui_cfw=>flush.
  IF result EQ abap_true.
    CALL METHOD cl_gui_frontend_services=>file_delete
      EXPORTING
        filename = file_name
      CHANGING
        rc       = rc
      EXCEPTIONS
        OTHERS   = 0.

* FLUSH TO EXECUTE THE DELETION
    CALL METHOD cl_gui_cfw=>flush.
  ENDIF.

ENDFORM.                    " CLEAR_EXISTING_DATA_FILE
*&---------------------------------------------------------------------*
*&      FORM  DOWNLAOD_EMPLOYEE_DATA_TO_PC
*&---------------------------------------------------------------------*
*  Download here for e.g. employee data to PC (Data File)
*----------------------------------------------------------------------*
* No Parameters passed to this subroutine
*----------------------------------------------------------------------*
FORM download_employee_data_to_pc.
  DATA: file_name TYPE string.
  DATA: cnt TYPE i.
  DATA: lt_download TYPE STANDARD TABLE OF string,
        lv_download TYPE string,
        lv_hstr(1024) TYPE c.

  CLASS cl_abap_char_utilities DEFINITION LOAD.
  CONSTANTS: lc_tab TYPE string
                    VALUE cl_abap_char_utilities=>horizontal_tab.

  FIELD-SYMBOLS: <field> TYPE any,
                 <data_tab_wa> TYPE any.

  PERFORM get_all_field_names.

  CLEAR lv_download.
  LOOP AT fieldnames.
    WRITE fieldnames TO lv_hstr LEFT-JUSTIFIED.
    IF sy-tabix > 1.
      CONCATENATE lv_download lc_tab lv_hstr
                  INTO lv_download.
    ELSE.
      CONCATENATE lv_download lv_hstr
                  INTO lv_download.
    ENDIF.
  ENDLOOP.
  APPEND lv_download TO lt_download.

* THEN THE DATA TABLE
  LOOP AT t_app_letr
       ASSIGNING <data_tab_wa>.
    cnt = 0.
    CLEAR lv_download.
    sy-subrc = 0.
    WHILE sy-subrc = 0.
      cnt = cnt + 1.
      ASSIGN COMPONENT cnt OF STRUCTURE <data_tab_wa> TO <field>.
      CHECK sy-subrc = 0.
      WRITE <field> TO lv_hstr LEFT-JUSTIFIED.
      IF cnt > 1.
        CONCATENATE lv_download lc_tab lv_hstr
                    INTO lv_download.
      ELSE.
        CONCATENATE lv_download lv_hstr
                    INTO lv_download.
      ENDIF.
    ENDWHILE.
    APPEND lv_download TO lt_download.
  ENDLOOP.

  file_name = twrkfile.
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                = file_name
      write_field_separator   = 'X'
      trunc_trailing_blanks   = 'X'
    TABLES
      data_tab                = lt_download
    EXCEPTIONS
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6
      header_not_allowed      = 7
      separator_not_allowed   = 8
      filesize_not_allowed    = 9
      header_too_long         = 10
      dp_error_create         = 11
      dp_error_send           = 12
      dp_error_write          = 13
      unknown_dp_error        = 14
      access_denied           = 15
      dp_out_of_memory        = 16
      disk_full               = 17
      dp_timeout              = 18
      file_not_found          = 19
      dataprovider_exception  = 20
      control_flush_error     = 21
      OTHERS                  = 22.
  IF sy-subrc <> 0.
    CASE sy-subrc.
      WHEN 1.
        RAISE file_write_error.
      WHEN 2.
        RAISE no_batch.
      WHEN 3.
        RAISE gui_refuse_filetransfer.
      WHEN 4.
        RAISE invalid_type .
      WHEN 5.
        RAISE no_authority.
      WHEN 6.
        RAISE unknown_error.
      WHEN 7.
        RAISE header_not_allowed.
      WHEN 8.
        RAISE separator_not_allowed.
      WHEN 9.
        RAISE filesize_not_allowed.
      WHEN 10.
        RAISE header_too_long.
      WHEN 11.
        RAISE dp_error_create.
      WHEN 12.
        RAISE dp_error_send.
      WHEN 13.
        RAISE dp_error_write.
      WHEN 14.
        RAISE unknown_dp_error.
      WHEN 15.
        RAISE access_denied.
      WHEN 16.
        RAISE dp_out_of_memory.
      WHEN 17.
        RAISE disk_full.
      WHEN 18.
        RAISE dp_timeout.
      WHEN 19.
        RAISE file_not_found.
      WHEN 20.
        RAISE dataprovider_exception.
      WHEN 21.
        RAISE control_flush_error.
      WHEN OTHERS.
        RAISE unknown_error.
    ENDCASE.
  ENDIF.

ENDFORM.                               " DOWNLAOD_EMPLOYEE_DATA_TO_PC
*&---------------------------------------------------------------------*
*&      FORM  OPEN_MS_WORD
*&---------------------------------------------------------------------*
* Opens the MS Word Document
*----------------------------------------------------------------------*
* No parameters passed here.
*----------------------------------------------------------------------*
FORM start_ms_word .
  DATA: xcode   LIKE sy-xcode,
        ok_code LIKE sy-xcode,
        rc TYPE i,
        platform TYPE i,
        registry_entry(255) TYPE c,
        reg_value TYPE string,
        temp_dir TYPE string.
  DATA: version_str(80) TYPE c,
        word_version TYPE i.
  DATA: documents TYPE ole2_object.

* START WITH OLE AUTOMATION
  CALL METHOD cl_gui_frontend_services=>registry_get_value
    EXPORTING
      root                = cl_gui_frontend_services=>hkey_classes_root
      key                 = 'WORD.BASIC\CURVER'
      value               = ''
    IMPORTING
      reg_value           = reg_value
    EXCEPTIONS
      get_regvalue_failed = 1
      cntl_error          = 2
      error_no_gui        = 3
      OTHERS              = 4.
  IF sy-subrc <> 0.
    RAISE download_problem.
  ENDIF.
  CALL METHOD cl_gui_cfw=>flush.
  version_str = reg_value.

  SHIFT version_str LEFT BY 11 PLACES.
  MOVE version_str TO word_version.

  IF word_version < 8.
    CREATE OBJECT wordobj 'WORD.BASIC'.
  ELSE.
    CREATE OBJECT worddoc 'WORD.DOCUMENT'.
    GET PROPERTY OF worddoc 'APPLICATION' = wordapp.
    SET PROPERTY OF wordapp 'VISIBLE' = 1.
    GET PROPERTY OF wordapp 'WORDBASIC' = wordobj.
    CALL METHOD OF
        wordobj
        'FILECLOSE'.
  ENDIF.
  CALL METHOD OF
      wordobj
      'APPSHOW'.

* SERIENBRIEFDATEI ЖFFNEN
  IF word_version > 8.
    GET PROPERTY OF wordapp 'DOCUMENTS' = documents.

    CALL METHOD OF
        documents
        'OPEN'

      EXPORTING
        #01       = dwrkfile  "FILE NAME
        #02       = 0.              "CONFIRM CONVERSION
  ELSE.
    CALL METHOD OF
        wordobj
        'FILEOPEN'

      EXPORTING
        #01        = dwrkfile
        #02        = 0.
  ENDIF.

ENDFORM.                    " OPEN_MS_WORD
*&---------------------------------------------------------------------*
*&      FORM  FILL_MS_WORD_WITH_DATA
*&---------------------------------------------------------------------*
* Fills the MS word merge fields with data
*----------------------------------------------------------------------*
* No parameters passed for this subroutine
*----------------------------------------------------------------------*
FORM fill_ms_word_with_data .
  DATA: passwort(15).
  CALL METHOD OF
      wordobj
      'MAILMERGEMAINDOCUMENTTYPE'

    EXPORTING
      #01                         = 0.
  CALL METHOD OF
      wordobj
      'MAILMERGEOPENDATASOURCE'

    EXPORTING
      #01                       = twrkfile
      #02                       = 0
      #03                       = 1
      #04                       = 0
      #05                       = 0
      #06                       = passwort.
  CALL METHOD OF
      wordobj
      'MAILMERGEEDITMAINDOCUMENT'.
  CALL METHOD OF
      wordobj
      'MAILMERGETODOC'.

ENDFORM.                    " FILL_MS_WORD_WITH_DATA
*&---------------------------------------------------------------------*
*&      FORM  GET_ALL_FIELD_NAMES
*&---------------------------------------------------------------------*
*  Gets all the field names from the input word file name
*----------------------------------------------------------------------*
* No parameters for this subroutine.
*----------------------------------------------------------------------*
FORM get_all_field_names.
  TYPE-POOLS: sydes.
  TYPE-POOLS slis.
  DATA:  td TYPE sydes_desc.
  DATA: name_header TYPE sydes_nameinfo.
  DATA: name LIKE name_header.
  DATA: types_header TYPE sydes_typeinfo.
  DATA: type LIKE types_header.
  DATA: prev_tabix LIKE sy-tabix.
  DATA: continue_field(1) TYPE c.
  DATA: search_str(40) TYPE c.
  DATA: s_length(5) TYPE p.

  DATA: BEGIN OF stru_tab OCCURS 0,
          name(30) TYPE c,
          fldname(30) TYPE c,
          index    LIKE sy-tabix,
          length(3) TYPE n,
          type(1)   TYPE c,
          decimals(2) TYPE n,
        END OF stru_tab.

  CLEAR: td.
  DESCRIBE FIELD t_app_letr INTO td.

  CLEAR: stru_tab[], stru_tab.
  DO 1000 TIMES.
    READ TABLE td-types INTO types_header INDEX sy-index.
    IF sy-subrc NE 0.
      EXIT.
    ENDIF.
    type = types_header.
    stru_tab-index = type-idx_name.
    stru_tab-type  = type-type.
    stru_tab-length = type-length.
    stru_tab-decimals = type-decimals.
    CHECK stru_tab-index NE 0.
    APPEND stru_tab.
  ENDDO.

  DO 1000 TIMES.
    READ TABLE td-names INTO name_header INDEX sy-index.
    IF sy-subrc NE 0.
      EXIT.
    ENDIF.
    name = name_header.
    IF continue_field NE space.
      READ TABLE stru_tab INDEX prev_tabix.
      IF sy-subrc EQ 0.
        CONCATENATE stru_tab-fldname name-name INTO stru_tab-fldname.
        MODIFY stru_tab INDEX prev_tabix.
        CLEAR: prev_tabix, continue_field.
      ENDIF.
    ELSE.
      LOOP AT stru_tab WHERE index EQ sy-index.
        stru_tab-fldname = name-name.
        prev_tabix = sy-tabix.
        MODIFY stru_tab.
      ENDLOOP.
    ENDIF.
    IF name-continue EQ '*'.
      continue_field = 'X'.
    ELSE.
      continue_field = space.
    ENDIF.
  ENDDO.
* NOW BUILD FIELDNAMES
  LOOP AT stru_tab.
    fieldnames-field   = stru_tab-fldname.
    APPEND fieldnames.
  ENDLOOP.
ENDFORM.                               " GET_ALL_FIELD_NAMES
 
*&---------------------------------------------------------------------*
*& Report  ZNVK_SEND_HTML_MAIL
*&
*&---------------------------------------------------------------------*
*following blog will tell  you that how to end a  email as other webmails.
*following Example wil show you that how the Employee data will come in a HTML format
*&---------------------------------------------------------------------*
REPORT  znvk_send_html_mail.
*Diclare a types to hold the Employee data
TYPES:BEGIN OF ty_employee,
pernr TYPE pa0002-pernr,
begda TYPE pa0002-begda,
endda TYPE pa0002-endda,
vorna TYPE pa0002-vorna,
nachn TYPE pa0002-nachn,
END OF ty_employee.
*Diclate a types for employee data table
TYPES:tt_employee  TYPE  STANDARD  TABLE  OF  ty_employee.
*Diclate a workarea  to hold the Employee data
DATA: gf_employee     TYPE  ty_employee.
*Diclate a table  to hold the Employee data
DATA: gt_employee     TYPE  tt_employee.
*All the diclarations to send the email is same for this also
*except that diclare the doc type specify as HTML
DATA:
*- Structure to hold Output Details in delimited format
         gf_output_soli TYPE  soli,
*- Structure to hold Imported Object Components
         gf_objpack     TYPE sopcklsti1,
*- Structure to hold data in single line format
         gf_objhead     TYPE solisti1,
*- Structure to hold data in single line format
         gf_objtxt      TYPE solisti1,
*- Structure to hold data for API Recipient List
         gf_reclist     TYPE somlreci1,
*- Structure to hold  email data
         gf_doc_chng    TYPE sodocchgi1,
*- Internal Table to hold Output Details in delimited format
         gt_output_soli TYPE TABLE OF soli,
*- Internal Table to hold Imported Object Components
         gt_objpack     TYPE TABLE OF sopcklsti1,
*- Internal Table to hold data in single line format
         gt_objhead     TYPE TABLE OF solisti1,
*- Internal Table to hold data in single line format
         gt_objtxt      TYPE TABLE OF solisti1,
*- Internal Table to hold data for API Recipient List
         gt_reclist     TYPE TABLE OF somlreci1.
DATA:BEGIN OF lt_emp OCCURS 0,
       emp TYPE pa0001-pernr,
 END OF lt_emp.
DATA:l_begda(10),
     l_endda(10).
DATA: g_lines     TYPE sy-tabix,  "To hold number of records
      g_msg_lines TYPE sy-tabix,  "To hold number of records
      g_sent_all(1) TYPE c.
**                C O N S T A N T S                                     **
CONSTANTS : c_int(3)      TYPE c VALUE 'INT',   "Internet mail address
            c_doc_type_htm(3) TYPE c VALUE 'HTM',   "Code for document class
            c_rec_type    TYPE c VALUE 'U',     "Recipient type
            c_express     TYPE c VALUE 'X'.     "Send express

START-OF-SELECTION.
*Hotcoaded few employee numbers
  lt_emp-emp = 00000003.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000004.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000005.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000006.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000007.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000008.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000009.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000010.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000012.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000013.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000014.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000015.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000016.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000017.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000018.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000024.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000025.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000027.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000028.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000029.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000030.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000032.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000033.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000034.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000035.
  APPEND  lt_emp.CLEAR lt_emp.
  lt_emp-emp = 00000036.
  APPEND  lt_emp.CLEAR lt_emp.
*select to get the employee Biodata
  SELECT
    pernr
    begda
    endda
    vorna
    nachn
  FROM pa0002
  INTO TABLE gt_employee
  FOR ALL ENTRIES IN lt_emp
  WHERE pernr = lt_emp-emp.
*Once the Employee Diodata came
*As following we can pripare the html Body format
*Set the Subject line
  gf_doc_chng-obj_name  = 'HTML Format Email from SAP'.
  gf_doc_chng-obj_descr = 'HTML Format Email from SAP'.
*Set the Body background colour
  gf_objtxt-line = '<body bgcolor = "#E6E6FA">'.
*- Append
  APPEND gf_objtxt TO gt_objtxt.
*- Clear
  CLEAR gf_objtxt.
*Set font color and its type
  CONCATENATE '<FONT COLOR = "#191970" face="Garamond">' '<b>' INTO gf_objtxt-line.
*- Append
  APPEND gf_objtxt TO gt_objtxt.
*- Clear
  CLEAR gf_objtxt.
*Pripare mail body
  CONCATENATE '<p>' 'Dear Sir/Madam,' '</p>'
              INTO gf_objtxt-line.
*- Append
  APPEND gf_objtxt TO gt_objtxt.
*- Clear
  CLEAR gf_objtxt.
  gf_objtxt-line = space.
*- Append
  APPEND gf_objtxt TO gt_objtxt.
*- Clear
  CLEAR gf_objtxt.
  CONCATENATE '<p>'
              '    The following employee has updated  His/Her profile.'
              '</p>'
                 INTO gf_objtxt-line SEPARATED BY space.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR  gf_objtxt.
  gf_objtxt-line = '<center>'.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR  gf_objtxt.
*  Pripare Employee data in table format to dispay in Mail body
  gf_objtxt-line = '<TABLE  width= "100%" border="1">'.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR  gf_objtxt.
  CONCATENATE '<TR ><td align = "LEFT" BGCOLOR = "#708090">'
              '<FONT COLOR = "BLUE"><B>Employee number</B> </FONT>'
                '</td>'  INTO gf_objtxt-line.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR  gf_objtxt.
  CONCATENATE '<td align = "LEFT"  BGCOLOR = "#708090">'
                '<FONT COLOR = "BLUE"> <B>Begin Date</B> </FONT>'
                '</td>'  INTO gf_objtxt-line.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR  gf_objtxt.
  CONCATENATE '<td align = "LEFT"  BGCOLOR = "#708090">'
                '<FONT COLOR = "BLUE"><B>End date</B> </FONT>'
                '</td>'  INTO gf_objtxt-line.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR  gf_objtxt.
  CONCATENATE '<td align = "LEFT"  BGCOLOR = "#708090">'
                   ' <FONT COLOR = "BLUE"><B>first name</B> </FONT>'
                   '</td>'  INTO gf_objtxt-line.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR  gf_objtxt.
  CONCATENATE '<td align = "LEFT"  BGCOLOR = "#708090">'
                   '<FONT COLOR = "BLUE"><B>last name</B> </FONT>'
                   '</td></tr>'  INTO gf_objtxt-line.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR  gf_objtxt.
  LOOP AT gt_employee INTO gf_employee.
    WRITE: gf_employee-begda TO  l_begda.
    WRITE: gf_employee-endda TO  l_endda.
    CONCATENATE '<TR><td align = "LEFT">'
                '<FONT COLOR = "BLUE">' gf_employee-pernr '</FONT>'
                '</td>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO gt_objtxt.
    CLEAR  gf_objtxt.

    CONCATENATE '<td align = "LEFT">'
                '<FONT COLOR = "BLUE">' l_begda '</FONT>'
                  '</td>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO gt_objtxt.
    CLEAR  gf_objtxt.
    CONCATENATE '<td align = "LEFT">'
                '<FONT COLOR = "BLUE">' l_endda '</FONT>'
                  '</td>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO gt_objtxt.
    CLEAR  gf_objtxt.
    CONCATENATE '<td align = "LEFT">'
                '<FONT COLOR = "BLUE">' gf_employee-vorna '</FONT>'
                 '</td>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO gt_objtxt.
    CLEAR  gf_objtxt.
    CONCATENATE '<td align = "LEFT">'
                '<FONT COLOR = "BLUE">'    gf_employee-nachn '</FONT>'
                     '</td></tr>'  INTO gf_objtxt-line.
    APPEND gf_objtxt TO gt_objtxt.
    CLEAR  gf_objtxt.
  ENDLOOP.
  gf_objtxt-line = '</TABLE>'.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR  gf_objtxt.
  gf_objtxt-line = '</center>'.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR  gf_objtxt.
  CONCATENATE '<p>' ' Please confirm the appropriate actions'
                       'have taken place in regards to this change'
                 '</p>'
                 INTO gf_objtxt-line SEPARATED BY space.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR  gf_objtxt.
  CONCATENATE '<p>' ' For further questions, please contact HR Direct'
                 '</p>'
                 INTO gf_objtxt-line SEPARATED BY space.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR gf_objtxt.
  gf_objtxt-line =   'Regards,<br />'.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR gf_objtxt.
  gf_objtxt-line =   'Vamsi<br />'.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR gf_objtxt.
  gf_objtxt-line = '<br><br><b><center><i><font color = "RED">This is an auto generated Email.'.
  APPEND gf_objtxt TO gt_objtxt.
  CLEAR gf_objtxt.
  gf_objtxt-line = '</FONT></body>'.
*- Append
  APPEND gf_objtxt TO gt_objtxt.
*- Clear
  CLEAR gf_objtxt.

END-OF-SELECTION.
  DESCRIBE TABLE gt_objtxt LINES g_msg_lines.
  READ TABLE gt_objtxt INTO gf_objtxt INDEX g_msg_lines.
  gf_doc_chng-doc_size = ( g_msg_lines - 1 ) * 255 + strlen( gf_objtxt ).
*- Creation of the entry for the compressed document
  gf_objpack-transf_bin = ' '.
  gf_objpack-head_start = 1.
  gf_objpack-head_num   = 0.
  gf_objpack-body_start = 1.
  gf_objpack-body_num   = g_msg_lines.
  gf_objpack-doc_type   = c_doc_type_htm.
*- Append
  APPEND gf_objpack TO gt_objpack.
*- Clear
  CLEAR gf_objpack.
*- Creation of the document attachment
*- Describe
  DESCRIBE TABLE gt_output_soli LINES g_lines.
*- Don't create attachment if no data is present
  IF g_lines <> 0.
    LOOP AT gt_output_soli INTO gf_output_soli.
      gf_objtxt = gf_output_soli.
*- Append
      APPEND gf_objtxt TO gt_objtxt.
*- Clear
      CLEAR gf_objtxt.
    ENDLOOP.
  ENDIF.
*- Completing the recipient list
  gf_reclist-receiver = 'vamsin@intelligroup.com'.
  gf_reclist-rec_type = c_rec_type.
  gf_reclist-express  = c_express.
*- Append
  APPEND gf_reclist TO gt_reclist.
*- Clear
  CLEAR gf_reclist.
  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data              = gf_doc_chng
      put_in_outbox              = 'X'
      sender_address             = 'NTWDEV'
      commit_work                = 'X'
    IMPORTING
      sent_to_all                = g_sent_all
    TABLES
      packing_list               = gt_objpack
      object_header              = gt_objhead
      contents_txt               = gt_objtxt
      receivers                  = gt_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.
    cl_os_transaction_end_notifier=>raise_commit_requested( ).
    CALL FUNCTION 'DB_COMMIT'.
    cl_os_transaction_end_notifier=>raise_commit_finished( ).
  ENDIF.
 
*send email notification to user using PDF attachment

DATA: lv_filesize TYPE i,
      lv_buffer TYPE string,
      lv_attachment TYPE i,
      lv_testo TYPE i.

DATA: li_pdfdata TYPE STANDARD TABLE OF tline,
      li_mess_att TYPE STANDARD TABLE OF solisti1,
      li_mtab_pdf TYPE STANDARD TABLE OF tline,
      li_objpack TYPE STANDARD TABLE OF sopcklsti1,
      li_objtxt TYPE STANDARD TABLE OF solisti1,
      li_objbin TYPE STANDARD TABLE OF solisti1,
      li_reclist TYPE STANDARD TABLE OF somlreci1,
      li_objhead TYPE soli_tab.

DATA: lwa_pdfdata TYPE tline,
      lwa_objpack TYPE sopcklsti1,
      lwa_mess_att TYPE solisti1,
      lwa_objtxt TYPE solisti1,
      lwa_objbin TYPE solisti1,
      lwa_reclist TYPE somlreci1,
      lwa_doc_chng TYPE sodocchgi1.

CONSTANTS: lc_u TYPE char1 VALUE 'U',
            lc_0 TYPE char1 VALUE '0',
            lc_1 TYPE char1 VALUE '1',
            lc_pdf TYPE char3 VALUE 'PDF',
            lc_raw TYPE char3 VALUE 'RAW',
            lc_ordform TYPE char15 VALUE 'ZORDCONFIRM_01',
            lc_attachment TYPE char10 VALUE 'ATTACHMENT'.

CALL FUNCTION 'CONVERT_OTF'
  EXPORTING
    format                = lc_pdf
    max_linewidth         = 132
  IMPORTING
    bin_filesize          = lv_filesize
  TABLES
    otf                   = pv_otfdata
    lines                 = li_pdfdata
  EXCEPTIONS
    err_max_linewidth     = 1
    err_format            = 2
    err_conv_not_possible = 3
    err_bad_otf           = 4
    OTHERS                = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

LOOP AT li_pdfdata INTO lwa_pdfdata.
  TRANSLATE lwa_pdfdata USING ' ~'.
  CONCATENATE lv_buffer lwa_pdfdata INTO lv_buffer.
  CLEAR lwa_pdfdata.
ENDLOOP.

TRANSLATE lv_buffer USING '~ '.
DO.
  lwa_mess_att = lv_buffer.
  APPEND lwa_mess_att TO li_mess_att.
  CLEAR lwa_mess_att.
  SHIFT lv_buffer LEFT BY 255 PLACES.
  IF lv_buffer IS INITIAL.
    EXIT.
  ENDIF.
ENDDO.

* Object with PDF.
REFRESH li_objbin.
li_objbin[] = li_mess_att[].
DESCRIBE TABLE li_objbin LINES lv_attachment.

* Object with main text of the mail.
lwa_objtxt = space.
APPEND lwa_objtxt TO li_objtxt.
CLEAR lwa_objtxt.

DESCRIBE TABLE li_objtxt LINES lv_testo.

* Create the document which is to be sent

lwa_doc_chng-obj_name = text-008.
lwa_doc_chng-obj_descr = text-008.

lwa_doc_chng-sensitivty = lc_0.
lwa_doc_chng-obj_prio = lc_1.
lwa_doc_chng-doc_size = lv_testo * 225.

* Pack to main body.
CLEAR lwa_objpack-transf_bin.

* header
lwa_objpack-head_start = 1.

* The document needs no header (head_num = 0)
lwa_objpack-head_num = 0.

* body
lwa_objpack-body_start = 1.
lwa_objpack-body_num = lv_testo.
lwa_objpack-doc_type = lc_raw.
APPEND lwa_objpack TO li_objpack.
CLEAR lwa_objpack.

* Create the attachment.
* Fill the fields of the packing_list for the attachment:
lwa_objpack-transf_bin = gc_x .

* header
lwa_objpack-head_start = 1.
lwa_objpack-head_num = 1.

* body
lwa_objpack-body_start = 1.
lwa_objpack-body_num = lv_attachment.
lwa_objpack-doc_type = lc_pdf.
lwa_objpack-obj_name = lc_attachment.

lwa_objpack-obj_descr = text-008.

lwa_objpack-doc_size = lv_attachment * 255.
APPEND lwa_objpack TO li_objpack.
CLEAR lwa_objpack.

lwa_reclist-receiver = pv_emailid.
lwa_reclist-rec_type = lc_u.
lwa_reclist-notif_del = gc_x.
lwa_reclist-notif_ndel = gc_x.
APPEND lwa_reclist TO li_reclist.

IF li_reclist IS NOT INITIAL.

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = lwa_doc_chng
      put_in_outbox              = gc_x
    TABLES
      packing_list               = li_objpack
      object_header              = li_objhead
      contents_bin               = li_objbin
      contents_txt               = li_objtxt
      receivers                  = li_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 ID sy-msgid TYPE 'I' NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDIF.
 

The Notes client is an OLE automation controller and server.External applications can create and reference the automation objects, then work down through the object hierarchies.A Notes client must be installed on the same machine as SAP GUI is installed. Notes runs as a separate process when acting as an OLE automation server.

The automation is based on  late binding. A Notes.NotesSession object has to be created and work down through the hierarchies using the available methods. For example, if you want to send a mail, create a Notes.NotesSession OLE automation object, and then use the GetDatabase method of NotesSession to set a reference variable.The below shown codes explains in detail about different OLE objects and how to send a mail. 

The following OLE objects must be declared for the process.

  • Notessession
  • NotesDatabase
  • NotesDocument
  • NotesRichTextItem

Sample Code .

TYPE-POOLS ole2 .
parameters: email(50).

DATA  : notes TYPE ole2_object,
             dbdirectory TYPE ole2_object.
             database TYPE ole2_object.
             document TYPE ole2_object.
             attachment TYPE ole2_object.
             notesrtf TYPE ole2_object.
             notesregistration TYPE ole2_object.
             notesstyle TYPE ole2_object.

CREATE OBJECT notes 'Lotus.Notessession'. "Represents the current environment and access to information(Address book,User info etc) 
CREATE OBJECT database 'Lotus.notesDatabase'."Represents the Notes Database
 
CREATE OBJECT document 'Lotus.notesDocument'. "Represents a document in database
 
CREATE OBJECT notesrtf  'Lotus.notesRichTextItem'."Represents a Rich Text Item type
 

 **//  Initialize a COM Session with the current User-Id

CALL METHOD OF notes 'Initialize'.

**// Creates a new DbDirectory object using the name of the server you want to access.

CALL METHOD OF notes 'getdbDirectory' = dbdirectory EXPORTING #1 = ''.

**// Opens the current user's mail database.

CALL METHOD OF dbdirectory 'OpenMailDatabase' = database .

**// Creates a document in a database and returns a Document object that represents the new document.

CALL METHOD OF database 'CreateDocument' = document .

**//Use the "SendTo" property to populate the recievers//

CALL METHOD OF document 'ReplaceItemValue' EXPORTING #1 = 'SendTo' #2 = email.

**//use the "Subject" property to set the subject of the mail

CALL METHOD OF document 'ReplaceItemValue' EXPORTING #1 = 'Subject' #2 = 'hi'.

**//The body of the mail can be created as a rich text item//

CALL METHOD OF document 'CreateRichTextItem' = notesrtf EXPORTING #1 = 'Body'.

**//Append the text to the body of the mail//

CALL METHOD OF notesrtf 'AppendText' EXPORTING #1 = 'Hi...From SAP,through lotus notes..regards..jinesh'.

**// "Send" Method mails a document.

**// If true, the form is stored and sent along with the document. If false, it isn't.

CALL METHOD OF document 'Send' EXPORTING #1 = 'FALSE'.
if sy-subrc = 0.
write : 'Mail Send Successfully'.
endif.

//**Free all the objects.

FREE OBJECT notes.
FREE OBJECT dbdirectory .
FREE OBJECT database.
FREE OBJECT document .
FREE OBJECT attachment .
FREE OBJECT notesrtf .
FREE OBJECT notesregistration .
FREE OBJECT notesstyle.

Note : I have not  included a proper error handling method in the above code.

  
           There might be a scenario where in an E-mail notification is required in a classical report where data outputted resides in many internal tables with complex logic. Here it is not a feasible option to send the list output to E-mail with excel as it may take lot of time in building the E-mailing logic. This article addresses this issue in a simple way.
Just copy paste below piece of code in a new report to understand the functionality.

Sample Code: 

DATA: li_receivers       TYPE STANDARD TABLE OF soos1,
      li_listobject      TYPE STANDARD TABLE OF abaplist,
      li_ali             TYPE STANDARD TABLE OF soli,
      li_ali1            TYPE STANDARD TABLE OF soli,
      li_ali2            TYPE STANDARD TABLE OF soli,
      lwa_objecthdchange TYPE sood1,
      lwa_receivers      TYPE soos1,
      lwa_ali            TYPE soli.
DATA: l_lines   TYPE i,
      l_length  TYPE i.
DO 10 TIMES.
  NEW-LINE.
  ULINE (99).
  WRITE: /1 sy-vline,
          2 'column1',
         24 sy-vline,
         25 'Column2',
         49 sy-vline,
         50 'Column3',
         74 sy-vline,
         75 'Column4',
         99 sy-vline.
ENDDO.
NEW-LINE.
ULINE (99).
NEW-LINE.
CALL FUNCTION 'SAVE_LIST'
  EXPORTING
    list_index         = '0'              "Pass the list index like 0, 1, 2...
  TABLES
    listobject         = li_listobject
  EXCEPTIONS
    list_index_invalid = 1
    OTHERS             = 2.
IF sy-subrc NE 0.
  RAISE invalid_list.
ENDIF.
Convert the list to ALI format
CALL FUNCTION 'TABLE_COMPRESS'
  TABLES
    in             = li_listobject
    out            = li_ali
  EXCEPTIONS
    compress_error = 1
    OTHERS         = 2.
IF sy-subrc NE 0.
  RAISE compress_error.
ENDIF.
CLEAR: lwa_objecthdchange.
DESCRIBE TABLE li_ali LINES l_lines.
DESCRIBE FIELD lwa_ali LENGTH l_length IN CHARACTER MODE.
lwa_objecthdchange-objlen = l_length * l_lines.
lwa_objecthdchange-objla  = sy-langu.
lwa_objecthdchange-objnam = 'List'.
MOVE sy-title TO lwa_objecthdchange-objdes.
MOVE: 1 TO lwa_objecthdchange-objpri,
      0 TO lwa_objecthdchange-objsns.
CLEAR: lwa_receivers.
MOVE: 'X'                 TO lwa_receivers-snddr,
      'X'                 TO lwa_receivers-sndex,
      'U'                 TO lwa_receivers-recesc,
      'E-MAIL' TO lwa_receivers-recextnam.          "Pass the recipient ID here.
APPEND lwa_receivers TO li_receivers.Send email
CALL FUNCTION 'SO_OBJECT_SEND'
 EXPORTING
*   FOLDER_ID                        = ' '
*   FORWARDER                        = ' '
*   OBJECT_FL_CHANGE                 = ' '
   object_hd_change                 = lwa_objecthdchange
*   OBJECT_ID                        = ' '
   object_type                      = 'ALI'
*   OUTBOX_FLAG                      = ' '
   owner                            = sy-uname
*   STORE_FLAG                       = ' '
*   DELETE_FLAG                      = ' '
   sender                           = sy-uname
*   CHECK_SEND_AUTHORITY             = ' '
*   CHECK_ALREADY_SENT               = ' '
*   GIVE_OBJECT_BACK                 =
*   ORIGINATOR                       = ' '
*   ORIGINATOR_TYPE                  = 'J'
*   LINK_FOLDER_ID                   = ' '
*   SEND_REQUEST_OID                 = ' '
*   IP_ENCRYPT                       = 'U'
*   IP_SIGN                          = 'U'
*   IP_REC_COUNT_ADD                 =IMPORTING
*   OBJECT_ID_NEW                    =
*   SENT_TO_ALL                      =
*   ALL_BINDING_DONE                 =
*   OFFICE_OBJECT_KEY                =
*   ORIGINATOR_ID                    =
*   E_SEND_REQUEST_OID               =
TABLES
   objcont                          = li_ali
*   OBJHEAD                          =
*   OBJPARA                          =
*   OBJPARB                          =
   receivers                        = li_receivers
*   PACKING_LIST                     =
*   ATT_CONT                         =
*   ATT_HEAD                         =
*   NOTE_TEXT                        =
*   LINK_LIST                        =
*   APPLICATION_OBJECT               =
 EXCEPTIONS
   active_user_not_exist            = 1
   communication_failure            = 2
   component_not_available          = 3
   folder_not_exist                 = 4
   folder_no_authorization          = 5
   forwarder_not_exist              = 6
   note_not_exist                   = 7
   object_not_exist                 = 8
   object_not_sent                  = 9
   object_no_authorization          = 10
   object_type_not_exist            = 11
   operation_no_authorization       = 12
   owner_not_exist                  = 13
   parameter_error                  = 14
   substitute_not_active            = 15
   substitute_not_defined           = 16
   system_failure                   = 17
   too_much_receivers               = 18
   user_not_exist                   = 19
   originator_not_exist             = 20
   x_error                          = 21
   OTHERS                           = 22.
   IF sy-subrc IS INITIAL.
     MESSAGE 'Mail has been sent successfully' TYPE 'S'.
   ELSE.
     MESSAGE 'Error occured while sending the mail' TYPE 'S'.
   ENDIF.



 

 Above code shows a sample output of the report without any processing logic. The actual output data determination logic is much complex in real time scenarios.  A scanned copy of the output is sent as a mail notification to the recipients i.e. what you see in report output and E-mail is one and the same. This is best suited only for classical reports. For ALV reports it is always better to use E-mail with excel attachment as we have all the data available in one final internal table and lot of options are available with excel.


 

Thanks,

Vinod.

 

Author: Prasath Natesan
Submitted: 04-Jan-2008
Modif 08-Mar-2010: Sandra Rossi
Related Links/References:

Introduction

Emails are one of the common methods of notifying users about various changes performed in the system. But when the user needs to view/process the data he/she needs to manually login to the system through the required transactions to access the data. SAP shortcuts come handy in these situations enabling the users to login to the required transactions directly.

Using SAP shortcuts through email will benefit the users in the following ways,

  1. Delivered to a single inbox, hence user does not have to keep checking the UWL/SBWP or other inboxes
  2. User does not need to remember the different transactions that he/she needs to work on.
  3. Option of parameter handling simplifies the job of user by preloading the screen with required information

Creating SAP shortcut at run time

The following function module can be used to create a shortcut for any SAP transaction. Further, certain values available in the transaction can be defaulted by passing the values as parameters to this FM. This shortcut created can then be attached in a mail and sent to the appropriate recipients.

Before creating the function modulen you have to define ZST_SHORTCUT_PAR as a DDIC structure, which 2 components FIELDNAME of type C of length 60, and FIELDVALUE of type C of length 255.

Note: if you want to test the program quickly without creating the function module and the DDIC structure, have a look at appendix 2.

FUNCTION zfm_create_shortcut.
*"---------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(RECIPIENT_USER_ID) TYPE  SYUNAME
*"     REFERENCE(TRANSACTION) TYPE  TCODE
*"  EXPORTING
*"     REFERENCE(CONTENT) TYPE  STRING
*"  TABLES
*"      SHORTCUT_PARAM STRUCTURE  ZST_SHORTCUT_PAR OPTIONAL
*"---------------------------------------------------------------------

*** Declaration for shortcut content
  DATA :  parameter TYPE text255,
          v_pernr(12) TYPE c.
  DATA :  v_tcode TYPE tcode.

* Check if transaction code is available
  CLEAR v_tcode.
  SELECT SINGLE tcode FROM tstc
                INTO v_tcode
                WHERE tcode EQ transaction.

  IF v_tcode IS INITIAL.
    MESSAGE 'Enter a valid transaction' TYPE 'E' DISPLAY LIKE 'A'.
    EXIT.
  ENDIF.

* Populate the parameters to be passed to the shortcut
  IF NOT shortcut_param[] IS INITIAL.
    CLEAR parameter.
    LOOP AT shortcut_param.
      CONCATENATE parameter shortcut_param-fieldname '='
    shortcut_param-fieldvalue ';'
                INTO parameter.
    ENDLOOP.
  ENDIF.

*** create the shortcut content for the required transaction
  CALL FUNCTION 'SWN_CREATE_SHORTCUT'
    EXPORTING
      i_transaction           = transaction
      i_parameter             = parameter
      i_sysid                 = sy-sysid
      i_client                = sy-mandt
      i_user                  = recipient_user_id
      i_language              = sy-langu
      i_windowsize            = 'Normal window'
    IMPORTING
      shortcut_string         = content
    EXCEPTIONS
      inconsistent_parameters = 1
      OTHERS                  = 2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFUNCTION.

This FM receives RECIPIENT_USER_ID and TRANSACTION as import parameters. The value of parameters if any can be passed through table parameter SHORCTCUT_PARAM. On execution the shortcut content is created and returned through the export parameter "CONTENT". The table SHORTCUT_PARAM refers to a custom structure described in Appendix 1.

Example scenario

Consider a scenario where the employee has requested for a change in address. Now once the change in address is completed a notification email is sent to the employee indicating the successful change in address. In a normal scenario the employee needs to log into the system manually and enter the required transaction. Then the required details (employee number, infotype and subtype) need to be entered before displaying the updated information.

This process can be simplified by sending a shortcut which will navigate the user to the required transaction with all required data pre-loaded. The sample code for this process is given below

*&---------------------------------------------------------------------*
*& Report  ZRP_MAIL_SHORTCUT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zrp_mail_shortcut.

************************************************************************
***    Report to send mail to employee to display temp address   ***
************************************************************************
*** Declarations for attachment creation
DATA: doc_chng  LIKE sodocchgi1.
DATA: tab_lines LIKE sy-tabix,
      body_start LIKE sy-tabix.
DATA: it_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA: it_objpack   LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: it_objbin    LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: it_reclist   LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
DATA: it_shortcut_param LIKE zst_shortcut_par OCCURS 0 WITH HEADER LINE.
DATA: content TYPE string.

*** Pass the required parameters and create the shortcut
CLEAR it_shortcut_param.
REFRESH it_shortcut_param.

it_shortcut_param-fieldname = 'RP50G-PERNR'.
it_shortcut_param-fieldvalue = '1001'. "Employee number
APPEND it_shortcut_param.

it_shortcut_param-fieldname = 'RP50G-CHOIC'.
it_shortcut_param-fieldvalue = '0006'. " Address Infotype
APPEND it_shortcut_param.

it_shortcut_param-fieldname = 'RP50G-TIMR1'.
it_shortcut_param-fieldvalue = 'X'.    "Period selected as "Today"
APPEND it_shortcut_param.

it_shortcut_param-fieldname = 'RP50G-SUBTY'.
it_shortcut_param-fieldvalue = '2'.    "Temporary address subtype
APPEND it_shortcut_param.

CALL FUNCTION 'ZFM_CREATE_SHORTCUT'
  EXPORTING
    recipient_user_id = 'DEVHYD'
    transaction       = 'PA20'
  IMPORTING
    content           = content
  TABLES
    shortcut_param    = it_shortcut_param.

*** Mail Subject
doc_chng-obj_descr = 'Employee address changed'.
*** Mail Contents
CONCATENATE ' The requested change has been made to your temporary address.'
' Please double click on the attachment and choose display to view the updated address'
INTO it_objtxt.
APPEND it_objtxt.

*** Creation of the entry for the document
DESCRIBE TABLE it_objtxt LINES tab_lines.
CLEAR it_objpack-transf_bin.
it_objpack-head_start = 1.
it_objpack-head_num = 0.
it_objpack-body_start = 1.
it_objpack-body_num = tab_lines.
it_objpack-doc_type = 'RAW'.
APPEND it_objpack.

*** Populate attachment content
CLEAR : tab_lines, it_objbin.
CONCATENATE content it_objbin-line INTO it_objbin-line.
APPEND it_objbin.
DESCRIBE TABLE it_objbin LINES tab_lines.

*** Creation of the entry for the compressed attachment
it_objpack-transf_bin = 'X'. "Will get content from content_bin
it_objpack-head_start = 1.
it_objpack-head_num   = 1.
it_objpack-body_start = 1.
it_objpack-body_num   = tab_lines.
it_objpack-doc_type   = 'EXT'.
it_objpack-obj_name   = 'SAPSHORTCUTMAIL'.
it_objpack-obj_descr  = 'DisplayAddress.SAP'.
it_objpack-doc_size   = tab_lines * 255.
APPEND it_objpack.


*** target recipent(s)
CLEAR it_reclist.
it_reclist-receiver = 'employeemailid@employeecompany.com'.
it_reclist-rec_type = 'U'.
APPEND it_reclist.

*** Sending the document to recipients with the shortcut attachment
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    document_data              = doc_chng
    put_in_outbox              = 'X'
    commit_work                = 'X'
  TABLES
    packing_list               = it_objpack
    contents_bin               = it_objbin
    contents_txt               = it_objtxt
    receivers                  = it_reclist
  EXCEPTIONS
    too_many_receivers         = 1
    document_not_sent          = 2
    operation_no_authorization = 4
    OTHERS                     = 99.

The above code uses the function module ZFM_CREATE_SHORTCUT to create the required SAP shortcut and then sends it as attachment by email. The user can now double click on the shortcut from his email and reach the transaction directly with required information preloaded.

When the user double clicks on the attachment the pop up window for entering the password is opened as shown below,

Once the user enters the password and clicks on "Log on" the required transaction is opened up directly as shown below,


As highlighted in the above picture the values - Employee number, Period, Infotype and subtype are preloaded when the user reaches the transaction. The user can now hit the display button and view the required data.

Note: The system on which the shortcut is executed should have SAP GUI installed and have the target system configured in the SAP logon pad. If the configuration is not already available then on launching the shortcut the system asks for the logon details as shown below,

Appendix 1: Structure for passing shortcut parameters

A custom name-value pair structure as shown below was created for passing the shortcut parameters.

Appendix 2: creating the report without the FM and DDIC structure

This section shows how to test the program quickly without creating the function module and the DDIC structure.*

In the program, perform the following changes:

Replace this section

By this section

REPORT  zrp_mail_shortcut.

************************************************************************
***    Report to send mail to employee to display temp address   ***
************************************************************************
REPORT  zrp_mail_shortcut.

DATA : BEGIN OF zst_shortcut_par,
          fieldname   TYPE c LENGTH 60,
          fieldvalue  TYPE c LENGTH 255,
        END OF zst_shortcut_par.

************************************************************************
***    Report to send mail to employee to display temp address   ***
************************************************************************
CALL FUNCTION 'ZFM_CREATE_SHORTCUT'
  EXPORTING
    recipient_user_id = 'DEVHYD'
    transaction       = 'PA20'
  IMPORTING
    content           = content
  TABLES
    shortcut_param    = it_shortcut_param.
PERFORM zfm_create_shortcut
  TABLES
    it_shortcut_param
  USING
    'DEVHYD'
    'PA20'
  CHANGING
    content.

[At the end of the report]

*&---------------------------------------------------------------------*
*&      Form  zfm_create_shortcut
*&---------------------------------------------------------------------*
FORM zfm_create_shortcut
  TABLES
    shortcut_param    STRUCTURE  zst_shortcut_par
  USING
    recipient_user_id TYPE  syuname
    transaction       TYPE  tcode
  CHANGING
     content          TYPE  string.


*** Declaration for shortcut content
  DATA :  parameter TYPE text255,
          v_pernr(12) TYPE c.
  DATA :  v_tcode TYPE tcode.

* Check if transaction code is available
  CLEAR v_tcode.
  SELECT SINGLE tcode FROM tstc
                INTO v_tcode
                WHERE tcode EQ transaction.

  IF v_tcode IS INITIAL.
    MESSAGE 'Enter a valid transaction' TYPE 'E' DISPLAY LIKE 'A'.
    EXIT.
  ENDIF.

* Populate the parameters to be passed to the shortcut
  IF NOT shortcut_param[] IS INITIAL.
    CLEAR parameter.
    LOOP AT shortcut_param.
      CONCATENATE parameter shortcut_param-fieldname '='
    shortcut_param-fieldvalue ';'
                INTO parameter.
    ENDLOOP.
  ENDIF.

*** create the shortcut content for the required transaction
  CALL FUNCTION 'SWN_CREATE_SHORTCUT'
    EXPORTING
      i_transaction           = transaction
      i_parameter             = parameter
      i_sysid                 = sy-sysid
      i_client                = sy-mandt
      i_user                  = recipient_user_id
      i_language              = sy-langu
      i_windowsize            = 'Normal window'
    IMPORTING
      shortcut_string         = content
    EXCEPTIONS
      inconsistent_parameters = 1
      OTHERS                  = 2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    "zfm_create_shortcut

Here is the code to send the Smartform to mail as PDF attachment.

REPORT ztest_nreddy_pdf_mail.
* Internal Table declarations
DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
      i_tline TYPE TABLE OF tline WITH HEADER LINE,
      i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
      i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
* Objects to send mail.
      i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
      i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
* Work Area declarations
      wa_objhead TYPE soli_tab,
      w_ctrlop TYPE ssfctrlop,
      w_compop TYPE ssfcompop,
      w_return TYPE ssfcrescl,
      wa_doc_chng TYPE sodocchgi1,
      w_data TYPE sodocchgi1,
      wa_buffer TYPE string, "To convert from 132 to 255
* Variables declarations
      v_form_name TYPE rs38l_fnam,
      v_len_in LIKE sood-objlen,
      v_len_out LIKE sood-objlen,
      v_len_outn TYPE i,
      v_lines_txt TYPE i,
      v_lines_bin TYPE i.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  EXPORTING
    formname           = 'ZTEST'
  IMPORTING
    fm_name            = v_form_name
  EXCEPTIONS
    no_form            = 1
    no_function_module = 2
    OTHERS             = 3.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
w_ctrlop-getotf = 'X'.
w_ctrlop-no_dialog = 'X'.
w_compop-tdnoprev = 'X'.
CALL FUNCTION v_form_name
  EXPORTING
    control_parameters = w_ctrlop
    output_options     = w_compop
    user_settings      = 'X'
  IMPORTING
    job_output_info    = w_return
  EXCEPTIONS
    formatting_error   = 1
    internal_error     = 2
    send_error         = 3
    user_canceled      = 4
    OTHERS             = 5.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
i_otf[] = w_return-otfdata[].
CALL FUNCTION 'CONVERT_OTF'
  EXPORTING
    format                = 'PDF'
    max_linewidth         = 132
  IMPORTING
    bin_filesize          = v_len_in
  TABLES
    otf                   = i_otf
    lines                 = i_tline
  EXCEPTIONS
    err_max_linewidth     = 1
    err_format            = 2
    err_conv_not_possible = 3
    OTHERS                = 4.
IF sy-subrc <> 0.
ENDIF.
LOOP AT i_tline.
  TRANSLATE i_tline USING '~'.
  CONCATENATE wa_buffer i_tline INTO wa_buffer.
ENDLOOP.
TRANSLATE wa_buffer USING '~'.
DO.
  i_record = wa_buffer.
  APPEND i_record.
  SHIFT wa_buffer LEFT BY 255 PLACES.
  IF wa_buffer IS INITIAL.
    EXIT.
  ENDIF.
ENDDO.
* Attachment
REFRESH: i_reclist,
          i_objtxt,
          i_objbin,
          i_objpack.
CLEAR wa_objhead.
i_objbin[] = i_record[].
* Create Message Body Title and Description
i_objtxt = 'test with pdf-Attachment!'.
APPEND i_objtxt.
DESCRIBE TABLE i_objtxt LINES v_lines_txt.
READ TABLE i_objtxt INDEX v_lines_txt.
wa_doc_chng-obj_name = 'smartform'.
wa_doc_chng-expiry_dat = sy-datum + 10.
wa_doc_chng-obj_descr = 'smartform'.
wa_doc_chng-sensitivty = 'F'.
wa_doc_chng-doc_size = v_lines_txt * 255.
* Main Text
CLEAR i_objpack-transf_bin.
i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_txt.
i_objpack-doc_type = 'RAW'.
APPEND i_objpack.
* Attachment (pdf-Attachment)
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
DESCRIBE TABLE i_objbin LINES v_lines_bin.
READ TABLE i_objbin INDEX v_lines_bin.
i_objpack-doc_size = v_lines_bin * 255 .
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'smart'.
i_objpack-obj_descr = 'test'.
APPEND i_objpack.
CLEAR i_reclist.
i_reclist-receiver = 'nareshreddy.k@gmail.com'.
i_reclist-rec_type = 'U'.
APPEND i_reclist.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    document_data              = wa_doc_chng
    put_in_outbox              = 'X'
    commit_work                = 'X'
  TABLES
    packing_list               = i_objpack
    object_header              = wa_objhead
    contents_bin               = i_objbin
    contents_txt               = i_objtxt
    receivers                  = i_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.
  WRITE:/ 'Error When Sending the File', sy-subrc.
ELSE.
  WRITE:/ 'Mail sent'.
ENDIF.
 

If you want to send some text as Body of the Mail then follow this once.

When you are calling the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'.. points to remember

  1. You have to pass the body of content in table CONTENTS_TXT(ia m using I_OBJBIN) (each line a record) then. Suppose i have appended 11 records to the table CONTENTS_TXT
  2. PACKING_LIST(i am using I_OBJPACK) table you have to append a record as follows
i_objpack-transf_bin = ' '.
i_objpack-head_start = 000000000000001.
i_objpack-head_num = 000000000000001.
i_objpack-body_start = 000000000000002.
i_objpack-body_num = 000000000000010.
i_objpack-doc_type = 'RAW'.
APPEND i_objpack.
 

By the above code system treat the first line in table I_OBJBIN as header and the 2nd line to 10 lines tread as body.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    document_data              = wa_doc_chng
    put_in_outbox              = 'X'
  TABLES
    packing_list               = i_objpack
    object_header              = wa_objhead
    contents_bin               = i_objbin
    contents_txt               = i_objtxt
    receivers                  = i_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.
 

Author: Alessandro Spadoni
Submitted: 16,Nov 2010
Related Links: http://en.wikipedia.org/wiki/Regular_expression

Snippet to validate an Email using class CL_ABAP_REGEX

DATA: regex   TYPE REF TO cl_abap_regex,
 matcher TYPE REF TO cl_abap_matcher,
 match   TYPE c LENGTH 1,
 mail_to_check(100),
 result TYPE WDY_BOOLEAN.

 mail_to_check = 'mail@example.com'.

 result = abap_true.  "Email is valid

CREATE OBJECT regex
 EXPORTING
 pattern     = '\w+(\.\w+)*@(\w+\.)+(\w{2,4})'
 ignore_case = abap_true.

matcher = regex->create_matcher( text = mail_to_check ).

 IF matcher->match( ) IS INITIAL.
 result = abap_false.  "Email not valid
 EXIT.
 ENDIF.

Author: Devendra R Paralkar
Submitted: July 6, 2007
Related Links:

Description

In many cases it is required to send notifications/messages to Users depending upon some event/action that has occurred in SAP. There are standard function modules available in SAP for achieving this functionality. Here we will discuss in addition to sending mails how we can achieve text formatting using a combination of powerful SAP function modules and simple HTML tags.

Program Logic

SAP has provided us many function modules for this purpose. We will use "SO_DOCUMENT_SEND_API1" in our case. One of the parameters that need to be passed to this Function is the structure document_data. Here we have a field doc_type, in order to have required text formatting we pass this parameter as 'HTM'. By using this extension we can format the body of this mail using HTML tags.

REPORT Z_SEND_HTML_MAIL .

* Selection screen: enter receiver (default is yourself)
PARAMETERS p_rec TYPE so_recname OBLIGATORY DEFAULT sy-uname.
PARAMETERS p_typ TYPE so_escape OBLIGATORY DEFAULT 'B'. "sap user

* Data Declaration
DATA: wa_docdata TYPE sodocchgi1,
      wa_objpack TYPE sopcklsti1 ,
      it_objpack TYPE TABLE OF sopcklsti1,
      wa_objtxt TYPE solisti1,
      it_objtxt TYPE TABLE OF solisti1,
      wa_reclist TYPE somlreci1,
      it_reclist TYPE TABLE OF somlreci1.
DATA: tab_lines TYPE i.

* Start program
PERFORM fill_text.
PERFORM fill_object_details.
*create receiver list
PERFORM create_receivers_list.
*send mail
PERFORM send_mail.
WRITE: / 'End of Program'.
*---------------------------------------------------------------------*
*Form fill_text
*---------------------------------------------------------------------*
FORM fill_text .
  wa_objtxt = '<SPAN style="font-family:arial;font-size:10.5pt;color:blue">'.
  APPEND wa_objtxt TO it_objtxt.
  wa_objtxt = '<B><U>Test Program for Send Mail.</U></B> <BR>'.
  APPEND wa_objtxt TO it_objtxt.
  wa_objtxt = '<A HREF="http://www.sap.com">Best wishes</A>'.
  APPEND wa_objtxt TO it_objtxt.
  wa_objtxt = '<I>This code is formatted using HTML.</I>'.
  APPEND wa_objtxt TO it_objtxt.
  wa_objtxt = 'Have a nice day.'.
  APPEND wa_objtxt TO it_objtxt.
  wa_objtxt = '<SPAN>'.
  APPEND wa_objtxt TO it_objtxt.
ENDFORM. " fill_text
*---------------------------------------------------------------------*
*Form fill_object_details
*---------------------------------------------------------------------*
FORM fill_object_details .
  DESCRIBE TABLE it_objtxt LINES tab_lines.
  READ TABLE it_objtxt INTO wa_objtxt INDEX tab_lines.
  wa_docdata-obj_name = 'TEST_HTML'.
  wa_docdata-obj_descr = 'Test for HTML Code'.
  wa_docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( wa_objtxt ).
  CLEAR wa_objpack-transf_bin.
  wa_objpack-head_start = 1.
  wa_objpack-head_num = 0.
  wa_objpack-body_start = 1.
  wa_objpack-body_num = tab_lines.
  wa_objpack-doc_type = 'HTM'.
  APPEND wa_objpack TO it_objpack.
ENDFORM. " fill_object_details
*---------------------------------------------------------------------*
*Form create_receivers_list
*---------------------------------------------------------------------*
FORM create_receivers_list .
  wa_reclist-receiver = p_rec.
  wa_reclist-rec_type = p_typ.
  APPEND wa_reclist TO it_reclist.
ENDFORM. " create_receivers_list
*---------------------------------------------------------------------
*Form send_mail
*---------------------------------------------------------------------\
FORM send_mail .
  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data              = wa_docdata
      put_in_outbox              = ' '
      commit_work                = 'X'
    TABLES
      packing_list               = it_objpack
      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.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
    WITH sy-msgv1.
  ELSE.
    WRITE : / 'Mail sent to', p_rec.
  ENDIF.
ENDFORM. " send_mail

Author: Jatra Riwayanto
Submitted: 24.09.2007

Description:
There is several folder in our workplace like inbox, outbox, private folder.
This simple program will display mail list in inbox folder.

Selection Screen

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
SELECTION-SCREEN BEGIN OF BLOCK BLC01 WITH FRAME TITLE TEXT-S10.
  PARAMETERS: P_UNAME LIKE SY-UNAME OBLIGATORY DEFAULT SY-UNAME.
SELECTION-SCREEN END OF BLOCK BLC01.

Class Definition

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
CLASS LCL_MAIN DEFINITION.
  PUBLIC SECTION.
    METHODS: DISPLAY_INBOX.
*             DISPLAY_MAIL IMPORTING IM_MAILID TYPE STRING.
    EVENTS:  MESSAGE EXPORTING VALUE(MSG1) TYPE STRING
                               VALUE(MSG2) TYPE STRING OPTIONAL
                               VALUE(MSG3) TYPE STRING OPTIONAL
                               VALUE(MSG4) TYPE STRING OPTIONAL.
  PRIVATE SECTION.
    METHODS: CLEAR_DATA,
             GET_INBOX_CONTENT.
*---------------------------------
* L.O.C.A.L  D.A.T.A.
*---------------------------------
    DATA: USER      TYPE SOUDNAMEI1,
          UDAT      TYPE SOUDATAI1,
          FDAT      TYPE SOFOLDATI1,
          IT_FDAT   TYPE TABLE OF SOFOLENTI1,
          WA_FDAT   TYPE SOFOLENTI1.

    DATA: MSG1      TYPE STRING,
          MSG2      TYPE STRING,
          MSG3      TYPE STRING,
          MSG4      TYPE STRING.

    DATA: FOLD_ID   TYPE SOODK.
ENDCLASS.                    "lcl_main DEFINITION

CLASS LCL_HANDLER DEFINITION.
  PUBLIC SECTION.
    METHODS HANDLE_MESSAGE
            FOR EVENT MESSAGE OF LCL_MAIN
            IMPORTING MSG1 MSG2 MSG3 MSG4.
ENDCLASS.                    "lcl_handler DEFINITION

Class Implementation

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
CLASS LCL_MAIN IMPLEMENTATION.
*----------------------------------------------*
* METHOD clear_data                            *
*----------------------------------------------*
  METHOD CLEAR_DATA.
    CLEAR:    USER,
              UDAT,
              FDAT,
              IT_FDAT[],
              WA_FDAT,
              FOLD_ID
  ENDMETHOD.                    "clear_data

*----------------------------------------------*
* METHOD DISPLAY_INBOX                         *
*----------------------------------------------*
  METHOD DISPLAY_INBOX.
    CALL METHOD CLEAR_DATA( ).
    CALL METHOD GET_INBOX_CONTENT( ).
    IF IT_FDAT[] IS INITIAL.
      RAISE EVENT MESSAGE EXPORTING MSG1 = 'No emails in this inbox'.
    ENDIF.

    ULINE AT (114).
    FORMAT COLOR COL_HEADING.
    WRITE: / '|' NO-GAP, (020) 'Object ID'        LEFT-JUSTIFIED,
             '|' NO-GAP, (030) 'Subject'          LEFT-JUSTIFIED,
             '|' NO-GAP, (015) 'Date Recieved'    LEFT-JUSTIFIED,
             '|' NO-GAP, (040) 'Sender '          LEFT-JUSTIFIED,
             '|'.
    ULINE AT /(114).
    FORMAT COLOR OFF.

    LOOP AT IT_FDAT INTO WA_FDAT.
      FORMAT COLOR COL_NORMAL INTENSIFIED ON.
      WRITE: / '|' NO-GAP, (020) WA_FDAT-OBJECT_ID  UNDER 'Email ID'
                                 HOTSPOT ON,
               '|' NO-GAP, (030) WA_FDAT-OBJ_DESCR   LEFT-JUSTIFIED,
               '|' NO-GAP, (015) WA_FDAT-REC_DATE    LEFT-JUSTIFIED,
               '|' NO-GAP, (040) WA_FDAT-SEND_FNAM   LEFT-JUSTIFIED,
               '|'.
    ENDLOOP.
    ULINE AT /(114).
  ENDMETHOD.                    "DISPLAY_INBOX

*----------------------------------------------*
* METHOD GET_INBOX_CONTENT                         *
*----------------------------------------------*
  METHOD GET_INBOX_CONTENT.
    MOVE P_UNAME TO USER-SAPNAME.
    CALL FUNCTION 'SO_USER_READ_API1'
      EXPORTING
        USER                      = USER
*    prepare_for_folder_access = 'X'
      IMPORTING
        USER_DATA                 = UDAT
      EXCEPTIONS
        USER_NOT_EXIST            = 1
        PARAMETER_ERROR           = 2
        X_ERROR                   = 3
        OTHERS                    = 4.

    IF SY-SUBRC NE 0.
      CASE SY-SUBRC.
        WHEN 1. MSG1 = 'User Does not exist !'.
        WHEN 2. MSG1 = 'Parameter Error !'.
        WHEN 3. MSG1 = 'X Error!'.
        WHEN 4. MSG1 = 'Others Error !'.
      ENDCASE.
      RAISE EVENT MESSAGE EXPORTING MSG1 = MSG1.
    ENDIF.

*   Select inbox folder
    MOVE UDAT-INBOXFOL TO FOLD_ID.

    CALL FUNCTION 'SO_FOLDER_READ_API1'
      EXPORTING
        FOLDER_ID                  = FOLD_ID
      IMPORTING
        FOLDER_DATA                = FDAT
      TABLES
        FOLDER_CONTENT             = IT_FDAT
      EXCEPTIONS
        FOLDER_NOT_EXIST           = 1
        OPERATION_NO_AUTHORIZATION = 2
        X_ERROR                    = 3
        OTHERS                     = 4.

    IF SY-SUBRC NE 0.
      CASE SY-SUBRC.
        WHEN 1. MSG1 = 'Folder Does not exist !'.
        WHEN 2. MSG1 = 'No Authorization !'.
        WHEN 3. MSG1 = 'X Error!'.
        WHEN 4. MSG1 = 'Others Error !'.
      ENDCASE.
      RAISE EVENT MESSAGE EXPORTING MSG1 = MSG1.
    ENDIF.

  ENDMETHOD.                    "GET_INBOX_CONTENT

ENDCLASS.                    "lcl_main IMPLEMENTATION

CLASS LCL_HANDLER IMPLEMENTATION.

  METHOD HANDLE_MESSAGE .
    MESSAGE I398(00) WITH MSG1 MSG2 MSG3 MSG4.
    LEAVE LIST-PROCESSING..
  ENDMETHOD.                    "handle_message

ENDCLASS.                    "lcl_handler IMPLEMENTATION

Main Program

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
START-OF-SELECTION.
  DATA: O_MAIN           TYPE REF TO LCL_MAIN,
        O_HANDLER        TYPE REF TO LCL_HANDLER.

  CREATE OBJECT: O_MAIN, O_HANDLER.
  SET HANDLER O_HANDLER->HANDLE_MESSAGE FOR ALL INSTANCES.

  CALL METHOD O_MAIN->DISPLAY_INBOX.

Selection Screen:

*Inbox Content:*

The code below demonstrates how to send an SAP mail to a users inbox (SBWP)

REPORT zsapmail NO STANDARD PAGE HEADING.

TABLES: drad,
        qinf,
        draw,
        souc,
        sofd,
        drap.

DATA: p_return_code LIKE sy-subrc.

DATA: d_username LIKE drap-prnam.

* mail declarations
DATA : BEGIN OF new_object_id.         " the newly created email object
        INCLUDE STRUCTURE soodk.
DATA : END OF new_object_id.

DATA : BEGIN OF folder_id.             " the folder id of the outbox
        INCLUDE STRUCTURE soodk.
DATA : END OF folder_id.

DATA : BEGIN OF rec_tab OCCURS 5.     " the table which will contain the
        INCLUDE STRUCTURE soos1.       " information on the destination
DATA : END OF rec_tab.

DATA : BEGIN OF object_hd_change.      " the table which contains the
        INCLUDE STRUCTURE sood1.       " info for the object we will be
DATA : END OF object_hd_change.        " creating

DATA : object_type LIKE sood-objtp.    " the type of object

DATA : BEGIN OF objhead OCCURS 5.      " the header of the object
        INCLUDE STRUCTURE soli.
DATA : END OF objhead.

DATA : BEGIN OF objcont OCCURS 0.      " the contents of the object
        INCLUDE STRUCTURE soli.        " i.e. the text etc
DATA : END OF objcont.

DATA : BEGIN OF objpara OCCURS 5.      " formatting options
        INCLUDE STRUCTURE selc.
DATA : END OF objpara.

DATA : BEGIN OF objparb OCCURS 5.      " formatting options
        INCLUDE STRUCTURE soop1.
DATA : END OF objparb.

DATA : BEGIN OF t_mail_text OCCURS 0,  "Message table for messages to
        string(255),                   "user via mailbox
       END OF t_mail_text.

PARAMETER: p_uname LIKE sy-uname.

************************************************************************
**START-OF-SELECTION
START-OF-SELECTION.
  d_username = p_uname.
  PERFORM populate_email_text.

  PERFORM setup_trx_and_rtx_mailboxes USING p_return_code.
  PERFORM create_and_send_mail_object.

*---------------------------------------------------------------------*
*       FORM POPULATE_EMAIL_TEXT                                      *
*---------------------------------------------------------------------*
*       Inserts text for email message                                *
*---------------------------------------------------------------------*
FORM populate_email_text.
  CLEAR t_mail_text-string.            "puts a blank line in
  APPEND t_mail_text.
  APPEND t_mail_text.

*  adds failed list  on to end of success list.
  t_mail_text-string = 'Test email message line 1'.
  APPEND t_mail_text.
  t_mail_text-string = 'Test email message line 1'.
  APPEND t_mail_text.
  CLEAR t_mail_text-string.            "puts a blank line in
  APPEND t_mail_text.
  t_mail_text-string = 'Header1    Header2    Header3'.
  APPEND t_mail_text.
  t_mail_text-string = '-----------    ----------    -----------'.
  APPEND t_mail_text.
ENDFORM.                    "POPULATE_EMAIL_TEXT

*&---------------------------------------------------------------------*
*&      Form  SETUP_TRX_&_RTX_MAILBOXES
*&---------------------------------------------------------------------*
*   Ensure that the mailboxes of the sender (INTMGR) are set up OK
*----------------------------------------------------------------------*
FORM setup_trx_and_rtx_mailboxes USING p_return_code.

* get the user no of the sender in order to add the mail to the
* user name's outbox for future reference
  SELECT SINGLE * FROM souc
           WHERE sapnam = sy-uname.    "SAP name of a SAPoffice user
  IF sy-subrc NE 0.
    "Error finding the SAPoffice user info for the user
    MESSAGE e064(zr53) WITH sy-uname.
    p_return_code = 1.
    EXIT.
  ENDIF.
*Get the outbox No for the sender from the user No where the folder
  " type is an outbox
  SELECT * FROM sofd WHERE owntp = souc-usrtp   "Owner type from ID
                       AND ownyr = souc-usryr   "Owner year from the ID
                       AND ownno = souc-usrno   "Owner number from the I
                       AND folrg = 'O'."Output box
  ENDSELECT.

  IF sy-subrc NE 0.
    " Error getting folder information for the user
    MESSAGE e065(zr53) WITH sy-uname.
    p_return_code = 1.
    EXIT.
  ENDIF.
ENDFORM.                               " SETUP_TRX_&_RTX_MAILBOXES

*&---------------------------------------------------------------------*
*&      Form  CREATE_AND_SEND_MAIL_OBJECT
*&---------------------------------------------------------------------*
FORM create_and_send_mail_object.

  folder_id-objtp = sofd-foltp.        " the folder type ( usually FOL )
  folder_id-objyr = sofd-folyr.        " the folder year ( usually 22 )
  folder_id-objno = sofd-folno.        " the folder no.
  object_type     = 'RAW'.             " the type of object being added

* build up the object information for creating the object
  object_hd_change-objla  = sy-langu.  " the language of the email
  object_hd_change-objnam = 'PS to DM Interface'. " the object name

* mail subject 'Mass Linking of QA, pass/fail'
  MOVE text-002 TO object_hd_change-objdes.

  object_hd_change-dldat = sy-datum.   " the date of the email
  object_hd_change-dltim = sy-uzeit.   " the time of the email
  object_hd_change-objpri = '1'.       " the priority ( highest )
  object_hd_change-objsns = 'F'.       " the object sensitivity
* F is functional, C - company sensitive

* object_hd_change-skips  = ' '.       " Skip first screen
* object_hd_change-acnam  = 'SM35'.    " Batch imput transaction

* object_hd_change-vmtyp  = 'T'.       " Transaction type

* add the text lines into the contents of the email
  CLEAR objcont.
  REFRESH objcont.
*  free objcont.      " added this to delete the mail contents records
  LOOP AT t_mail_text.
    objcont-line = t_mail_text-string.
    APPEND objcont.
  ENDLOOP.
  CLEAR objcont.

* build up the table of receivers for the email
  rec_tab-rcdat = sy-datum.            " the date to send the email
  rec_tab-rctim = sy-uzeit.            " the time to send the email
* the SAP username of the person who will receive the email
  rec_tab-recnam = d_username.
* the user type of the person who will send the email ( USR )
  rec_tab-sndtp = souc-usrtp.
* the user year of the person who will send the email ( 22 )
  rec_tab-sndyr = souc-usryr.
* the user number of the person who will send the email
  rec_tab-sndno = souc-usrno.
* the sap username of the person who will send the email
  rec_tab-sndnam = sy-uname.

* get the user info for the receiver of the document
  SELECT SINGLE * FROM souc WHERE sapnam = d_username.
  IF sy-subrc NE 0.
    WRITE : / text-001, d_username.    "usnam.
    EXIT.
  ENDIF.

* the user number of the person who will receive the email ( USR )
  rec_tab-recno = souc-usrno.
* the user type of the person who will receive the email ( USR )
  rec_tab-rectp = souc-usrtp.
* the user year of the person who will receive the email ( USR )
  rec_tab-recyr = souc-usryr.
* the priority of the email ( highest )
  rec_tab-sndpri = '1'.
* check for delivery on the email
  rec_tab-deliver = 'X'.
* send express so recipient knows there is a problem
  rec_tab-sndex = 'X'.
* check for a return receipt
  rec_tab-read = 'X'.
* the sap username of the person receiving the email
  rec_tab-adr_name = d_username.       "usnam.
* add this receiver to the internal table
  APPEND rec_tab.
  CLEAR rec_tab.

* call the function to create the object in the outbox of the sender
  CALL FUNCTION 'SO_OBJECT_INSERT'
    EXPORTING
      folder_id                  = folder_id
      object_hd_change           = object_hd_change
      object_type                = object_type
      owner                      = sy-uname
    IMPORTING
      object_id                  = new_object_id
    TABLES
      objcont                    = objcont
      objhead                    = objhead
      objpara                    = objpara
      objparb                    = objparb
    EXCEPTIONS
      active_user_not_exist      = 1
      communication_failure      = 2
      component_not_available    = 3
      dl_name_exist              = 4
      folder_not_exist           = 5
      folder_no_authorization    = 6
      object_type_not_exist      = 7
      operation_no_authorization = 8
      owner_not_exist            = 9
      parameter_error            = 10
      substitute_not_active      = 11
      substitute_not_defined     = 12
      system_failure             = 13
      x_error                    = 14
      OTHERS                     = 15.
  IF sy-subrc NE 0.
    MESSAGE a063(zr53) WITH sy-subrc.
    EXIT.
  ENDIF.

* call the function to send the already created email to the receivers
  CALL FUNCTION 'SO_OBJECT_SEND'
    EXPORTING
      folder_id                  = folder_id
      object_id                  = new_object_id
      outbox_flag                = 'X'
      owner                      = sy-uname
    TABLES
      receivers                  = rec_tab
    EXCEPTIONS
      active_user_not_exist      = 1
      communication_failure      = 2
      component_not_available    = 3
      folder_not_exist           = 4
      folder_no_authorization    = 5
      forwarder_not_exist        = 6
      note_not_exist             = 7
      object_not_exist           = 8
      object_not_sent            = 9
      object_no_authorization    = 10
      object_type_not_exist      = 11
      operation_no_authorization = 12
      owner_not_exist            = 13
      parameter_error            = 14
      substitute_not_active      = 15
      substitute_not_defined     = 16
      system_failure             = 17
      too_much_receivers         = 18
      user_not_exist             = 19
      x_error                    = 20
      OTHERS                     = 21.
  IF sy-subrc EQ 0.
    MESSAGE i035(zr53) WITH new_object_id d_username. "usnam.
  ELSE.
    MESSAGE i036(zr53) WITH d_username."      sy-subrc.
  ENDIF.
ENDFORM.                               " CREATE_AND_SEND_MAIL_OBJECT
 

Sending mail from SAP and getting read-receipt.
  

  1. BASIS settings to be done :            SCOT->Settings->Confirmation of Receipts -> SAP expects receipt confirmations for Internet mail   
  2. Requesting Read Receipt using Class:               CLEAR send_request.
        TRY.
    *     ------- create persistent send request -----------------------
            send_request = cl_bcs=>create_persistent( ).

*     ------- create and set document with attachment --------------
*     create document from internal table with text

*Create the content of the mail
 ONCATENATE 'This is for test' INTO v_objdes SEPARATED BY space.
        APPEND  v_objdes TO text.
        document = cl_document_bcs=>create_document(
                        i_type    = 'RAW'
                        i_text    = i_text
                        i_subject = v_objdes ).
  
        REFRESH i_text.
        CLEAR v_objdes.   
CALL METHOD send_request->set_document( document ).
 sender = cl_sapuser_bcs=>create( sy-uname ).        
        CALL METHOD send_request->set_sender
          EXPORTING
            i_sender = sender.
          
  *     -------- add recipient (e-mail address) ----------------------
*     create recipient - please replace e-mail address !!!
*    here only need to specify about read receipt
         {}v_mail  = 'papiya@gmail.com'.
          l_recipient_soos-recesc = 'U'.
        l_recipient_soos-recextnam = v_mail.
        l_recipient_soos-read      = 'X'.

        TRY.
            CALL METHOD cl_send_request_bcs=>create_recipient_from_soos1
              EXPORTING
                i_soos1 = l_recipient_soos
              RECEIVING
                result  = recipient.
          CATCH cx_send_req_bcs .
        ENDTRY.
*     add recipient with its respective attributes to send request
        CALL METHOD send_request->add_recipient
          EXPORTING
            i_recipient = recipient
            i_express   = 'X'.
        CLEAR v_mail.
TRY.
          CALL METHOD send_request->set_status_attributes
            EXPORTING
              i_requested_status = i_requested_status
              i_status_mail      = i_status_mail.
* CATCH cx_send_req_bcs .
        ENDTRY.
 SPAN

Unknown macro: { font-family}

.L0S33

Unknown macro: { color}

.L0S52

Unknown macro: { color}

CALL METHOD send_request->send(
          EXPORTING
            i_with_error_screen = 'X'
          RECEIVING
            result              = sent_to_all ).WITH FUNCTION MODULE :
 DATA: wa_email TYPE zdm_email_id_s,
         wa_document      TYPE sodocchgi1,
         v_desc_lines    TYPE sy-tabix,
         it_mail_msg_ob  TYPE TABLE OF solisti1,
         wa_mail_msg_ob  TYPE solisti1,
         it_packing_ob   TYPE TABLE OF sopcklsti1,
         wa_packing_ob   TYPE sopcklsti1,
         it_receivers_ob TYPE TABLE OF somlreci1,
         wa_receivers_ob TYPE somlreci1.

  CONSTANTS: c_sender         TYPE soextreci1-receiver VALUE 'WF-BATCH',
             c_ehs_email_ob   TYPE sopcklsti1-obj_name VALUE 'EHS_EMAIL',
             c_int_ob         TYPE soextreci1-adr_typ  VALUE 'INT',
             c_255_ob         TYPE i       VALUE '255',
             c_zero_ob(15)    TYPE c       VALUE '0'  ,
             c_one_ob(15)     TYPE c       VALUE '1'  ,
             c_doc_type_ob(3TYPE c       VALUE 'RAW'.

  IF zdm_email[] IS NOT INITIAL.
**  Getting the receivers email IDs

      wa_receivers_ob-receiver = 'papiya@gmail.com'.

      wa_receivers_ob-rec_type = 'U'.
      wa_receivers_ob-notif_read = 'X'.

      APPEND wa_receivers_ob TO it_receivers_ob.
    **  Filling the Mail Content
 
        clear wa_mail_msg_ob.
        CONCATENATE text-025
                    text-026
               INTO wa_mail_msg_ob
          SEPARATED BY space.
        APPEND wa_mail_msg_ob to it_mail_msg_ob.
        clear wa_mail_msg_ob.
        move text-027 to wa_mail_msg_ob.
        append wa_mail_msg_ob to it_mail_msg_ob.

        move space to wa_mail_msg_ob.
        APPEND wa_mail_msg_ob to it_mail_msg_ob.

 
    CONCATENATE 'This is just a test document' '.'
           INTO wa_mail_msg_ob
      SEPARATED BY space.
    APPEND wa_mail_msg_ob TO it_mail_msg_ob.

    DESCRIBE TABLE it_mail_msg_ob LINES v_desc_lines.
    READ TABLE it_mail_msg_ob INDEX v_desc_lines
                            INTO wa_mail_msg_ob.
    wa_document-doc_size  = ( v_desc_lines - 1 ) * c_255_ob
                                              + STRLEN( wa_mail_msg_ob ).
    wa_document-obj_langu = sy-langu.
    wa_document-obj_name  = c_ehs_email_ob.
**  Filling the Mail Title

    CONCATENATE 'ATTN:This is test.'
           INTO wa_document-obj_descr
      SEPARATED BY space.

    wa_packing_ob-transf_bin = space.
    wa_packing_ob-head_start = c_one_ob.
    wa_packing_ob-head_num   = c_zero_ob.
    wa_packing_ob-body_start = c_one_ob.
    DESCRIBE TABLE it_mail_msg_ob LINES wa_packing_ob-body_num.
    wa_packing_ob-doc_type   = c_doc_type_ob.
    APPEND wa_packing_ob TO it_packing_ob.
** Sending Mail for obsolete
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
      EXPORTING
        document_data                    = wa_document
        sender_address                   = c_sender
*                 SENDER_ADDRESS_TYPE              = 'B'
       commit_work                      = 'X'
      TABLES
        packing_list                     = it_packing_ob
        contents_txt                     = it_mail_msg_ob
        receivers                        = it_receivers_ob
      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.

    ENDIF.

  ENDIF.

  EXIT.
To check if the settings done by you are correct:
You need to check the MIME data of an email:
To check the MIME:
A) Please implement note 845449 if it is not already in your
system.


B) Please run report RSCONN06 and select the Always Save option for
outgoing emails. Send another email and then display the MIME
version of this email. The MIME version can be displayed for outbound
e-mails in transaction SOST by right-clicking on a send job using
'Display MIME display ' or 'MIME version'.
If it is showing like the settings below your settings are perfect.
Disposition-Notification-To: Papiya <papiya@gmail.com>
Return-Receipt-To: Papiya <papiya@gmail.com>
Lastly also these steps has to be noted for the delivery and the read receipt settings to work perfectly:
When 'A' sends email with a *Delivery Receipt* request, to "B" the Delivery Receipt is answered by ESMTP on B's mail server. A Delivery Receipt is sent from the server hosting the recipient's mailbox, when the message is delivered to the mail box. The purpose of this is to confirm to the sender that the message reached the recipient's mailbox's (Delivery Service Notifications) refers to both a service that may optionally be provided by Message Transfer Agents
 (MTAs) using the Simple Mail Transfer Protocol (SMTP), and a message format to be used to return indications of message delivery to the sender of that message. Specifically, the DSN SMTP service is used to request that indications of successful delivery or delivery failure (in the DSN format) be returned. Issuance of a DSN upon delivery failure is the default behavior, whereas issuance of a DSN upon successful delivery requires a specific request from the sender.
Moreover some settings need to be done in the recipient client's mail box also.
For Microsoft outlook the settings that need to be done are:

In many email clients, you can configure delivery and read receipts.  A delivery receipt is an email alert when your email has been delivered to an accepting mail server for the recipient of your email.  A read receipt is an email you receive when a user reads the email.  However, a read receipt is only sent if the user desires to send you one - as such I find it unreliable.  I also find it annoying when I receive emails with a read receipt request.  They cause outlook to give a popup message unless you've configured it to always ignore or always send read receipts.  This article will show you how to configure your Outlook 2007 email client (this might also work the same in Outlook 2003 and before) to request delivery receipts (read receipts are on the same screen if you insist) on all emails you send out.

  1. From the Oulook Tools menu, select Options (if you don't see the Options menu item, you may ahve to expand the menu window with that little double arrow that points downward).
  2. In the next screen for Options, click on the Email Options button
  3. In the next screen Email Options, click on the Tracking Options button.
  4. In the Tracking Options screen, you have a checkmark for Delivery receipt.  Click this and all your emails you send out will give you an alert when your email server delivers them.

If you start getting annoyed with all of the delivery receipts, then just come back here and take that check mark off.  Also notice the options on this screen for how to reply to read receipts and why I don't believe in them.  Never send a response is an option.  Additionally, if they have checked Always send a response and it only becomes "read" from their preview pane in Outlook (which you should turn off), but they didn't actually read it, you get a read receipt.

Sending Mails - Home Page

Author: Suresh Maryala
Submitted: 07/10/2008
Related Links:

  • Selection Screen Details

As part of the Selection screen user inputs Training Name, Location, Begin date, End Date, Pernr or User type and Pernr number or user id. . 

Program Logic

Based on information provided to selection screen, program reads infotype 105 to find the user id or pernr and also the e-mail address. User id is stored in sub type 0001 and e-mail address is stored in sub type 0010.  Process

  • *# Read infotype 0105 to find the PERNR, User ID and E-mail address
    1. Build internal table for Microsoft calendar entry
    2. Build training details to be part of text
    3. Call so_raw_to_rtf to convert the calendar entry details to have line breaks
    4. Call method send_request to send the e-mail 
    5. Add entry in table TSOPE with VCS and ASCII check box selected
  •  

ABAP Code

DATA: text               TYPE bcsy_text.
DATA: document           TYPE REF TO cl_document_bcs.
DATA: sender             TYPE REF TO cl_sapuser_bcs.
DATA: recipient          TYPE REF TO if_recipient_bcs.
DATA: bcs_exception      TYPE REF TO cx_bcs.
DATA: sent_to_all        TYPE os_boolean.
DATA: it_content         TYPE soli_tab.
DATA: it_attach          TYPE soli_tab.
DATA: send_request       TYPE REF TO cl_bcs.
DATA: l_subject          LIKE sodocchgi1-obj_descr,
      l_sender_type      LIKE soextreci1-adr_typ,
      l_recsize          TYPE i,
      l_receiver         TYPE sy-subrc.
DATA: lt_soli            TYPE soli_tab    .
DATA: ls_soli            LIKE LINE OF lt_soli.
DATA: lt_soli_new        TYPE soli_tab.
DATA: ls_email           TYPE pa0105-usrid_long.
DATA: ls_uname           TYPE pa0105-usrid.
DATA: ls_pernr           TYPE pernr-pernr.
DATA: ls_begin(10)       TYPE c.
DATA: ls_end(10)         TYPE c.
DATA: result        TYPE REF TO cl_document_bcs.
DATA: BEGIN OF ls_data,
  sender TYPE lsoppvar-sender,  "sender
  kbgda  TYPE ppvar-kbgda,      "begin date
  kndda  TYPE ppvar-endda,      "end date
  kbtim  TYPE ppvar-kbtim,      "begin time first day
  ketim  TYPE ppvar-ketim,      "end time last day
  kstxt  TYPE ppvar-kstxt,      "training text
  b_ort  TYPE ppvar-b_ort,      "training location
  rstxt  TYPE ppvar-rstxt,      "room text
  amail  TYPE lsoppvar-amail,   "recipient eMail
  astxt  TYPE ppvar-astxt,      "recipient
END OF ls_data.
FIELD-SYMBOLS: <fs_soli> LIKE ls_soli.
************************************************************************
* SELECTION SCREEN DEFINITION
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK group WITH FRAME TITLE text-001.
PARAMETERS:  p_trnam   LIKE p1000-stext DEFAULT 'TRAINING NAME',
             p_locnm   LIKE p1000-stext DEFAULT 'LOCATION',
             p_begda   LIKE p1000-begda DEFAULT '20081101',
             p_endda   LIKE p1000-endda DEFAULT '20081104',
             p_ltype   LIKE lso_borkey_participation-learnertype DEFAULT 'P',
             p_lid     LIKE lso_borkey_participation-learnerid DEFAULT '10000137'.
SELECTION-SCREEN END   OF BLOCK group.
************************************************************************
* INITIALIZATION
************************************************************************
INITIALIZATION.

START-OF-SELECTION.
  CASE p_ltype.
    WHEN 'P'.
* Move PERNR number to variable
      ls_pernr = p_lid.
    WHEN 'US'.
      ls_uname = p_lid.
      CONDENSE ls_uname.
      SELECT SINGLE pernr FROM pa0105 INTO ls_pernr WHERE
                                usrid = ls_uname AND
                                begda LE sy-datum AND
                                endda GE sy-datum AND
                                subty = '0001'.
  ENDCASE.
* Read infotype 0105 and subtypes 0001 and 0010
* Sub type 0001 has username
* sub type 0010 has e-mail
  SELECT SINGLE usrid_long FROM pa0105 INTO ls_email WHERE
                         pernr = ls_pernr AND
                         begda LE sy-datum AND
                         endda GE sy-datum AND
                         subty = '0010'.
  SELECT SINGLE usrid FROM pa0105 INTO ls_uname WHERE
                         pernr = ls_pernr AND
                         begda LE sy-datum AND
                         endda GE sy-datum AND
                         subty = '0001'.
  PERFORM f_data.
*&---------------------------------------------------------------------*
*&      Form  f_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_data .
* Calendar logic begin
  ls_soli-line = 'BEGIN:VCALENDAR'.
  APPEND ls_soli TO lt_soli.
  ls_soli-line = 'PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN'.
  APPEND ls_soli TO lt_soli.
  ls_soli-line = 'VERSION:1.0'.
  APPEND ls_soli TO lt_soli.
  ls_soli-line = 'METHOD:REQUEST'.
  APPEND ls_soli TO lt_soli.
  ls_soli-line = 'BEGIN:VEVENT'.
  APPEND ls_soli TO lt_soli.
  CONCATENATE 'ATTENDEE;CN=' ls_uname ';ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:' ls_email INTO ls_soli-line.
  APPEND ls_soli TO lt_soli.
  CONCATENATE 'DTSTART:' p_begda 'T140000Z' INTO ls_soli-line.
  APPEND ls_soli TO lt_soli.
  CONCATENATE 'DTEND:' p_endda 'T220000Z' INTO ls_soli-line.
  APPEND ls_soli TO lt_soli.
  CONCATENATE 'LOCATION:' p_locnm INTO ls_soli-line.
  APPEND ls_soli TO lt_soli.
  ls_soli-line = 'TRANSP:OPAQUE'.
  APPEND ls_soli TO lt_soli.
  ls_soli-line = 'SEQUENCE:1'.
  APPEND ls_soli TO lt_soli.
  ls_soli-line = 'DESCRIPTION: Course Participation'.
  APPEND ls_soli TO lt_soli.
  CONCATENATE 'SUMMARY: Course Participation for ' ls_uname INTO ls_soli-line SEPARATED BY space.
  APPEND ls_soli TO lt_soli.
  ls_soli-line = 'PRIORITY:5'.
  APPEND ls_soli TO lt_soli.
  ls_soli-line = 'X-MICROSOFT-CDO-IMPORTANCE:1'.
  APPEND ls_soli TO lt_soli.
  ls_soli-line = 'CLASS:PUBLIC'.
  APPEND ls_soli TO lt_soli.
  ls_soli-line = 'END:VEVENT'.
  APPEND ls_soli TO lt_soli.
  ls_soli-line = 'END:VCALENDAR'.
  APPEND ls_soli TO lt_soli.
* End of Calendar
* Call this function module to convert data created for calendar entry
*
  CALL FUNCTION 'SO_RAW_TO_RTF'
    TABLES
      objcont_old = lt_soli[]
      objcont_new = lt_soli_new[].
  l_subject = 'Course Participation'.
  ls_soli-line = 'This is to notify following course has been approved'.
  APPEND ls_soli TO it_content.
  CLEAR ls_soli.
  APPEND ls_soli TO it_content.
  CONCATENATE 'Training Name: ' p_trnam INTO ls_soli-line.
  APPEND ls_soli TO it_content.
  CLEAR ls_soli.
  APPEND ls_soli TO it_content.
  WRITE p_begda TO ls_begin.
  WRITE p_endda TO ls_end.
  CONCATENATE 'Begin Date: ' ls_begin INTO ls_soli-line.
  APPEND ls_soli TO it_content.
  CLEAR ls_soli.
  APPEND ls_soli TO it_content.
  CONCATENATE 'End Date: ' ls_end INTO ls_soli-line.
  APPEND ls_soli TO it_content.
  CLEAR ls_soli.
  APPEND ls_soli TO it_content.
  CONCATENATE 'Location Name: ' p_locnm INTO ls_soli-line.
  APPEND ls_soli TO it_content.
  CLEAR ls_soli.
  APPEND ls_soli TO it_content.
  TRY.
* Create persistent send request
      send_request = cl_bcs=>create_persistent( ).
      document = cl_document_bcs=>create_document(
                                    i_type    = 'RAW'
                                    i_text = it_content[]
                                    i_subject = l_subject ).
      DESCRIBE TABLE lt_soli.
      CALL METHOD document->add_attachment
        EXPORTING
          i_attachment_type    = 'VCS'
          i_attachment_subject = 'Course'
          i_att_content_text   = lt_soli_new[].
* Add document to send request
      CALL METHOD send_request->set_document( document ).
* Get sender object
      sender = cl_sapuser_bcs=>create( sy-uname ).
* Add sender
      CALL METHOD send_request->set_sender
        EXPORTING
          i_sender = sender.
*     ------ add recipient (e-mail address) ----------------------
*     create recipient

*  Enter a valid e-mail address
      recipient = cl_cam_address_bcs=>create_internet_address(
                                        ls_email ).
*     add recipient with its respective attributes to send request
      CALL METHOD send_request->add_recipient
        EXPORTING
          i_recipient  = recipient
          i_express    = 'U'
          i_copy       = ' '
          i_blind_copy = ' '
          i_no_forward = ' '.
********Trigger e-mails immediately****************************
      send_request->set_send_immediately( 'X' ).
      CALL METHOD send_request->send(
        EXPORTING
          i_with_error_screen = 'X'
        RECEIVING
          result              = sent_to_all ).
      IF sent_to_all = 'X'.
        WRITE 'Document Sent Successfully'.
      ENDIF.
      COMMIT WORK.
    CATCH cx_document_bcs INTO bcs_exception.
      WRITE: 'Error Occurred'.
      WRITE: 'Error Type', bcs_exception->error_type.
      EXIT.
  ENDTRY.
ENDFORM.                    " f_data

Author: Subrahmanya Pindiproli
Submitted: 14-May-2012

HTML Formatted attachments using ABAP 

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*-----------------------------------------------------------------------*

* Program Name        : ZRPT_FORMATTED_EMAIL_1                          *
* Author              : Subrahmanya Pindiproli                          *
* Requested By        : N.A                                             *
* Date created        : 2012/04/12                                      *
* SAP Release         : ECC6.0                                          *
* Project Name        : N.A                                             *
* Task #              :                                                 *
* Description         : Formatted Emails using HTML in ABAP using the   *
*                       FM : SO_NEW_DOCUMENT_ATT_SEND_API1              *
*-----------------------------------------------------------------------*
* Change History                                                        *
*-----------------------------------------------------------------------*
*                                                                       *
*                                                                       *
*-----------------------------------------------------------------------*
REPORT  zrpt_formatted_email_1.

*-----------------------------------------------------------------------*
*                   D A T A    D E C L A R A T I O N S                  *
*-----------------------------------------------------------------------*

DATA:
t_objtxt   TYPE STANDARD TABLE OF solisti1,             " Message body
t_objpack  TYPE STANDARD TABLE OF sopcklsti1,           " Packing list
t_reclist  TYPE STANDARD TABLE OF somlreci1,            " Receipient list
t_html     TYPE STANDARD TABLE OF w3html.               " Html


DATA:
lv_tmp_str TYPE                   string,
wa_htmlline TYPE                  w3html.

DATA : t_table       TYPE STANDARD TABLE OF ssfbin,
       t_attachment  TYPE STANDARD TABLE OF solix.


DATA:
wa_docdata TYPE sodocchgi1,                             " Document data
wa_objtxt  TYPE solisti1,                               " Message body
*wa_objbin  TYPE solisti1,                               " Attachment data
wa_objpack TYPE sopcklsti1,                             " Packing list
wa_reclist TYPE somlreci1.                              " Receipient list

*DATA: w_tab_lines TYPE i.                               " Table lines

* Internal Table for Data in Email Body
TYPES : BEGIN OF ty_mara,
        matnr TYPE matnr,
        bismt TYPE bismt,
        groes TYPE groes,
  END OF ty_mara.

DATA : t_mara   TYPE STANDARD TABLE OF ty_mara,
*       l_count  TYPE                   i,
       v_ld_sender_address LIKE  soextreci1-receiver,
       v_ld_sender_address_type LIKE  soextreci1-adr_typ,
       v_sent_all(1) TYPE c.

* Constants
CONSTANTS :   c_u TYPE so_escape VALUE 'U'.              "Specification of recipient type
*              c_x TYPE sonv-flag VALUE 'X'.

*-----------------------------------------------------------------------*
*                S E L E C T I O N     S C R E E N                      *
*-----------------------------------------------------------------------*
PARAMETERS: p_email TYPE char120 OBLIGATORY
                    VISIBLE LENGTH 40 LOWER CASE.

*-----------------------------------------------------------------------*
*              S T A R T    O F    S E L E C T I O N                    *
*-----------------------------------------------------------------------*
START-OF-SELECTION.

* Get Report Data
  PERFORM get_data.

* Process Data ( Placeholder Subroutine )
  PERFORM process_data.

* Creating message
  PERFORM create_message.

* Sending Message
  PERFORM send_message.

*&---------------------------------------------------------------------*
*&      Form  create_message
*&---------------------------------------------------------------------*
*       Create the Email Title, Description, Body and populate the     *
*       receiver list.                                                 *
*----------------------------------------------------------------------*
FORM create_message .

**1 Title, Description & Body
  PERFORM create_title_desc_body.

**2 Receivers
  PERFORM fill_receivers.

ENDFORM.                    " create_message

*&---------------------------------------------------------------------*
*&      Form  CREATE_TITLE_DESC_BODY
*&---------------------------------------------------------------------*
*       Title, Description and body
*----------------------------------------------------------------------*
FORM create_title_desc_body.

  PERFORM itab_to_html.
  PERFORM build_email_body.

ENDFORM.                    " CREATE_TITLE_DESC_BODY

*&---------------------------------------------------------------------*
*&      Form  fill_receivers
*&---------------------------------------------------------------------*
*       Filling up the Receivers
*----------------------------------------------------------------------*
FORM fill_receivers .

  wa_reclist-receiver = p_email.
  wa_reclist-rec_type = c_u.
  APPEND wa_reclist TO t_reclist.
  CLEAR  wa_reclist.


ENDFORM.                    " fill_receivers
*&---------------------------------------------------------------------*
*&      Form  send_message
*&---------------------------------------------------------------------*
*       Sending Mail
*----------------------------------------------------------------------*
FORM send_message .

* function module to send email
  IF NOT t_attachment[] IS INITIAL .
*Describe the body of the message
    CLEAR wa_objpack.
    REFRESH t_objpack.
    wa_objpack-transf_bin = space.
    wa_objpack-head_start = 1.
    wa_objpack-head_num = 0.
    wa_objpack-body_start = 1.

    DESCRIBE TABLE t_objtxt LINES wa_objpack-body_num.
    wa_objpack-doc_type = 'RAW'.
    APPEND wa_objpack TO t_objpack.

*Create attachment notification
    wa_objpack-transf_bin = 'X'.
    wa_objpack-head_start = 1.
    wa_objpack-head_num   = 1.
    wa_objpack-body_start = 1.

*Create packing list
    DESCRIBE TABLE t_attachment LINES wa_objpack-body_num.
    wa_objpack-doc_type   =  'HTML'.
    wa_objpack-obj_descr  =  'Material Master Data'.
    wa_objpack-doc_size   =  wa_objpack-body_num * 255.
    APPEND wa_objpack TO t_objpack.

    CLEAR v_sent_all.

*Call FM to send e-mail with attachment
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
      EXPORTING
        document_data              = wa_docdata
        put_in_outbox              = 'X'
        sender_address             = v_ld_sender_address
        sender_address_type        = v_ld_sender_address_type
        commit_work                = 'X'
      IMPORTING
        sent_to_all                = v_sent_all
      TABLES
        packing_list               = t_objpack
        contents_hex               = t_attachment
        contents_txt               = t_objtxt
        receivers                  = t_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 NE 0.
      WRITE: 'Sending Failed'.
    ELSE.
      WRITE: 'Sending Successful'.
    ENDIF.

  ENDIF.
ENDFORM.                    " send_message
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       A core subroutine to fetch the data from the corresponding     *
*       database tables.                                               *
*----------------------------------------------------------------------*
FORM get_data .
  REFRESH t_mara.
  SELECT matnr bismt groes UP TO 10 ROWS
         FROM mara INTO TABLE t_mara.

  IF sy-subrc EQ 0.
    SORT t_mara BY matnr.
  ENDIF.
ENDFORM.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  PROCESS_DATA
*&---------------------------------------------------------------------*
*       This is a placeholder subroutine and can be used for processing*
*       the report data and getting into final internal tables before  *
*       starting the HTML formatting and emailing the data             *
*----------------------------------------------------------------------*
FORM process_data .

ENDFORM.                    " PROCESS_DATA

*&---------------------------------------------------------------------*
*&      Form  ITAB_TO_HTML
*&---------------------------------------------------------------------*
*       This is a subroutine which uses standard SAP Function Modules  *
*       WWW_ITAB_TO_HTML_HEADERS, WWW_ITAB_TO_HTML_LAYOUT  and         *
*       WWW_ITAB_TO_HTML                                               *
*----------------------------------------------------------------------*
FORM itab_to_html.

  DATA:
    t_header  TYPE STANDARD TABLE OF w3head WITH HEADER LINE,    " Header
    t_fields  TYPE STANDARD TABLE OF w3fields WITH HEADER LINE,  " Fields
    fs_header TYPE w3head,
    w_head    TYPE w3head.

  DATA:  t_fcat  TYPE                   lvc_t_fcat,             " Fieldcatalog
         wa_fcat LIKE LINE OF           t_fcat.

*-Populate Fieldcatalog
  REFRESH t_fcat. CLEAR wa_fcat.
  wa_fcat-coltext = 'Material Number'.
  APPEND wa_fcat TO t_fcat.
  wa_fcat-coltext = 'Old Material No.'.
  APPEND wa_fcat TO t_fcat.
  wa_fcat-coltext = 'Size/Dimensions'.
  APPEND wa_fcat TO t_fcat.

*-Fill the Column headings and Properties

  LOOP AT t_fcat INTO wa_fcat.
    w_head-text = wa_fcat-coltext.
*-Populate the Column Headings
    CALL FUNCTION 'WWW_ITAB_TO_HTML_HEADERS'
      EXPORTING
        field_nr = sy-tabix
        text     = w_head-text
        fgcolor  = 'black'
        bgcolor  = 'red'
      TABLES
        header   = t_header.

*-Populate Column Properties
    CALL FUNCTION 'WWW_ITAB_TO_HTML_LAYOUT'
      EXPORTING
        field_nr = sy-tabix
        fgcolor  = 'black'
        size     = '7'
      TABLES
        fields   = t_fields.
  ENDLOOP.

*-Title of the Display
  fs_header-text = 'Automated Emails from SAP Applications'.
  fs_header-font = 'Arial'.
  fs_header-size = '2'.

*-Preparing the HTML from Intenal Table
  REFRESH t_html.

  CALL FUNCTION 'WWW_ITAB_TO_HTML'
    EXPORTING
      table_header = fs_header
    TABLES
      html         = t_html
      fields       = t_fields
      row_header   = t_header
      itable       = t_mara.


  LOOP AT t_html INTO wa_htmlline.
    CONCATENATE lv_tmp_str wa_htmlline INTO lv_tmp_str.
  ENDLOOP .


**** Convert HTML data in pit_attach-content to RAW data format
  IF NOT lv_tmp_str IS INITIAL.
    CALL FUNCTION 'SSFH_STRING_TO_TABUTF8'
      EXPORTING
       cstr_input_data         = lv_tmp_str
       codepage                = '4110'
* IMPORTING
*   OSTR_INPUT_DATA_L       =
      TABLES
        ostr_input_data         = t_table
   EXCEPTIONS
     conversion_error        = 1
     internal_error          = 2
     OTHERS                  = 3.

    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    t_attachment[] = t_table[].
    REFRESH: t_table[].
  ENDIF.



ENDFORM.                    "ITAB_TO_HTML
*&---------------------------------------------------------------------*
*&      Form  BUILD_EMAIL_BODY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_email_body .

*...Title
  wa_docdata-obj_name  = 'This is the Email Subject'.

*...Description
  wa_docdata-obj_descr = 'Description of Email with a max length of 50 Chars'.


  wa_objtxt-line = 'Dear Sir / Madam'.
  APPEND wa_objtxt TO t_objtxt.

  wa_objtxt-line = 'This is an Automated Email from SAP Applications. '.
  APPEND wa_objtxt TO t_objtxt.



  CLEAR wa_objtxt.  APPEND wa_objtxt TO t_objtxt.
  CLEAR wa_objtxt.  APPEND wa_objtxt TO t_objtxt.
  CLEAR wa_objtxt.  APPEND wa_objtxt TO t_objtxt.


*   Signature with background color
  wa_objtxt-line = 'Best Regards,'.
  APPEND wa_objtxt TO t_objtxt.
  wa_objtxt-line = 'Subrahmanya Pindiproli'.
  APPEND wa_objtxt TO t_objtxt.
  wa_objtxt-line = 'Principal Consultant - ERP'.
  APPEND wa_objtxt TO t_objtxt.
ENDFORM.                    " BUILD_EMAIL_BODY

Sending an email in ABAP should be done via BCS (class CL_BCS and related).

Don't use these obsolete APIs:

  • SO_OBJECT_SEND is an old function module for sending emails.
  • Etc.

This WIKI can be used as a reference for sending the report output as a screenshot in the body of the E-mail.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA: li_receivers       TYPE STANDARD TABLE OF soos1,
      li_listobject      TYPE STANDARD TABLE OF abaplist,
      li_ali             TYPE STANDARD TABLE OF soli,
      li_ali1            TYPE STANDARD TABLE OF soli,
      li_ali2            TYPE STANDARD TABLE OF soli,
      lwa_objecthdchange TYPE sood1,
      lwa_receivers      TYPE soos1,
      lwa_ali            TYPE soli.
DATA: l_lines   TYPE i,
      l_length  TYPE i.

DO 10 TIMES.
  NEW-LINE.
  ULINE (99).
  WRITE: /1 sy-vline,
          2 'column1',
         24 sy-vline,
         25 'Column2',
         49 sy-vline,
         50 'Column3',
         74 sy-vline,
         75 'Column4',
         99 sy-vline.
ENDDO.

NEW-LINE.
ULINE (99).
NEW-LINE.

CALL FUNCTION 'SAVE_LIST'
  EXPORTING
    list_index         = '0'    "Pass the list index like 0, 1, 2...
  TABLES
    listobject         = li_listobject
  EXCEPTIONS
    list_index_invalid = 1
    OTHERS             = 2.
IF sy-subrc NE 0.
  RAISE invalid_list.
ENDIF.

* Convert the list to ALI format
CALL FUNCTION 'TABLE_COMPRESS'
  TABLES
    in             = li_listobject
    out            = li_ali
  EXCEPTIONS
    compress_error = 1
    OTHERS         = 2.
IF sy-subrc NE 0.
  RAISE compress_error.
ENDIF.

CLEAR: lwa_objecthdchange.
DESCRIBE TABLE li_ali LINES l_lines.
DESCRIBE FIELD lwa_ali LENGTH l_length IN CHARACTER MODE.

lwa_objecthdchange-objlen = l_length * l_lines.
lwa_objecthdchange-objla  = sy-langu.
lwa_objecthdchange-objnam = 'List'.

MOVE sy-title TO lwa_objecthdchange-objdes.

MOVE: 1 TO lwa_objecthdchange-objpri,
      0 TO lwa_objecthdchange-objsns.

CLEAR: lwa_receivers.
MOVE: 'X'                 TO lwa_receivers-snddr,
      'X'                 TO lwa_receivers-sndex,
      'U'                 TO lwa_receivers-recesc,
      'E-MAIL' TO lwa_receivers-recextnam.          "Pass the recipient ID here.

APPEND lwa_receivers TO li_receivers.

* Send email
CALL FUNCTION 'SO_OBJECT_SEND'
 EXPORTING
*   FOLDER_ID                        = ' '
*   FORWARDER                        = ' '
*   OBJECT_FL_CHANGE                 = ' '
   object_hd_change                 = lwa_objecthdchange
*   OBJECT_ID                        = ' '
   object_type                      = 'ALI'
*   OUTBOX_FLAG                      = ' '
   owner                            = sy-uname
*   STORE_FLAG                       = ' '
*   DELETE_FLAG                      = ' '
   sender                           = sy-uname
*   CHECK_SEND_AUTHORITY             = ' '
*   CHECK_ALREADY_SENT               = ' '
*   GIVE_OBJECT_BACK                 =
*   ORIGINATOR                       = ' '
*   ORIGINATOR_TYPE                  = 'J'
*   LINK_FOLDER_ID                   = ' '
*   SEND_REQUEST_OID                 = ' '
*   IP_ENCRYPT                       = 'U'
*   IP_SIGN                          = 'U'
*   IP_REC_COUNT_ADD                 =
* IMPORTING
*   OBJECT_ID_NEW                    =
*   SENT_TO_ALL                      =
*   ALL_BINDING_DONE                 =
*   OFFICE_OBJECT_KEY                =
*   ORIGINATOR_ID                    =
*   E_SEND_REQUEST_OID               =
TABLES
   objcont                          = li_ali
*   OBJHEAD                          =
*   OBJPARA                          =
*   OBJPARB                          =
   receivers                        = li_receivers
*   PACKING_LIST                     =
*   ATT_CONT                         =
*   ATT_HEAD                         =
*   NOTE_TEXT                        =
*   LINK_LIST                        =
*   APPLICATION_OBJECT               =
 EXCEPTIONS
   active_user_not_exist            = 1
   communication_failure            = 2
   component_not_available          = 3
   folder_not_exist                 = 4
   folder_no_authorization          = 5
   forwarder_not_exist              = 6
   note_not_exist                   = 7
   object_not_exist                 = 8
   object_not_sent                  = 9
   object_no_authorization          = 10
   object_type_not_exist            = 11
   operation_no_authorization       = 12
   owner_not_exist                  = 13
   parameter_error                  = 14
   substitute_not_active            = 15
   substitute_not_defined           = 16
   system_failure                   = 17
   too_much_receivers               = 18
   user_not_exist                   = 19
   originator_not_exist             = 20
   x_error                          = 21
   OTHERS                           = 22.

IF sy-subrc IS INITIAL.
  MESSAGE 'Mail has been sent successfully' TYPE 'S'.
ELSE.
  MESSAGE 'Error occured while sending the mail' TYPE 'S'.
ENDIF.

  • No labels