Skip to Content

The present e-mail is a complement of other blogs we have written about SAP ChaRM with Workflow and Notifications, like http://scn.sap.com/community/it-management/alm/solution-manager/blog/2014/01/21/sap-crmsolman-charm-multiple-target-agents-via-sap-workflow–minimal-abap-development

As incentive, you will be using the latest available SAP classes to deliver e-mails:  CL_BCS and CL_DOCUMENT_BCS.  They even replaced the already known function modules SO_*DOCUMENT* and SO_OBJECT_SEND.  That will make happy your manager and will add a line to your resume. 😉

Unavoidable Reality: 

Once you implement SAP Workflow with ChaRM, it could turn into an avalanche with people asking you all sorts of new features they want.

One of the first ones we got was “Would it be possible that the if a user gets an e-mail, other people in the HR Org Structure get copied that same e-mail in case the person to whom is directed the e-mail is not in the office and any of the other individuals is acting  in her/his absence?”  Not even a thank you, you guys did a good job, but just a quick breath after our go live, having to go back to the board to do some thinking  … again.   😥

The answer is simple.  Yes, it is possible, but the SAP Workflow Step e-mail delivered by SAP does not have the capability of sending Carbon Copies of Blind Carbon Copies.  For that you have to use a standard activity and use a method that will call delivered classes provided by SAP, that do the work for you.

Before we start, notice there is some material related in SAP Workflow on how to resolve this, but we are just adding our experience over here for the ChaRM user community, to still show that as long as you can develop some basic ABAP code, and you are willing to, you can do it yourself.

Let’s begin.

Our initial scenario:  We have a WF that has to e-mail steps.  Let’s take a look at one of them.

SWDD_30.gif

As you can see below, we are passing the list of e-mail accounts (one or several) in the container variable MANAGEREMAIL.

SWDD_31.gif

The variable looks like below and in the properties tab you could define it as multiline or not, depending whether you are passing one or various values.

SWDD_32.gif

Note:  The location of the e-mail addresses for user accounts and business partners is table ADR6.  The link below shows the diagram with the path to get to that table from the ChaRM stand point.

http://scn.sap.com/community/it-management/alm/solution-manager/blog/2014/01/20/sap-charm-basic-business-transaction-table-storage-diagram

With the current scenario you may provide a list of e-mail addresses, but each individual will be in the To:, field of an e-mail and not option for somebody getting there as CC or BCC of the e-mail, with this type of WF step called E-Mail.

So, what is the solution?

Instead of using the e-mail step, create a standard task, which is to call a method, to be created by you, in which you define receive some parameters from the WF, including the list of e-mail addresses, and then step by step you define the e-mail subject, the body of the e-mail (content),who is it going to, who is getting CC or BCC, and finally you deliver that e-mail.

Our new scenario:

SWDD_33.gif

Let’s take a look at the first Activity that handles the new approach for the e-mail.

SWDD_34.gif

As you see, we call a method.

SWDD_35.gif

Below, some of the code in the method that is relevant for this blog.

begin_method zch_email_when_urgent_rfc changing container.

* Place all your variables here.   Weshow some variables that are relevant for this excercise.

* E-mail related variables to SAP classes CL_BCS and CL_DOCUMENT_BCS:

DATA:

    lv_send_request     TYPE REF TO cl_bcs, ” Send request
     lv_subject             
TYPE so_obj_des, ” E-Mail Subject
     lv_body                 
TYPE bcsy_text, ” Mail body
     lv_message          
TYPE bcsy_text, ” Atchmnt for success
     wa_text               
TYPE soli, ” Work area for attach
     lv_document         
TYPE REF TO cl_document_bcs, ” Mail body
     lv_sender              
TYPE REF TO if_sender_bcs, ” Sender address
     lv_recipient           
TYPE REF TO if_recipient_bcs, ” Recipient
     lv_size                 
TYPE soodobjlen, ” Size of Attachment
     lv_lines                
TYPE i, ” Lines count
     lv_email               
TYPE ad_smtpadr, ” Email ID
     lv_address           
TYPE bcsy_resv,
     wa_address          
TYPE bcss_resv,
     lv_extension          
TYPE soodkobjtp VALUE ‘RAW’. ” TXT format

* Other variables.

DATA:

      lv_rfcnumber           TYPE crmd_orderadm_hobject_id, ” RfC number

     lv_rfcreqname           TYPE crmt_partner_no, ” Requester BP

      lt_manageremail      TYPE adr6smtp_addr OCCURS 0, ” List of e-mails from managers.
     lv_manageremail_wa
TYPE adr6smtp_addr, ” work area for internal table.

     lt_teamleademail      TYPE adr6smtp_addr OCCURS 0, ” Team Lead only e-mail address. ” NEW
     lv_teamleademail_wa
