Sort presentation

Embed Size (px)

DESCRIPTION

IBM mainframe sort utility. Inspired by Kolusu.

Text of Sort presentation

  • 1. SORT by RK

2. AgendaSORT FLOWINCLUDE / OMITINRECJOINSUM / DUPKEYSEXIT Routines (MODS)OUTRECOUTFILOUTFIL ReportsDATE Operations 3. Basic Points The first byte of every fixed-length record is position 1, the second byte position 2, and so on. Bytes 1 through 4 of variable-length records are reserved for the Record Descriptor Word (RDW). For these records, the first byte of the data portion is position 5. When proper processing depends on data format, the format of the field must be specified. The format of the field must be appropriate to the task. For example, only numeric fields canbe SUMmed. When all the fields have the same format, the format value can be specified just once throughthe FORMAT=f subparameter. The FORMAT=f subparameter cannot be used when theINCLUDE/OMIT parameter is specified on the OUTFIL control statement.Identify a comment card image by placing an asterisk (*) in column 1. Comments can extend through column 80. To add a comment to a control statement card image, leave one or more blanks after thelast parameter or comma on the image and follow with the comment, which can extendthrough column 71. 4. Basic Points Contd Comment lines can be inserted between a control statement and its continuation bycoding an asterisk (*) in column one.COL. 72 SORT FIELDS=(1,10,A,20,5,A,45,7,A),FORMAT=CH,STOPAFT=100, *COMMENT EQUALSIn the above example, no continuation character is required. The control statement isinterrupted after a parameter-comma combination before column 72. COL. 16COL.72OUTFIL OUTREC=(1:10,8,30:40,10),HEADER2=(1:CUSTOMER NUMBXER,30:ITEM NUMBER)In this example, a continuation character is necessary because the literal string in theHEADER2 specification would extend beyond column 71. The X in column 72 is thecontinuation character. The literal string is continued in column 16 of the next card image. 5. SORT JCL//SORT EXEC PGM=SORT//SORTIN DD DISP=SHR,DSN=INPUT.FILE//SORTOUT DD DSN=OUTPUT.FILE,//DISP=(,CATLG,DELETE),//UNIT=SYSDA,SPACE=(TRKS,(40,20),RLSE)//SYSOUT DD SYSOUT=*//SYSPRINT DD SYSOUT=*//SYSINDD * SORT FIELDS=COPY/*SORTINSORTOUTACCOUNT# MOBILE# STATUS DATE AMOUNT ACCOUNT# MOBILE# STATUS DATE AMOUNT----+----+----+----+----+----+----+---- ----+----+----+----+----+----+----+----10000001 5000001 0 011511 100.5010000001 5000001 0 011511 100.5010000001 5000002 1 021512 050.5010000001 5000002 1 021512 050.5010000001 5000003 2 011512 000.5010000001 5000003 2 011512 000.5010000002 5100001 2 021512 111.5010000002 5100001 2 021512 111.5010000002 5200002 1 021512 120.5010000002 5200002 1 021512 120.5010000006 5600001 0 021512 100.5010000006 5600001 0 021512 100.5010000003 5300001 0 021512 020.5010000003 5300001 0 021512 020.50 6. SORT FLOWBEFORE SORT SORT AFTER SORTSORTIN SUM / DUPKEYS SKIPRECE15 OUTREC JOINSORT E35INCLUDE/OMITOUTFIL SORTOUT STOPAFT INREC 7. STOPAFTSTOPAFT ParmSTOPAFT=n STOPAFT=n (a decimal number) sorts/copies at most n records.These will be the first n records after any input processing due to an E15, anINCLUDE/OMIT statement, or the SKIPREC parameter. If STOPAFT=n has been specified on the SORT control statement as well asin the PARM field, the PARM specification will take precedence.//SORT EXEC PGM=SORT,PARM=STOPAFT=100 orSORT FIELDS=COPY,STOPAFT=100 First 100 records will be taken and remaining records will be skipped. These100 will be send to next control of SORT for processing. 8. SKIPRECSKIPREC ParmSKIPREC=n SKIPREC=n instructs the sort to skip a decimal number n of records beforesorting/copying the input file. The records skipped are deleted from the input file before E15 andINCLUDE/OMIT processing is begun. If SKIPREC=n has been specified on the SORT control statement as well asin the PARM field, the PARM specification will take precedence.//SORT EXEC PGM=SORT,PARM=SKIPREC=100 orSORT FIELDS=COPY,SKIPREC=100 First 100 records will be skipped and remaining records will be send toSORT for processing. 9. STOPAFT /SKIPREC//SORTCHK1 EXEC PGM=SORT//SORTIN DD *111 1 0001 1111 2 0001 2111 3 0001 3222 1 0001 1333 1 0001 1444 3 0001 2444 4 0001 4444 2 0001 2//SORTOUT DD SYSOUT=*//SYSOUT DD SYSOUT=*//SYSPRINT DD SYSOUT=*//SYSINDD * SORT FIELDS=(1,3,CH,A),SKIPREC=02,STOPAFT=5/*SORTOUT------------111 3 0001 3222 1 0001 1333 1 0001 1444 3 0001 2444 4 0001 4 10. INCLUDE / OMITINCLUDE/OMIT COND=ALL / NONE /COMPARISIONINCLUDE COND=((1,4,CH,EQ,C1995,OR,1,4,CH,EQ,C1996),AND,5,5,CH,EQ,CPARIS)INCLUDE COND=(1,4,CH,EQ,10,4,CH) OR (1,4,EQ,10,4),FORMAT=CHINCLUDE COND=(15,3,ZD,EQ,100,AND,20,1,CH,NE,X40)INCLUDE COND=(35,8,ZD,LE,&DATE1,AND,45,8,ZD,GT,&DATE1-14) If you have multiple strings to search: (1,4,CH,EQ,L(C1995,C1996) OR (1,40,SS,EQ,L(C1995,C1996)) Numeric CheckINCLUDE COND=(35,8,ZD,EQ,NUM)SORTIN (FB RECORD)----+----1----+----2----+----3----+----4----+----5----+1995PARIS1997 100 R1996LONDN1996 ANYTOWN1997CINCI1998 200 ANYTOWN1999INDIA1999 20120220 20120218Options vlscomp 11. INRECThe INREC control statement reformats the input records. Use the INREC control statement to add, delete, or reformat fields before the records are sorted ormerged. Except for CONVERT, all the functions performed by the OUTREC control statement, such asinserting character strings or changing the data format of a numeric field, can also be performed bythe INREC control statement.Note: that INREC is performed after E15 exit processing and INCLUDE/OMIT control statementprocessing.INREC FIELDS=(1,15,20,5)SORTIN SORTOUT----+----1----+----2----+----3 ----+----1----+----2ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOTUVWXINREC FIELDS=(1,4,5,9,ZD,PD,X,20,5) Variable Block (1,4 RECORD LENGTH)SORTIN SORTOUT (HEX ON)----+----1----+----2----+----3 ----+----1----+123456789RAMA ABCDEFGHI ABCDE 135794CCCCC 2468F012345 12. INREC contdINREC IFTHEN=(WHEN=INIT,BUILD=(1,15,CCVG,19,27)),IFTHEN=(WHEN=(1,2,CH,EQ,CNJ),BUILD=(1,30,CNEW JERSEY)),IFTHEN=(WHEN=(1,2,CH,EQ,CNY),OVERLAY=(31:CNEW YORK )),IFTHEN=(WHEN=NONE,OVERLAY=(31:CNO MATCH ))SORTIN----+----1----+----2----+----3----+----4----+----5----+HYDERABAD INDIANJUSANYUSAPARISSORTOUT----+----1----+----2----+----3----+----4----+HYDERABADCVGNO MATCHNJ CVGNEW JERSEYNY CVGNEW YORKPARISCVGNO MATCH 13. INREC contd INREC FIELDS=(1,7,SFF,TO=ZD,9,7,UFF,TO=PD) * SIGNED FREE FORM FORMAT* UNSIGNED FREE FORM FORMAT SORTIN SORTOUT (HEX ON) ----+----1----+----2----+----3 ----+----1--19.85 +20.05 000198LFFFFFFD00050001985020FINREC PARSE=(%1=(ENDBEFR=C,,FIXLEN=4),* STOCK SYMBOL (MAX LEN 4) %2=(ENDBEFR=C,,FIXLEN=6),* CURRENT PRICE (MAX LEN 6) %3=(FIXLEN=1), * SIGN OF TODAYS CHANGE %4=(ENDBEFR=C ,FIXLEN=5)), * CHANGE AMOUNT (MAX LEN 5)BUILD=(01:%1, * STOCK SYMBOL 07:%2,JFY=(SHIFT=RIGHT), * CURRENT PRICE 15:%3, * SIGN OF TODAYS CHANGE 16:%4,JFY=(SHIFT=RIGHT)) * CHANGE AMOUNTSORT FIELDS=(1,4,CH,A)* SORT BY STOCK SYMBOLSORTIN SORTOUT----+----1----+--- ----+----1----+-----DIS,34.56,+1.09DIS 34.56 + 1.09T,37.05,-.42 GOOG 449.12 -11.62GOOG,449.12,-11.62 T 37.05 - .42** If you dont want to store just say % in PARSE 14. JOIN Using JOIN you can extract and sort data from two different files. One file point toSORTJNF1 other point to SORTJNF2.The join files do not need to be presorted on the fields specified on theJOINKEYS statement. By default, SyncSort will sort the records to the propersequence before performing the join operation. The FIELDS parameter is required. It describes the fields to be used to match recordsfrom the two files, SORTJNF1 and SORTJNF2. The number of JOINKEYS fields and their lengths and sorted order (A or D) must bethe same for both files, although their starting positions need not be the same. Each JOINKEYS field may be anywhere within the record through column 32750,the maximum length of a field is 4080 bytes, and the sum of all fields on a JOINKEYSstatement cannot exceed 4080 bytes. For variable-length records, any JOINKEYS fields that are completely or partiallymissing will be padded with binary zeros when performing the comparison. 15. JOIN Cntd..//SORTJNF1 DD *//SORTJNF2 DD *----+----1----+----2----+----3-----+----1----+----2----+----3-000001 0310.00 12/01/2002 2178I7454C JOSEPH SMITH NY000002 8055.22 12/02/2002 2123D2111A JAMES JONES NJ000003 0310.00 12/05/2002 2178I2178I JOHN JACKSON DE000004 0020.00 12/06/2002 2111A2123D MARY LEEFLJOINKEYS FILE=F1,FIELDS=(27,5,A)JOINKEYS FILE=F2,FIELDS=(1,5,A)REFORMAT FIELDS=(F1:16,11,1,7,8,8,27,6,F2:7,14,21,3)File1File2SORT FIELDS=COPYOUTFIL FILES=01,HEADER2=(DATE ,TRANS# ,TRANAMT ,CUST# ,CUSTOMER NAME ,ADD)DATE TRANS# TRANAMT CUST# CUSTOMER NAME ADD12/06/2002 000004 0020.00 2111A JAMES JONES NJ12/02/2002 000002 8055.22 2123D MARY LEEFL12/05/2002 000003 0310.00 2178I JOHN JACKSONDE12/01/2002 000001 0310.00 2178I JOHN JACKSONDE 16. JOIN Cntd..//SORTJNF1 DD *//SORTJNF2 DD *----+----1----+----2----+----3-----+----1----+----2----+----3-000001 0310.00 12/01/2002 2178I7454C JOSEPH SMITH NY000002 8055.22 12/02/2002 2123D2111A JAMES JONES NJ000003 0310.00 12/05/2002 2178I2178I JOHN JACKSON DE000004 0020.00 12/06/2002 2111A2123D MARY LEEFLJOINKEYS FILE=F1,FIELDS=(27,5,A)File1File2JOINKEYS FILE=F2,FIELDS=(1,5,A)JOIN UNPAIRED,F2REFORMAT FIELDS=(F1:16,11,1,7,8,8,27,6,F2:7,14,21,3),FILL=C SORT FIELDS=COPYOUTFIL FILES=01,HEADER2=(DATE ,TRANS# ,TRANAMT ,CUST# ,CUSTOMER NAME ,ADD)DATE TRANS# TRANAMT CUST# CUSTOMER NAME ADD12/06/2002 000004 0020.00 2111A JAMES JONES NJ12/02/2002 000002 8055.22 2123D MARY LEEFL12/05/2002 000003 0310.00 2178I JOHN JACKSONDE12/01/2002 000001 0310.00 2178I JOHN JACKSONDEJOSEPH SMITHNY 17. JOIN contd File1File2 File1File2 File1File2 File1 File2 Left Outer JoinRight Outer Join Full Outer Join JOIN JOIN UNPAIRED,F1 JOIN UNPAIRED,F2 JOIN UNPAIRED UNPAIRED,ONLYJOIN UNPAIRED [,F1] [,F2] [,ONLY] To retain unpaired records from SORTJNF1 (a left outer join) in addition to all joined records,JOIN UNPAIRED,F1 To retain unpaired records from SORTJNF2 (a right outer join) in addition to all joined records.JOIN UNPAIRED,F2 To retain unpaired records from both SORTJNF1 an