Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

ADD & SUB in SORT Control Card

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 268
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Fri Mar 01, 2013 9:42 am    Post subject: ADD & SUB in SORT Control Card
Reply with quote

Hi ,

I have an input file as below:

Code:


000AAAAAA|2011|1
000BBBBBB|2011|1
000CCCCCC|2011|2
000DDDDDD|2011|2
000EEEEEE|2011|3
000FFFFFF|2011|3
000GGGGGG|2011|4
000HHHHHH|2011|4


The 2nd field is Year and 3rd is Quarter seperated by '|' symbol.

Desired output is to increase the quarter to 1 and if it's 4 then set it to 1 and increase the year by 1, i.e.

Code:

000AAAAAA|2011|2
000BBBBBB|2011|2
000CCCCCC|2011|3
000DDDDDD|2011|3
000EEEEEE|2011|4
000FFFFFF|2011|4
000GGGGGG|2012|1
000HHHHHH|2012|1



I'm using the below SORT Card to achieve this:

Code:

  OPTION COPY                                         
     INREC IFTHEN=(WHEN=(16,1,CH,EQ,C'1'),           
          BUILD=(1,15,16,1,ZD,ADD,+1,TO=ZD,LENGTH=1)),
           IFTHEN=(WHEN=(16,1,CH,EQ,C'2'),           
          BUILD=(1,15,16,1,ZD,ADD,+1,TO=ZD,LENGTH=1)),
           IFTHEN=(WHEN=(16,1,CH,EQ,C'3'),           
          BUILD=(1,15,16,1,ZD,ADD,+1,TO=ZD,LENGTH=1)),
           IFTHEN=(WHEN=(16,1,CH,EQ,C'4'),           
          BUILD=(1,10,11,4,ZD,ADD,+1,TO=ZD,LENGTH=4, 
                 15,1,16,1,ZD,SUB,+3,TO=ZD,LENGTH=1))




It's working fine, but somehow I find it a bit clumsy. Am I doing it in an efficient manner. Is ther any other simple solution which I can try.

Please note that: Both the files are having RECFM= FB and LRECL=80 .

Thanks.
Back to top
View user's profile Send private message

bodatrinadh

Active User


Joined: 05 Jan 2007
Posts: 101
Location: chennai (India)

PostPosted: Fri Mar 01, 2013 11:03 am    Post subject: Reply to: ADD & SUB in SORT Control Card
Reply with quote

Hi mistah kurtz,

You can try this - Instead of Build you can try Overlay -


Code:

OPTION COPY
    INREC IFTHEN=(WHEN=(16,1,CH,EQ,C'1'),
        OVERLAY=(16:C'2')),
          IFTHEN=(WHEN=(16,1,CH,EQ,C'2'),
        OVERLAY=(16:C'3')),
          IFTHEN=(WHEN=(16,1,CH,EQ,C'3'),
        OVERLAY=(16:C'4')),
          IFTHEN=(WHEN=(16,1,CH,EQ,C'4'),
        OVERLAY=(16:C'1'))


Thanks
-3nadh
Back to top
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 268
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Fri Mar 01, 2013 11:07 am    Post subject:
Reply with quote

thanks..but in case of "4" I want to increase the year by 1 as well and Reset quarter to 1.
Back to top
View user's profile Send private message
bodatrinadh

Active User


Joined: 05 Jan 2007
Posts: 101
Location: chennai (India)

PostPosted: Fri Mar 01, 2013 1:07 pm    Post subject: Reply to: ADD & SUB in SORT Control Card
Reply with quote

Sorry, i didn't notice the Year field..

Here is the code...Bit extended...

Code:

OPTION COPY                                               
    INREC IFTHEN=(WHEN=(16,1,CH,EQ,C'1'),                 
        OVERLAY=(16:C'2')),                               
          IFTHEN=(WHEN=(16,1,CH,EQ,C'2'),                 
        OVERLAY=(16:C'3')),                               
          IFTHEN=(WHEN=(16,1,CH,EQ,C'3'),                 
        OVERLAY=(16:C'4')),                               
          IFTHEN=(WHEN=(16,1,CH,EQ,C'4'),                 
       OVERLAY=(11:11,4,ZD,ADD,+1,TO=ZD,LENGTH=4,16:C'1'))
   OUTREC OVERLAY=(11:11,4,ZD,EDIT=(TTTT))               


Thanks
-3nadh
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Fri Mar 01, 2013 1:21 pm    Post subject: Reply to: ADD & SUB in SORT Control Card
Reply with quote

why not add 1 to the quarter
and check the result for the <overflow>
algorithmically more logic and portable to other situations
any lenght, any number of cases
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Fri Mar 01, 2013 2:39 pm    Post subject: Reply to: ADD & SUB in SORT Control Card
Reply with quote

