Skip to Content

Extraction of Lookup field data from MDM

Applies to:

SAP ECC 6.0. and further.

Summary:

This is a sequel to my previous post elaborating the extraction of data from MDM to R/3. An insight into the basic concepts of data retrieval from MDM, like connection setup between MDM-R/3, retrieval of simple fields from MDM to R/3 etc, is a prerequisite.

Author(s):    Aastha Mehrotra

Company:    Larsen & Toubro Infotech

Created on:  23rd Nov, 2012

Author Bio:

Aastha Mehrotra has been engaged with Larsen and Toubro Infotech for over 3 years, her acquaintance with the IT industry being the same.

The author has worked on a variety of projects with a number of  clients in SAP as an ABAP Developer. She is well versed in couple of other ABAP technologies, for instance WebDynpro for ABAP, Workflows and Smart Forms. However, the Magnum Opus in her career has been her distinguished work in the field of Data Extraction from MDM to SAP R/3.  Aastha did a major research on retrieving flat as well as lookup data from MDM into SAP R/3 system, using the MDM ABAP APIs. She also applied her know how on MDM ABAP APIs, in two implementation projects. She has also imparted trainings on Setting up connection between MDM and SAP R/3 as well as Extracting data from MDM to SAP R/3.

Introduction:
This document is a furtherance to my previous document about the extraction of data from MDM http://scn.sap.com/docs/DOC-25463. This extension to the previous article was mandatorily required owing to the fact that- not all fields in MDM tables can be retrieved directly using the methods of the CL_MDM_GENERIC_API. There are certain fields in MDM which have their lookup tables in place (these correspond to the deep structures in R/3). These fields cannot be extracted with the help of the method illustrated in my previous post about the extraction of data from MDM.

This post will take you a step ahead accomplishing the process of data retrieval from MDM to R/3 using the class based API.

Again, I assume that the viewers of this post would already have an insight into the basics of the data extraction from MDM to ABAP. Refer http://scn.sap.com/docs/DOC-25463.

Summary of the process manifested by far:

We have already discussed the following in the previous post:

  • The installation of the ADD-ON MDM_TECH using the transaction code SAINT, as a mandat to establish channel between MDM and R/3.
  • The configuration settings for the connection between MDM and R/3 are maintained using the transaction code MDMAPIC.
  • MDM ABAP APIs are used for the extraction and we use the class based generic API.
  • The two methods of extraction have been elaborated- 1) Interfaces of the generic API 2) Function groups of the generic API
  • Entire process of extracting the data using the ‘Connect’, ‘Query’ and ‘Retrieve_Simple’ methods has been illustrated along with the supporting code samples.
  • The exceptions that might occur during the extraction

Extracting the look up data:

The basic process while extracting the lookup data remains the same as during the extraction of the flat fields.

1) Defining the logon language, country and region for the server.

2) Providing the logical connection name for all operations as specified in MDMAPIC.

3) Create API instance for a particular logical repository.

4) Connect to the repository using the method Connect()

5) Create the parameters for the Query() method

6) Retrieve addresses of Query based records in a particular DDIC structure

7) Retrieve the data in a predefined structure with types of fields corresponding to the types in MDM

Everything remains the same till this point of time. A slight diversion happens for the lookup fields from this point. For the flat fields we have already retrieved the correct values in the structure we designed, say for instance lt_result_ddic in the example below. Lookup fields are the key mapped fields. Hence, for the lookup fields we have included in the structure, only the key would be retrieved in the first go. or the Key would be retrieved against the field name in the structure lt_result_ddic.

/wp-content/uploads/2012/11/sdn1_160504.png

Creating the Key Table  for a particular lookup Field:

Suppose, in the table below ‘Z_ORGANIZATION’ is a lookup field. The fields ‘Z_BIRTH_DATE’ and ‘Z_HIRE_DATE’ have been included to throw some light on the extraction of the date fields. The correct type to be used in R/3, corresponding to type date in MDM is ‘MDM_CDT_DATE_TIME’. If we specify this type for the date fields in the structure we are creating, the correct values would automatically be extracted.

/wp-content/uploads/2012/11/sdn2_160548.png

The lookup table for the field ‘Z_ORGANIZATION’ is as follows. It contains the two fields ‘Z_CODE’ and ‘Z_DESCRIPTION’. ‘Z_CODE’ contains the code for the field and the the latter field contains the description of the field. We need to access these two values with the help of the keys that we have extracted in the first round of extraction using RETRIEVE_SIMPLE() (the last step of the last article).

/wp-content/uploads/2012/11/sdn3_160583.png

For achieving this we utillize the following piece of code:

DATA: wa_key_organization  TYPE mdm_gdt_integervalue,
           lt_key_organization  TYPE mdm_keys.

wa_key_organization = ls_result_ddic-z_organization.
APPEND wa_key_organization TO lt_key_organization.

This would help us consolidate all the key values we have obtained from MDM in the lt_result_ddic structure, in the table lt_key_organization. Before, we go ahead with extracting the actual data using the key values we must be sure about the name of the lookup table and the field names in the lookup table as we have to create a similar strusture in R/3 as we did for the people table structure (refer http://scn.sap.com/docs/DOC-25463)

Once we have all the keys in a table we can go ahead with the extraction of the lookup data. This key table is of the same type as the key table we receive as output from the QUERY() method.  Thus, we can pass it directly to the RETRIEVE_SIMPLE method and  the resulting structure this time would be the lookup table table for Z_ORGANIZATION, containing the final values for the code and the description.

   DATA: lt_org TYPE TABLE OF ztest_org.
TRY.
    CALL METHOD lr_api->mo_core_service->retrieve_simple
      EXPORTING
        iv_object_type_code = ‘Z_ORGANIZATION’
        it_keys                    = lt_key_organization
      IMPORTING
        et_ddic_structure      = lt_org.
  CATCH cx_mdm_communication_failure  INTO cx_exception.
  CATCH cx_mdm_usage_error INTO cx_exception.
*   handle exception
  CATCH cx_mdm_provider INTO cx_exception.
*   handle exception
  CATCH cx_mdm_kernel INTO cx_exception.
*   handle exception
  CATCH cx_mdm_server_rc_code INTO cx_exception.
*   handle exception
  CATCH cx_mdm_not_supported INTO cx_exception.
*   handle exception
  CLEANUP.
*   Disconnect after finishing work. This prevents server resource exhausting
    TRY.
********************************************************************************
        lr_api->mo_accessor->disconnect( ).
********************************************************************************
*     Ignore all exceptions here:
      CATCH cx_root.
    ENDTRY.

ENDTRY.

This way we would get the desired values for the lookup fields in the table lt_org.

I hope this post would help you with the lookup data extraction. In case there is any confusion, please feel free to comment and I would try to tune in.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply