Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
Showing results for 
Search instead for 
Did you mean: 
Former Member


In different business scenarios generally there is a need to maintain Counter Values in our data model. The general purpose is we create a Number field and maintain values for it.

But there can be cases where we have a need to maintain a counter value in a field where the maximum length can be 4. So maintaining a Number counter will allow maximum of 9999 values. but if we create a characters counter from AAAA to ZZZZ, the applicable range will increase from 9999 to (26^4 = 456976). Case that we encountered in the name of Analysis Auth that can be maximum of 12 char but we wanted to have 8 characters reserved for Application Area, Sub Area and Access purpose and 4 char for counter. The example shown below works till counter of length 10.

Maintaining Character Counter is NOT a direct way to just increase it with one. We can achieve this with using some coding. Have created a class for it with specific methods.

This class takes a character value as input and by default returns the next incremented value. Example if you pass AAAD as input, the value will be changed and updated to AAAE.

In case if we want to have value increamented with multiple differences, say a difference of 3 for each counter (may be required if on same object - 3 parallel runs are processing). The character input AAAD can be passed with difference value 3; and the method will update the value to AAAG.


To achieve this one can create a class ZCL_CHAR_COUNTER with following 3 methods in it.





CHAR_COUNTER_INCREMENT: This is the method that will be called outside of this class with having two parameters. One is the import of incremental difference that is defaulted to value 1 and second is the Character Field with option changing. With additional check added to have only characters coming along with converting to upper case.

For the times we want to increment the counter - a internal method INCREMENT_INITIATE is called then it calls INCREMENT_RECURSION.


Attached are the files with code.


The input parameter to class is character string and a counter value and update the same character string with increated value. Below are example outputs for use of this class/method.





1 Comment
Labels in this area