Header Ads

Attachment to Business Partner or Product in CRM

Great blog by Bhanu chander .
This Blog is a step by step tutorial for attaching documents to a Business Partner and Product in CRM using ABAP from Application Server.

Business Partner is a Person, Organizations and Group to which we have a Business Relationship. A Business Partner can be for example An Account, Prospect, Vendor or Competitor. Account can be subdivided into Person (a private person), Organization (Part of a legal person or legal person), and Group (Partner Group).

SAP CRM provides creation of Product in Product Master. Product Master can be defined with different Product Types. Product types are as follows Material, Service, Financing, and Warranty.

The Objective is to automate the process of attaching additional document to a Business Partner or Product document tab.

Business partner:
1.jpg

CRM Web UI of Business Partner
2.jpg

Product:
3.jpg
CRM Web UI of Product
4.jpg

Procedure for Attachment Uploading in CRM:
The step by step process involved in uploading attachment to Business Partner or Product from Application Layer automatically (with the help of a program) is as follows.

  1. File that needs to be attachment to Business Partner or Product is available on Application server (AL11).
  2. The file can be place on Application server with the help of a Basis team, or a utility program can be developed to place files on Application server.
    E.g.: Files on Application Server
5.JPG
3.    Once the files to be uploaded are available on Application server, we need to fetch the file details as follows.
4.    Read the File from application server into internal table one at a time in binary format. As file in Binary format support multiple formats of attachments.
5.    Reading File from Application server as follows
            a.  OPEN DATASET lv_file FOR INPUT MESSAGE lv_msg IN LEGACY BINARY MODE. 
                    lv_file is the absolute file path on Application Server
        lv_msg if any error occurs in opening file, the corresponding error message is assigned for the reference.
b.  Move the data read into internal table of type binary format i.e. SDOKCNTBIN along with the size of the file, e.g.: i_text[].
6.    Attaching File
a.    In order to attach documents from Application Server to an existing Business partner or Product one of the mostly used
       class is CL_CRM_DOCUMENTS (KW Explorer in CRM).
b.    This class have various build in methods for document attachment, method CREATE_WITH_TABLE (Create a Document (Content in Table)) is used in this procedure.

C.  The basic parameters used in this method CREATE_WITH_TABLE are shown below
6.jpg
Of all the parameters listed, we are concerned about few parameters like BUSINESS_OBJECT, PROPERTIES, FILE_ACCESS_INFO, FILE_CONTENT_BINARY, and RAW_MODE.

à EXPORTING.

i.        BUSINESS_OBJECT: Local Persistent Object Reference - BOR-Compatible, following attribute are to be considered.
1.    INSTID: Instance Identification in BOR Compatibility, Persistent Object Reference. Pass the Business partner GUID or Product GUID for which Account or the Product the attachment need to be maintained. Business Partner GUID can be found in table BUT000 and Product GUID in COMM_PRODUCT.

2.    TYPEID: Type of Objects in Persistent Object References. Object reference are present in table TOJTB.
7.jpg
TYPEID = TOJTB-NAME, w.r.t Business Partner and Product.
3.    CATID: Category of Objects in Persistent Object References, as Business partner and Product are Business Objects.
CATID = ‘BO’ (BO = BO Instances of BOR Object Types).

ii.        PROPERTIRES: SDOK: Object attribute, name and feature. It has following attributes.

1.    NAME: It represents Attribute of a document or a relationship.
2.    VALUE: Attribute Value.
The above two parameters have a combination of 3 values to be passed w.r.t NAME and VALUE i.e.
8.jpg
  • Unique Name with in a folder
NAME = ‘KW_RELATIVE_URL’.
VALUE = File Name for the attachment.                E.g.: EXCEL.xlsx

  • Short Description
NAME = ‘DESCRIPTION’.
VALUE = File description text.                            E.g.: Excel file

  • Language
Name = ‘LANGUAGE’.
    VALUE = Language in which the attachment is loaded.    E.g.: ‘EN’.
