- In the exmaple Master Data Data Read class we used another class, ZCL_MDM_CONN_POOL_ROOT, to establish the connection to MDM. This is just a reusable utility class that caches the API connection and contains logic to map the SAP logon langauge to the MDM Language.
- The complete source code of this class can be downloaded here.
- Class Properties:
- Class Private Types:
- Class Attributes:
- Class Methods:
- GET_MDM_CONNECTION
METHOD get_mdm_connection.
*@78\QImporting@ LANGUAGE TYPE SYLANGU DEFAULT SY-LANGU
*@78\QImporting@ UNAME TYPE SYUNAME DEFAULT SY-UNAME
*@78\QImporting@ REPOSITORY TYPE MDM_LOG_OBJECT_NAME
*@78\QImporting@ USE_CONNECTION_POOL TYPE BOOLEAN DEFAULT ABAP_TRUE
*@7B\QReturning@ VALUE( API ) TYPE REF TO CL_MDM_GENERIC_API
*@03\QException@ CX_MDM_MAIN_EXCEPTION
IF use_connection_pool = abap_true.
DATA wa_api LIKE LINE OF api_cache.
READ TABLE api_cache INTO wa_api
WITH KEY language = language
uname = uname
repository = repository.
IF sy-subrc = 0.
****Cached Connection Record is found, make sure the API reference is bound
IF wa_api-api IS BOUND.
api = wa_api-api.
GET TIME STAMP FIELD wa_api-last_access.
MODIFY TABLE api_cache FROM wa_api.
ELSE.
****Not bound - Delete the Connection Record and Create a New Instance
DELETE api_cache WHERE language = language
AND uname = uname
AND repository = repository.
api = zcl_mdm_conn_pool_root=>create_mdm_connection(
language = language
uname = uname
repository = repository
use_connection_pool = use_connection_pool ).
ENDIF.
ELSE.
****No Cached Record - Create a New Instance
api = zcl_mdm_conn_pool_root=>create_mdm_connection(
language = language
uname = uname
repository = repository
use_connection_pool = use_connection_pool ).
ENDIF.
ELSE.
****By Pass the Connection Pool and create a one-off Instance
api = zcl_mdm_conn_pool_root=>create_mdm_connection(
language = language
uname = uname
repository = repository
use_connection_pool = use_connection_pool ).
ENDIF.
ENDMETHOD.
- CREATE_MDM_CONNECTION
METHOD create_mdm_connection.
*@78\QImporting@ LANGUAGE TYPE SYLANGU DEFAULT SY-LANGU
*@78\QImporting@ UNAME TYPE SYUNAME DEFAULT SY-UNAME
*@78\QImporting@ REPOSITORY TYPE MDM_LOG_OBJECT_NAME
*@78\QImporting@ USE_CONNECTION_POOL TYPE BOOLEAN DEFAULT ABAP_TRUE
*@7B\QReturning@ VALUE( API ) TYPE REF TO CL_MDM_GENERIC_API
*@03\QException@ CX_MDM_MAIN_EXCEPTION
DATA mdm_language TYPE mdm_cdt_language_code.
mdm_language = zcl_mdm_conn_pool_root=>expand_mdm_language( language ).
**** Instantiate the API with our repository key from the dialog
CREATE OBJECT api
EXPORTING
iv_log_object_name = repository.
****Connect to the Repository
api->mo_accessor->connect( mdm_language ).
IF use_connection_pool = abap_true.
DATA wa_api LIKE LINE OF api_cache.
wa_api-api = api.
wa_api-language = language.
wa_api-uname = uname.
wa_api-repository = repository.
GET TIME STAMP FIELD wa_api-last_access.
INSERT wa_api INTO TABLE api_cache.
ENDIF.
ENDMETHOD.
- EXPAND_MDM_LANGUAGE
METHOD expand_mdm_language.
*@78\QImporting@ LANGUAGE TYPE SYLANGU DEFAULT SY-LANGU Language Key of Current Text Environment
*@7B\QReturning@ VALUE( MDM_LANGUAGE ) TYPE MDM_CDT_LANGUAGE_CODE MDM: CDT language code
CASE language.
WHEN c_english.
mdm_language-language = 'eng'.
mdm_language-country = 'US'.
mdm_language-region = 'USA'.
when c_german.
mdm_language-language = 'ger'.
mdm_language-country = 'DE'.
* mdm_language-region = 'USA'.
WHEN OTHERS.
****Use the repository Default
CLEAR mdm_language.
ENDCASE.
ENDMETHOD.