PeopleCode to AutoIncrement an AlphaNumeric Transaction Number

Your rating: None

I have code to auto-increment an alphanumeric field, using SQL calls. It is specific to a 4-character field, but can easily be adapted to different length fields.

SQLExec("SELECT decode(substr(oldvalue,2,3),'ZZZ', TRANSLATE(UPPER(SUBSTR(oldvalue,1,1)),'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0'),substr(oldvalue,1,1)) ||decode(substr(oldvalue,3,2),'ZZ',TRANSLATE(UPPER(SUBSTR(oldvalue,2,1)), '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0'),substr(oldvalue,2,1))||decode(substr(oldvalue,4,1),'Z', TRANSLATE(UPPER(SUBSTR(oldvalue,3,1)), '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0'),substr(oldvalue,3,1))||TRANSLATE(UPPER(SUBSTR(oldvalue,4,1)), '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0') FROM dual, (select :1 as oldvalue from dual)", &priorvalue, &newvalue);
If &newvalue = "0000" Then
   &bOverrun_Error = True;
End-If;

Please try to help out with unanswered topics on the forum. Chances are you have had the same issue/question some time in your IT career!

Comments

Have a question? Please ask it on the forum instead.

Re: PeopleCode to AutoIncrement an AlphaNumeric

Posts: 302
Join date: 06/23/08
Lepa's picture

Larry as your SQL works fine I'm just curious on what kind of requirement derived such code. I find it odd to increment an alpha numeric character :) - none the less, your SQL works perfect.

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog

Re: AutoIncrement an AlphaNumeric Transaction Number

Posts: 13
Join date: 03/18/08
Larry's picture

Have an alphanumeric field, ACTIVITY_ID. Was given requirements to create a Mass Add page, allowing user to auto-generate a large number of Project_Activity rows given a starting point within an alphanumeric range, along with the # of new rows desired, along with other common field values. Tried to get user to agree to only numeric incrementing, but they insisted upon alphanumeric. Go figure.

Re: PeopleCode to AutoIncrement an AlphaNumeric Transaction Num

Posts: 30
Join date: 06/30/08
Nitin's picture

In Inventory the MSR no gets generated automatically.
Could that PeopleCode logic will also work for your requirement?

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <div> <pre> <br> <code> <a> <em> <blockquote> <strong> <ul> <ol> <li> <dl> <dt> <b> <p> <h1> <h2> <u> <img>
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>.

More information about formatting options

CAPTCHA
The question below is to prevent automated spam submissions.
6 + 12 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.