iii.        FILE_ACCESS_INFO : File Access Information properties has following attributes
9.jpg
  • File Size: Size of the file which have to be attached, point 5.b.
  • Binary flag: As the file is read in Binary format.
  • First line: Stating the line number in the internal table to be read.
  • File Name: Absolute file path of the attachment from application server.
  • Mime type: Internal representation of File format/extension which the file need to be read. MIME types are available in table SDOKMIME (MIME content type for file name enhancement).
  • Property: Extension of the file.
                        e.g.: The properties of the attachment are saved as
                        10.jpg
iv.        FILE_CONTENT_BINARY: File contents of internal table saved as per    point 5.
v.        RAW_MODE: Indicating that file is Raw Data. (pass value  ‘X’)


à  IMPORTING
i.        The Importing parameter are as follows: LOIO, PHIO, and ERROR.
  • LOIO: A unique Logical Document number is generated for attachment.
                        E.g.:
                              11.jpg
  • PHIO: A unique Physical Document number is generated for attachment.
                        E.g.:
                              12.jpg
  • ERROR: Any error while attaching Document are assigned.

This above process is common for Business Partner and Product, but product have Predefined folders were attachments are saved.
13.JPG
As we intend to place the attachment in DOCUMENTS->PICTURES->THUMBNAILS, so the class CL_CRM_DOCUMENTS has a method GET_INFO_FOR_FOLDER (Get Folders for BOR Objects/Attributes).
The various parameters used in this method are BUSINESS_OBJECT, PROPERTIES_RESULT, and FOLDERS.
à  EXPORTING
i.        BUSINESS_OBJECT: Local Persistent Object Reference - BOR-Compatible, it has following attributes
1.    INSTID: Instance Identification in BOR Compatibility, Persistent Object Reference. Pass the Product GUID for the product to which the attachment need to be uploaded, Product GUID can be found from table COMM_PRODUCT for the corresponding Product.
2.    TYPEID: Type of Objects in Persistent Object References. Object reference are present in table TOJTB.   
TYPEID = TOJTB-NAME, Product.
14.JPG
3.    CATID: Category of Objects in Persistent Object References, Product as Business Objects. 
CATID = ‘BO’ (BO = BO Instances of BOR Object Types).

à  IMPORTING
i.          PROPERTIES_RESULT: The predefined folder details are fetched. Now read the folder in which we want to attach the files.
                    E.g.: As we are trying to place files to THUMBNAILS folder, read the NAME and VALUE attributes.
Read PROPERTIES_RESULT where NAME = 'KW_RELATIVE_URL' and          VALUE = 'THUMBNAILS' and get OBJTYPE, CLASS, and OBJID fill this values into internal table LS_FOLDER type SKWF_IO.
ii.      FOLDERS: Table with folders.
Once the Folder details are fetched, pass above details to Class CL_CRM_DOCUMENTS, the method CREATE_WITH_TABLE with necessary parameters.

Pseudo Code:
Sample pseudo code and usage of class CL_CRM_DOCUMENTS and methods used for create attachment in Document tab of Business partner or Product.
Pseudo Code  (file1)

With the above code we can attachment multiple attachments that are maintained either form Application server or Presentation server, this program main objective mass loading of attachment to Business Partner or Product automatically.
Example of attachments attached.
Excel 1 Test.xslx (file2)    Test PPT1.pptx (file3)
  1. After execution of the sample code, go to Transaction BP / COMMPR01 else CRM_UI.
  2. Check Business Partner Attachment in GUI T-CODE: BP or in WEB UI under ACCOUNT MANAGEMENT -> ACCOUNT passing Account ID (BP).
  3. Pass Account ID (BP) Number for which attachment are loaded.
    15.JPG
4.    Check the details of Account by clicking on the Name of the Account.
    16.JPG
5.    Check the Details of the Attachment by clicking on Name of the attachment.
17.JPG
E.g: Test PPT 1.pptx
18.JPG
Similarly other attachments can be viewed by double click on the link of the attachment.

