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 

Get count of field value occurrences for a Group

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


Joined: 31 Oct 2006
Posts: 12
Topics: 2

PostPosted: Thu Mar 29, 2018 4:18 am    Post subject: Get count of field value occurrences for a Group Reply with quote

Hi,

I am having a requirement like below and would like to do in DFSORT in one step. Please help me on this.

Code:

Input file

FL1 FL2 (REC Length 8, Fixex Block)
--- ---
PPP AAA1
PPP AAA2
QQQ BBB1
RRR CCC1
RRR
RRR CCC1
RRR CCC2 
SSS DDD3
TTT EEE4
------------------------------


Desired output file looks like below.

Code:

Output file

FL1 FL5 (REC Length 8, Fixex Block)
--- ---
PPP 2
QQQ 1
RRR 2
SSS 1
TTT 1


*For RRR, count only non space FL2 values for each FL1 and for duplicate FL2 values count as 1. Here it is

RRR CCC1  count1
RRR       no count
RRR CCC1  count1
RRR CCC2  count2


Thanks,
Nath
Back to top
View user's profile Send private message
guhanath
Beginner


Joined: 31 Oct 2006
Posts: 12
Topics: 2

PostPosted: Thu Mar 29, 2018 4:59 am    Post subject: Reply with quote

Hi,

I have modified my output file. Please find below the expected output file.

Code:

Output file

FL1 FL2   FL3 (REC Length 8, Fixex Block)
--- -----  ----
PPP AAA1 1
PPP AAA2 1
QQQ BBB1 1
RRR CCC1 1
RRR      0
RRR CCC1 0
RRR CCC2 1 
SSS DDD3 1
TTT EEE4 1
------------------------------



Get count(always 1) on unique value (Combination of FL1 and FL2) and zero count for spaces at FL2 & next duplicate value (Combination of FL1 and FL2) from input file.

Thanks,
Nath
Back to top
View user's profile Send private message
Arun Raj
Sort Forum Moderator
Sort Forum Moderator


Joined: 14 Jun 2017
Posts: 7
Topics: 1

PostPosted: Thu Mar 29, 2018 8:02 am    Post subject: Reply with quote

guhanath,

When you have duplicates on FL2, can it be like this?

Code:
RRR CCC1 
RRR       
RRR CCC2 
RRR CCC1 
Back to top
View user's profile Send private message
guhanath
Beginner


Joined: 31 Oct 2006
Posts: 12
Topics: 2

PostPosted: Thu Mar 29, 2018 8:46 am    Post subject: Reply with quote

Hi Arun Raj,

Yes. It's may be the order as you mention. But first duplicate record should have 1 and remaining duplicate records should be 0.

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


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

PostPosted: Thu Mar 29, 2018 11:15 am    Post subject: Reply with quote

guhanath,

If you need to zero out the duplicate records, then you NEED to SORT the data. By doing so, the order of the records is lost. If you don't need the same order of the input records, here are untested control cards that would give you a 4 byte counter value making the output file a length of 12

Code:

//STEP0100 EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*   
//SORTIN   DD DISP=SHR,DSN=your 8 byte FB file
//SORTOUT  DD SYSOUT=* 
//SYSIN    DD *         
  SORT FIELDS=(1,8,CH,A),EQUALS                             
  OUTREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,8),PUSH=(09:SEQ=4)),
         IFTHEN=(WHEN=(4,4,CH,EQ,C' ',OR,09,4,ZD,GT,1),     
                 OVERLAY=(9:4C'0'))                         

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


Joined: 31 Oct 2006
Posts: 12
Topics: 2

PostPosted: Fri Mar 30, 2018 1:10 am    Post subject: Reply with quote

Hi Kolusu,

Thanks, its working for me.

Can i get this code in ICETOOL instead of SORT? I can use CTL1CNTL cards in that than SORT to re-sorting the records.

Thanks,
Nath.
Back to top
View user's profile Send private message
guhanath
Beginner


Joined: 31 Oct 2006
Posts: 12
Topics: 2

PostPosted: Fri Mar 30, 2018 8:50 am    Post subject: Reply with quote

Hi,

How can i use KEYBEGIN suppose my input file is like below for the same output.

Code:


Input file

FL1 FL2  FL3 (REC Length 13, Fixex Block)
--- ---- ----
PPP NKY1 KEY1
PPP NKY2 KEY2
QQQ NKY3 KEY3
RRR NKY4 KEY4
RRR NKY5     
RRR NKY6 KEY4
RRR NKY7 KEY5
SSS NKY8 KEY6
TTT NKY9 KEY7

Now the key is combination of FL1 + FL3 and not FL2

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


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

PostPosted: Fri Mar 30, 2018 10:39 am    Post subject: Reply with quote

guhanath wrote:
Hi Kolusu,
Can i get this code in ICETOOL instead of SORT? I can use CTL1CNTL cards in that than SORT to re-sorting the records.


bonk why do you need an ICETOOL code? You do realize that ICETOOL under the covers calls DFSORT? so what exactly are you trying to achieve ?

guhanath wrote:
How can i use KEYBEGIN suppose my input file is like below for the same output.


Please don't expect to be spoon fed. You got a working solution and if you atleast did some basic homework you would have figured it. Assuming you are a programmer , try to solve the issue programmatically. The simple thing to do is put the FLD1 and FLD3 as a combined field and then use the KEYBEGIN on the combined field. It is just a walk in the park. *sigh*

