Skip to main content

SAP CRM: Telephone Number update using BOL

Submitted by Stefan Barsuhn on

The BOL model defines the TEL_NOMOB field of the Account -> BuilStandardAddress relation as changeable:
image 6

However, if you change this property via BOL, the update will not persist.

The reason for this lies quite deep in some very old ABAP coding (all comments in German):
image 7

The BOL framework calls FM BUPA_ADDRESS_CHANGE, which eventually calls FM ADDR_PERSONAL_COMM_MAINTAIN.

Along this way, the TEL_NOMOB field is translated into the field  TELNR_LONG, however, this is overwritten as it is the export parameter of FM TELNUMBER_STRUCT_TO_NORMAL:

image 8

So long story short: The TEL_NOMOB should be read-only (just as parameter TEL_NOTEL, which holds the long form of the landline).

So how do we update the TEL_NOMOB field if we only have the international ("canonical") version of the phone number?

Assuming we have the account header (me->account) already loaded, here's an example for landline:

DATA: lv_phone_country TYPE land1,
      lv_phone_new     TYPE ad_tlnmbr,
      ls_phone_mess    TYPE bapiret2.

" the phone number we want to save
lv_phone_new = "+61 (0400000000)".

" get address relation
  DATA(lr_address) = me->account->get_related_entity( 'BuilStandardAddressRel' ).
  IF lr_address IS NOT BOUND.
    " error handling
  ENDIF.

  " get current phone country
  lr_address->get_property_as_value(
    EXPORTING
      iv_attr_name = 'COUNTRYTEL'    " Component Name
    IMPORTING
      ev_result    = lv_phone_country
  ).

  " convert submitted phone number from canonical format
  " to country and number
  CALL METHOD cl_crm_buil_services=>convert_from_canonical
    EXPORTING
      iv_country  = lv_phone_country
    IMPORTING
      ev_country  = lv_phone_country
      es_messages = ls_phone_mess
    CHANGING
      cv_phone    = lv_phone_new.

  " if phone country is empty, then the phone number had a wrong format
  IF lv_phone_country IS INITIAL.
" error handling, wrong format
  ENDIF.

  " now set phone country ...
  lr_address->set_property(
    EXPORTING
      iv_attr_name           =  'COUNTRYTEL'   " Component Name
      iv_value               = lv_phone_country
  ).

  " ... and new phone number
  lr_address->set_property(
    EXPORTING
      iv_attr_name           =  'TELEPHONETEL'   " Component Name
      iv_value               = lv_phone_new
  ).

It converts the canoncial (international) phone number into country and national number and then updates the two fields phone country and phone number.

Notes:

  • for mobile phone the country field is COUNTRYMOB and phone number field is TELEPHONEMOB
  • for mobile phones, if you only supply COUNTRYMOBISO and COUNTRYMOB is initial, country will be overwritten with the country from the address (this happens in CL_BUIL_ADDRESS=>modify, line 2213 and looks like a bug to me)
    image 27
  • note that using this approach, there is the potential issue that one country code (e.g. +61) applies to more than one country (e.g. Australia and Christmas Islands). In that case, the method cl_crm_buil_services=>convert_from_canonical will default to the iv_country you supply it with, if that is one of the options, or if the country code does not match the iv_country it will pick the first one. But in any case, you will receive a warning message in parameter es_messages, that you can evaluate.

Tags