6.    In order to check the attachment for Product GUI T-CODE: COMMPR01 or in Web UI as follows SALES OPERATIONS->PRODUCTS.
7.    Give the product ID for which attachment are loaded.
19.JPG
8.    Double click on Product ID to check details.
20.JPG
Click on Name of the attachment to open attachments.               
Eg: Excel 1 Text.xslx
21.JPG
Conclusion: This Document explains the procedure to attach multiple attachments from Application server to Business Partner or Products (Generally Mass Uploading of Attachments)



***********************************************************************
**   Data Declarations     **
***********************************************************************
DATA: li_bor               TYPE sibflporb,
      li_prop              TYPE sdokproptys,
      lwa_prop             TYPE sdokpropty,
      li_file_access_info  TYPE sdokfilacis,
      lwa_file_access_info TYPE sdokfilaci,
      lv_loio              TYPE skwf_io,
      lv_phio              TYPE skwf_io,
      lv_error             TYPE skwf_error,
      i_text             TYPE TABLE OF sdokcntbin,
      ls_folder       TYPE skwf_io,
      t_requ         TYPE crm_kw_propst,
      t_propvalue     TYPE TABLE OF sdokproptl,
      wa_propvalue   TYPE sdokproptl,
      wa_requ         TYPE crm_kw_props
      lv_folder       TYPE skwf_ios.
     

***********************************************************************
** Filling required fields     **
***********************************************************************
***Business Object
li_bor-typeid = 'BUS1006' (Business Partner)
'BUS1178' (Product)
        li_bor-catid  = 'BO'.
        li_bor-instid =  partner guid. (Business partner /Product)

***FileName
         lwa_prop-name  = 'KW_RELATIVE_URL'.
         lwa_prop-value = File Name.  (e.g.: EXCEL1.xlsx)
APPEND lwa_prop TO li_prop.

***Description
         lwa_prop-name  = 'DESCRIPTION'.
         lwa_prop-value = Attachment Description (e.g.: Excel).
         APPEND lwa_prop TO li_prop.

***Language
         lwa_prop-name  = 'LANGUAGE'.
         lwa_prop-value = sy-langu. (Language in which attachment is loaded)                          
         APPEND lwa_prop TO li_prop.

***Assign file properties
         CLEAR: lwa_file_access_info.
         lwa_file_access_info-file_size  = Size of attachment on Application server.
         lwa_file_access_info-binary_flg = 'X'.
         lwa_file_access_info-first_line = 1.
         lwa_file_access_info-file_name  = Absolute file path on Appication server.
         lwa_file_access_info-mimetype   = Internal File type extension
         lwa_file_access_info-property   = File Extension.
         APPEND lwa_file_access_info TO li_file_access_info.


***********************************************************************
**    Required for PRODUCT Attachment for FOLDER IDENTIFICATION      **
***********************************************************************

CALL METHOD cl_crm_documents=>get_info_for_folder
             EXPORTING
               business_object   = li_bor
** properties_request = query
*              properties_query  =
             IMPORTING
               properties_result = t_requ
               folders           = lv_folder.


           LOOP AT t_requ INTO wa_requ.
             t_propvalue[] = wa_requ-properties[].
             READ TABLE t_propvalue INTO wa_propvalue
               WITH KEY name = 'KW_RELATIVE_URL'
                       value = 'THUMBNAILS'.
             IF sy-subrc = 0.
               ls_folder-objtype = wa_requ-objtype.
               ls_folder-class   = wa_requ-class.
               ls_folder-objid   = wa_requ-objid.
               CONTINUE.
             ENDIF.
           ENDLOOP.


***********************************************************************
** Create Attachment in Document Tab     **
***********************************************************************
CALL METHOD cl_crm_documents=>create_with_table
           EXPORTING
             business_object     = li_bor
             properties          = li_prop
             file_access_info    = li_file_access_info
             file_content_binary = i_text[] "Binary file of Attachment from Application server
    parent_folder       = ls_folder     "Required for Product attachment
             raw_mode            = 'X'
           IMPORTING
             loio                = lv_loio
             phio                = lv_phio
             error               = lv_error.
Powered by Blogger.