Original requirement:

Requirement is to retrieve the all the files attached in Content repository though GOS for a particular document and pull formatted text from SO10 and attach those attachments retrieved from Archiving and send it as a HTML mail , but before sending mail the client can modify the content , add the receivers whoever needs the mail and also they can able to edit the attachments (ie., delete or add whichever they need) .

Background to the issue:

Recently we had a requirement , where the client wants to edit the content of the mail being sent and modify the attachments as they need on the go and send that mail in HTML mail format.

The following are the difficulties.

1. How to retrieve the contents from Archieve server(ie., Sharepoint /SAP content repository)?

2. How to enable the user to edit the attachments and edit the body of the mail on the go?

3. The last challenge is emerged from the solution given from the step 2 (No other go we found in the short time , may be you viewers should able to provide it).

Despite of these challenges we faced some other issues , that i’ll be explain as and when we move through the blog.

Detailed steps:

1. How to get the content repository archieve id:

  SELECT SINGLE archiv_id
         FROM toaom
         INTO lv_arc_id
         WHERE sap_object = lc_objtype AND
               ar_object = lc_object.

2.How to retrieve the list of documents attached under a particular document

There are many blogs which says how to retrieve the normal attachments from GOS. But there are only one or two blog which i found for retriving the archieved document(Stored in Sharepoint (Via Gimmal setup) / SAP content repository.

            objecttype    = lc_objtype
            object_id     = lv_obect_id
            client        = sy-mandt
            archiv_id     = lv_arc_id
            until_ar_date = sy-datum
            count         = lv_count
            connections   = lit_connections
            nothing_found = 1
            OTHERS        = 2.

The above code helps in retrieving the all the document details attached to GOS ( attachments through store business document)

3. How to Read the description of the Archived attachment:

Normally for Archive objects , we wont be able to track the actual name  of the object and to enable this specific note 1451769 has to be implemented.

It has to be queried from the table TOAAT table by passing the ARC_DOC_ID obtained from LIT_CONNECTION Table.

4.To read the individual attachment and move to Dynamic screen where the user can able to edit the attachements and edit the body of the mail:

  LOOP AT lit_connections ASSIGNING <lfs_connections>.
            IF <lfs_connections> IS ASSIGNED.
              lv_doctype = <lfs_connections>-reserve.
* Get the Content of each entry from GOS Archive attachment)
                  archiv_id                = <lfs_connections>-archiv_id
                  archiv_doc_id            = <lfs_connections>-arc_doc_id
                  document_type            = lv_doctype
                  length                   = lv_length
                  offset                   = lv_offset
                  binlength                = lv_length
                  binarchivobject          = lit_data
                  error_archiv             = 1
                  error_communicationtable = 2
                  error_kernel             = 3
                  OTHERS                   = 4.
              IF sy-subrc EQ space.
                TRY .
                    CALL METHOD cl_rmps_general_functions=>convert_1024_to_255
                        im_tab_1024 = lit_data[]
                        re_tab_255  = lit_bdata[].
                  CATCH cx_bcs INTO lref_bcs.
                    MESSAGE i022(zw2c) WITH lref_bcs->error_type.
                CLEAR: lv_len,lv_len1.
***change done by Janagar (For file name Note:        1451769)
                READ TABLE lit_att_desc INTO lwa_att_desc WITH KEY arc_doc_id = <lfs_connections>-arc_doc_id
                 BINARY SEARCH.
                IF sy-subrc = 0.
                  lv_att = lwa_att_desc-filename.
***end of change done by Janagar (for file name Note: 1451769)
                DESCRIBE TABLE lit_bdata  LINES lv_len .
                lv_len = lv_len * 2 * 255.
                lv_len1 = lv_len.
                lref_document = cl_document_bcs=>create_document(
                                i_type    = lc_a_type "lc_i_type " changed by janagar
****added by janagar
                                i_length = lv_len1
                                i_hex = lit_bdata[]
****end of addition by janagar
                                i_subject = lv_att ).
                APPEND lref_document TO lit_attachments.
          UNASSIGN <lfs_connections>.
          CALL METHOD lref_send_request->set_document( lref_document ).
        IF i_link = abap_true.
          lwa_object = i_object.
*     Sender infor
        lref_sender = cl_cam_address_bcs=>create_internet_address(
                  i_sender ).
        lref_send_request->set_sender( lref_sender ).
        IF i_t_emails[] IS NOT INITIAL.
          LOOP AT i_t_emails ASSIGNING <lfs_emails>.
            IF <lfs_emails> IS ASSIGNED.
              lv_mail = <lfs_emails>-smtp_addr.
              lref_rec = cl_cam_address_bcs=>create_internet_address( lv_mail ).
              lwa_recipients-recipient = lref_rec.
              APPEND  lwa_recipients TO lit_recipients.
          UNASSIGN <lfs_emails>.
        lref_send_request = cl_bcs=>short_message(
            i_subject       = i_subject
            i_text          = i_t_note
            i_recipients    = lit_recipients
            i_sender        = lref_sender
            i_attachments   = lit_attachments
*          i_appl_object   = lwa_object
            i_starting_at_x = 2
            i_starting_at_y = 1 ).
        e_send_request = lref_send_request->oid( ).
      CATCH cx_bcs INTO lref_bcs.
        MESSAGE i022(zw2c) WITH lref_bcs->error_type.

