Focal Point
[SOLVED]Generating alphanumeric values in Mainframe Focus

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/7331082213

January 02, 2009, 07:14 AM
Shrikant
[SOLVED]Generating alphanumeric values in Mainframe Focus
Hi,

I am in need to convert the order numbers (from 00001 to 99999) present in numeric format to alphanumeric format starting from (A001...A009...A00A...A00Z...A010...A019...A01A...A01Z...A020 and so on).

Is there a in-built function in Focus to provide similar results.

Thanks,
Shrikant

This message has been edited. Last edited by: Shrikant,


FOCUS 7.2.3
Platform: IBM system Z9 Business class
O/P formats: Flat files, excel and CSV files
January 02, 2009, 08:31 AM
FrankDutch
Shrikant

It's not the same but I started a question some years ago about converting numbers to binair and hexadecimal.

You may find that usefull for your problem

take a look here




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

January 02, 2009, 09:40 AM
<JG>
To convert from Base 10 (decimal) to any other base up to and including Base 36 which is what is wanted.

 
-SET &base=36;
-SET &num = 99999;  
-*
-SET &string   = '0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z';
-SET &value   = '' ;
-* 
-REPEAT ENDREPEAT WHILE &num NE 0;
-SET &div = &num / &base;
-SET &rem = &num - (&div * &base);
-SET &token = &rem + 1;
-SET &char = GETTOK(&string, 71, &token.EVAL, ',', 1, 'A1');
-SET &value = '&char.EVAL' || '&value.EVAL';
-SET &num = ÷
-ENDREPEAT
-TYPE &value


It's only possible in DM unless you write a subroutine.

However using an outer loop you could read, convert and re-write a data file.

can process numbers from 1 to 99999999

This message has been edited. Last edited by: <JG>,
January 05, 2009, 07:09 AM
<JG>
Just for a bit of fun this converts any 2 to 36 base to any other 2 to 36 base
(The limitations for DM numerics still apply)

 
-SET &basein=16;
-SET &baseout=8;
-SET &numin = AAAAA;
-DEFAULTH &numout = 0
-*
-SET &stringin   = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
-SET &stringout   = '0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z';
-SET &value   = '' ;
-*
-SET &tpos=&numin.LENGTH +1;
-SET &power= &numin.LENGTH;
-SET &partno=1;
-REPEAT BASEIN WHILE &partno NE &tpos;
-SET &part = SUBSTR(&numin.LENGTH, '&numin.EVAL', &partno, &partno, 1, 'A1');
-SET &mod = POSIT(&stringin, 36, '&part.EVAL', 1, 'I2');
-SET &valout = 0;
-SET &valout = ((&mod -1) * (&basein ** (&power -1)));
-SET &numout = &numout + &valout;
-SET &power = &power -1;
-SET &partno=&partno + 1;
-BASEIN
-*
-REPEAT BASEOUT WHILE &numout NE 0;
-SET &div = &numout / &baseout;
-SET &rem = &numout - (&div * &baseout);
-SET &token = &rem + 1;
-SET &char = GETTOK(&stringout, 71, &token.EVAL, ',', 1, 'A1');
-SET &value = '&char.EVAL' || '&value.EVAL';
-SET &numout = ÷
-BASEOUT

-TYPE &value

January 05, 2009, 02:55 PM
j.gross
Here's JG's approach, coded in Define for the problem at hand.
DEFINE FILE yourfile
 BASE/I2=36;
 CHARS/A36='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';

 I/I10=NUMBER;
 Z/I2 = IMOD(I,BASE,'I2');
 I=INT(I/BASE);
 Y/I2 = IMOD(I,BASE,'I2');
 I=INT(I/BASE);
 X/I2 = IMOD(I,BASE,'I2');
 XX/A1=SUBSTR(36,CHARS,X+1,X+1,1,'A1');
 YY/A1=SUBSTR(36,CHARS,Y+1,Y+1,1,'A1');
 ZZ/A1=SUBSTR(36,CHARS,Z+1,Z+1,1,'A1');
 CODE/A4='A' | XX | YY |ZZ;
 CHECK/I10 = X*BASE*BASE + Y*BASE + Z;
END
TABLE FILE yourfile
 LIST NUMBER X  Y  Z  CODE  CHECK
END

NUMBER is the incoming value (integer);
CODE is the resulting Axxx value.
For a code scheme with three base-36 digits, the maximum encodable Number is 46655.


- Jack Gross
WF through 8.1.05
January 06, 2009, 04:58 AM
Shrikant
Thanks all for your responses.

I have implemented JG's and Jack's code successfully. I have done a slight modification to Jack's code as mentioned below to meet the actual requirement.

  
DEFINE FILE file
BASE/I2=36;
CHARS/A36='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
I/I10=NUMBER;
Z/I2 = IMOD(I,BASE,'I2');
I=INT(I/BASE);
Y/I2 = IMOD(I,BASE,'I2');
I=INT(I/BASE);
X/I2 = IMOD(I,BASE,'I2');
I=INT(I/BASE);
W/I2 = IMOD(I,BASE,'I2');
WW/A1=SUBSTR(36,CHARS,W+11,W+11,1,'A1');
XX/A1=SUBSTR(36,CHARS,X+1,X+1,1,'A1');
YY/A1=SUBSTR(36,CHARS,Y+1,Y+1,1,'A1');
ZZ/A1=SUBSTR(36,CHARS,Z+1,Z+1,1,'A1');
CODE/A4= WW | XX | YY |ZZ;
END

TABLE FILE file
PRINT CODE
BY NUMBER
END


Thanks again for all your help!!

-Shrikant


FOCUS 7.2.3
Platform: IBM system Z9 Business class
O/P formats: Flat files, excel and CSV files
January 06, 2009, 05:05 AM
Shrikant
I would also like to hear from you guys if this can be met without a input file, meaning FOCUS actually generating the similar alphanumeric values to a certain defined limit instead of converting the numbers stored in a data file.


FOCUS 7.2.3
Platform: IBM system Z9 Business class
O/P formats: Flat files, excel and CSV files
January 06, 2009, 06:23 AM
<JG>
Just use an outer loop using a WHILE value and increase the number processed
by the required step interval.

 
-SET &base=36;
-SET &number = 0;  
-SET &step = 5;
-SET &limit = 1000;
-*
-SET &string   = '0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z';
-* 
-REPEAT ENDLOOP WHILE &number LT &limit;
-SET &value   = '' ;
-SET &number = &number + &step;
-SET &num = &number;
-REPEAT ENDREPEAT WHILE &num NE 0;
-SET &div = &num / &base;
-SET &rem = &num - (&div * &base);
-SET &token = &rem + 1;
-SET &char = GETTOK(&string, 71, &token.EVAL, ',', 1, 'A1');
-SET &value = '&char.EVAL' || '&value.EVAL';
-SET &num = ÷
-ENDREPEAT
-TYPE Decimal .. &number -- Base 16 &value
-ENDLOOP