Skip to end of metadata
Go to start of metadata

Applies to:

SAP CRM

Summary

This document illustrates the method to programmatically create IBASE(s) within SAP CRM, in a CRM Service Scenario.
Section 2 gives a summary of the requirements and the corresponding mapping of the same into SAP CRM.

However, the functional illustration is given only for understanding the basis behind the use of IBASE(s) within CRM to capture the billing. The document is only a technical document that explains the code which is used for creating IBASE(s), creating a hierarchy of IBASE (s) i.e. creating Individual Components, creating IBASE counters and IBASE Readings using an ABAP code.

The target audience for the document are SAP Technical Consultants, who work in CRM Service Scenarios, and use the IBASE technology for their systems. Knowledge of basic transactions and concept of IBASE for SAP CRM is required to understand the following document.

The document is technical in nature and illustrates:  

1.      Creation of IBASE programmatically.

2.      Creation of Individual Objects or Components.

3.      Creation of Hierarchy of IBASE(s).

4.      Creation of Counters.

5.      Creation of Readings.

 Please note all code mentioned in this document is to be used only as an example to be used in actual scenarios of development.

Author(s):  

   
Company:     IBM INDIA PRIVATE LIMITED
Created on:    18-AUG-2010
Author(s) Bio
Priyanka Bansal is an SAP CRM Advisory Consultant with IBM India Private Limited. She has 6 years of SAP experience, and has worked as techno-functional consultant in CRM domain across industries like Electronics, Banking and Professional Services.

Table of Contents

Summary of CRM Service Scenario
Technical Section
Create Installed Base (IBASE) in SAP CRM using ABAP
Create Components of IBASE in SAP CRM using ABAP
Create Counters for IBASE in SAP CRM using ABAP
Create/Change Readings for counters of IBASE in SAP CRM using ABAP

Summary of CRM Service Scenario

Client 'ABC' is a global client who sells Advertisement space on internet to customers. They have an e-portal where the customer can login, and configure his/her own advertisement.
Based on the configured advertisement (configured product), area of advertisement, size of advertisement and the time duration for the advertisement to be published, the invoice is to be generated for the customer 'XYZ'.
Following points illustrate how the above scenario is mapped within SAP CRM. The technical landscape of the client 'ABC' is on SOA architecture, whereby the SAP CRM system serves as a backend, a middleware system is used to call SAP services and publish them to the Portal, which serves as the front end for customer.
A) Products are to be made configurable within SAP CRM; hence the products of client 'ABC' are set up within SAP using Variant Configuration.
B) When the customer 'XYZ' configures his/her advertisement and adds it to the shopping basket, a quotation is created within SAP CRM programmatically.
C) When the quotation is saved; an IBASE is created within SAP CRM.
D) Different IBASE categories are used to define different product groupings.
E) IBASE hierarchy is used to represent the Advert Branch Classification i.e. it maps to every product that is added to the quotation.
F) Counters will be created for Pay-As-You-Go (PAYG) option.
G) Once the product in the shopping basket is checked out, an order will be created within SAP CRM. The corresponding quotation and the linked IBASE(s) will now be used. A reading will be associated with the IBASE. This reading will be incremented by 1, every time the customer's advertisement is published. Based on the reading, an invoice is generated for the customer using CRM Billing.

Technical Section:

Create Installed Base in SAP CRM using ABAP

CALL FUNCTION 'CRM_ICSS_CREATE_IBASE'
  EXPORTING
     i_ibase_type                 = <ibase category>
    i_extid                          = <quotation external reference number>
    i_descr                         = <Text object - CRM_ORDERI and text id - 1000>
*   I_ADDRESS_DATA   =
  i_partner                       = <Sold-to-party from quotation>
 IMPORTING
   e_ibib1                       = lv_ibib1
 EXCEPTIONS
   data_not_consistent                = 1
   ibase_locked                           = 2
   not_succesful                          = 3
   description_required              = 4
   ibase_category_required       = 5
   ace_authorization                  = 6
   OTHERS                                = 7
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Create Components of IBASE in SAP CRM using ABAP

--> Attaching an IBASE as component to a higher level IBASE

DATA: ls_comp_det     TYPE crmt_icss_ibase_component2.

DATA: lt_attr         TYPE TABLE OF crmt_icss_attr_values,
            ls_father     TYPE  ibap_dat1,
            lv_object_id     TYPE comt_product_id.

