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:

  1.   SELECT SINGLE archiv_id 
  2.          FROM toaom 
  3.          INTO lv_arc_id 
  4.          WHERE sap_object = lc_objtype AND 
  5.                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.

  1.         CALL FUNCTION ‘ARCHIV_GET_CONNECTIONS’ 
  2.           EXPORTING 
  3.             objecttype    = lc_objtype 
  4.             object_id     = lv_obect_id 
  5.             client        = sy-mandt 
  6.             archiv_id     = lv_arc_id 
  7.             until_ar_date = sy-datum 
  8.           IMPORTING 
  9.             count         = lv_count 
  10.           TABLES 
  11.             connections   = lit_connections 
  12.           EXCEPTIONS 
  13.             nothing_found = 1 
  14.             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:

  1.   LOOP AT lit_connections ASSIGNING <lfs_connections>. 
  2.             IF <lfs_connections> IS ASSIGNED. 
  3.               lv_doctype = <lfs_connections>-reserve. 
  4. * Get the Content of each entry from GOS Archive attachment) 
  5.               CALL FUNCTION ‘ARCHIVOBJECT_GET_BYTES’ 
  6.                 EXPORTING 
  7.                   archiv_id                = <lfs_connections>-archiv_id 
  8.                   archiv_doc_id            = <lfs_connections>-arc_doc_id 
  9.                   document_type            = lv_doctype 
  10.                   length                   = lv_length 
  11.                   offset                   = lv_offset 
  12.                 IMPORTING 
  13.                   binlength                = lv_length 
  14.                 TABLES 
  15.                   binarchivobject          = lit_data 
  16.                 EXCEPTIONS 
  17.                   error_archiv             = 1 
  18.                   error_communicationtable = 2 
  19.                   error_kernel             = 3 
  20.                   OTHERS                   = 4. 
  21.               IF sy-subrc EQ space
  22.                 TRY . 
  23.                     CALL METHOD cl_rmps_general_functions=>convert_1024_to_255 
  24.                       EXPORTING 
  25.                         im_tab_1024 = lit_data[] 
  26.                       RECEIVING 
  27.                         re_tab_255  = lit_bdata[]. 
  28.                   CATCH cx_bcs INTO lref_bcs. 
  29.                     MESSAGE i022(zw2c) WITH lref_bcs->error_type. 
  30.                 ENDTRY. 
  31.                 CLEAR: lv_len,lv_len1. 
  32. ***change done by Janagar (For file name Note:        1451769) 
  33.                 READ TABLE lit_att_desc INTO lwa_att_desc WITH KEY arc_doc_id = <lfs_connections>-arc_doc_id 
  34.                  BINARY SEARCH. 
  35.                 IF sy-subrc = 0. 
  36.                   lv_att = lwa_att_desc-filename. 
  37.                 ENDIF. 
  38. ***end of change done by Janagar (for file name Note: 1451769) 
  39.                 DESCRIBE TABLE lit_bdata  LINES lv_len . 
  40.                 lv_len = lv_len * 2 * 255. 
  41.                 lv_len1 = lv_len. 
  42.                 lref_document = cl_document_bcs=>create_document( 
  43.                                 i_type    = lc_a_type “lc_i_type “ changed by janagar 
  44. ****added by janagar 
  45.                                 i_length = lv_len1 
  46.                                 i_hex = lit_bdata[] 
  47. ****end of addition by janagar 
  48.                                 i_subject = lv_att ). 
  49.                 APPEND lref_document TO lit_attachments. 
  50.               ENDIF. 
  51.             ENDIF. 
  52.           ENDLOOP. 
  53.           UNASSIGN <lfs_connections>. 
  54.           CALL METHOD lref_send_request->set_document( lref_document ). 
  55.         ENDIF. 
  56.         IF i_link = abap_true. 
  57.           lwa_object = i_object. 
  58.         ENDIF. 
  59. *     Sender infor 
  60.         lref_sender = cl_cam_address_bcs=>create_internet_address( 
  61.                   i_sender ). 
  62.         lref_send_request->set_sender( lref_sender ). 
  63.         IF i_t_emails[] IS NOT INITIAL. 
  64.           LOOP AT i_t_emails ASSIGNING <lfs_emails>. 
  65.             IF <lfs_emails> IS ASSIGNED. 
  66.               lv_mail = <lfs_emails>-smtp_addr. 
  67.               lref_rec = cl_cam_address_bcs=>create_internet_address( lv_mail ). 
  68.               lwa_recipients-recipient = lref_rec. 
  69.               APPEND  lwa_recipients TO lit_recipients. 
  70.             ENDIF. 
  71.           ENDLOOP. 
  72.           UNASSIGN <lfs_emails>. 
  73.         ENDIF. 
  74.         lref_send_request = cl_bcs=>short_message( 
  75.             i_subject       = i_subject 
  76.             i_text          = i_t_note 
  77.             i_recipients    = lit_recipients 
  78.             i_sender        = lref_sender 
  79.             i_attachments   = lit_attachments 
  80. *          i_appl_object   = lwa_object 
  81.             i_starting_at_x = 2 
  82.             i_starting_at_y = 1 ). 
  83.         COMMIT WORK AND WAIT. 
  84.         e_send_request = lref_send_request->oid( ). 
  85.       CATCH cx_bcs INTO lref_bcs. 
  86.         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 usingTEXT_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
short_msg_screenshot.PNGshort_msg_atta_screenshot.PNGNow 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.PNGFor 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.

  1. * Convert RTF to RAW 
  2.       CALL FUNCTION ‘SO_RTF_TO_RAW’ 
  3.       EXPORTING 
  4.         line_size   = 80 
  5.       TABLES 
  6.         objcont_old = objcont 
  7.         objcont_new = objcont. 

