Page 1 of 1

Match 2 files with key range

PostPosted: Mon Aug 31, 2009 12:31 pm
by j2422tw
Dear all:

I've a problem when using SORT to resolve my file matching.

The first file is :
----+----1----+----2----+----3----+----4
001000000001        001009999999       A
013000004475        013000004479       B
013000005100        013000005100       C
022010033447        022010033447       D
030200013570        030200013579       E
040000000005        040000000005       F
050000000006        050000000006       G


The second file is :

----+----1----+----2----+----3----+----4
001000000123       HELLO
012000003350       PEN
013000005100       BOOK
022010033447       COMPUWARE
030200013573       ASUS
040000000004       FLOWER
050000000006       GOOGLE


The output will be :

----+----1----+----2----+----3----+----4
001000000123       HELLO          A
013000005100       BOOK           C
022010033447       COMPUWARE      D
030200013573       ASUS           E
050000000006       GOOGLE         G


I using the second file's key (column 1 to 12) to match the first file's key range(from column 1,12 to column 21,32), if the second file's key is in key range of first file, then combine the data to output.

The two files is FB and length is 40, and the key and key range are number.

Could it be done by SORT?

Thanks a lot,
Jerry

Re: Match 2 files with key range

PostPosted: Fri Sep 04, 2009 3:39 pm
by j2422tw
Refer Skolusu's solution, I make a example , maybe is not very well, share to everyone:
//STEP0100 EXEC PGM=ICETOOL                           
//TOOLMSG  DD SYSOUT=*                               
//DFSMSG   DD SYSOUT=*                               
//IN1      DD *                                       
001000000001        001009999999       A             
013000004475        013000004479       B             
013000005100        013000005100       C             
022010033447        022010033447       D             
030200013570        030200013579       E             
040000000005        040000000005       F             
050000000006        050000000006       G             
//IN2      DD *                                       
001000000123       HELLO                             
001000010123       HELLO-1                           
001000200123       HELLO-3                           
001003000123       HELLO-5                           
011003000123       HELLO-7                           
012000003350       PEN                               
013000005100       BOOK                               
022010033447       COMPUWARE                                         
030200013573       ASUS                                             
040000000004       FLOWER                                           
050000000006       GOOGLE                                           
//TEMP1    DD DSN=&&TEMP1,DISP=(MOD,PASS),SPACE=(CYL,(1,1),RLSE)     
//OUT1     DD SYSOUT=*                                               
//TOOLIN   DD *                                                     
  COPY FROM(IN1) TO(TEMP1) USING(CTL1)                               
  COPY FROM(IN2) TO(TEMP1) USING(CTL2)                               
  SORT FROM(TEMP1) USING(CTL3)                                       
//CTL1CNTL DD *                                                     
  SORT FIELDS=COPY                                                   
  OUTFIL OUTREC=(1,12,27X,40,1,C'1',/,                               
                21,12,27X,40,1,C'3')                                 
//CTL2CNTL DD *                                                     
  SORT FIELDS=COPY                                                   
  OUTFIL OUTREC=(1,40,C'2')                                         
//CTL3CNTL DD *                                                       
  SORT FIELDS=(1,12,CH,A,41,1,CH,A)                                   
    OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(41,1,ZD,EQ,1),                   
                              END=(41,1,ZD,EQ,3),                     
                   PUSH=(42:41,1,40,1))                               
    OUTFIL FNAMES=OUT1,BUILD=(1,34,43,1,5X),INCLUDE=(41,2,ZD,EQ,21)   
//                                                                     


The output is :

001000000123       HELLO          A
001000010123       HELLO-1        A
001000200123       HELLO-3        A
001003000123       HELLO-5        A
013000005100       BOOK           C
022010033447       COMPUWARE      D
030200013573       ASUS           E
050000000006       GOOGLE         G


Many thank Frank & Skolusu's comtibution for this forum, you give me many enlightenment.

Jerry