CLEAR ls_father.
  ls_father-ibase = p_ibase.                      " Root Ibase Number

* IBASE as component of another IBASE
 ls_comp_det-ibase = '504'.                      " Subcomponent Ibase number
 ls_comp_det-extobjtyp = 'IBASE'.


 CALL FUNCTION 'CRM_ICSS_CREATE_COMPONENT'
    EXPORTING
      i_father                                = ls_father
      i_comp_det                         = ls_comp_det
*   I_ADDRESS_DATA                     =
*   I_PARTNER                          =
*   iv_iobject_id                      = lv_object_id  20/11
*   IV_CATEGORY_GUID                   =
* IMPORTING
*   E_COMP                             =
    TABLES
      it_attr                            = lt_attr
* EXCEPTIONS
*   DATA_NOT_CONSISTENT                = 1
*   IBASE_LOCKED                       = 2
*   NOT_SUCCESFUL                      = 3
*   PRODUCT_NOT_FOUND                  = 4
*   IOBJECT_EXIST                      = 5
*   IOBJECT_USED_BY_ANOTHER_COMP       = 6
*   NOT_VALID_RANGE                    = 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.


* Save IBASE
  CALL FUNCTION 'CRM_IBASE_SAVE'.
  COMMIT WORK AND WAIT.





--> Attaching a product as component to the IBASE

 DATA: ls_comp_det     TYPE crmt_icss_ibase_component2.

DATA: lt_attr         TYPE TABLE OF crmt_icss_attr_values,
            ls_father     TYPE  ibap_dat1,
            lv_object_id     TYPE comt_product_id.

CLEAR ls_father.
  ls_father-ibase = p_ibase.  " Root Ibase Number

* Product as Component
 ls_comp_det-product_id = 'HT1000'.
 ls_comp_det-descr = 'Test component1'. " 20/11
 ls_comp_det-objnr = '472073E3B4F14176E1008000097C2FFA'.          "Ibase Guid
 ls_comp_det-product_guid_c = '45C74BF4B28940D000000000097C2FFA'.     " Product_guid
 lv_object_id = 'HT1000'. 20/11

CALL FUNCTION 'CRM_ICSS_CREATE_COMPONENT'
    EXPORTING
      i_father                           = ls_father
      i_comp_det                         = ls_comp_det
*   I_ADDRESS_DATA                     =
*   I_PARTNER                          =
*   iv_iobject_id                      = lv_object_id  20/11
*   IV_CATEGORY_GUID                   =
* IMPORTING
*   E_COMP                             =
    TABLES
      it_attr                            = lt_attr
* EXCEPTIONS
*   DATA_NOT_CONSISTENT                = 1
*   IBASE_LOCKED                       = 2
*   NOT_SUCCESFUL                      = 3
*   PRODUCT_NOT_FOUND                  = 4
*   IOBJECT_EXIST                      = 5
*   IOBJECT_USED_BY_ANOTHER_COMP       = 6
*   NOT_VALID_RANGE                    = 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.


* Save IBASE
  CALL FUNCTION 'CRM_IBASE_SAVE'.
  COMMIT WORK AND WAIT.




Create Counters for IBASE in SAP CRM using ABAP

Steps for creation of counters for an IBASE are:
1. Fill in all the data in a counter work area of type CRMT_MPK_MPOINT_WRK. The required fields are CATEGORY, APPL_GROUP, TYPE, UNIT, STATUS, and FUNCTION. Separately take care of fields VALUE_MIN, VALUE_MAX, OVERFLOW and VALUE_PLAN.
2. Check data i.e. check unit exists or not in the logon language, check Application group exists or not
3. Save the counter
4. Create a Measuring point against this counter
5. Link the counter to the IBASE component

The following piece of code also shows some part of the IBASE creation code, however the same has been kept only for reference and is commented. The data used for counter creation is given below. This data is mentioned solely for the purpose of making the test code more clear.

The counters are created with the following information
•    Application group - UBB
•    Counter Category - Z01
•    Counter TP- 1
•    Unit of measure - Day
•    Usage function - 0RPD

