Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
So, WHEN=GROUP with BEGIN for type 005, PUSH the entire record to get a copy at the end of the current record, SEQ=1, RECORDS=2.
OUTFIL to INCLUDE= or OMIT= the records you don't want, which are when the SEQuence field is 1, or when original record equal to 002 and PUSHed record equal to 005.
The IFTHEN=(WHEN=(logical expression to identify the 2s, and BUILD two records, PUSHED first then original, seperated by / (the slash operator). IFTHEN=(WHEN=NONE to just BUILD to original size.
Joined: 03 Dec 2007 Posts: 49 Location: United States
Thanks Rohit.
Bill, Looks like your solution would omit some of the required records.
May be the way I was asking my question is not right. Here is my question again
Input file has below set of data and first three postions are record types
001 A
002 B
005 C
002 D
005 E
002 F
003 G
003 H
003 I
004 J
005 K
002 L
005 M
099 N
I want to omit records '002' and '005' if record type 005 immediately followed by 002
Output:
001 A
002 F
003 G
003 H
003 I
004 J
005 K
099 N
A lot has already been written on this regarding your query. I suppose you may want to search the web (for your own better understanding) OR read the DFSORT manual for WHEN=GROUP (if nothing more).
So far my output is
001 A
002 B002 B
002 D002 D
002 F002 F
003 G002 F
003 H
003 I
004 J
005 K
002 L002 L
099 N
I dont want below records
---------------
001 A
002 B002 B - Not required
002 D002 D - Not required
002 F002 F
003 G002 F
003 H
003 I
004 J
005 K
002 L002 L - Not required
099 N
You seem to be on the right track. Keep in mind, Analysis comes first and then the coding. So, most of the times (if not all), we first need to think of a logic to achieve what we want.
Follow me on this:
1. Use a group of 2 records that starts with 002 and push the first 3 bytes. You will get something like this
001 A
002 002 B
005 002 C
002 002 D
005 002 E
002 002 F
003 002 G
003 H
003 I
004 J
005 K
002 002 L
005 002 M
099 N
2. Now you can easily omit records that have '002 002' and '005 002'. But that will also omit record 'F' which we don't want.
3. Now think of this: What if we write the records in the opposite order and delete/omit group of 2 records that begin with 005 in the same way we did in point 1. This time the group will begin with 005.
009 N
005 005 M
002 005 L
005 005 K
004 005 J
003 I
003 H
003 G
002 F
005 005 E
002 005 D
005 005 C
002 005 B
001 A
This will delete an additional record 'K'. Point to note: 'F' is not deleted here and 'K' was not deleted in point 1. Rest of the records that we deleted/omitted, were the records that we actually wanted to remove.
4. Now, if you do a SUM=NONE to remove duplicates on the 'addition' of sets you get from point 1 and point 3 (i.e. add them 1 after other), you should be able to get what you want.
Your code is missing the SEQ on the PUSH and the OMIT where the sequence within the group is one. Then you need a BUILD with a slash operator, /, to get any remaining doubled-up records into two separate records. I used IFOUTLEN to get all records to original length.
This is only lightly tested, as your test data is not extensive.
Since you have to do multiple things here and I am sure you would like to do all of this in a single step, let's go to our multi talented friend ICETOOL.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
RahulG31,
If you are passing the data three times, mostly there will be a better way to do it, and if not, it will be better in a general-purpose language.
Avoid actually sorting the data unless it needs to be sorted. Which leads to avoiding SUM FIELDS=NONE unless the data has to be sorted (NB, because JNFnCNTL cannot use OUTFIL, sometimes you will SORT and SUM= to arrive at data for the join itself).
@ Bill: As you said, your control card is 'lightly tested'. So, I tried to modify the input data with consecutive 002 and it didn't work there. I had input as:
Code:
001 A
002 B
005 C
002 D
002 E
005 F
099 G
and it only gave me A and G
Code:
001 A
099 G
I think we should have also got a D in the output?
Anyways, I think Venkata would be able to handle that
.