MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

KEYBEGIN and BEGIN in SORT

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
Magesh_J
Intermediate


Joined: 21 Jun 2014
Posts: 259
Topics: 54

PostPosted: Fri Feb 16, 2018 6:49 pm    Post subject: KEYBEGIN and BEGIN in SORT Reply with quote

Hi,

I am trying to create sort code for following requirement.


Field1 - 1,5,ZD
Field2 - 29,3,CH
Date1 - 21,4,PD
Date2 - 25,4,PD
Field5 - 40,9,CH
Field6 - 38,2,PD
Months - 77,2,PD


Code:

Field1 Field2   DATE1  DATE2   Field5     Field6      Months
12345  99       214037 214037                          72
12345  88                       000000000  986         72 
12345  88                       000000000  987         72
12345  30F      217026 217026                          72
12346  99       214037 214037                          72
12346  88                       000001239  986         72
12346  88                       000000000  987         72
12346  30F      217026 217026                          72
12347  99       214037 214037                          60
12347  88                       000001239  986         60
12347  88                       000001238  987         60
12347  30F      217026 217026                          60
12348  99       214037 214037                          60
12348  88                       000001239  986         60
12348  88                       000001238  987         60
12348  40F      217026 217026                          60


From the input following fields has to be derived

DATE3 = DATE2(99 FIELD2) + Months
DATE4 = DATE3 - DATE1(30F field2)


Conditions :
1.Only one record for each account in the output.
2.If the account has 0000000 in both the fields of Field5(986 and 987), the account should be exculded. (Example Field1 12345)
3.the account should have Date4 > 15 Days
4.If the account dont have 30F then record should be excluded (Example Field1 12348)

Output I should have following fields in edited format with CSV.

FIELD1 FIELD2(30F) DATE3(Derived field) DATE2(99 FIELD2) DATE4(should be in Days format).


IS it correct to have KEYBEGIN and BEGIN or do we have any other method to push the record to the last record of the account
example
Code:

IFTHEN=(when=group,keybegin=(1,5),begin=(29,3,ch,eq,C'99 '),
Push=(21:21,4)),
IFTHEN=(when=group,keybegin=(1,5),begin=(29,3,ch,eq,C'88 ',and,38,2,pd,eq,986),
Push=(133:40,9)),
IFTHEN=(when=group,keybegin=(1,5),begin=(29,3,ch,eq,C'88 ',and,38,2,pd,eq,987),
Push=(142:40,9)),


Is there way in the sort to add months from the give date in format (CYYDDD)
Is there way in the sort to find the day's difference from the give date format (CYYDDD)


Thanks
Magesh
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12359
Topics: 75
Location: San Jose

PostPosted: Fri Feb 16, 2018 9:18 pm    Post subject: Reply with quote

Magesh_J,

You cannot use both BEGIN and KEYBEGIN at the same time. If I understand your requirement correctly then you can do it differently. Also looks like your dates are of really weird format like in this topic

https://www.mvsforums.com/helpboards/viewtopic.php?t=12415

So use the following DFSORT Control Cards (untested)
Code:

//SYSIN    DD *                                                   
  OPTION COPY                                                     
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(29,3,CH,EQ,C'99'),             
          PUSH=(81:21,04)),                                       
        IFTHEN=(WHEN=(38,2,PD,EQ,986,AND,40,9,ZD,EQ,0),           
       OVERLAY=(85:C'N')),                                       
        IFTHEN=(WHEN=(38,2,PD,EQ,987,AND,40,9,ZD,EQ,0),           
       OVERLAY=(86:C'N'))                                         
                                                                 
  OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(38,2,PD,EQ,986),               
           PUSH=(085:085,1)),                                     
         IFTHEN=(WHEN=GROUP,BEGIN=(38,2,PD,EQ,987),               
           PUSH=(086:086,1)),                                     
         IFTHEN=(WHEN=(29,3,CH,EQ,C'30F',AND,85,2,CH,NE,C'NN'),   
        OVERLAY=(087:C'20',81,4,PD,EDIT=(TTTTT),                 
                 095:87,7,Y4T,ADDMONS,77,2,PD,TOGREG=Y4T,         
                 104:C'20',21,4,PD,EDIT=(TTTTT),                 
                 112:095,8,Y4T,DATEDIFF,104,7,Y4T))               
                                                                 
  OUTFIL INCLUDE=(112,8,SFF,GT,15),                               
   BUILD=(001,05,C';',                                           
          029,03,C';',                                           
          095,04,C'-',099,2,C'-',101,2,C';',                     
          087,07,Y4T,TOGREG=Y4T(-),C';',                         
          113,7)                                                 
                                                                 