*************
** Counter creation
* Steps: 1. Fill in all the data in a counter work area of type CRMT_MPK_MPOINT_WRK. The required fields are CATEGORY,
*           APPL_GROUP, TYPE, UNIT, STATUS, FUNCTION. Separately take care of fields VALUE_MIN, VALUE_MAX, OVERFLOW
*           and VALUE_PLAN.
*        2. Check data i.e. check unit exists or not in the logon language, check Application group exists or not
*        3. Save the counter
*        4. Link the counter to the IBASE component
*************

DATA: lcl_mpk_mpoint  TYPE REF TO cl_mpk_mpoint,
      lcl_mpk_counter TYPE REF TO cl_mpk_counter,
      ls_mpk_mpoint   TYPE crmt_mpk_mpoint_wrk,
      lo_mpoint       TYPE REF TO cl_mpk_mpoint,
      lv_cc           TYPE char1,
      lv_guid         TYPE crmt_object_guid,
      lv_unit         TYPE msehi,
      lv_unit_new     TYPE msehi,
      lt_messages     TYPE comt_il_error_tab,
      lt_return       TYPE bapiret2.

ls_mpk_mpoint-description = 'Prtest5'.
ls_mpk_mpoint-category    = 'ZCC'.
ls_mpk_mpoint-appl_group  = 'UBB'.
ls_mpk_mpoint-type        = '1'.
ls_mpk_mpoint-unit        = 'D'.
ls_mpk_mpoint-status      = '1'.
ls_mpk_mpoint-function    = '0MET'.

* Save the counter
CALL METHOD cl_mpk_mpoint=>get_instance(
   EXPORTING
      iv_guid   = ls_mpk_mpoint-guid
   RECEIVING
      ro_mpoint = lo_mpoint
   EXCEPTIONS
     OTHERS = 1 ).
IF sy-subrc NE 0.
  CALL METHOD cl_mpk_counter=>create_new( RECEIVING  rv_guid           = ls_mpk_mpoint-guid
                                           EXCEPTIONS create_new_failed = 1 ).
  IF sy-subrc NE 0.
    RAISE save_failed.
  ENDIF.
  lv_cc = 'X'.
  CALL METHOD cl_mpk_mpoint=>get_instance(
     EXPORTING
        iv_guid   = ls_mpk_mpoint-guid
     RECEIVING
        ro_mpoint = lo_mpoint
     EXCEPTIONS
       OTHERS = 1 ).
  IF sy-subrc NE 0.
    RAISE save_failed.
  ENDIF.

  IF ls_mpk_mpoint-appl_group IS NOT INITIAL.
*             set application data
    lo_mpoint->set_application_group( EXPORTING  iv_appl_group             = ls_mpk_mpoint-appl_group
                                      EXCEPTIONS create_application_failed = 1 ).
  ENDIF.
ENDIF.

* Conversion exit for unit
lv_unit = ls_mpk_mpoint-unit.

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
  EXPORTING
    input          = lv_unit
    language       = sy-langu
  IMPORTING
    output         = lv_unit_new
  EXCEPTIONS
    unit_not_found = 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.

ls_mpk_mpoint-unit = lv_unit_new.

IF lv_cc EQ 'X'.
  lo_mpoint->create( EXPORTING  is_data       = ls_mpk_mpoint
                     EXCEPTIONS create_failed = 1 ).
ELSE.
  CALL METHOD lo_mpoint->change
    EXPORTING
      is_data       = ls_mpk_mpoint
    EXCEPTIONS
      change_failed = 1
      OTHERS        = 2.
ENDIF.
IF sy-subrc NE 0.
  CALL FUNCTION 'CRM_MPK_GET_APPLOG_FOR_CNT'
    EXPORTING
      iv_counter_guid        = ls_mpk_mpoint-guid
      iv_screen_0400_prepare = 'X'
    EXCEPTIONS
      counter_not_found      = 1
      OTHERS                 = 2.
  IF sy-subrc <> 0.                                         "#EC NEEDED

  ENDIF.
  RAISE save_failed.
ENDIF.

*IF iv_active_switch EQ 'X'.
*  PERFORM counter_active_switch USING ls_counter_wrk-status
*                                      ls_counter_wrk-object_id.
*ENDIF.
*
*IF iv_buffer_only NE 'X'.
CALL METHOD cl_mpk_mpoint=>save_all( ).
*  IF iv_commit_work EQ 'X'.
*    COMMIT WORK AND WAIT.
*  ENDIF.
*ENDIF.
*ls_counter_new_wrk = go_mpoint->get_data( iv_skip_buffer = 'X' ).
*PERFORM convert_chars_do_p USING ls_counter_new_wrk.
*gs_counter_wrk = ls_counter_new_wrk.

