How to use Value Mapping in Java Mapping

Value Mapping is a crucial feature in SAP PI/PO that helps in transforming data values dynamically during integration processes. When implementing Value Mapping in Java Mapping, there is no need to import additional libraries since it utilizes the built-in XPI Mapping Libraries.

Why Use Value Mapping in Java Mapping?

  • Simplifies data transformation by mapping values dynamically.
  • Eliminates the need for hardcoded values, making the integration more flexible.
  • Enhances maintainability and reduces manual effort.

Fetching Values from Value Mapping Table

In the example below, we retrieve a value from the Value Mapping table by providing Context, Agency, Scheme, and Input Value. The same approach can be extended to update or delete values from the table.

import com.sap.aii.mapping.value.api.IFIdentifier;
import com.sap.aii.mapping.value.api.ValueMappingException;
import com.sap.aii.mapping.value.api.XIVMFactory;
import com.sap.aii.mapping.value.api.XIVMService;

public class ValueMapping {

    public static final String VM_SOURCE_CONTEXT = "http://sap.com/xi/XI";
    public static final String VM_TARGET_CONTEXT = "http://sap.com/xi/XI";
    public static final String VM_SOURCE_AGENCY = "Param";
    public static final String VM_SOURCE_SCHEME = "Name";
    public static final String VM_TARGET_AGENCY = "PI";
    public static final String VM_TARGET_SCHEME = "Value";

    public static void main(String[] args){
        
        String output= getValue(VM_SOURCE_CONTEXT, VM_SOURCE_AGENCY,VM_SOURCE_SCHEME, "InputValue", VM_TARGET_CONTEXT, VM_TARGET_AGENCY, VM_TARGET_SCHEME);
    }

    public static String getValue(String srcContext, String srcAgency,
                                  String srcScheme, String srcValue, String tgtContext,
                                  String tgtAgency, String tgtScheme) {
        String result = "";
        IFIdentifier vmSource = XIVMFactory.newIdentifier(srcContext,
                srcAgency, srcScheme);
        IFIdentifier vmTarget = XIVMFactory.newIdentifier(tgtContext,
                tgtAgency, tgtScheme);
        try {
            result = XIVMService.executeMapping(vmSource, vmTarget, srcValue);
        } catch (ValueMappingException vmEx) {
            throw new RuntimeException(vmEx);
        }
        return result;
    }

  

}

Steps to Implement

  1. Define Value Mapping in Integration Directory with appropriate context, agency, scheme, and values.
  2. Use Java Mapping to fetch, update, or delete values dynamically.
  3. Deploy and Test the mapping in SAP PI/PO to verify the transformation.

Conclusion

Value Mapping in Java Mapping provides a seamless way to transform values without external dependencies. By leveraging XPI Mapping Libraries, integration scenarios become more efficient and adaptable. This method is particularly useful in scenarios where dynamic value replacement is required across different systems.

Do you use Value Mapping in your Java Mappings? Share your experiences in the comments!

Also read about

1 comment

Post Comment

You May Have Missed