TYPE adr6smtp_addr. ” work area for internal table. ” NEW

*  The retrieval of the values from the container into the variables should go here …

* Now the e-mail subject.

CONCATENATE ‘Urgent RfC ‘ lv_rfcnumber ‘ requires Manager approval.’ INTO lv_subject.

* preparation of the e-mail body.  Here is where you do the carving of your e-mail.  Nothing really fancy at this moment, only passing of some variables.

wa_textline+0 = ‘The following Urgent RfC requires your approval’.

* you need to append line by line to lv_body
APPEND wa_text TO lv_body.

* a blank line … yeah!!! even that 😥
APPEND space TO lv_body.

* and some example of the rest of the lines in the e-mail.
CLEAR : wa_text.
wa_text
line+0 = ‘Urgent Criteria ‘.
wa_text
line+38 = ‘:’.
wa_text
line+40 = lv_rfcemergencycriteria.
APPEND wa_text TO lv_body.
CLEAR : wa_text.
wa_text
line+0 = ‘RfC Number ‘.
wa_text
line+38 = ‘:’.
wa_text
line+40 = lv_rfcnumber.
APPEND wa_text TO lv_body.
CLEAR : wa_text.
wa_text
line+0 = ‘Requester ‘.
wa_text
line+41 = ‘:’.
wa_text
line+43 = lv_rfcreqname.
APPEND wa_text TO lv_body.

wa_textline+0 = ‘Regards,’.
APPEND wa_text TO lv_body.
APPEND space TO lv_body.
APPEND space TO lv_body.
CLEAR : wa_text.
wa_text
line+0 = ‘Change Management Team.’.
APPEND wa_text TO lv_body.
CLEAR : wa_text.

* Once you complete the e-mail body, it is time to tell the system this is an e-mail.    FYI, we did not invent anything below.  We just replaced with our variables in what is the standard set of steps to create e-mails using classes CL_BCS and CL_DOCUMENT_BCS.


*create a persistent send request.   First instruction to define from now on we are on e-mail mode.
lv_send_request
= cl_bcs=>create_persistent( ).

*create document for mail body   As you see, we pass the subject and the e-mail body.
lv_document
= cl_document_bcs=>create_document(
i_type
= ‘RAW’
i_subject
= lv_subject “Mail subject
i_text
= lv_body ). ” Mail body

*add the document to send request.   This is also standard.
CALL METHOD lv_send_request->set_document( lv_document ).

*sender address … you (sy-uname) or usually user WF-BATCH.
lv_sender
= cl_sapuser_bcs=>create( syuname ).
CALL METHOD lv_send_request->set_sender
EXPORTING
i_sender
= lv_sender.

* Now, the list of recipients.   As we have them in a table, we have to pass one by one in a loop.
LOOP AT lt_manageremail INTO lv_manageremail_wa.
     lv_email = lv_manageremail_wa.
     lv_recipient
= cl_cam_address_bcs=>create_internet_address( lv_email ).

     CALL METHOD lv_send_request->add_recipient
          EXPORTING
               i_recipient
= lv_recipient
               i_express
= ‘X’
               i_copy
= ‘ ‘
               i_blind_copy
= ‘ ‘
               i_no_forward
= ‘ ‘.

ENDLOOP.

* Now, the list of CCs.   As we have them in another table, we have to pass one by one in a loop.

* I know, I know.  We could have passed them in the same table with an additional field to tell the difference

* whether the record is arecipient, CC or BCC.  Sorry for being lazy!!

* We count the lines first, as it may be possible our HR evaluation path may have not found any records.
DESCRIBE TABLE lt_teamleademail. ” NEW
IF sytfill > 0.

     LOOP AT lt_teamleademail INTO lv_teamleademail_wa. ” NEW
          lv_email
= lv_teamleademail_wa. ” NEW
          lv_recipient
= cl_cam_address_bcs=>create_internet_address( lv_email ).

          CALL METHOD lv_send_request->add_recipient
               EXPORTING
                    i_recipient
= lv_recipient
                    i_express
= ‘X’
                    i_copy
= ‘X’
                    i_blind_copy
= ‘ ‘
                    i_no_forward
= ‘ ‘.
     ENDLOOP.
ENDIF.

* Once all is completed, we deliver the e-mail imimmediately, which even bypassing SOST/SCOT delays.
lv_send_request
->set_send_immediately( ‘X’ ).

* send mail
CALL METHOD lv_send_request->send( ).

COMMIT WORK.

end_method

That is all colleagues.   For specific details about all you can do in the e-mail, fancy fonts, attach documents, etc., please follow the link below.  Thanks for that to Sri Hari Anand Kumar.

http://scn.sap.com/docs/DOC-10328

Regards,

Juan

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply