Friday 14 June 2019

Routing Condition formation in SAP CPI

Based on certain routing conditions the messages are directed to different receivers. Store the condition in any header or property values and call them in router dynamically. Different acceptable formats are below:

In Router configuration, mention the Expression Type: Non-XML


Usage of Operators in Non-XML Conditions


OperatorExample
=${header.SenderId} = '1'
!=${header.SenderId} != '1'
>${header.SenderId} > '1'
>=${header.SenderId} >= '1'
<${header.SenderId} < '1'
<=${header.SenderId} <= '1'
and${header.SenderId}= '1' and ${header.ReceiverId} = '2'
or${header.SenderId}= '1' or ${header.ReceiverId}= '2'
contains${header.SenderId} contains '1'
not contains${header.SenderId} not contains '1'
in${header.SenderId} in '1,2'
not in${header.SenderId} not in '1,2'
regex${header.SenderId} regex '1.*'
not regex${header.SenderId} not regex '1.*'



Friday 7 June 2019

Accessing value mapping in groovy script

For some scenarios, we would need to access the deployed Value mapping table in the iflow, there is a possible way to access the values using the below script:


Groovy Script:

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;

def Message processData(Message message)
{
def a = ITApiFactory.getApi(ValueMappingApi.class, null);

//format sourceAgency, sourceIdentifier, sourceValue, targetAgency, targetIdentifier

def mappedValue = a.getMappedValue("C4C", "Country", "yMKT", "Country", "Austria");

def messageLog = messageLogFactory.getMessageLog(message);

messageLog.setStringProperty("Mapped Value", mappedValue);

return message;
}


Hope this Helps!!!



Wednesday 5 June 2019

Converting the File from field fixed length file to XML Success-factor Simplified


There is no standard way of converting the flat file into XML format using the fixed field length in CPI, as we have in PI using FCC parameters. To solve this problem, you can implement the below code.


GroovyScript:

import com.sap.gateway.ip.core.customdev.util.Message;

import java.util.HashMap;

    def Message processData(Message message) {

//Body

    def body = message.getBody(java.lang.String) as String;
    def lines = body.split("\n");

//root node
    def body1 ="<Files>";

//looping to read the lines and form a XML
    for(i=0;i<lines.length;i++)

     {

         body1 += "<EmpDetails>";
         body1 += "<Name>"+lines[i].substring(0,4)+"</Name>";
         body1 += "<Age>"+lines[i].substring(4,6)+"</Age>";
         body1 += "<DOB>"+lines[i].substring(6,26)+"</DOB>";
         body1 += "<JobTitle>"+lines[i].substring(14,26)+"</JobTitle>";
         body1 += "<Country>"+lines[i].substring(26,31)+"</Country>";
         body1 += "</EmpDetails>";
    }

//closing root note
    body1 +="</Files>";

//storing the converted XML to body
    message.setBody(body1);

    return message;

   }


Input File(Flat):

Rama2123051990SrConsultantIndia
Ravi3322021994 ConsultantIndia
Siva3322021994SrConsultantIndia

Output File(XML):

<Files>
<EmpDetails>
<Name>Rama</Name>
<Age>21</Age>
<DOB>23051990SrConsultant</DOB>
<JobTitle>SrConsultant</JobTitle>
<Country>India</Country>
</EmpDetails>
<EmpDetails>
<Name>Ravi</Name>
<Age>33</Age>
<DOB>22021994 Consultant</DOB>
<JobTitle> Consultant</JobTitle>
<Country>India</Country>
</EmpDetails>
<EmpDetails>
<Name>Siva</Name>
<Age>33</Age>
<DOB>22021994SrConsultant</DOB>
<JobTitle>SrConsultant</JobTitle>
<Country>India</Country>
</EmpDetails>
</Files>

Hope this helps!!!