IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Help with WHEN=GROUP,BEGIN=


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
techslam

New User


Joined: 03 Dec 2010
Posts: 87
Location: India

PostPosted: Thu Jul 24, 2014 12:34 pm
Reply with quote

I have below input record
Code:

----+----1----+
BLUEJAY     10
BLUEJAY     20
BLUEJAY     60
BLUEJAY     60
RAVEN       10
RAVEN       20
RAVEN       60
FINCH       10
FINCH       60
FINCH       60
FINCH       60
FINCH       60
BLUEJAY     60
SPARROW     60
SPARROW     60
EAGLE       60
EAGLE       60
CROW        10
CROW        20
CROW        60
CROW        60


Records are in group with position (1,12) being the key field for each group. Group starts with' 10' and ends with '60' in position (13,2).
Group can have multiple '60' type records and the last 60 type records will be the end of group.
So, below BLUEJAY is a group.
Code:

BLUEJAY     10
BLUEJAY     20
BLUEJAY     60
BLUEJAY     60


However , BLUEJAY at 13th record does not have any record type 10, but only 60 type record.

My requirement is to identify all such records which does not have a 10 type record , but they have only 60 type record.

So my output will be as below -

Code:

BLUEJAY     60
SPARROW     60
SPARROW     60
EAGLE       60
EAGLE       60


i have tried a lot of but unable to figure out to get this done.
Any help will be highly appreciated.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Jul 24, 2014 2:17 pm
Reply with quote

You can have multiple conditions on on BEGIN. You can have multiple IFTHEN=(WHEN=GROUP. You can have IFTHEN=(WHEN=INIT to do something unconditionally.

If you use your existing GROUP but include a SEQ, you can establish a second group where the SEQ-field is equal to one, and the record-type is not equal to ten. Push a flag to indicate those. Since you can't PUSH a constant, add the flag to the temporarily extended record first, then PUSH that to a new position. You should then be able to identify individual, or groups of, disconnected 60s. Except in one situation.

This is where a 60 is actually disconnected (however that happened) but is coincidentally adjactend to a 10 or another 60 for the same referenece. See if you can create those, then see if you can identify them.
Back to top
View user's profile Send private message
magesh23586

Active User


Joined: 06 Jul 2009
Posts: 213
Location: Chennai

PostPosted: Fri Jul 25, 2014 12:36 am
Reply with quote

Here is the code for you.

Code:

//S1 EXEC PGM=SORT       
//SYSOUT DD SYSOUT=*     
//SORTIN DD *             
BLUEJAY     10           
BLUEJAY     20           
BLUEJAY     60           
BLUEJAY     60           
RAVEN       10           
RAVEN       20           
RAVEN       60           
FINCH       10           
FINCH       60           
FINCH       60           
FINCH       60           
FINCH       60           
BLUEJAY     60           
SPARROW     60           
SPARROW     60           
EAGLE       60                                                       
EAGLE       60                                                       
CROW        10                                                       
CROW        20                                                       
CROW        60                                                       
CROW        60                                                       
/*                                                                   
//SORTOUT DD SYSOUT=*                                               
//SYSIN DD *                                                         
  INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,12),END=(14,2,ZD,LE,61),     
               PUSH(15:1,12)),                                       
        IFTHEN=(WHEN=GROUP,BEGIN=(15,1,CH,NE,C' '),                 
               END=(13,2,CH,NE,C'60'),                               
               PUSH(35:ID=1))                                       
  OPTION COPY                                                       
  OUTFIL INCLUDE=((15,1,CH,NE,C' ',                                 
                 AND,13,2,CH,NE,C'10'),OR,(35,1,CH,NE,C' ',         
                 AND,13,2,CH,NE,C'10')),                             
         BUILD(1,14)                                                 
/*                                                                   


Hope this helps...
Back to top
View user's profile Send private message
magesh23586

Active User


Joined: 06 Jul 2009
Posts: 213
Location: Chennai

PostPosted: Fri Jul 25, 2014 11:28 am
Reply with quote

FYI..
PUSH(15:1,12)), or PUSH(15:ID=1)), both will work.
PUSH(15:ID=1)) is better..

Thanks
Magesh
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Jul 25, 2014 5:52 pm
Reply with quote

magesh23586,

Your code works, here's a simplification:

Code:
 OPTION COPY
 INREC IFTHEN=(WHEN=GROUP,
                 KEYBEGIN=(1,12),
                 RECORDS=1,
                 PUSH(15:1,12)),
       IFTHEN=(WHEN=GROUP,
                 BEGIN=(15,1,CH,NE,C' ',
                       AND,
                        13,2,CH,EQ,C'60'),
                 END=(13,2,CH,NE,C'60'),
                 PUSH(35:ID=1))
 OUTFIL OMIT=(35,1,CH,EQ,C' ',
             OR,
              13,2,CH,NE,C'60'),
        BUILD(1,14)


Your first GROUP will always end after one record, it is marking the first of a group. So use RECORDS=1, not END= (where did you get LE,C'61' from?).

The GROUPs we are interested in are those that start with 60, so the second GROUP can be limited to that. This will simplify the OUTFIL. The "end" of the GROUP can, however, go beyond the key, but not a problem, so we need to deal with that.

Using OMIT= makes the OUTFIL easier to follow. Now excludes all records not marked by the second GROUP, and those marked by the second GROUP which are not 60.

The ID=1 is fine for the first GROUP, and the second, because all we need to know is ID or not ID, it does not matter if it overflows (more than nine groups).

techslam,

To see how this is working, comment out the entire OUTFIL.

Once you are happy that you understand it, you can change the first PUSH to an ID=1 and change the location of the second PUSH to immediately after that ID, and change the position of the OMIT= to that position (16 in the example).

Assuming you are trying to find data errors, remember that it might be possible for a 60 to coincidentally appear in the "right" place, and it will not be possible to code for that from what we know. If there is something somewhere which tells how many 60s there should be for a 10, that should be included in this.
Back to top
View user's profile Send private message
magesh23586

Active User


Joined: 06 Jul 2009
Posts: 213
Location: Chennai

PostPosted: Sat Jul 26, 2014 11:16 am
Reply with quote

Bill Woodger wrote:
Your first GROUP will always end after one record, it is marking the first of a group. So use RECORDS=1, not END= (where did you get LE,C'61' from?).


LE,C'61' is just a negative condition to stop/end with one record, RECORDS=1 does the same, Thanks for the suggestion. I was little rush while coding doesn't strike to me.

Bill Woodger wrote:
Using OMIT= makes the OUTFIL easier to follow. Now excludes all records not marked by the second GROUP, and those marked by the second GROUP which are not 60.


I don't recommend OMIT, Its always confusing.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Compare latest 2 rows of a table usin... DB2 1
No new posts Problem with IFTHEN=(WHEN=GROUP,BEGIN... DFSORT/ICETOOL 5
No new posts Splitting group records based on deta... DFSORT/ICETOOL 8
No new posts SORT HELP - SORT A COLUMN and GROUP B... DFSORT/ICETOOL 9
No new posts INCLUDE COND with WHEN=GROUP SYNCSORT 12
Search our Forums:

Back to Top