Here is the solution.

Code:

  SORT FIELDS=(01,4,CH,A,                                     
               10,4,CH,A),EQUALS                               
                                                               
  OUTREC IFOUTLEN=17,                                         
         IFTHEN=(WHEN=INIT,OVERLAY=(18:1,4,10,4)),             
         IFTHEN=(WHEN=GROUP,KEYBEGIN=(18,8),PUSH=(14:SEQ=4)), 
         IFTHEN=(WHEN=(10,4,CH,EQ,C' ',OR,14,4,ZD,GT,1),       
                 OVERLAY=(17:C'0'))                           

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


Joined: 31 Oct 2006
Posts: 12
Topics: 2

PostPosted: Mon Apr 02, 2018 9:35 am    Post subject: Reply with quote

Hi Kolusu,

Thanks for solution.

Quote:
why do you need an ICETOOL code? You do realize that ICETOOL under the covers calls DFSORT? so what exactly are you trying to achieve ?


I would like to re-ordering the records by including SEQNUM while sorting the file. After i would like to sort the file on SEQNUM. To do this in ICETOOL i can use CTL1CTL cards instead of SORT. That's the reason i have asked for ICETOOL version.

Any how i have done this in ICETOOL and got the expected result. Thank you very much for the solution.

Below is the working code for my requirement:

Code:

//ICETL1   EXEC  PGM=ICETOOL                                   
//TOOLMSG  DD  SYSOUT=*                                         
//DFSMSG   DD  SYSOUT=*                                         
//INA1     DD  *                                               
RRR AAAA CCC1                                                   
RRR HHHH                                                       
RRR TTTT CCC2                                                   
RRR UUUU CCC1                                                   
PPP QQQQ AAA1                                                   
PPP OOOO                                                       
QQQ MMMM BBB1                                                   
SSS IIII DDD3                                                   
TTT JJJJ EEE4                                                   
/*                                                             
//OUTA1    DD  DSN=&&TEMP1,                                     
//            DISP=(NEW,PASS,DELETE),                           
//            DCB=(LRECL=080,RECFM=FB),SPACE=(CYL,(150,75),RLSE)
//OUTA2    DD  DSN=OUTPUT FILE....,                                 
//            DISP=(NEW,CATLG,DELETE),                               
//            DCB=(LRECL=017,RECFM=FB),SPACE=(CYL,(150,75),RLSE)     
//TOOLIN   DD  *                                                     
  COPY FROM(INA1)      TO(OUTA1)  USING(CTL1)                       
  COPY FROM(OUTA1)     TO(OUTA2)  USING(CTL2)                       
/*                                                                   
//CTL1CNTL DD *                                                     
    SORT FIELDS=(01,4,CH,A,                                         
                  10,4,CH,A),EQUALS                                 
    INREC OVERLAY=(27:SEQNUM,8,ZD)                                   
                                                                     
     OUTREC IFOUTLEN=080,                                           
            IFTHEN=(WHEN=INIT,OVERLAY=(18:1,4,10,4)),               
            IFTHEN=(WHEN=GROUP,KEYBEGIN=(18,8),PUSH=(14:SEQ=4)),     
            IFTHEN=(WHEN=(10,4,CH,EQ,C' ',OR,14,4,ZD,GT,1),       
                    OVERLAY=(17:C'0'))                             
/*                                                                 
//CTL2CNTL DD *                                                   
    SORT FIELDS=(27,8,CH,A)                                       
    OUTREC FIELDS=(1,17)                                           
/*                                                                 




Output:
----+----1----+--
RRR AAAA CCC10001
RRR HHHH     0000
RRR TTTT CCC20001
RRR UUUU CCC10000
PPP QQQQ AAA10001
PPP OOOO     0000
QQQ MMMM BBB10001
SSS IIII DDD30001
TTT JJJJ EEE40001


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


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

PostPosted: Mon Apr 02, 2018 11:32 am    Post subject: Reply with quote

guhanath,

If your input file is only 13 bytes why make the temp dataset as 80 bytes? The resources required depends on the LRECL. Since you are doing 2 sorts, your goal should be reducing the resources required.

Also remove the DCB properties in the JCL. DFSORT will automatically calculate the LRECL and BLKSIZE based on the control cards or input file properties.

Code:

//CTL1CNTL DD *                                                     
  SORT FIELDS=(01,4,CH,A,                                         
               10,4,CH,A),EQUALS 
                               
  INREC OVERLAY=(18:SEQNUM,8,ZD)   

  OUTREC IFOUTLEN=25,                                         
         IFTHEN=(WHEN=INIT,OVERLAY=(26:1,4,10,4)),
         IFTHEN=(WHEN=GROUP,KEYBEGIN=(26,8),PUSH=(14:SEQ=4)),
         IFTHEN=(WHEN=(10,4,CH,EQ,C' ',OR,14,4,ZD,GT,1),
              OVERLAY=(17:C'0'))
/*
//CTL2CNTL DD *                                                   
  SORT FIELDS=(18,8,CH,A)                                       
  OUTREC FIELDS=(1,17)                                           
/*

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


Joined: 31 Oct 2006
Posts: 12
Topics: 2

PostPosted: Mon Apr 09, 2018 12:45 am    Post subject: Reply with quote

Hi Kolusu,

Thanks for the suggestion and i have implemented without DCB. The code is working well. Thank You.

Thanks,
Nath.
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