ojdiaz
New User
Joined: 19 Nov 2008 Posts: 98 Location: Spain
|
|
|
|
Maybe this seems simple, but I've had spend quite some time trying to figure how to do this with a SORT/ICTOOL and i can't seem to figure how how.
I have an input file of 20 bytes FB LRECL like this example:
Code: |
key aaa ky2 ddddddd
001 xxx 000 xxxxxxx
001 xxx 001 xxxxxxx
001 xxx 002 xxxxxxx
001 xxx 003 xxxxxxx
001 xxx 004 xxxxxxx
002 xxx 000 xxxxxxx
002 xxx 001 xxxxxxx
002 xxx 002 xxxxxxx
003 xxx 001 xxxxxxx
003 xxx 002 xxxxxxx
003 xxx 004 xxxxxxx
004 xxx 099 xxxxxxx
005 xxx 010 xxxxxxx
005 xxx 015 xxxxxxx
|
I have a key field in bytes 1 trhough 3, and a secod key in in bytes 9 trhough 12
I need to split the file and put the first record from each key1 group into a file, and the rest of the records in the other. The outputs should look like this:
Output File 1
Code: |
001 xxx 000 xxxxxxx
002 xxx 000 xxxxxxx
003 xxx 001 xxxxxxx
004 xxx 099 xxxxxxx
005 xxx 010 xxxxxxx
|
Output File 2
Code: |
001 xxx 001 xxxxxxx
001 xxx 002 xxxxxxx
001 xxx 003 xxxxxxx
001 xxx 004 xxxxxxx
002 xxx 001 xxxxxxx
002 xxx 002 xxxxxxx
003 xxx 002 xxxxxxx
003 xxx 004 xxxxxxx
005 xxx 015 xxxxxxx
|
I though on using the COPY FIRST from ICETOOL and that works nice for the first record of each group,
Code: |
SELECT FROM(S1DQPREV) TO(S2DQTOP1) ON(1,3,CH) FIRST(1) USING(CTL2)
//CTL2CNTL DD *
SORT FIELDS=(1,3,A),FORMAT=CH |
Then using FIRSTDUP for the rest of the records:
Code: |
SELECT FROM(SQDQPREV) TO(S3DQREST) ON(1,3,CH) FIRSTDUP(999) USING(CTL2) |
However, when i Tried that, The number don't add up:
Code: |
*COPIA EL PRIMER REGISTRO PARA CADA COMBINACION OFICINA - ENTORNO
SELECT FROM(E1DQPREV) TO(S1DQTOP1) ON(1,3,CH) FIRST(1) USING(CTL2)
DFSORT CALL 0001 FOR SORT FROM E1DQPREV TO S1DQTOP1 USING CTL1CNTL COMPLETED
RECORD COUNT: 000000000000301
NUMBER OF RECORDS RESULTING FROM CRITERIA: 000000000000296
OPERATION RETURN CODE: 00
*COPIA EL RESTRO DE LOS REGISTROS
SELECT FROM(E1DQPREV) TO(S2DQREST) ON(1,3,CH) FIRSTDUP(999) USING(CTL1)
DFSORT CALL 0002 FOR SORT FROM E1DQPREV TO S2DQREST USING CTL1CNTL COMPLETED
RECORD COUNT: 000000000000301
NUMBER OF RECORDS RESULTING FROM CRITERIA: 000000000000010
OPERATION RETURN CODE: 00 |
Any advice in implementing this? I though on using HEADERS/TRAILERS from the OUTFIL operator, but i'm still elarning how to use it and I might be missing something.
Thanks a lot in advance
Best regards
Oliver |
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
You were on the right track. Here's a DFSORT/ICETOOL job that will do what you asked for:
Code: |
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//S1DQPREV DD DSN=... input file
//S2DQTOP1 DD DSN=... output file1
//S3DQREST DD DSN=... output file2
//TOOLIN DD *
SELECT FROM(S1DQPREV) TO(S2DQTOP1) ON(1,3,CH) FIRST -
DISCARD(S3DQREST)
/*
|
|
|