Skip to Content
Technical Articles
Author's profile photo Balamurugan Jaipraakaash

Groovy Script “replaceALL” in your Agile Integrations using SAP CI/CPI

Introduction :

In this blog post I’m going to brief about, How effectively we can use Groovy script to tackle Agile developments in your SAP CI/CPI projects.

The requirement that we had is, need of change in IDoc basic type to the latest basic type used in ABAP code which sends the data to SAP CI. In CI/CPI we need to update the IDoc basic type to its latest where we have already completed the IDoc mappings. Keeping the effort estimation & amount of rework in consideration, we’ve handled this change through a simple Groovy script where it will replace the IDoc basic type to its latest in runtime instead of replacing the entire IDoc XSD which will remove the existing entire message mappings & would require to do complete remap.

The scenario is an outbound asynchronous iFlow, where source is SAP S/4 HANA and target is 3rd party P2P application. Also knowing about  replaceALL method in prior will help to understand the objective of this blog post.

Solution:

Below is where we’ve add the Groovy script in our iFlow specific to the requirement. One can add the script just 1 step before the message mapping or so as per the requirement.

 

 

And the Groovy script goes by as follows,

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
    //Body 
       def body = message.getBody(String) as String;
       message.setBody(body.replaceAll("INVCON03","INVCON02"));
       return message;
}

with this code in place there is no need to do any further changes in your iFlow to convert the basic type. The above code will replace all the instance of “INVCON02” to “INVCON03” in the iFlow. For example in IDoc XSD, parameter in Content Modifier’s Header/Property type as X-Path etc.

Conclusion:

To conclude, you’ve learnt How effectively one can use “replaceALL” method in Groovy, which eventually adds up an agility to meet your deliverables on time ( a Change request basically) without much effort or rework been put.

 

Hope you had an interesting read with this one and do leave your feedback in the comment section.

Stay tuned! Happy Learning folks 🚀

 

Best,

Balamurugan

Integration Consultant.

Assigned tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.