|
View previous topic :: View next topic
|
| Author |
Message |
lokeshwar_manoharan
New User
Joined: 22 Sep 2008 Posts: 49 Location: Chennai,Tamilnadu
|
|
|
|
I have a requirement
In my input file:
I need to get records based a condition such
1) a record should be picked by a condition (5-9 characters should be 'PLUS') and written to output file
2) The immediate subsequent record should also be written to output file(without any condition)
Any solution to this requirement? |
|
| Back to top |
|
 |
Alissa Margulies
SYNCSORT Support
Joined: 25 Jul 2007 Posts: 496 Location: USA
|
|
|
|
lokeshwar,
Is 'PLUS' included in the first record of the file? If so, assuming the input file is FB/80, you can code the following:
| Code: |
//SYSIN DD *
SORT FIELDS=COPY
OUTREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(5,4))
OUTFIL INCLUDE=(81,8,ZD,EQ,1),BUILD=(1,80) |
|
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
lokeshwar,
It would be better if you post some sample input/output records. |
|
| Back to top |
|
 |
lokeshwar_manoharan
New User
Joined: 22 Sep 2008 Posts: 49 Location: Chennai,Tamilnadu
|
|
|
|
Input
| Code: |
PLUS STUDENT SSN 000-09-6843
11111111 F EFF 032408-000000 AGD 0531
PLUS STUDENT SSN 000-09-6842
22222222 F EFF 032408-000000 AGD 0531
32222222 F EFF 032408-000000 AGD 0531
42222222 F EFF 032408-000000 AGD 0531
PLUS STUDENT SSN 000-09-6842
52222222 F EFF 032408-000000 AGD 0531
|
Output should be
| Code: |
PLUS STUDENT SSN 000-09-6843
11111111 F EFF 032408-000000 AGD 0531
PLUS STUDENT SSN 000-09-6842
22222222 F EFF 032408-000000 AGD 0531
PLUS STUDENT SSN 000-09-6842
52222222 F EFF 032408-000000 AGD 0531
|
ie whenever a record has PLUS in 5th position should be written and also the immediate record should also be written to output file |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
lokeshwar,
Try this SYNCTOOL job.
| Code: |
//STEP01 EXEC PGM=SYNCTOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN= Input file ---- FB,LRECL=80
//T1 DD DSN=&&T1,DISP=(,PASS)
//OUT DD SYSOUT=*
//TOOLIN DD *
COPY FROM(IN) TO(T1) USING(CTL1)
SELECT FROM(T1) TO(OUT) ON(81,8,CH) ALLDUPS USING(CTL2)
//CTL1CNTL DD *
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(81:SEQNUM,8,ZD)),
IFTHEN=(WHEN=(5,4,CH,EQ,C'PLUS'),
OVERLAY=(81:81,8,ZD,ADD,+1,M11,LENGTH=8))
//CTL2CNTL DD *
OUTFIL BUILD=(1,80)
/* |
OUT
| Code: |
PLUS STUDENT SSN 000-09-6843
11111111 F EFF 032408-000000 AGD 0531
PLUS STUDENT SSN 000-09-6842
22222222 F EFF 032408-000000 AGD 0531
PLUS STUDENT SSN 000-09-6842
52222222 F EFF 032408-000000 AGD 0531 |
|
|
| Back to top |
|
 |
Alissa Margulies
SYNCSORT Support
Joined: 25 Jul 2007 Posts: 496 Location: USA
|
|
|
|
lokeshwar,
While Arun's SYNCTOOL application will work, it passes the data twice. The SORT step that I previously provided will only pass the data once. If your input is small, then the performance difference is negligible. However, if you have a significant amount of data, then this may be an issue. |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
Alissa,
The syncsort job provided by you works perfectly for the sample input given above; but I believe it may not give the desired results when the input looks like the one below. I can't test this as I m out of office now Corrections are welcome.
| Code: |
----+----+----+----+----+----+----+--
PLUS STUDENT SSN 000-09-6843
11111111 F EFF 032408-000000 AGD 0531
PLUS STUDENT SSN 000-09-6842
22222222 F EFF 032408-000000 AGD 0531
32222222 F EFF 032408-000000 AGD 0531
42222222 F EFF 032408-000000 AGD 0531
PLUS STUDENT SSN 000-09-6842
52222222 F EFF 032408-000000 AGD 0531
52222223 F EFF 032408-000000 AGD 0531
52222224 F EFF 032408-000000 AGD 0531
52222225 F EFF 032408-000000 AGD 0531 |
|
|
| Back to top |
|
 |
Alissa Margulies
SYNCSORT Support
Joined: 25 Jul 2007 Posts: 496 Location: USA
|
|
|
|
Arun,
That is correct. I only gave a solution for what the OP specifically asked for, based on the sample input records. My solution will not work with your sample data. For your example, you can code the following:
| Code: |
//SYSIN DD *
INREC IFTHEN=(WHEN=(5,4,CH,EQ,C'PLUS'),OVERLAY=(81:C'1')),
IFTHEN=(WHEN=NONE,OVERLAY=(81:C'2'))
SORT FIELDS=COPY
OUTREC OVERLAY=(82:SEQNUM,8,ZD,RESTART=(81,1))
OUTFIL INCLUDE=(82,8,ZD,EQ,1),BUILD=(1,80) |
|
|
| Back to top |
|
 |
Alissa Margulies
SYNCSORT Support
Joined: 25 Jul 2007 Posts: 496 Location: USA
|
|
|
|
This application will address all 3 scenarios using SyncSort:
| Code: |
//SYSIN DD *
INREC IFTHEN=(WHEN=(INIT),OVERLAY=(81:SEQNUM,8,ZD)),
IFTHEN=(WHEN=(5,4,CH,EQ,C'PLUS'),OVERLAY=(89:C'1')),
IFTHEN=(WHEN=NONE,OVERLAY=(89:C'2'))
SORT FIELDS=COPY
OUTREC OVERLAY=(90:SEQNUM,8,ZD,RESTART=(89,1))
OUTFIL OMIT=((89,1,ZD,EQ,2,AND,81,8,ZD,EQ,1),OR,
(90,8,ZD,NE,1)),BUILD=(1,80) |
|
|
| Back to top |
|
 |
lokeshwar_manoharan
New User
Joined: 22 Sep 2008 Posts: 49 Location: Chennai,Tamilnadu
|
|
|
|
Thanks man its working. But I can't get what this is doing. Can u please tell in brief?
| Code: |
//CTL1CNTL DD *
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(81:SEQNUM,8,ZD)),
IFTHEN=(WHEN=(5,4,CH,EQ,C'PLUS'),
OVERLAY=(81:81,8,ZD,ADD,+1,M11,LENGTH=8))
|
|
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
lokeshwar,
The first IFTHEN inserts an 8 digit sequence number 1,2,3.... at 81st position. The second IFTHEN increments the sequence number by 1 wherever it encounters a 'PLUS' at 5th pos. For your sample input the temporary dataset T1 will have something like this.
| Code: |
----+----+----+----+----+----+----+-- pos-81
PLUS STUDENT SSN 000-09-6843 00000002
11111111 F EFF 032408-000000 AGD 0531 00000002
PLUS STUDENT SSN 000-09-6842 00000004
22222222 F EFF 032408-000000 AGD 0531 00000004
32222222 F EFF 032408-000000 AGD 0531 00000005
42222222 F EFF 032408-000000 AGD 0531 00000006
PLUS STUDENT SSN 000-09-6842 00000008
52222222 F EFF 032408-000000 AGD 0531 00000008 |
From T1, the SELECT operator copies only those records which have duplicate entries at 81st pos which is exactly what you need. The final BUILD discards the sequence numbers which we dont need any more. |
|
| Back to top |
|
 |
lokeshwar_manoharan
New User
Joined: 22 Sep 2008 Posts: 49 Location: Chennai,Tamilnadu
|
|
|
|
Thanks a lot..!!
Lokesh |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|