## How to increase the no. of records accomodated in a sequence no. field of 6-digit (Numeric Field) length?

625 pts.
Tags:
AS/400
AS/400 Fields
AS/400 Records

Software/Hardware used:
AS/400

Thanks. We'll let you know when a new response is added.

## Discuss This Question: 13 Replies

Thanks. We'll let you know when a new response is added.
• I have a field(Sequence Number) which is a numeric-field(Len 6,0).   What kind of "numeric" field? Zoned or packed decimal?   If The data type can be changed to handle characters, why can't it simply changed to be a larger number? Surely that would be easier with much less work.   Tom
report
• Yes, I did something like this
that the field was character.

Before you start the computation,
you should consider characters that should not be used.
We eliminated I and O because they might be
confused with 1 and 0.
That left 24 characters + 10 digits.

Positions 1 to 5 can each have 34 characters ,
position 6 can have 10

Compute number of values as 34 * 34 * 34 * 34 * 34 * 10

or 34 ^5 * 10

If I've used the calculator correctly it would be something like:

525,218,750 - 100,000 = 525,118,750

For our purpose, increasing the number of digits would
have required layout changes to every file, report,
and screen.
But changing this to character may require similar efforts.

report
• Every file with this field will need the type changed.Every program that puts this file into a hold field, screen field, report field will need to have the type changed on the field.Every program that computes a new serial number will need a code change to call a procedure to compute the new serial number.Any place where edit words or edit codes on the field will need to be changed.  But because the field is the same width, it will fit on the screens and reports.You may also be a sequencing issue if you sort or key on this field.  The letters A-Z come before 0-9.
report
• You may also be a sequencing issue if you sort or key on this field.  The letters A-Z come before 0-9.   True, but alternate sequences can be defined and used. I'd expect that most users would quickly adapt to thinking of the letters as collating after digits. Where it would get tricky would be if positions after the left-most would need to be used in the future.   It's possible only the left-most position would be needed. That position has cycled from '0' to '9' in its lifetime, i.e., ten different values. With 24 new values to use, the projected future life ought to be at least double what it's been so far.   Tom
report
• IF you change the DDS for this file to make the field larger 9P 0, Then you can just do a CHGPF command and it will not have to copy the data to the new format. Just recompile all the programs (Which you will need to do no matter what solution you choose).. If you are going to change the field type, I would suggest creating the file with SQL and using IDENTITY. That way you do not have to have logic to update the number and any Insert into the program from whatever source will automatically write the seq number.
report
• Dear All!First let me thank each one of you for your prompt response/replies to my question.Tom!The numeric field is of length (Packed  6,0).I don't have the privilege to increase the length of this field, as we have no spaces left on the screen(that's what I meant by limit/restriction). this seq# field is also part of the account number automatically generated, which is to be displayed on the screen. This account no. is also used across other applications. hence I can't go for length-increase. Charlie!I have the same to tell you that I don't have space to make the field larger viz.,9P 0. This is a kind of R & D we have to come up with a new possibility.Thanks very much,- Svanky
report
• What questions remain to be addressed?
report
• Dear All!Iam not getting anything you guys are saying.The numeric field is of length (Packed  6,0). I don’t have the privilege to increase the length of this field, as we have no spaces left on the screen. This is also used across other applications. hence I can’t go for length-increase. I can only change it's data-type to char.What I know that I need a logic to build the above requirement(which is in my initial question)? Any thoughts/help(if somebody has already implemented this logic else-where; may be field-length would have been different; doesn't matter) would be greatly appreciated.Thanks -Svanky
report
• Yes, change the data type to character everywhere. It has to be changed in any other file that links to this file, too, not just display or print files.   There will be one or more programs that create new account numbers. In those programs, the account number should be created in a DS that is six bytes long. The first byte will be a 1-byte character subfield. The remaining five bytes will be a zoned decimal subfield. You will increment that field when you create a new account.   When the subfield goes past 99999, it will overflow. You will want to ensure that it's set back to zero when it overflows.   Also on overflow, you'll check the first byte to see if it's "9". If it is, you'll change it to be "A". If it's already "A", you'll set it to "B". If it's "B", set it to "C"... etc.   I'd probably create a 2-dimensional array that has 24 rows and is two elements wide. Each element will be 1 byte. The first element will have values "9", "A", "B", etc.; and the second will have "A", "B", "C", etc.
9 A
A B
B C
C D
...etc.
Do a %lookup() on the first byte of the account number when overflow happens, and use the second element as the new account number first byte.  Tom
report
• Sorry, I don't have the code available but it was something like this:
H DEBUG(*YES)   DFTACTGRP(*NO)
D
D SerialNum       S              6a   inz('ABC999')
*Prototype
D Increment       PR             6a
D  SerialNum                     6a
/FREE
SerialNum = Increment(serialNum);
*INLR = *ON;
RETURN;
/END-FREE
// ------------------------------
// -- Increment module -- adds 1 to serial number
// ------------------------------
P Increment       B
D Increment       PI             6a
D  SerialIn                      6A

D SerialNumDS     DS
D SerialNum                      6a
D SNA                            1a   overlay(SerialNum) dim(6)

D D34DS           DS
D D20V                          20A   INZ('0123456789ABCDEFGHJK')
D D14V                          14A   INZ('LMNPQRSTUVWXYZ')
D D34                            1    DIM(34) OVERLAY(D34DS)
D
D D10DS           DS
D D10V                          10A   INZ('0123456789')
D D10                            1    DIM(10) OVERLAY(D10DS)
D
D dig             S              1S 0
D pos             S              2S 0
/Free
SerialNum = SerialIn;
// assumes   last three can only be numeric
For dig = 6 downto 4 by 1;
pos = %lookup(sna(dig):D10   ) + 1;
if pos <= %ELEM(D10);
sna(dig) = d10(pos);
return SerialNum;  // bug out with new number;
else;
sna(dig) = d10( 1 ); // loop and increment next digit
endif;
Endfor;

//assumes   first three can be alpha/numeric
For dig = 3 downto 1 by 1;
pos = %lookup(sna(dig):D34   ) + 1;
if pos <= %ELEM(D34);
sna(dig) = d34(pos);
return SerialNum;  // bug out with new number;
else;

sna(dig) = d34( 1 );
endif;
EndFor;
if SerialNum = '000000';
SerialNum = '000001';
endif;
Return SerialNum;
/END-FREE
P Increment       E

report
• it looked normal when I submitted it
D34DS           DS
D D20V                          20A   INZ(’0123456789ABCDEFGHJK’)
D D14V                          14A   INZ(‘LMNPQRSTUVWXYZ’)
D D34                            1    DIM(34) OVERLAY(D34DS)
D D10                            1    DIM(10) OVERLAY(D34DS)