Monday, 23 October 2017

JSON Code for conversion of String to Integer/ Remove double quotes from JSON:

All input data will consider as the String after converting from the XML to JSON, as the output sends to database which supports only without double quoted for the integer. This can be achieved by the below code

IMG:001

Add the groovy script after the XML to JSON Converter then it would work.

import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.json.*
def Message processData(Message message)
{
def body = message.getBody(java.lang.String) as String;
def jsonSlurper = new JsonSlurper();
def jsonDataObject = jsonSlurper.parseText(body);

//Convert the JSON String to Int
jsonDataObject.Contact.id = convertToInt(jsonDataObject.Contact.id);
jsonDataObject.assignedTo.account.id = convertToInt(jsonDataObject.assignedTo.account.id);
jsonDataObject.assignedTo.staff.id = convertToInt(jsonDataObject.assignedTo.staff.id);
jsonDataObject.c.apf = convertToBoolean(jsonDataObject.c.apf);

//Integer conversion  
message.setBody(new JsonBuilder(jsonDataObject).toPrettyString())
return message
}
   static Object convertToInt(Object inputValue){
        if(inputValue.isNumber()){
          return inputValue.toInteger();
        }else{
          return inputValue;
        }
   }}

//Boolean Conversion
static Object convertToBoolean(Object inputValue){
        if(inputValue.equals("true")){
          return true;
        }else{
          return false;
        }

Input: "id":"3261390"
Output: "id":3261390

Issue fix:
If there is no value for the fields then it could not handle that, throws the error eg: ” property id : line 20 it cannot convert null value”

Instead of

jsonDataObject.assignedTo.account.id = convertToInt(jsonDataObject.assignedTo.account.id);

Add the below code:

if(jsonDataObject.assignedTo!= null)
{if(jsonDataObject.assignedTo.account.id!=null)
{  jsonDataObject.assignedTo.account.id = convertToInt(jsonDataObject.assignedTo.account.id);}}




Thursday, 23 February 2017

SAP PI/PO: Java Program to read the input file and rename output file based on validation


Requirement:

Based on the input folder and filename the output filename need to be modified.
This is passthrough interface but when we have more than 5 bank and each bank has 20 codes with 3 prefix (S,N,P)then we need to create 300 flows. This takes more time to develop it. So for reducing it we used the below java mapping code to achieve this requirement.

Eg:

In Input folder name: /home/bankdata/invoices/testin/ICICIBank or /home/bankdata/invoices/testin/HDFCBank

Filename – S_1234.txt,N_3433.txt,P_2354.txt
This S_1234 code present for all banks with different data.

In Output folder name: /home/bankdata/invoices/testin

Output file name: TECH_(bank name)_PSCT_ (code)_timestamp. extension(.csv)

Value Mapping: 
If S_1234.txt, N_3433.txt,P_2354.txt

Source value          Target value
ICICIBank+S   -     TECH_ICICIBank_PSTT_1234_20170223-120123.csv


ICICIBank+N   -     TECH_ICICIBank_PNTT_3433_20170223-120123.csv
ICICIBank+P   -     TECH_ICICIBank_PPTT_2354_20170223-120123.csv
HDFCBank+S   -     TECH_HDFCBank_PSTT_1234_20170223-120123.csv
etc......

Java Mapping Program Code:

package dynamicfilename;

import java.io.InputStream;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import com.sap.aii.mapping.value.api.*;

public class dynamicfile extends AbstractTransformation
{
 private static final String String = null;

public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)                                                                        throws StreamTransformationException
{
  try
  {
   InputStream inputstream = transformationInput.getInputPayload().getInputStream();
   OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();
   Map mapParameters = (Map) transformationInput.getInputHeader().getAll();
   // a) Set Output File name
   mapParameters.put(DynamicConfigurationKey.create("http://sap.com/xi/XI/Dynamic",
                                                       StreamTransformationConstants.DYNAMIC_CONFIGURATION),"");
   DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
   DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
   DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "Directory");
   String filename = conf.get(key);
   String directory = conf.get(key1);
   String bankname = directory.substring(31); //Bank name
   String filestart = filename.substring(0,1); //filename start character
   String filename_bank_concat = bankname+"+"+filestart;
  
   String context = "http://sap.com/xi/XI";
   String senderAgency = "ECC";
        String senderScheme = "Directory";
        String receiverAgency = "Bank";
        String receiverScheme = "Filename";
        
        IFIdentifier source = XIVMFactory.newIdentifier(context, senderAgency, senderScheme);
     IFIdentifier target = XIVMFactory.newIdentifier(context, receiverAgency , receiverScheme);
        IFRequest request = XIVMFactory.newRequest(source,target,filename_bank_concat);
        String destvalue = "";
      IFResponse response = XIVMService.executeMapping(request);
           String[] targetValues = response.getTargetValues();
           // take first value of result
      if(targetValues.length>0)
      destvalue= targetValues[0];
     
      String code = filename.substring(2,6);     // output payment code 7570
      DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-hhmmss");
      conf.put(key, (destvalue+code+"_"+dateFormat.format(new Date())+".csv"));
      conf.put(key1, (“/home/bankdata/invoices/testin/"));
   //copy the content of file
   byte[] b = new byte[inputstream.available()];
   inputstream.read(b);
   outputstream.write(b);
  }
  catch (Exception exception)
  {
   getTrace().addDebugMessage(exception.getMessage());
   throw new StreamTransformationException(exception.toString());
  }
 }
}








SAP PI/PO: Java Program to read the content from input file to output file


The below java code is to copy the data from the input file and paste the same data to output file.

package dynamicfilename;

import java.io.InputStream;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import com.sap.aii.mapping.value.api.*;

public class dynamicfile extends AbstractTransformation
{
 private static final String String = null;

public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)                                                                        throws StreamTransformationException
{
  try
  {
   InputStream inputstream = transformationInput.getInputPayload().getInputStream();
   OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();
   byte[] b = new byte[inputstream.available()];
   inputstream.read(b);
   outputstream.write(b);
  }
  catch (Exception exception)
  {
   getTrace().addDebugMessage(exception.getMessage());
   throw new StreamTransformationException(exception.toString());
  }
 }
}