b) add html tags to the existing content.

  1. *Adding line break. 
  2.       LOOP AT objcont ASSIGNING <lfs_objcont>. 
  3.         CONCATENATE <lfs_objcont>-LINE ‘<br/>’ INTO <lfs_objcont>-LINE SEPARATED BY space
  4.       ENDLOOP. 
  5. Add Font and html tag at the start of the code 
  6.       objcont-LINE = ‘<html><body> <basefont face=”Arial” size=”2″>’
  7.       INSERT objcont INTO objcont INDEX 1. 
  8. *Add the image or company logo at the end of end of the mail , just add the following Tag 
  9. * Add Image 
  10.       cl_mime_repository_api=>get_api( )->get( 
  11.       EXPORTING i_url = `/SAP/PUBLIC/xxx.jpg` 
  12.       IMPORTING e_content = lv_current ). 
  13. **** 
  14. Add end tag to HTML. 
  15.       objcont-LINE = ‘</body></html>’
  16.       APPEND objcont. 

  1. *Convert XString data to Itab 
  2.       WHILE lv_current IS NOT INITIAL. 
  3.         lwa_hex-LINE = lv_current. 
  4.         APPEND lwa_hex TO lit_hex1. 
  5.         SHIFT lv_current LEFT BY 255 PLACES IN BYTE MODE. 
  6.       ENDWHILE. 
  7.       DESCRIBE TABLE lit_hex1 LINES lv_img1_size. 
  8.       lv_img1_size = lv_img1_size * 255. 
  9. *  Attach HTML Data to Mail 
  10.       lr_email_body = cl_document_bcs=>create_document( 
  11.       i_type = ‘HTM’ 
  12.       i_text = lit_data 
  13.       i_subject = lv_subject ). 
  14.       lv_object_id-objtp = objects-objtp. 
  15.       lv_object_id-objyr = objects-objyr. 
  16.       lv_object_id-objno = objects-objno. 
  17.       . 
  18.       lv_attachment = cl_document_bcs=>getu_instance_by_key( i_sood_key = lv_object_id ). 
  19. ***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. 
  20.       CALL METHOD lv_attachment->if_document_bcs~get_body_part_count 
  21.       RECEIVING 
  22.       re_count = lv_count 
  23.       . 
  24.       lv_count = lv_count – 1. 
  25.       DO lv_count TIMES. 
  26.         lv_count1 = sy-INDEX + 1. 
  27.         CALL METHOD lv_attachment->if_document_bcs~get_body_part_attributes 
  28.         EXPORTING 
  29.           im_part       = lv_count1 
  30.           receiving 
  31.           re_attributes = lv_attrib. 
  32.         . 
  33.         lv_atta_size = lv_attrib-filename. 
  34.         CALL METHOD lv_attachment->if_document_bcs~get_body_part_content 
  35.         EXPORTING 
  36.           im_part        = lv_count1 
  37.           receiving 
  38.           re_content     = ls_comment. 
  39.         DESCRIBE TABLE ls_comment-cont_hex LINES lv_lines. 
  40.         lit_att_size = lv_lines * sy-tleng . 
  41.         lr_email_body->add_attachment( 
  42.         EXPORTING 
  43.           i_attachment_type    = ‘jpg’ 
  44.           i_attachment_subject = lv_atta_size 
  45.           i_attachment_size    = lit_att_size 
  46.           i_att_content_hex    = ls_comment-cont_hex ). 
  47.       ENDDO. 
  48. *Attach Image to Mail 
  49.       lr_email_body->add_attachment( 
  50.       EXPORTING 
  51.         i_attachment_type     =  ‘jpg’                  ” DOCUMENT CLASS FOR ATTACHMENT 
  52.         i_attachment_subject  =  ‘img1’                ” ATTACHMENT TITLE 
  53.         i_attachment_size     =  lv_img1_size           ” SIZE OF DOCUMENT CONTENT 
  54.         i_att_content_hex     =  lit_hex1 ). 
  55.       . 
  56.       lv_email = cl_bcs=>create_persistent( ). 
  57.       lv_email->set_document( lr_email_body ). 
  58. Add Receivers 
  59.       LOOP AT rec_tab. 
  60.         IF rec_tab-adr_name IS NOT INITIAL. 
  61.           lv_mail_address = rec_tab-adr_name. 
  62.           lv_receiver = cl_cam_address_bcs=>create_internet_address( lv_mail_address ). 
  63.           lv_email->add_recipient( i_recipient = lv_receiver ). 
  64.         ENDIF. 
  65.         CLEAR: rec_tab. 
  66.       ENDLOOP. 
  67. Add Sender 
  68.       lref_sender = cl_cam_address_bcs=>create_internet_address( ‘donotreply@XXXX.co.uk ). 
  69.       lv_email->set_sender( i_sender = lref_sender ). 
  70.       lv_email->set_send_immediately( ‘X’ ).  “SEND EMAIL DIRECTLY 
  71. *Send 
  72.       lv_email->send( i_with_error_screen = ‘X’ ). 
  73.       IF sy-subrc = 0. 
  74. * Commit Work 
  75. This part is to commit HTML mail and interupt the actual text mail 
  76.         COMMIT WORK
  77.         MESSAGE S001(00) WITH ‘Message Sent Successfully’
  78.         LEAVE TO SCREEN 0. 
  79.       ENDIF. 
  80.     ENDIF. 

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.

Be the first to leave a comment

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

Leave a Reply