More than two years back I wrote a blog, PI/XI: Maintaining Sequence Numbers in File Name scheme? talking about drawbacks of the existing counter functionality in the File adapter and about the workarounds. Today we are still stuck with those workarounds and the majority of times, depend upon lookups to help us with this requirement.

Recently there was a blog by Raja Sekhar Reddy titled How to maintain counter sequence to file name in Receiver File(FTP/NFS) scenarios which talks about building an incremental logic in ECC and exposing it as a RFC and calling it in PI to retrieve the counter value. I am sure many of us use this work around. But I believe that we should utilize standard functionalities as much as possible.

SAP provides a standard out of the box functionality called Number Ranges that can be used for our purpose. In this blog, I will talk about setting up a number range object in PI itself and retrieving the incremental counter by writing a simple wrapper around a standard FM made available to us.

Setting up a Number Range Object:

Login to the ABAP stack of PI and go to the transaction SNRO. Provide the name of the object and create.

Provide the Number Length Domain and a % for the warning.

The you can set the interval i.e the Start and End of your expected Counter/Sequence.

Creating a wrapper for the FM:

Once your number range and the intervals are setup, you can now use this as input to a standard FM available i.e NUMBER_GET_NEXT. The FM will retrive you the counter/sequence value as per the setup of the number range object that was defined by you.

A screenshot of the test execution is shown as below;

Unfortunately this FM is not RFC enabled and hence we will not be able to use it directly in our RFC Lookup. Hence either you can make a copy of the FM and adjust the code or you can write a simple Wrapper and expose it as a RFC enable FM for your lookup.

I have used the option of a wrapper and created a RFC ‘Z_NUMBER_GET_NEXT’.

You can now import this RFC into ESR and use it in your lookup. Use the output in combination with ASMA and Dynamic configuration to create the output file name.

More about Number ranges – Click here


I still believe that SAP should work towards providing a standard feature within the File adapter to provide a flexible solution for us to set counter values. Having additional lookups is an overload on the performance and are also error prone i.e a looup failure potentially results in the mapping failure. Hence in case you believe that we should have a standard feature available, Vote for this IDEA today.

To report this post you need to login first.


You must be Logged on to comment or reply to a post.

  1. Bhavesh Kantilal
    Strangely Seeburger provides this functionality of the shelf. Define a Counter Name, use it in your mapping with the Seeburger shipped function. Its as simple as that!
    Kind of odd that this request never reached SAP Development.In the world of EDI when you need to maintain running Interchange ID’s this is a standard  requirement. I guess the B2B Add on from SAP would have this feature and should get shipped into the standard one as well… but then hey I am speculating here.
    Back to your solution, when you write a wrapper FM in your code, how do you ensure that the call is Single Threaded,i.e, what if multiple runs of the mappings happen at the same time? I assume the standard SAP module takes care of Single Threading but what about your Z module, does Single Threading Still Work?


      1. Uwe Schieferstein

        I described a different approach using ABAP class mapping to generate sequence numbers. In order to ensure sequential numbering it is important to define the number range object as unbuffered. This works very well in our SAP-PI environment (dual stack) and only occasionally numbers get lost e.g. after a restart of the entire PI system. A major drawback, however, is the fact that mapping containing ABAP classes cannot be tested in the ESR.



  2. Goradindla Sreerama Reddy

    We have to do depend on ECC or JDBC etc for Sequence numbers and counters until it is
    inbuilt in PI espically with latest version of PI 7.3 java version which will not have AAP stack this will not work on that.



Leave a Reply