Skip to Content
Technical Articles

SAP CPI – How to generate sequentially numbered File name.

Introduction:

This is the simple IFlow for generating a file name with a sequential number in SAP CPI and you can easily implement this flow in any IFlows in CPI to create a sequentially numbered File name and also the same can be used in the message mapping.

 

IFLOW:

Below is the iFlow to generate the sequential number.

 

  1. Content Modifier: Declared the local variable [count] in Exchange property and the first filename starts with 5000(default value).

 

2.Groovy Script: Incrementing the [count value] by using the below script. First imported the property value of count to script then incrementing the value by 10(based on need, we can change the increment count) and finally the increased value set to the count property.

Script code:

import com.sap.gateway.ip.core.customdev.util.Message;
def Message processData(Message message)
{

def body = message.getBody(java.lang.String) as String;
def messageLog = messageLogFactory.getMessageLog(message);
def out= message.getProperty(“count”);
out=Integer.parseInt(out);
out=out+10;
out=out.toString();
message.setProperty(“count”,out);

messageLog.setStringProperty(“Logging#1”, “Printing Payload As Attachment”)
messageLog.addAttachmentAsString(“ResponsePayload:”, out, “text/plain”);
return message;
}

 

3. Write Variable: Once the count value set by the script, we need to store the property value. So the write variable is used to store the updated value of count property, whenever the iFlow starts the respected value will be storing in this Variable.

 

4. Receiver: Adding the count property value in the filename of the receiver.

 

The configuration part is over. Go ahead and deploy the iFlow, we will get a sequential number in the filename like (5000,5010,5020,50++) shown below.

 

Conlusion:

Hope this blog post will help the beginners, to generate the files with a sequence number.

2 Comments
You must be Logged on to comment or reply to a post.
  • Hi naveen kumar171,

    thanks for writing the article. Can you point out the advantages over using SAP CPI’s number range feature? See here: https://blogs.sap.com/2018/06/26/cloud-integration-working-with-number-ranges/

    Note: There are some advantages in your implementation (like setting the step size of your sequential number), but for simple upcounting sequences the “number range” feature might be the better choice.

    Maybe you could point out this advantages/disadvantages of your solution in your article, to give some decision-making aid for the community.

    Regards,
    Raffael

  • Hi Raffael Herrmann,

    Thanks for looking into this and I appreciate you for mentioning the wonderful blog post of Number range uses in Cloud integration.

    I should’ve added the advantages, but I preferred this could help to customize the sequence functionality of the filename as well as in the message mapping. Going forward will do that.

    Thanks,

    Naveen.