View previous topic :: View next topic
Author
Message
mistah kurtz Active User Joined: 28 Jan 2012Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
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
bodatrinadh Active User Joined: 05 Jan 2007Posts: 101 Location: chennai (India)
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
mistah kurtz Active User Joined: 28 Jan 2012Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
thanks..but in case of "4" I want to increase the year by 1 as well and Reset quarter to 1.
Back to top
bodatrinadh Active User Joined: 05 Jan 2007Posts: 101 Location: chennai (India)
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
enrico-sorichetti Superior Member Joined: 14 Mar 2007Posts: 10873 Location: italy
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
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
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
mistah kurtz Active User Joined: 28 Jan 2012Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
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
enrico-sorichetti Superior Member Joined: 14 Mar 2007Posts: 10873 Location: italy
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
Back to top
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
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
mistah kurtz Active User Joined: 28 Jan 2012Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
Thanks a lot guys. :-)
Back to top
mistah kurtz Active User Joined: 28 Jan 2012Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
Just to say thanks to all of you..its working smooth like silk :-)
Back to top
Please enable JavaScript!