I_T_NOTE is been populated by retriveing the text dynamically from the Standard text and replace the variables in the standard text by using

TEXT_SYMBOL_REPLACE function module.

Now we have done everything we want and now the main challenge here is how to read the modified content and attachment done by the user.

I have debugged and managed to get the enhancement place , where i can get the attachments dynamically.

When we call the short message there will a FM called SO_DYNP_OBJECT_SEND , this will enable the popup to populate the values and edit the attachments dynamically and also convert the Text contents to HTML contents. The original popup out of this code will be like below



Now the attachments here are visible as BIN because if i keep it as JPG , when the user double clicks on the attachments it gives the error and now in binary mode if the user prompts save it to JPG as in our case it is only JPG attached to the GOS content repository.

Now the following archive document has to be sent as mail.

GOS screen shot.PNG

For converting the above contents to html the following enhancement has to be created. create an implicit enhancement at the end of SO_DYNP_OBJECT_SEND function module and following steps has to be followed.

a) Convert the text format internally , OBJCONT has the body of the text container.

* Convert RTF to RAW
        line_size   = 80
        objcont_old = objcont
        objcont_new = objcont.

b) add html tags to the existing content.

*Adding line break.
      LOOP AT objcont ASSIGNING <lfs_objcont>.
        CONCATENATE <lfs_objcont>-LINE '<br/>' INTO <lfs_objcont>-LINE SEPARATED BY space.
*  Add Font and html tag at the start of the code
      objcont-LINE = '<html><body> <basefont face="Arial" size="2">'.
      INSERT objcont INTO objcont INDEX 1.
*Add the image or company logo at the end of end of the mail , just add the following Tag
* Add Image
      cl_mime_repository_api=>get_api( )->get(
      EXPORTING i_url = `/SAP/PUBLIC/xxx.jpg`
      IMPORTING e_content = lv_current ).
Add end tag to HTML.
      objcont-LINE = '</body></html>'.
      APPEND objcont.

*Convert XString data to Itab
      WHILE lv_current IS NOT INITIAL.
        lwa_hex-LINE = lv_current.
        APPEND lwa_hex TO lit_hex1.
        SHIFT lv_current LEFT BY 255 PLACES IN BYTE MODE.
      DESCRIBE TABLE lit_hex1 LINES lv_img1_size.
      lv_img1_size = lv_img1_size * 255.
*  Attach HTML Data to Mail
      lr_email_body = cl_document_bcs=>create_document(
      i_type = 'HTM'
      i_text = lit_data
      i_subject = lv_subject ).
      lv_object_id-objtp = objects-objtp.
      lv_object_id-objyr = objects-objyr.
      lv_object_id-objno = objects-objno.
      lv_attachment = cl_document_bcs=>getu_instance_by_key( i_sood_key = lv_object_id ).
***while doing the above step , there would be a text file which has contents from the text container also passed as an attachment along with the image and to segregate this we have to use the below logic.
      CALL METHOD lv_attachment->if_document_bcs~get_body_part_count
      re_count = lv_count
      lv_count = lv_count - 1.
      DO lv_count TIMES.
        lv_count1 = sy-INDEX + 1.
        CALL METHOD lv_attachment->if_document_bcs~get_body_part_attributes
          im_part       = lv_count1
          re_attributes = lv_attrib.
        lv_atta_size = lv_attrib-filename.
        CALL METHOD lv_attachment->if_document_bcs~get_body_part_content
          im_part        = lv_count1
          re_content     = ls_comment.
        DESCRIBE TABLE ls_comment-cont_hex LINES lv_lines.
        lit_att_size = lv_lines * sy-tleng .
          i_attachment_type    = 'jpg'
          i_attachment_subject = lv_atta_size
          i_attachment_size    = lit_att_size
          i_att_content_hex    = ls_comment-cont_hex ).
*Attach Image to Mail
        i_attachment_type     =  'jpg'                  " DOCUMENT CLASS FOR ATTACHMENT
        i_attachment_subject  =  'img1'                " ATTACHMENT TITLE
        i_attachment_size     =  lv_img1_size           " SIZE OF DOCUMENT CONTENT
        i_att_content_hex     =  lit_hex1 ).
      lv_email = cl_bcs=>create_persistent( ).
      lv_email->set_document( lr_email_body ).
*  Add Receivers
      LOOP AT rec_tab.
        IF rec_tab-adr_name IS NOT INITIAL.
          lv_mail_address = rec_tab-adr_name.
          lv_receiver = cl_cam_address_bcs=>create_internet_address( lv_mail_address ).
          lv_email->add_recipient( i_recipient = lv_receiver ).
        CLEAR: rec_tab.
*  Add Sender
      lref_sender = cl_cam_address_bcs=>create_internet_address( 'donotreply@XXXX.co.uk' ).
      lv_email->set_sender( i_sender = lref_sender ).
      lv_email->set_send_immediately( 'X' ).  "SEND EMAIL DIRECTLY
      lv_email->send( i_with_error_screen = 'X' ).
      IF sy-subrc = 0.
* Commit Work
This part is to commit HTML mail and interupt the actual text mail
        COMMIT WORK.
        MESSAGE S001(00) WITH 'Message Sent Successfully'.
        LEAVE TO SCREEN 0.

The mail looks like this.

Actual mail screen shot.PNG

Thanks for going through the blog and provide your feedback or suggestions below as this is my first blog.

To report this post you need to login first.


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

Leave a Reply