COMMIT WORK AND WAIT.

* Link with IBASE
*CALL FUNCTION 'CRM_MPK_IL_CREATE_LINK'
*  EXPORTING
*    iv_reltype            = 'IBCMP'
*    iv_source_guid        = '46E72670D8C96571E10000000A011621'
*    iv_counter_guid       = '473DAC4F8BE939DFE10000000A011621'
**   IV_MAIN_COUNTER       = ' '
*   iv_1o_link_kind       = 'B'
* IMPORTING
*   et_messages           = lt_messages
**   EV_ERROR              = LT_ERROR
* EXCEPTIONS
*   lock_failed           = 1
*   other_il_error        = 2
*   unknown_il_type       = 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 'CRM_MPK_IL_LINK_MAINTAIN'
  EXPORTING
    iv_operation            = '01'
    iv_reltype              = 'IBCMP'
*    iv_source_guid          = '473C7C47486339E1E10000000A011621'       "Instance 12571 in 12570
    iv_source_guid          = '46E72670D8C96571E10000000A011621'       "Instance 12462 in 12441
    iv_counter_guid         = ls_mpk_mpoint-guid
*    iv_counter_guid         = '473C7C32486339E1E10000000A011621'
*   IV_MAIN_COUNTER         = ' '
*   IV_IL_SAVE_CALL         = ' '
    iv_1o_link_kind         = 'B'
 IMPORTING
   et_messages             = lt_messages
*   EV_ERROR                =
 EXCEPTIONS
   lock_failed             = 1
   other_il_error          = 2
   unknown_il_type         = 3
   unknown_operation       = 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 'CRM_MPK_SAVE_MD_LINKS'
  IMPORTING
    return = lt_return.

COMMIT WORK AND WAIT.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
 IMPORTING
   return        =   lt_return.





 



Create/Change Readings for Counters of IBASE in SAP CRM using ABAP


Study the two form routines 'create_reading' and 'change_reading' separately to understand how the readings are created and changed for counters in IBASE(s) in SAP CRM.

*&---------------------------------------------------------------------*
*& Report  ZSS_CREATE_IBASE_READING
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZSS_CREATE_IBASE_READING.

DATA: lcl_mpk_mpoint  TYPE REF TO cl_mpk_mpoint,
          lcl_mpk_counter TYPE REF TO cl_mpk_counter.
* Sub routine reate_reading create reading for a particular counter and change_reading change the
* value of the counter.

***Few Important table for IBASE
***Counte Reading CRMD_MPK_READING
***Counter CRMD_MPK_MPOINT
****Few usefull function module
***CRMD_IBASE_GET_DETAIL
****CRM_MPK_GET_COUNTER_ITEM_ALL
****CRM_MPK_GET_CNT_LIST_FOR_IBASE

perform create_reading.
perform change_reading.

*&---------------------------------------------------------------------*
*&      Form  create_reading
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM create_reading .

* Read counters for iobject/ibase
* lr_counter_md ?=
* cl_crm_counter_md=>if_crm_counter_md~get_instance( iv_object = p_count ).
* CALL METHOD lr_counter_md->if_crm_counter_md~read
* IMPORTING
* et_counter_data = lt_counter_data.

data : iv_counter_guid TYPE CRMT_MPK_OBJECT_GUID ,
          lo_mpoint TYPE REF TO CL_MPK_MPOINT.
data : ls_reading type CRMT_MPK_READING_WRK,
          lv_guid TYPE CRMT_MPK_OBJECT_GUID.

iv_counter_guid = '473C5975486239E4E10000000A011621'.

cl_mpk_mpoint=>get_instance(
EXPORTING
iv_guid = iv_counter_guid
**iv_object_id = iv_counter_id
RECEIVING
ro_mpoint = lo_mpoint
EXCEPTIONS
OTHERS = 1 ).
if sy-subrc eq 1.
write : / 'Problem'...
return.
endif.
data : lv_time_stamp_from type CRMT_MPK_TIMESTAMP_FROM.

