× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On 10-Dec-2015 13:20 -0600, Stone, Joel wrote:
On 04-Dec-2015 18:41 -0600, CRPence wrote:
On 04-Dec-2015 16:38 -0600, Stone, Joel wrote:
I have a length 4 alphanum field which I need to find the next
value (incremented by one value).

Examples:
A001 => A002
BBBB => BBBC
WXYZ => WXZ0

And my shop would like it done in COBOL, but any algorithm will
suffice.

Maybe use a base 36 table???

<<SNIP>>


Such a TABLE is easily enough created:

<<SNIPped: see:
[http://archive.midrange.com/midrange-l/201512/msg00143.html] >>


<<SNIP>>
I wish I could say that I understand what you are doing here. I
think that you are populating the entire 36 ** 4 table entries, and
then stepping into that table to get the next increment.

Really neat use of SQL

<<SNIP>>


Yes. The effect of comma-delimited table-reference specifications is an implicit CROSS JOIN; i.e. the /cross product/ aka Cartesian Product result of combining the sets. Every _combination_ of the base-36 /digits/ generated in the row-values clause are repeated four times for every possible value in each digit position of places 36**3, 36**2, 36**1, and 36**0. Thus the query in the INSERT statement [by implicit CROSS JOIN] is generating all possible base-36 numbers.

Then, indeed, the SQL query SELECT statements given, showed a couple ways to find _the next higher increment_ from a known value that would be supplied as the operand [likely a host variable or parameter marker] of the greater-than predicate.

Perhaps more straightforward, would be seeing the same done with just the decimal digits, and limited to only two digit positions 10**1 and 10**0 [and perhaps more elucidating, my having properly ordered the use of x# as eXponent\digit-position references: x1->10**1 and x0->10**0]:

with
dig1b10 ( dec1Dig /* One Decimal Digit (0 to 9) */ ) as
( values
('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9')
)
, dig2b10 ( dec2Dig /* Two Decimal Digits (00 to 99) */ ) as
( select char( x1.dec1Dig concat x0.dec1Dig , 2 )
from dig1b10 x1 /* left-most digit; the tens aka 10**1 */
, dig1b10 x0 /* right-most digit; the ones aka 10**0 */
)
select dec2Dig from dig2b10
-- the above will produce decimal numbers 00 to 99 but of
-- course, as the char(2) string, per every combination of
-- all decimal digits zero to nine in both digit-positions:
-- zero||zero->nine, one||zero->nine, … nine||zero->nine


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.