//*                                                               

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Magesh_J
Intermediate


Joined: 21 Jun 2014
Posts: 259
Topics: 54

PostPosted: Mon Feb 19, 2018 11:53 am    Post subject: Reply with quote

Hi Kolusu,

Thanks for the code. Sorry I should have informed you this in my first post.
The reason why asking for keybegin and begin is because i need to end the push when the key is changed.
kolusu wrote:
You cannot use both BEGIN and KEYBEGIN at the same time. If I understand your requirement correctly then you can do it differently

I need to group the record for every key, the following push statement will push records until it finds the next 986 or 987
kolusu wrote:
Code:
  OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(38,2,PD,EQ,986),               
           PUSH=(085:085,1)),                                     
         IFTHEN=(WHEN=GROUP,BEGIN=(38,2,PD,EQ,987),               
           PUSH=(086:086,1)),


Example
Code:

12346  99       214037 214037                          72
12346  88                       000001239  986         72
12346  88                       000001239  987         72
12346  30F      217026 217026                          72
12347  99       214037 214037                          60
12347  30F      217026 217026                          60
12348  99       214037 214037                          60
12348  88                       000001239  986         60
12348  88                       000001238  987         60
12348  40F      217026 217026                          60
In the above example, the record 12347 may be extracted because Push 'NN' extended from key value 12346 to 12348.

Two approaches I am thinking,
Code:
IFTHEN=(WHEN=GROUP,BEGIN=(38,2,PD,EQ,986),END=(29,3,CH,EQ,C'99 '),               
           PUSH=(085:085,1))
Code:

IFTHEN=(WHEN=INIT,OVERLAY=(133:SEQ,ZD,3,RESTART=(1,5)),
IFTHEN=(WHEN=GROUP,BEGIN=(38,2,PD,EQ,986),END=(133,3,ZD,EQ,1),               
           PUSH=(085:085,1))

But both of them will extend until first record of the next key.
Is there any way to strictly stop the push when the key is changed ?.

Thanks
Magesh
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12359
Topics: 75
Location: San Jose

PostPosted: Mon Feb 19, 2018 12:15 pm    Post subject: Reply with quote

Magesh_J,

The issue is NOT with the push, but the missing the 986/987 record. You can end the push on OUTREC with (29,3,CH,EQ,C'99')

Since there is no 986/987 record and 30F record is present we are picking it up.

Do you need to drop off those records which don't have a 986, AND 987 record? ie. every group should have a 986 and 987 record.
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12359
Topics: 75
Location: San Jose

PostPosted: Mon Feb 19, 2018 12:27 pm    Post subject: Reply with quote

Magesh_J,

Here are the updated control cards. Instead of checking if the values are 0, check for NOT EQUAL to 0 and then you can validate them. I used a value of 1 and 2 for push so that it is easy to validate on OUTFIL

Code:

//SYSIN    DD *                                             
  OPTION COPY                                               
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(29,3,CH,EQ,C'99'),         
          PUSH=(81:21,04)),                                 
        IFTHEN=(WHEN=(38,2,PD,EQ,986,AND,40,9,ZD,NE,0),     
       OVERLAY=(85:C'1')),                                   
        IFTHEN=(WHEN=(38,2,PD,EQ,987,AND,40,9,ZD,NE,0),     
       OVERLAY=(86:C'2'))                                   
                                                             
  OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(38,2,PD,EQ,986),         
                              END=(29,3,CH,EQ,C'99'),       
           PUSH=(085:085,1)),                               
         IFTHEN=(WHEN=GROUP,BEGIN=(38,2,PD,EQ,987),         
                              END=(29,3,CH,EQ,C'99'),       
           PUSH=(086:086,1)),                               
                                                             
         IFTHEN=(WHEN=(29,3,CH,EQ,C'30F',AND,85,2,ZD,GT,1), 
        OVERLAY=(087:C'20',81,4,PD,EDIT=(TTTTT),             
                 095:87,7,Y4T,ADDMONS,77,2,PD,TOGREG=Y4T,   
                 104:C'20',21,4,PD,EDIT=(TTTTT),             
                 112:095,8,Y4T,DATEDIFF,104,7,Y4T))         
                                                             
  OUTFIL INCLUDE=(112,8,SFF,GT,15),                         
   BUILD=(001,05,C';',                                       
          029,03,C';',                                       
          095,04,C'-',099,2,C'-',101,2,C';',                 
          087,07,Y4T,TOGREG=Y4T(-),C';',                     
          113,7)                                             
                                                             
