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

ADD & SUB in SORT Control Card


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

Active User


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

PostPosted: Fri Mar 01, 2013 9:42 am
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
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: 316
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Fri Mar 01, 2013 11:07 am
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Mar 01, 2013 1:21 pm
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

Moderator Emeritus


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

PostPosted: Fri Mar 01, 2013 2:39 pm
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: 316
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Fri Mar 01, 2013 5:53 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Mar 01, 2013 9:47 pm
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

Moderator Emeritus


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

PostPosted: Fri Mar 01, 2013 9:49 pm
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: 316
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Fri Mar 01, 2013 10:17 pm
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: 316
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Mon Mar 04, 2013 8:07 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts Using Dynamic file handler in the Fil... COBOL Programming 2
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
Search our Forums:

Back to Top