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 

DFSORT to count multiple column and build a summary report

 
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: Mon Nov 17, 2014 3:08 pm    Post subject: DFSORT to count multiple column and build a summary report Reply with quote

Hi,

I trying to find the count of multiple columns, Is it possible.

The challenge here is we have 241 millions records input and length 198 VB. So if we use sort filelds, that will affect performance.
Below key shown is packed decimal

Code:

VAR1            VAR2                   VAR3
7/AN        9/PS                2/SNUM     
(1-7)       (8-16)              (17-18)     
2---------- 3------------------ 4-----------
********************************* TOP OF DAT
  AAAAA          12345671010100            0


I need built a summary report based on VAR2 PS hence converted to Character

Code:

INREC BUILD=(1,4,12,9,PD,TO=ZD,LENGTH=17,5)  ==> this is not working I am trying bulid RDW + Converted string + actual record.

OUTFIL BUILD FNAMES=OUTPUT1,BUILD=(1,4,22)  RDW + Actual record
OUTFIL BUILD FNMAES=REPORT   ==> here is where I am struck

VAR2 converted field.
Code:

08888472101010100
08888472101400100
08888472101400200
08888472901010100
08888472901400100
08888473101010100
08888784301010100
08888891902010100
08888891902200100
08888891902400100
03333473101010100
03333391902010100
03333391902200100
03333391902400100


Output Report.
Code:

DATE  11/15/14                               
TIME  050942                                 
                                 Report Sample
 Total number of records  read               14
Group              Header               Trailer
21                     1                        2
29                     1                        1
31                     2
43                     1
19                     2                        4


Group is in position 8th character of var2
I need to count the header and trailer record for each group.
Header is position 12th character of the Var2 if 12,1,Ch,EQ,C'01'
Trailer is position 12th character of the Var2 if 12,1,Ch,NE,C'01'

Note : The advantage is the group are specifics, So it can be hard coded in condition.

Please advice.

Thanks
Magesh
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 Nov 17, 2014 4:06 pm    Post subject: Reply with quote

Magesh_J,

You just need a summary report so all you need is to pull of the group number, header and trailer from the file using IFTHEN statement and then SORT that on a much shorter length.

So now the file is reduced to mere LRECL of 8 (RDW + group number + header/trailer)

I used CHANGE parm to set the initial count for header and trailer. So when the header is 01 , the counts for header are set to '1' and trailer to '0'. So '10' for the change and the reverse of it is header is set to '0' and trailer to '1' and hence in the NOMATCH it is '01'

Now we sort on the GROUP number and use the reporting features to generate the counts by TOTaling the header and trailer counters we set it up using the CHANGE command.

Code:

//STEP0100 EXEC PGM=SORT                                             
//SYSOUT   DD SYSOUT=*                                               
//SORTIN   DD DISP=SHR,DSN=Your Input VB 194 LRECL file
//SORTOUT  DD SYSOUT=*                                               
//SYSIN    DD *                                                     
  INREC IFTHEN=(WHEN=INIT,BUILD=(1,4,12,9,PD,ZD,LENGTH=17)),         
        IFTHEN=(WHEN=INIT,BUILD=(01,4,    $ RDW                     
                                 12,2,    $ GROUP                   
                                 16,2,CHANGE=(2,C'01',C'10'),       
                                 NOMATCH=(C'01')))                   
                                                                     
  SORT FIELDS=(5,2,CH,A)                                             
                                                                     
  OUTFIL VTOF,REMOVECC,NODETAIL,BUILD=(80X),                         
  HEADER2=(01:'DATE : ',DATE=(4MD/),                                 
           60:'PAGE : ',PAGE,/,                                     
           01:'TIME : ',TIME=(24:),/,                               
           25:'SUMMARY REPORT OF GROUPS',/,                         
           25:'========================',/,/,                       
           10:'GROUP              HEADER               TRAILER',/,   
           10:'=====              ======               ======='),   
  SECTIONS=(5,2,                                                     
  TRAILER3=(13:5,2,                                                 
            24:TOT=(7,1,ZD,EDIT=(III,III,III)),                     
            46:TOT=(8,1,ZD,EDIT=(III,III,III)))),                   
  TRAILER1=(/,                                                       
            03:'TOTAL NUMBER OF RECORDS  READ :   ',                 
            COUNT=(EDIT=(III,III,III)))                             
//*                                                                 


The generated output is something like this

Code:

