Kbase 16013: How to Increment an Alphabetic Field
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/05/1998 |
|
How to Increment an Alphabetic Field
INTRODUCTION:
=============
This Knowledgebase entry describes a technique for incrementing a
character field sequentially thru the alphabet and allowing the entry
to "loop" back to the beginning of the alphabet when the field has
been filled completely with "Z"s.
WHY YOU NEED TO KNOW THIS:
===========================
You may need to know this if you ever have the need to increment a
non numeric field.
PROCEDURAL APPROACH:
====================
The following internal procedure assumes a two (2) character field
is being manipulated.
PROCEDURE GetNextIncrement.
DEFINE INPUT-OUTPUT PARAMETER DataItem AS CHARACTER NO-UNDO.
DEFINE VARIABLE CharList AS CHARACTER NO-UNDO
FORMAT "X(26)" INITIAL "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
IF DataItem EQ "ZZ" THEN
ASSIGN DataItem = "AA".
ELSE
IF SUBSTRING(DataItem,2,1) EQ "Z" THEN
ASSIGN DataItem = SUBSTRING(CharList,INDEX(CharList,
SUBSTRING(DataItem,1,1)) + 1,1) + "A".
ELSE
ASSIGN DataItem = SUBSTRING(DataItem,1,1) +
SUBSTRING(CharList,INDEX(CharList,
SUBSTRING(DataItem,2,1)) + 1,1).
END PROCEDURE.
Progress Software Technical Support Note # 16013