//*

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Magesh_J
Intermediate


Joined: 21 Jun 2014
Posts: 259
Topics: 54

PostPosted: Mon Feb 19, 2018 3:29 pm    Post subject: Reply with quote

Hi Kolusu,

Kolusu wrote:
Code:
        IFTHEN=(WHEN=(38,2,PD,EQ,986,AND,40,9,ZD,NE,0),     
       OVERLAY=(85:C'1')),                                   
        IFTHEN=(WHEN=(38,2,PD,EQ,987,AND,40,9,ZD,NE,0),     
       OVERLAY=(86:C'2'))

Above code will update ' 2' when 986 is equal to zero and 987 not equal to zero.
kolusu wrote:
Code:
IFTHEN=(WHEN=(29,3,CH,EQ,C'30F',AND,85,2,ZD,GT,1)


In this case record will be extracted, but we dont want to extract the record.


Thanks
Magesh
Back to top
View user's profile Send private message
Magesh_J
Intermediate


Joined: 21 Jun 2014
Posts: 259
Topics: 54

PostPosted: Mon Feb 19, 2018 4:03 pm    Post subject: Reply with quote

Hi Kolusu,

Modified your code little working great.

Code:

    OPTION COPY                                       
   INREC IFTHEN=(WHEN=GROUP,                         
                 BEGIN=(29,2,CH,EQ,C'99'),           
                 PUSH=(141:21,04)),                   
                                                     
         IFTHEN=(WHEN=(29,2,CH,EQ,C'88',AND,         
                       38,2,PD,EQ,986,AND,           
                       40,9,ZD,NE,0),                 
                 OVERLAY=(145:C'N')),                 
                                                     
         IFTHEN=(WHEN=(29,2,CH,EQ,C'88',AND,         
                       38,2,PD,EQ,987,AND,
                       40,9,ZD,NE,0),            
                 OVERLAY=(146:C'N'))                 
                                                     
   OUTREC IFTHEN=(WHEN=GROUP,                         
                  BEGIN=(38,2,PD,EQ,986),             
                  END=(29,2,CH,EQ,C'99'),             
                  PUSH=(180:40,9,145:145,1)),         
                                                     
          IFTHEN=(WHEN=GROUP,                         
                  BEGIN=(38,2,PD,EQ,987),           
                   BEGIN=(38,2,PD,EQ,987),                           
                   END=(29,2,CH,EQ,C'99'),                           
                   PUSH=(189:40,9,146:146,1)),                       
                                                                     
          IFTHEN=(WHEN=(29,3,CH,EQ,C'30F',AND,145,2,CH,EQ,C'NN'),   
                  OVERLAY=(147:C'20',141,4,PD,EDIT=(TTTTT),         
                           155:147,7,Y4T,ADDMONS,77,2,PD,TOGREG=Y4T,
                           164:C'20',21,4,PD,EDIT=(TTTTT),           
                           172:155,8,Y4T,DATEDIFF,164,7,Y4T))       
                                                                     
   OUTFIL INCLUDE=(172,8,SFF,GT,15),                                 
          BUILD=(001,17,C';',                                       
                 029,03,C';',                                       
                 155,04,C'-',159,2,C'-',161,2,C';',                 
                 147,07,Y4T,TOGREG=Y4T(-),C';',                     
                173,7,C';',180,9,C';',189,9)               


Thanks
Magesh
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12359
Topics: 75
Location: San Jose

PostPosted: Mon Feb 19, 2018 5:00 pm    Post subject: Reply with quote

Magesh_J wrote:
Hi Kolusu,

Modified your code little working great.


Magesh_J

Glad It worked.

Are you always sure that your dates are always between 2000-2099? If not then may be you need to first expand the PD date to a readable format and validate the first Byte using CHANGE command to set the year to 19 when it is 1 and 20 when it is 2 and then 21 when it is 3 and so on.
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Magesh_J
Intermediate


Joined: 21 Jun 2014
Posts: 259
Topics: 54

PostPosted: Tue Feb 20, 2018 11:37 am    Post subject: Reply with quote

Hi Kolusu,

They are looking for only 2013 data.

1913 - Application was not designed
2113 - 95 years more.

So no issues, thanks for the kind support and help.

Regards,
Magesh
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12359
Topics: 75
Location: San Jose

PostPosted: Tue Feb 20, 2018 1:02 pm    Post subject: Reply with quote

Magesh_J wrote:
Hi Kolusu,

They are looking for only 2013 data.

1913 - Application was not designed
2113 - 95 years more.

So no issues, thanks for the kind support and help.

Regards,
Magesh


Magesh it is not issue with available data, but your goal is to design solutions that are error free and fool proof. So even if someone accidentally created a date that extends in 21xx, your control cards needs to handle that.
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12359
Topics: 75
Location: San Jose

PostPosted: Tue Feb 20, 2018 3:31 pm    Post subject: Reply with quote

Magesh_J,

I think adding 18 to the century portion is much better than having a CHANGE command.

Expand the CYYDDD with as 0CYYDDD and then add 18 to 0C portion to get the century portion.

So if your C is 1 then adding 18 would make it 19 and if C is 2 then adding 18 would make it 20 and so on. So you never have to change the control cards ever.

So change the last IFTHEN on OUTREC to the following

Code:

                                                                   
         IFTHEN=(WHEN=(029,3,CH,EQ,C'30F',AND,                     
                       145,2,CH,EQ,C'NN'),                         
              OVERLAY=(147:141,4,PD,EDIT=(TTTTTTT),               
                       147:147,2,ZD,ADD,+18,EDIT=(TT),             
                       155:147,7,Y4T,ADDMONS,77,2,PD,TOGREG=Y4T,   
                       164:021,4,PD,EDIT=(TTTTTTT),               
                       164:164,2,ZD,ADD,+18,EDIT=(TT),             
                       172:155,8,Y4T,DATEDIFF,164,7,Y4T))         
                                                                   

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Magesh_J
Intermediate


Joined: 21 Jun 2014
Posts: 259
Topics: 54

PostPosted: Wed Feb 21, 2018 11:28 am    Post subject: Reply with quote

Hi Kolusu,

Kolusu wrote:
Code:
164:164,2,ZD,ADD,+18,EDIT=(TT),
.

Wow Exclamation What an idea..Idea Idea Its working great. Thank You .


Regards,
Magesh
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group