SAP Cloud Platform Integration (CPI) Part 13 – Palette Functions 7 – CPI Value Mapping

In this post, we will explore SAP Cloud Platform Integration (CPI) Part 13 – Palette Functions 7 and learn how to create value mapping artifacts in CPI and use them in message mapping. I will also cover how to import value mapping sections and store them as properties through content.

Outline of this blog series: SAP Cloud Platform Integration (CPI) Part 13 – Palette Functions 7

1. SAP CPI Introduction
2. SAP BTP tools and features overview (BTP, Global Account, Sub-Account, Entitlements, Connectivity, Security)
3. SAP CPI Web IDE overview
4. Registering a trial account and enrolling to SAP CPI service
5. Deep dive into Cloud Integration features with real world scenario example
6. Use cases of palette functions
7. Adapter configurations
8. Using Cloud connector for connecting to backend SAP systems
9. Overview on API Management & Open Connectors
10. Integration using Open Connectors with real world example

In short, below is the content we will elaborate in this tutorial:

1. Value Mapping
2. Value mapping vs Fix values
3. Creation of value mapping artifact
4. Using value mapping in message mapping
5. Use value mapping entries as properties through groovy


1. Value Mapping

Esteem planning assumes a significant part in the CPI interface advancement. Esteem planning comes convenient, when you need to change the info field to an alternate portrayals or configurations. change information starting with one configuration then onto the next. During the worth planning process, the expressions “office” and “identifier” are utilized to recognize explicit qualities.

Office: with regards to esteem planning, “organization” alludes to the association or element that characterizes the worth being planned. This could be an organization, a principles body, or whatever other substance that characterizes values.

Identifier: An “identifier” is a special code or name used to address a specific worth inside a given office. It is an approach to particularly distinguish the worth being planned inside the particular office.

For e.g.:

For instance, suppose you are planning values between two frameworks, and one framework utilizes the worth “New York City” to address New York City. The office for this situation may be the US Postal Assistance (USPS), which characterizes the two-letter postal codes utilized for urban communities and states. The identifier for New York City inside the USPS framework is “NY”, so you would utilize this identifier while planning the worth to the objective framework.

Planning item codes, request types, unit of estimation codes. You need to make esteem planning as a different relic and transport it to different conditions. Likewise, fields, for example, DEV URL, QA URL, Goad URL can be kept up with in esteem planning so you can call it and store it as a property and pass it to address field. All things considered, you don’t need to hardcode the URL (hostname and port) in every single connection point, rather store it in like manner ONE Worth planning antiquity.

2. Value Mapping vs Fix Values

As said esteem planning is helpful if you have any desire to characterize the qualities as a typical and to change the qualities in different conditions.

In the other case, fix values, likewise a planning capability, is utilized to inside (inside graphical supervisor) to switch the source esteem over completely to fixed target esteem.

For e.g.:

In the event that we get a unit of estimation as PC, it ought to be changed as PIECE. This is normal across all frameworks (dev, QA, Goad) and this don’t need to be made as a worth planning. We can utilize fix values itself.

3. Creation of Value Mapping Artifact

Go inside the package -> Click on Edit -> Add -> Value Mapping.

Give some arbitrary name – > click on Make. This is the manner by which worth planning creation window seems to be.

As you can see its referenced as Bi-Directional planning, and that implies assuming we get source side worth, it will get switched over completely to target esteem. Also, in the event that you get target esteem in source side, it will get switched over completely to the source side worth in yield. The two different ways it will work.

Click on Alter – > Add.

You need to give source office, identifier and target organization, identifier.

Save and deploy.

4. Using value mapping in message mapping

Explore to the message planning segment in the IFlow and explore to the field where you need to execute the worth planning.

Source office, identifier, target organization and target identifier will be found in the worth planning ancient rarity. Also, on the off chance that you didn’t get the normal contribution from source which you haven’t kept up with in the worth planning, then, at that point, the choice “On disappointment” comes helpful. As a matter of course, “Utilize key” will be chosen.

In SAP CPI, the “On Disappointment” choice in esteem planning permits you to characterize what ought to happen while a planning comes up short or experiences a mistake during runtime. At the point when you select the “Utilization Key” choice in the On Disappointment setting, SAP CPI will involve the critical incentive for the objective field rather than the planned worth. This intends that assuming the planning fizzles, the worth in the objective field will be the key worth that was characterized for the objective field, as opposed to the planned worth that couldn’t be produced.