**create object LCL_MPK_COUNTER.
**ls_reading-mp_guid = '473C5975486239E4E10000000A011621'.
ls_reading-mp_guid = iv_counter_guid.
ls_reading-value = 1.
ls_reading-unit = 'EA'.
get time stamp field lv_time_stamp_from.
ls_reading-timestamp_from = lv_time_stamp_from.

  CALL METHOD cl_mpk_counter=>create_new( RECEIVING  rv_guid           = ls_reading-guid
                                           EXCEPTIONS create_new_failed = 1 ).

CALL METHOD lo_mpoint->CREATE_READING
  EXPORTING
    IS_READING    = ls_reading
*    IV_CHECK_ONLY =
*    IV_CLEAR_LOG  =
  RECEIVING
    RV_GUID       = lv_guid
  EXCEPTIONS
    CREATE_FAILED = 1
    others        = 2
        .
IF SY-SUBRC <> 0.
  write : / 'Error Counter Creation'.
else.
  write  : ' Done'...
ENDIF.
          data :       lt_messages     TYPE comt_il_error_tab,
                          lt_return       TYPE bapiret2.
CALL METHOD cl_mpk_mpoint=>save_all( ).
COMMIT WORK AND WAIT.

COMMIT WORK.
ENDFORM.                    " create_reading



**CALL FUNCTION 'CRM_MPK_IL_LINK_MAINTAIN'
**  EXPORTING
**    iv_operation            = '01'
**    iv_reltype              = 'IBCMP'
***    iv_source_guid          = '473C7C47486339E1E10000000A011621'      "Instance 12571 in 12570
**    iv_source_guid          = '473C5975486239E4E10000000A011621'       "Instance 12462 in 12441
**    iv_counter_guid         = ls_reading-guid
***    iv_counter_guid         = '473C7C32486339E1E10000000A011621'
***   IV_MAIN_COUNTER         = ' '
***   IV_IL_SAVE_CALL         = ' '
**    iv_1o_link_kind         = 'D'
** IMPORTING
**   et_messages             = lt_messages
***   EV_ERROR                =
** EXCEPTIONS
**   lock_failed             = 1
**   other_il_error          = 2
**   unknown_il_type         = 3
**   unknown_operation       = 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 'CRM_MPK_SAVE_MD_LINKS'
**  IMPORTING
**    return = lt_return.


*&---------------------------------------------------------------------*
*&      Form  change_reading
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM change_reading.

data : iv_counter_guid TYPE CRMT_MPK_OBJECT_GUID ,
         lo_mpoint TYPE REF TO CL_MPK_MPOINT.
data : ls_reading type CRMT_MPK_READING_WRK,
         lv_guid TYPE CRMT_MPK_OBJECT_GUID.
 
iv_counter_guid = '473C5975486239E4E10000000A011621'.

cl_mpk_mpoint=>get_instance(
EXPORTING
iv_guid = iv_counter_guid
**iv_object_id = iv_counter_id
RECEIVING
ro_mpoint = lo_mpoint
EXCEPTIONS
OTHERS = 1 ).
if sy-subrc eq 1.
write : / 'Problem'...
return.
endif.

data : lv_time_stamp_from type CRMT_MPK_TIMESTAMP_FROM.

* Create object LCL_MPK_COUNTER.
ls_reading-guid = '473C59E2486239E4E10000000A011621'.
ls_reading-mp_guid = iv_counter_guid.

ls_reading-value = 15.
ls_reading-object_id = 230.
get time stamp field lv_time_stamp_from.
ls_reading-timestamp_from = lv_time_stamp_from.

CALL METHOD LO_MPOINT->CHANGE_READING
  EXPORTING
    IS_READING    = ls_reading
*    IV_CHECK_ONLY =
*    IV_CLEAR_LOG  = 'X'
  EXCEPTIONS
    CHANGE_FAILED = 1
    others        = 2
        .


IF SY-SUBRC <> 0.
  write : / 'Error Counter Creation'.
else.
  write  : ' Done'...
ENDIF.
          data :       lt_messages     TYPE comt_il_error_tab,
                       lt_return       TYPE bapiret2.

CALL METHOD cl_mpk_mpoint=>save_all( ).
COMMIT WORK AND WAIT.

COMMIT WORK.

ENDFORM.                    " change_reading
 



2 Comments

  1. Former Member

    Good One.. Thanks for the Info !

  2. Very useful Post. 

    Thanks very much for this post. It helped a lot to me...!