DATE : 2014/11/17                                          PAGE :      1
TIME : 14:00:57                                                         
                        SUMMARY REPORT OF GROUPS                       
                        ========================                       
                                                                       
         GROUP              HEADER               TRAILER               
         =====              ======               =======               
            19                   2                     4               
            21                   1                     2               
            29                   1                     1               
            31                   2                                     
            43                   1                                     
                                                                       
  TOTAL NUMBER OF RECORDS  READ :            14                         

_________________
Kolusu
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 Nov 18, 2014 12:51 am    Post subject: Reply with quote

Kolusu,

Thanks, Its worked like charm, "Change" keyword is a great alternate thinking.

The other challenge we have is, We need to build two files. Sorry I should have explained this properly in my 1st quote.

Followed your advise and Built in two steps to achieve it.
1. VSAM File ==> Since it is a vsam file (SORT FIELDS(5,2) may result in key out of sequence, hence in first step no sort field
2. Report file. ==> Sort fields + Building report

Please advice if this is right.

Code:

//S1 EXEC PGM=SORT                                                   
//SYSOUT DD SYSOUT=*                                                 
//SORTIN DD DSN=VBFILE,DISP=SHR                     
//SORTOUT DD DSN=VSAMFILE,DISP=(NEW,CATLG,DELETE),     
//           SPACE=(CYL,(50,10),RLSE)                                 
//SORTOUT1 DD DSN=VBOUT,DISP=(NEW,CATLG,DELETE),   
//           SPACE=(CYL,(50,10),RLSE)                                 
//SYSIN DD *                                                         
    INREC BUILD=(1,4,5)                                               
    OPTION COPY                                                       
    OUTFIL FNAMES=SORTOUT,BUILD=(1,4,5)                               
    OUTFIL FNAMES=SORTOUT1,                                           
           IFTHEN=(WHEN=INIT,BUILD=(1,4,12,9,PD,ZD,LENGTH=17)),       
           IFTHEN=(WHEN=INIT,BUILD=(01,4,                             
                                    12,2,                             
                                    16,2,CHANGE=(2,C'01',C'10'),     
                                    NOMATCH=(C'01')))                 
//*                                                                   
//S2 EXEC PGM=SORT                                                     
//SYSOUT DD SYSOUT=*                                                   
//SORTIN DD DSN=VBOUT,DISP=SHR                       
//SORTOUT DD DSN=REPORT,DISP=(NEW,CATLG,DELETE),       
//           SPACE=(CYL,(50,10),RLSE)                                   
//SYSIN DD *                                                           
  SORT FIELDS=(5,2,CH,A)                                               
  OUTFIL VTOF,REMOVECC,NODETAIL,BUILD=(80X),                           
  HEADER2=(01:'DATE : ',DATE=(4MD/),                                   
           60:'PAGE : ',PAGE,/,                                         
           01:'TIME : ',TIME=(24:),/,                                   
           25:'SUMMARY REPORT OF GROUPS',/,                             
           25:'========================',/,/,                           
           10:'GROUP              HEADER               TRAILER',/,     
           10:'=====              ======               ======='),       
  SECTIONS=(5,2,                                                       
  TRAILER3=(13:5,2,                                                     
            24:TOT=(7,1,ZD,EDIT=(III,III,III)),                         
            46:TOT=(8,1,ZD,EDIT=(III,III,III)))),                       
  TRAILER1=(/,                                     


Thanks
Magesh
Back to top
View user's profile Send private message
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Tue Nov 18, 2014 8:04 am    Post subject: Reply with quote

Code:
   INREC BUILD=(1,4,5)


That says, "from the current record make a new current record (you can say that every time you see BUILD (or FIELDS on INREC/OUTREC or OUTREC on OUTFIL if you see old code)".

It continues by saying "copy the RDW from the current record to the new current record" and then "copy all the data from position five to the end of the current record to the new current record".

In short, you've just made an identical copy of your current record. You don't want to do that, and you certainly don't want to do that 241m times. Remove the INREC.

Code:
OUTFIL FNAMES=SORTOUT,BUILD=(1,4,5)


The default for OUTFIL is SORTOUT, so you don't need FNAMES. For the BUILD, see above. That's a further 241m of those you don't want.

In short, you can remove that OUTFIL completely and the input file will be copied, unchanged, to SORTOUT.

It is not at all a good idea to call DDname SORTOUT1, so change that. If you start any DDname with SORT you will at best confuse readers into thinking it is something that is part of SORT itself, and at worst you will actually screw something up.

If you are now writing out the file for analysis in a second step, you don't need the RDW. The RDW is doubling the space used by the file. Kill the RDW and use VTOF. Adjust your second step accordingly.

I'd also consider a comparison of Kolusu's original + REPRO against this. Say 1m record representative sample, and compare IO and CPU.
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: Tue Nov 18, 2014 12:30 pm    Post subject: Reply with quote

Magesh_J,

William pretty much discussed all the parameters. By default the output goes to SORTOUT, you really don't have to specify FNAMES for sortout. We can use REPRO to copy the input file to a VSAM cluster. However if you want to use DFSORT then here are optimized control cards. I converted the VB file to FB in first step and then build only the fields I need in step 2 there by reducing the sorting file length to just 4 bytes.

Code:

//STEP0100 EXEC PGM=SORT                                           
//SYSOUT   DD SYSOUT=*                                             
//SORTIN   DD DISP=SHR,DSN=Your Input VB file
//SORTOUT DD DSN=VSAMFILE,DISP=(NEW,CATLG,DELETE),     
//           SPACE=(CYL,(50,10),RLSE)   
//*                           
//TEMP     DD DSN=&&T1,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)         
//SYSIN    DD *                                                     
  OPTION COPY                                                       
  OUTFIL FNAMES=TEMP,VTOF,BUILD=(12,9,PD,ZD,LENGTH=17)             
//*                                                                 
//STEP0200 EXEC PGM=SORT                                           
//SYSOUT   DD SYSOUT=*                                             
//SORTIN   DD DISP=SHR,DSN=&&T1                                     
//SORTOUT  DD SYSOUT=*                                             
//SYSIN    DD *                                                     
  INREC BUILD=(08,2,                          $ GROUP               
               12,2,CHANGE=(2,C'01',C'10'),                         
               NOMATCH=(C'01'))                                     
                                                                   
  SORT FIELDS=(1,2,CH,A)                                           
                                                                   
  OUTFIL REMOVECC,NODETAIL,BUILD=(80X),                             
  HEADER2=(01:'DATE : ',DATE=(4MD/),                               
           60:'PAGE : ',PAGE,/,                                     
           01:'TIME : ',TIME=(24:),/,                               
           25:'SUMMARY REPORT OF GROUPS',/,                         
           25:'========================',/,/,                       
           10:'GROUP              HEADER               TRAILER',/, 
           10:'=====              ======               ======='),   
  SECTIONS=(1,2,                                                   
  TRAILER3=(13:1,2,                                                 
            24:TOT=(3,1,ZD,EDIT=(III,III,III)),                     
            46:TOT=(4,1,ZD,EDIT=(III,III,III)))),                   
  TRAILER1=(/,                                                     
            03:'TOTAL NUMBER OF RECORDS  READ :   ',               
            COUNT=(EDIT=(III,III,III)))                             
//*                       


And if you really want to get fancy you can use Joinkeys using the same file as both INA and INB like this
Code:

//STEP0100 EXEC PGM=SORT                                             
//SYSOUT   DD SYSOUT=*                                               
//INA      DD DISP=SHR,DSN=Your Input VB 198 LRECL file           
//INB      DD DISP=SHR,DSN=Same Input VB 198 LRECL file
//SORTOUT  DD SYSOUT=*                                               
//REPORT   DD SYSOUT=*                                               
//SYSIN    DD *                                                       
  OPTION COPY                                                         
  JOINKEYS F1=INA,FIELDS=(5,2,A),SORTED,NOSEQCK                       
  JOINKEYS F2=INB,FIELDS=(5,2,A)                                     
  JOIN UNPAIRED                                                       
  REFORMAT FIELDS=(F1:1,4,F2:5,4,F1:7)                               
                                                                     
  OUTFIL INCLUDE=(5,4,CH,EQ,C' '),BUILD=(1,4,9)                       
                                                                     
  OUTFIL FNAMES=REPORT,SAVE,VTOF,REMOVECC,NODETAIL,BUILD=(80X),       
  HEADER2=(01:'DATE : ',DATE=(4MD/),                                 
           60:'PAGE : ',PAGE,/,                                       
           01:'TIME : ',TIME=(24:),/,                                 
           25:'SUMMARY REPORT OF GROUPS',/,                           
           25:'========================',/,/,                         
           10:'GROUP              HEADER               TRAILER',/,   
           10:'=====              ======               ======='),     
  SECTIONS=(5,2,                                                     
  TRAILER3=(13:5,2,                                                   
            24:TOT=(7,1,ZD,EDIT=(III,III,III)),                       
            46:TOT=(8,1,ZD,EDIT=(III,III,III)))),                     
  TRAILER1=(/,                                                       
            03:'TOTAL NUMBER OF RECORDS  READ :   ',                 
            COUNT=(EDIT=(III,III,III)))                               
//*
//JNF1CNTL DD *                                                 
  INREC BUILD=(1,4,2X,5)                                       
//*                                                             
//JNF2CNTL DD *                                                 
  INREC IFTHEN=(WHEN=INIT,BUILD=(1,4,12,9,PD,ZD,LENGTH=17)),   
        IFTHEN=(WHEN=INIT,BUILD=(01,4,    $ RDW                 
                                 12,2,    $ GROUP               
                                 16,2,CHANGE=(2,C'01',C'10'),   
                                 NOMATCH=(C'01')))             
//*

_________________
Kolusu
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 Nov 18, 2014 1:15 pm    Post subject: Reply with quote

Thanks Willams really use full information.

Thanks kolusu for the code. Its working great.

Is VTOF is not possible with OUTFIL IFTHEN=(When ?
I am trying with below code.



Code:

OPTION COPY
OUTFIL FNAMES=OUT1,VTOF,                                 
       IFTHEN=(WHEN=INIT,BUILD=(12,9,PD,ZD,LENGTH=17)),     
       IFTHEN=(WHEN=INIT,BUILD=(8,2,                         
                                12,2,CHANGE=(2,C'01',C'10'),
                                NOMATCH=(C'01')))           


Error message

Code:

ICE000I 1 - CONTROL STATEMENTS FOR 5694-A01, Z/OS DFSORT V1R10 - 09:56 ON TUE NO
              OPTION COPY                                                       
              OUTFIL FNAMES=OUT1,VTOF,                                     
                     IFTHEN=(WHEN=INIT,BUILD=(12,9,PD,ZD,LENGTH=17)),           
                     IFTHEN=(WHEN=INIT,BUILD=(8,2,                             
                                              12,2,CHANGE=(2,C'01',C'10'),     
                                              NOMATCH=(C'01')))                 
ICE201I H RECORD TYPE IS V - DATA STARTS IN POSITION 5                         
ICE126A 9 INCONSISTENT REFORMATTING FOR OUT1: REASON CODE 05, IFTHEN 1     
ICE751I 0 C5-K90025 C6-K90025 C7-K54603 C8-K62201 E9-K60823 E7-K62201           
ICE052I 3 END OF DFSORT                                                         


Also have doubt with IFTHEN=(WHEN

Suppose input is FB 10
OUTFIL FNAMES=OUT1,INCLUDE(condition),BUILD=(1,5) Build exactly 5 length record in output

OUTFIL FNAMES=OUT1, IFTHEN=(WHEN=(condition),BUILD=(1,5)
Thought i give build above, it is getting only input record length 10 and not 5 Length character. i.e output file is with length 10 having records from (1,5)

Please advice how this works.

Thanks
Magesh
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: Tue Nov 18, 2014 1:27 pm    Post subject: Reply with quote

Magesh_J wrote:
Is VTOF is not possible with OUTFIL IFTHEN=(When ?
I am trying with below code.


Error message
Code:

ICE126A 9 INCONSISTENT REFORMATTING FOR OUT1: REASON CODE 05, IFTHEN 1     



Magesh_J,

Well if you looked at ICE126A(Suffix A stands for Abend and Suffix I stands for Informational) message in DFSORT Messages, Codes and Diagnosis Guide manual, it is quite self-explanatory. Here is the link to the message. See the explanation for reason code 5 and the NOTE in bold underneath it.

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/ice1cm60/2.2.122?

Magesh_J wrote:

Also have doubt with IFTHEN=(WHEN

Suppose input is FB 10
OUTFIL FNAMES=OUT1,INCLUDE(condition),BUILD=(1,5) Build exactly 5 length record in output

OUTFIL FNAMES=OUT1, IFTHEN=(WHEN=(condition),BUILD=(1,5)
Thought i give build above, it is getting only input record length 10 and not 5 Length character. i.e output file is with length 10 having records from (1,5)

Please advice how this works.


When you code IFTHEN=(WHEN=(condition) , DFSORT does not know if there are other conditions that would need the full record. So it retains the original LRECL as is. You can counter that with IFOUTLEN=5 or using WHEN=NONE

Remember IFTHEN in DFSORT works similar to EVALUATE statement in COBOL. So once the condition is true it skips the other IFTHEN conditions unless you have a HIT=NEXT.

IFTHEN=(WHEN=INIT and WHEN=GROUP will be executed ALWAYS before the WHEN=CONDITION. So you can have multiple WHEN=INIT and WHEN=GROUP and ALL of them will be executed.
_________________
Kolusu
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 Nov 18, 2014 1:35 pm    Post subject: Reply with quote

Thanks kolusu for the kind and detailed explanation



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