The “Utilization Key” choice can be helpful in situations where it is critical to guarantee that the objective field generally contains a worth, regardless of whether the planning comes up short for reasons unknown. Notwithstanding, it is essential to take note of that utilizing the key worth might bring about information irregularities or blunders assuming the objective framework depends on the planned incentive for handling.

Other On Disappointment choices accessible in SAP CPI incorporate “Raise Exemption”, which will cause the message handling to fizzle and produce a mistake message, and “Use Default Worth”, which permits you to determine a default esteem that will be utilized in the objective field while the planning falls flat.

5. Use value mapping entries as properties through groovy

We have a situation where, we really want to decide the collector framework URL, client, qualifications progressively founded on the client that they are trying. For eg: Assuming that we have 2 conditions in recipient side, yet we need to present it on one client and in later we could need to present it on another client. Thus, it won’t be a decent choice in the event that we have 2 IFlows for every client. In this way, in the event that we have kept up with the testing climate in happy modifier which can utilize it in sweet to decide the URL, client and qualification name.

Content Modifier:

Groovy:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap
import com.sap.it.api.ITApiFactory
import com.sap.it.api.mapping.ValueMappingApi
import groovy.json.*

  def Message processData(Message message) {

    try {

      // Read the routing condition from the property
      def value = message.getProperty("TestEnv")

      // Identify the Receiver based on the routing condition 
      if (value) {
        if (value.equals('FUT')) {
          Receiver = "S4_010"
        } else if (value.equals('UAT')) {
          Receiver = "S4_020"
        } else {
          throw new Exception("Receiver could not be identified") 
        }
      } else {
        throw new Exception("Routing Condition not Found") 
      }

      if (Receiver != null) {

        //Define the parameters required for this interface; Url, Client, User for each API/Service used 

        def p_Url = Receiver + "_Url"
        def p_xxx_User = Receiver + "_xxxx_User"
        def p_Client = Receiver + "_Client"

        //Call the Value Mapping API and pass the paramters
        def valueMapApi = ITApiFactory.getApi(ValueMappingApi.class, null)

        // Fetch the values for connection parameters 
        def RCV_Url = valueMapApi.getMappedValue('Receiver', 'Parameter', p_Url, 'Receiver', 'Value')
        def RCV_Client = valueMapApi.getMappedValue('Receiver', 'Parameter', p_Client, 'Receiver', 'Value')
        def RCV_L2C2_User = valueMapApi.getMappedValue('Receiver', 'Parameter', p_xxxx_User, 'Receiver', 'Value')

        if (RCV_Url != null || RCV_Client != null || RCV_xxxx_User != null) {
          message.setProperties(["Receiver": Receiver,
            "RCV_Url": RCV_Url,
            "RCV_Client": RCV_Client,
            "RCV_xxxx_User": RCV_xxxx_User
          ])
        } else {
          throw new Exception("Missing parameters in lookup") //Throw exception if parameters could not be retrieved from VM table
        }
      }
    } catch (Exception ex) {
      throw new Exception(ex)
    }

    return message

  }

Code Explained:

  1. Import the fundamental bundles.
  2. Peruse the property ‘TestEnv’ and store it in a variable.
  3. In attempt block, check Assuming worth is FUT or UAT. Assuming this is the case, pass the qualities to Recipient variable. It means, whether its client 10 or 20 in S4HANA.
  4. In the event that recipient doesn’t equivalent to Invalid, then add a few postfixes to the collector variable which as of now contains the client data. We are framing this example since we announced the same way in esteem planning.
  5. Call the worth planning Programming interface and pass the boundaries.
  6. Set the returned values from esteem planning as a property.
  7. Utilize this property in the URL, client and accreditation places.

This is the manner by which you can progressively decide the recipient framework and create the qualities. I’m certain there are other better ways. Generously share those in the remarks. Blissful learning!

 

YOU MAY BE INTERESTED IN

Best Practices for SAP Cloud Platform Development: A Comprehensive Guide

Your Earning Potential as a SAP ABAP Developer with 5 Years of Experience

Analysis Of Algorithm In DAA-2024

 

X
WhatsApp WhatsApp us