Agreed, enrico.

Use INREC, IFTHEN=(WHEN=INIT to OVERLAY the ADD to the quarter. Then IFTHEN=(WHEN=(logexp to test for that value having become "5", and adding to the year if so.

Another way, use IFTHEN=(WHEN=logexp with SS and "1,2,3" to ADD to the quarter. Use IFTHEN=(WHEN=NONE to set quarter to "1" and ADD one to the year.
Back to top
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 268
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Fri Mar 01, 2013 5:53 pm    Post subject: Reply to: ADD & SUB in SORT Control Card
Reply with quote

Hi Bill,

Did you mean something like below:

Code:


OPTION COPY                                               
    INREC IFTHEN=(WHEN=INIT,
        OVERLAY=(16:16,1,ZD,ADD,+1,TO=ZD,LENGTH=1))
          IFTHEN=(WHEN=(16,1,CH,EQ,C'5',
        OVERLAY=(11:11,4,ZD,ADD,+1,TO=ZD,LENGTH=4,16:C'1'))



But now I can't test it till Monday :-(

anyway Thanks Enrico and Bill for you inputs.
I will run it on Monday and wil let you know the results.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Fri Mar 01, 2013 9:47 pm    Post subject: Reply to: ADD & SUB in SORT Control Card
Reply with quote

yes ....

Code:
 ****** ***************************** Top of Data ******************************
 000001 //ENRICO1  JOB NOTIFY=&SYSUID,
 000002 //             MSGLEVEL=(1,1),CLASS=A,MSGCLASS=X
 000003 //*
 000004 //S1      EXEC PGM=SORT
 000005 //SYSPRINT  DD SYSOUT=*
 000006 //SYSOUT    DD SYSOUT=*
 000007 //SORTIN    DD *
 000008 00004
 000009 00011
 000010 00012
 000011 00013
 000012 00014
 000013 00021
 000014 //SYSIN     DD *
 000015   OPTION COPY
 000016   INREC IFTHEN=(WHEN=INIT,
 000017                 OVERLAY=(5:5,1,ZD,ADD,+1,TO=ZD,LENGTH=1)),
 000018         IFTHEN=(WHEN=(5,1,ZD,EQ,5),
 000019                 OVERLAY=(1:1,4,ZD,ADD,+1,TO=ZD,LENGTH=4,
 000020                          5:C'1'))
 000021 //SORTOUT   DD SYSOUT=*
 ****** **************************** Bottom of Data ****************************


to produce
Code:
********************************* TOP OF DATA **********************************
00011
00012
00013
00014
00021
00022
******************************** BOTTOM OF DATA ********************************


the different record layout is reasonably irrelevant to the suggestion
icon_cool.gif
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Fri Mar 01, 2013 9:49 pm    Post subject: Reply to: ADD & SUB in SORT Control Card
Reply with quote

A couple of typos, but that's basically it:

Code:
 OPTION COPY
    INREC IFTHEN=(WHEN=INIT,
        OVERLAY=(16:16,1,ZD,ADD,+1,TO=ZD,LENGTH=1)),
          IFTHEN=(WHEN=(16,1,CH,EQ,C'5'),
        OVERLAY=(11:11,4,ZD,ADD,+1,TO=ZD,LENGTH=4,16:C'1'))


Another way:

Code:
  INREC IFTHEN=(WHEN=INIT,
                 OVERLAY=(16:16,1,ZD,
                             MOD,+4,
                             ADD,+1,
                             TO=ZD,LENGTH=1)),
        IFTHEN=(WHEN=(16,1,CH,EQ,C'1'),
                 OVERLAY=(11:11,4,ZD,
                             ADD,+1,
                             TO=ZD,LENGTH=4))


MOD produces the remainder when, in this case, dividing by 4.

Once 3nadh put you on to the OVERLAY, there's nothing exactly "wrong" with what you did origially,

But, when you think to yourself "Mmmm... I've got add one until I get to 50 then start again from one, I did something like that once... Oh rats!".
Back to top
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 268
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Fri Mar 01, 2013 10:17 pm    Post subject:
Reply with quote

Thanks a lot guys. :-)
Back to top
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 268
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Mon Mar 04, 2013 8:07 am    Post subject:
Reply with quote

Just to say thanks to all of you..its working smooth like silk :-)
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts How to delete second instance from Fl... Gunapala CN DFSORT/ICETOOL 6 Tue Oct 18, 2016 11:42 pm
No new posts abend sort based on count records in ... anatol DFSORT/ICETOOL 5 Mon Oct 17, 2016 10:10 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us