Skip to end of metadata
Go to start of metadata
  • Master Data Read Classes have one basic requirement - They must implement the IF_RSMD_RS_ACCESS interface.
  • There are several examples of how implement a Master Data Read Class provided by SAP - like CL_RSMD_RS_GENERIC_DOMAIN and CL_RSMD_RS_GENERIC_TABLE.  For creating your own custom Master Data Read Class, it probably makes sense to start by copying from one these existing classes and only adjusting for your specific processing.
  • The complete source code (in SAPlink format) for an example implementation of a Master Data Read Class that uses MDM and the MDM ABAP APIs can be downloaded from here.
  • Of all the methods in the sample class the most important from the standpoint of the MDM integration is the GET_TEXT method. The example implementation supports the retrieval of STRING or INTEGER based supporting values for a given key from MDM:
METHOD if_rsmd_rs_access~get_text.

  DATA: object_name    TYPE mdm_log_object_name,
        table          TYPE mdm_table_code,
        query_field    TYPE mdm_field_code,
        l_s_chavlinfo  TYPE rsdm_s_chavlinfo,
        l_not_assigned TYPE rs_txtlg,
        l_initial_val  TYPE rsd_chavl.

  object_name = o_s_gendomain-object_name.
  table       = o_s_gendomain-table.
  query_field = o_s_gendomain-query_field.

  DATA lt_result_set_definition TYPE mdm_field_list_table.
  DATA ls_result_set_definition LIKE LINE OF lt_result_set_definition.
  DATA lt_result_set            TYPE mdm_result_set_table.
  DATA ls_result_set            LIKE LINE OF lt_result_set.
  DATA lt_result_set2            TYPE mdm_result_set_table.
  DATA ls_result_set2            LIKE LINE OF lt_result_set2.
  DATA ls_remote_key_filter     TYPE mdm_client_system_key_query.
  DATA api                      TYPE REF TO cl_mdm_generic_api.
  DATA language                 TYPE mdm_cdt_language_code.
  DATA keys                     TYPE mdm_keys.
  DATA exception                TYPE REF TO cx_mdm_main_exception.
  FIELD-SYMBOLS <field_value>   TYPE ANY.
  FIELD-SYMBOLS: <wa_field>      TYPE mdm_cdt_text,
                 <wa_string>     TYPE string,
                 <wa_integer>    TYPE mdm_gdt_integervalue,
                 <wa_taxonomy>   TYPE mdm_taxonomy_entry,
                 <wa_int>        TYPE mdm_gdt_integervalue.
  TYPE-POOLS: mdmif.


    DATA wa_cache LIKE LINE OF me->data_cache.
    READ TABLE data_cache INTO wa_cache
     WITH KEY object_name = object_name
              table       = table
              query_field = query_field.
    IF sy-subrc = 0.
      keys          = wa_cache-keys.
      lt_result_set = wa_cache-lt_result_set.

      api = zcl_mdm_conn_pool_root=>get_mdm_connection( repository = object_name ).

      DATA: result_set TYPE mdm_search_result_table.
      CALL METHOD api->mo_core_service->query
          iv_object_type_code = table
*         iv_hits_max         = 1
          et_result_set       = result_set.

****The results of a query only return the record keys - no details
****We then have to use a call to the method RETRIEVE to read
****the record details.
      DATA: result TYPE mdm_search_result.
      READ TABLE result_set INDEX 1 INTO result.
      IF sy-subrc = 0.
        keys = result-record_ids.

****We only need the output field we are interested read from MDM
****By using the result_set_definition parameter, we can control this
****and only retrieve that single column
      ls_result_set_definition-field_name = query_field.
      APPEND ls_result_set_definition TO lt_result_set_definition.
      CALL METHOD api->mo_core_service->retrieve
          iv_object_type_code      = table
          it_result_set_definition = lt_result_set_definition
          it_keys                  = keys
          et_result_set            = lt_result_set.

      CLEAR wa_cache.
      wa_cache-object_name   = object_name.
      wa_cache-table         = table.
      wa_cache-query_field   = query_field.
      wa_cache-keys          = keys.
      wa_cache-lt_result_set = lt_result_set.
      APPEND wa_cache TO data_cache.

*===Get the Initial Value Text===
    CALL METHOD _textpool_read
        i_repid = 'SAPLRSDM'
        i_key   = '001'
        e_text  = l_not_assigned.

    FIELD-SYMBOLS: <wa_result> LIKE LINE OF lt_result_set.
    FIELD-SYMBOLS: <wa_pair>   TYPE mdm_name_value_pair,
                   <wa_key>    LIKE LINE OF keys.

*===Append the text values in c_t_chavlinfo===
    DATA: tabix TYPE sy-tabix.
    DATA  l_integer TYPE mdm_gdt_integervalue.
    FIELD-SYMBOLS: <l_s_chavlinfo> TYPE rsdm_s_chavlinfo.
    LOOP AT c_t_chavlinfo ASSIGNING <l_s_chavlinfo>
        WHERE i_read_mode = rsdm_c_read_mode-text.
      CLEAR <l_s_chavlinfo>-c_rc.
      IF <l_s_chavlinfo>-c_chavl IS INITIAL
         OR <l_s_chavlinfo>-c_chavl EQ rsd_c_initial
         OR <l_s_chavlinfo>-c_chavl < 1.
        <l_s_chavlinfo>-e_chatexts-txtsh = l_not_assigned.
        <l_s_chavlinfo>-e_chatexts-txtmd = l_not_assigned.
        <l_s_chavlinfo>-e_chatexts-txtlg = l_not_assigned.
        l_integer = <l_s_chavlinfo>-c_chavl.
        READ TABLE keys ASSIGNING <wa_key> FROM l_integer.
        tabix = sy-tabix.
        READ TABLE lt_result_set ASSIGNING <wa_result> INDEX tabix.
        IF sy-subrc = 0.
          READ TABLE <wa_result>-name_value_pairs ASSIGNING <wa_pair>
            WITH KEY code = query_field.
          IF sy-subrc = 0.
****The data for the column could be one of various data types
****The value itself is returned as TYPE REF TO DATA and must
****be cast into a more specific data type before it can be processed.
            CASE <wa_pair>-type.
              WHEN 'STRING'.
                ASSIGN <wa_pair>-value->* TO <wa_string>.
                WRITE <wa_key> TO l_s_chavlinfo-c_chavl LEFT-JUSTIFIED.
                <l_s_chavlinfo>-e_chatexts-txtsh = <wa_string>.
                <l_s_chavlinfo>-e_chatexts-txtmd = <wa_string>.
                <l_s_chavlinfo>-e_chatexts-txtlg = <wa_string>.
              WHEN 'INTEGER'.
                ASSIGN <wa_pair>-value->* TO <wa_integer>.
                WRITE <wa_key> TO l_s_chavlinfo-c_chavl LEFT-JUSTIFIED.
                <l_s_chavlinfo>-e_chatexts-txtsh = <wa_integer>.
                <l_s_chavlinfo>-e_chatexts-txtmd = <wa_integer>.
                <l_s_chavlinfo>-e_chatexts-txtlg = <wa_integer>.
  • No labels