SAP PI/PO: Java Program to fetch the values from value mapping table


The below java code in ESR will take the data from the value mapping table maintained in ID

String context = "http://sap.com/xi/XI";
   String senderAgency = "ECC";
        String senderScheme = "Directory";
        String receiverAgency = "Bank";
        String receiverScheme = "Filename";
        
        IFIdentifier source = XIVMFactory.newIdentifier(context, senderAgency, senderScheme);
     IFIdentifier target = XIVMFactory.newIdentifier(context, receiverAgency , receiverScheme);
        IFRequest request = XIVMFactory.newRequest(source,target,filename_bank_concat);
        String destvalue = "";
      IFResponse response = XIVMService.executeMapping(request);
           String[] targetValues = response.getTargetValues();
           // take first value of result
      if(targetValues.length>0)

      destvalue= targetValues[0];

You can use the destvalue and perform your logic.





Tuesday, 20 September 2016

Successfactor and FieldGlass Basics



SAP announced the initial integration of the vendor management system (VMS) Fieldglass and the human capital management (HCM) solution SuccessFactors. Both Fieldglass and SuccessFactors are SAP solutions. SuccessFactors is used by enterprises to manage their employee workforces; Fieldglass, acquired by SAP in May 2014 for a reputed sum of more than $1 billion, enables the management of contingent workforce and staffing suppliers.


The 2014 acquisition was a watershed event in the staffing industry and the first concrete move toward supporting enterprises to achieve a “total talent management” or “blended workforce” model, blending the management of employee and contingent workers. This integration, expected since the acquisition, confirms SAP’s move in this direction — at least a first step.


With the integration, organizations will “now be able to upload data from Fieldglass into contingent profiles in SAP SuccessFactors Employee Central, making them visible to everyone in the organization through people searches and organizational charts,” the press release said. “The integration between SAP’s HCM and services procurement solutions allows companies to break down siloes and gain meaningful insights on all of their workers to achieve business goals.”


Also suggested are benefits that can be realized as the integration continues to develop:


· Realization of consistent processes (HR and contingent workforce management) across all talent


· Visibility into traditional and nontraditional workforce data — providing actionable insight into the total workforce


· Integration across all human capital and labor-based services, allowing a holistic view from permanent employees through contingent workforce/SOW through other labor-based services (BPO, legal, etc.) to worker-related services like travel and entertainment (T&E). Such integration allows procurement to look into all labor-related spend.


Fieldglass integration is not only extending into the human capital domain. In 2015, SAP has already started integrating Fieldglass and Ariba, including workflows between Fieldglass, Ariba Procurement and Ariba Network; integration of UIs; and OOTB master data integration — apparently heading toward an integrated purchase-to-pay (P2P) model that will span both products and services. It also appears that integration with Concur may be on the horizon.


Spend Matters Summary


Prior to publishing and the announcement of the news, we were not able to speak to SAP representatives to get a deeper understanding of the full extent of the Fieldglass-SuccessFactors integration and its technical implementation. It appears this initial integration introduces functionality that mainly supports HR users on the SuccessFactors side — though this remains to be validated. We hope to speak to SAP shortly and get a technical understanding of the integrations— and will report back what we learn.


Looking across the entire span of integrations from SuccessFactors to Fieldglass to Ariba, SAP appears to be ahead of the ERP pack at this point in integrating human capital management and service procurement solutions, although no single vendor (including SAP) has a set of collected, integrated assets that can begin to bridge all human capital, talent and external services management needs (which explains in part why Fieldglass is also focused on integration with Workday, Peoplesoft and others).


What will ultimately emerge from all of this is hard to say, but it could be a solution set that has not existed before and where the whole is greater than the sum of its part -- especially if SAP begins to leverage a platform-as-a-service drive (PaaS) driven model which can bridge its increasingly integrated internal solutions with external best of breed capabilities in emerging areas (e.g., freelancer management systems) which it does not support natively today.







Monday, 12 September 2016

Connecting a Customer System to SAP HCI

The URL explains the below list of information:

1.       Basic Setup for HTTPS-Based Communication
2.       Connecting to an On-Premise Landscape (Example Setup)
3.       Configuring Inbound Communication(Inbound/HTTPS/Basic Authentication)
4.       Configuring Outbound Communication
5.       Detailed Steps on Setting Up the Tenant Client Keystore and Creating X.509 Keys
6.       Concepts of Secure Communication

7.       Setting up Message-Level Security Use Cases