Posted: Mon May 07, 2007 6:43 pm Post subject: Want to convert Alphanumeric to Numeric for computation.
Hi all,
I am Arpit Vakharia. This is my first query on MVSForums.
I want to convert a range to a sequence. In the input I am having Min and Max as two different fields and a code. Now I want to convert the range i.e. from Min to Max one seperate record for each ZIP with same code. For eg: Consider that there are three fields:
Code:
ZIP_min ZIP_MAX Code
100 102 25
A01 A02 26.
Now in the output I want
Code:
ZIP Code
A01 25
A01 25
A02 25.
But my problem is that the range also contains the Alphanumeric fields.
Can any one please suggest some utility or some function to achieve the desired result?
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
Posted: Tue May 08, 2007 3:24 am Post subject:
I would use a COBOL solution to answer this intellectual exercise.
Code:
01 WORK-AREA.
05 BINARY-4-2 PIC S9 BINARY VALUE ZERO.
05 DISPLAY-4-2 PIC 99.
88 MAX-VAL-4-DISPLAY VALUE 99.
88 MIN-VAL-4-DISPLAY VALUE ZERO.
01 ITEM-GEN
REDEFINES
WORK-AREA.
05 FILLER PIC X(1).
05 ZIP-BUILD.
10 FIRST-CHAR PIC X(1).
88 MAX-ALPHA-VAL VALUE 'Z'.
88 MAX-NUM-VAL VALUE '9'.
88 MIN-ALPHA-VAL VALUE 'A'.
88 MIN-NUM-VAL VALUE '0'.
10 LAST-TWO PIC X(2).
:::::::::::::::::
MOVE MIN-ZIP
TO ZIP-BUILD IN ITEM-GEN
IF MAX-VAL-4-DISPLAY IN DISPLAY-4-2
THEN
SET MIN-VAL-4-DISPLAY IN DISPLAY-4-2
TO TRUE
EVALUATE TRUE
WHEN MAX-NUM-VAL IN FIRST-CHAR
SET MIN-ALPHA-VAL IN FIRST-CHAR
TO TRUE
WHEN MAX-ALPHA-VAL IN FIRST-CHAR
CONTINUE
WHEN OTHER
ADD 1
TO BINARY-4-2 IN WORK-AREA
END-EVALUATE
ELSE
ADD 1
TO DISPLAY-4-2 IN WORK-AREA
END-IF
IF ZIP-BUILD NOT > MAX-ZIP
THEN
MOVE ZIP-BUILD
TO <reference of your choice>
ELSE
SET ZIP-RANGE-COMPLETE TO TRUE
END-IF
this is predicated upon
zips are only and always 3 char
first char is alpha or numeric
first char is in range 0-9 thru A-Z and not A-Z thru 0-9
last two char are always numeric in the range 00 to 99
i consider this an intellectual exercise, because I don't know of any reason to expand the ranges.
in addition, at least take the time to post your question accurately. you output example is garbage. _________________ Dick Brenholtz
American living in Varel, Germany
Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
Posted: Tue May 08, 2007 1:01 pm Post subject:
Quote:
Now in the output I want the complete range from A0A0A0 to A0A9Z9 in different row for each ZIP with the same CODE (454).
It's not clear to me what you mean by the "complete range from A0A0A0 to A0A9Z9". Is the output Kolusu shows what you want? If not, please show the output records you would expect for your input record example, and explain exactly what you mean by the "range". _________________ Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
Posted: Tue May 08, 2007 1:59 pm Post subject:
don't think there is an international standard. depends on the country. some demand that there only be alpha in a certain char pos and some mix it. original poster seemed to indicate that there is no mixing.
I've had to play with zip code look-ups within 'ranges' for calculating transportation costs to countries other than the USA with their all numeric scheme. can be a lot of fun when the range file is generated and sorted in ascii and then transmitted to the mainframe. _________________ Dick Brenholtz
American living in Varel, Germany
Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
Posted: Tue May 08, 2007 2:24 pm Post subject:
Arpit Vakharia,
Does your input file have only one record with MIN and MAX for which you want the range, or does your input file have multiple records with MIN and MAX for each of which you want the range? _________________ Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
Posted: Thu May 10, 2007 4:24 am Post subject:
not a sort solution, but:
Code:
/* REXX */
/* */
/* */
/* */
/* */
/* */
/* remove the following three lines and remove the */
/* comment sentinals from the ARG when this is to */
/* be a callable routine */
zip_start = 'X9Z9Z9'
zip_end = 'Z9Z9Z9'
code_to_propagate = 453
/* */
/* ARG(zip_start, zip_end, code_to_propagate) */
/* */
zip_build = ''
/* */
/* used the asc-dec equivalant of the letter 'A' to */
/* build the alpha.tab. since it was easier */
/* */
DO i=1 to 26
alpha_tab.i = D2C(C2D('A') + (i-1))
END
pgm_ctr = 0 /* number of records generated */
/* */
/* ctl_tab to keep track of char pos and type */
/* */
ctl_tab.1 = 'A' /* alpha for pos 1 */
ctl_tab.2 = 'N' /* numeric for pos 2 */
ctl_tab.3 = 'A' /* alpha for pos 3 */
ctl_tab.4 = 'N' /* numeric for pos 4 */
ctl_tab.5 = 'A' /* alpha for pos 5 */
ctl_tab.6 = 'N' /* numeric for pos 6 not used */
/* */
PARSE VAR zip_start 1 zip_wrk.1 +1 zip_wrk.2 +1 zip_wrk.3 +1 zip_wrk.4 +1 zip_wrk.5 +1 zip_wrk.6 +1
zip_wrk.0 = 6
zip_build = ''
DO WHILE zip_build < zip_end
zip_wrk.6 = zip_wrk.6 + 1
IF zip_wrk.6 > 9 THEN
DO
zip_wrk.6 = 0
adder = 1
END
ELSE
adder = 0
DO i=5 to 1 BY -1
SELECT
WHEN ctl_tab.i = 'A' THEN
/* */
/* char is alpha */
/* */
IF adder > 0 THEN
DO
/* instead of scaning alpha.tab to find the letter, use C2D to set */
/* the index */
p = C2D(zip_wrk.i) - C2D('A') + 1
IF p > 25 THEN
DO
p = 1
adder = 1
END
ELSE
DO
p = p + 1
adder = 0
END
zip_wrk.i = alpha_tab.p
END
OTHERWISE
/* */
/* char is numeric */
/* */
DO
IF adder > 0 THEN
DO
zip_wrk.i = zip_wrk.i + adder
adder = 0
IF zip_wrk.i > 9 THEN
DO
zip_wrk.i = 0
adder = 1
END
END
END
END
END
zip_build = ''
DO i=1 to zip_wrk.0
zip_build = zip_build || zip_wrk.i
END
zip_build = zip_build || ' ' || code_to_propagate
pgm_ctr = pgm_ctr + 1
SAY zip_build /*<<<<<<<<<<<<<<<<this is the place to output the record */
END
SAY pgm_ctr 'Records Generated'
EXIT
/* */
/* END OF REXX */
_________________ Dick Brenholtz
American living in Varel, Germany
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum