Search

Showing posts with label SORT. Show all posts
Showing posts with label SORT. Show all posts

Tuesday, October 20, 2015

DFSORT - To search for the string from the file when position is not known

Search for a string when its position not known in the file records          

To Search for a particular string within a file when the exact position of that string within a record is not known and to write that record in the Output file, the following SORT card can be used.

//SYSIN    DD  *                                   
        SORT FIELDS=COPY                           
        INCLUDE COND=(1,80,SS,EQ,C'PQ2222222222')  
/*                                                 

Here,
 SS        -   Sub string,
 1         -   Starting position of the range
 80       -   Width of the search range
 EQ      -   Comparison operators

Note:
  1. Only EQ & NE can be used for comparison.
  2. We can even use OMIT COND instead of INCLUDE

Consider input files:

ABC.SORTIN
PQ000003 1000001 PQ2222222222 123                  
PQ000002 1000002 EF1111111111                   
PQ000004 1000002 AB3333333333 530 PQ2222222222    
PQ000003 1000001 CD5555555555 005                  
PQ000001 1000004 RQ1111111111         

PQR.SORTOUT
PQ000003 1000001 PQ2222222222 123              
PQ000004 1000002 AB3333333333 530 PQ2222222222        

We can also use AND/OR to combine conditions

//SYSIN    DD  *                                      
        SORT FIELDS=COPY                              
        INCLUDE COND=(1,80,SS,EQ,C'PQ2222222222',AND, 
                      1,80,SS,EQ,C'AB3333333333')     
/*                    
                               
XYZ.SORTOUT
PQ000004 1000002 AB3333333333 530 PQ2222222222

Sunday, March 24, 2013

SYNCSORT or DFSORT - PART 3


Problem Statement
//*********************************************************************
//* I have two files. 
//* FILEA contains only timestamp X(26).
//* FILEB contains Office X(3), Account X(6), timestamp X(26) and Identity number X(3)
//* I want all records of FILEB for timestamp values not present in FILEA
//*********************************************************************

SORT JCL Used:
Step 1: Sorted FILEB with timestamp as first field.

//SORT01   EXEC PGM=SORT
//SORTIN   DD  DSN= REC.FILE, ---FILE B(WITH LAYOUT GIVEN)
//             DISP=SHR
//SORTOUT  DD  DSN=OUTOUT.FILE,
//             DISP=(OLD,CATLG,DELETE),
//             SPACE=(CYL,(10,50),RLSE),VOL=(,,,40),
//             DCB=(RECFM=FB,BLKSIZE=0,LRECL=80)
//SYSOUT   DD  SYSOUT=*
//SYSPRINT DD  SYSOUT=*
//SORTLIST DD  SYSOUT=*
//SYSIN    DD  *
        INREC FIELDS=(10,26,1,9,36,3)
        SORT FIELDS=(1,26,CH,A)
/*

Step 2 Remove/Discard duplicates on from the sorted file and the FILE A which is sorted on timestamp.

//SORT02   EXEC PGM=ICETOOL
//INPUT    DD  DSN=OUTOUT.FILE,DISP=OLD      
//         DD  DSN=TMSTMP.FILE,DISP=OLD --FILE A(TIMESTAMPS)
//OUTPUT   DD  DSN=FILE.DISCARD,
//             DISP=(OLD,CATLG,DELETE),
//             SPACE=(TRK,(1,5),RLSE),
//             DCB=(RECFM=FB,BLKSIZE=0,LRECL=80)
//FINAL1   DD  DSN=FINAL.FILE,
//             DISP=(OLD,CATLG,DELETE),
//             SPACE=(TRK,(1,5),RLSE),
//             DCB=(RECFM=FB,BLKSIZE=0,LRECL=80)
//TOOLMSG  DD  SYSOUT=*
//DFSMSG   DD  SYSOUT=*
//TOOLIN DD *
  SELECT FROM(INPUT) TO(OUTPUT) ON(1,26,CH) ALLDUPS DISCARD(FINAL1)
/*
 ICETOOL is used here to sort on timestamp and remove dupicate timestamp records.

Step 3 Sorted as per layout in FILE B.

//SORT03   EXEC PGM=SORT
//SORTIN   DD  DSN=FINAL.FILE,
//             DISP=SHR
//SORTOUT  DD  DSN=FINAL1.FILE,
//             DISP=(OLD,CATLG,DELETE),
//             SPACE=(CYL,(10,50),RLSE),VOL=(,,,40),
//             DCB=(RECFM=FB,BLKSIZE=0,LRECL=80)
//SYSOUT   DD  SYSOUT=*
//SYSPRINT DD  SYSOUT=*
//SORTLIST DD  SYSOUT=*
//SYSIN    DD  *
        INREC FIELDS=(27,9,1,26,36,3)
        SORT FIELDS=(1,26,CH,A)
/*
Sorted again in original file form.

Please refer PART1 and PART2 here.

Saturday, March 16, 2013

Interview Questions for COBOL


How do you do in-line PERFORM? 
        
PERFORM ... <UNTIL> ...
<sentences>
END-PERFORM

When would you use in-line perform?

     When the body of the perform will not be used in other paragraphs. If the body of the perform is a generic type of code (used from various other places in the program), it would be better to put the code in a separate Para and use
      PERFORM Para name rather than in-line perform.

 What is the difference between CONTINUE & NEXT SENTENCE ?
 They appear to be similar, that is, the control goes to the next sentence in the paragraph. 
 But, Next Sentence would take the control to the sentence after it finds a full stop (.). 
 Check out by writing the following code example, one if sentence followed by 3 display statements 
 If 1 > 0 then next sentence end if display 'line 1' display 'line 2'. display 'line 3'. Note- there is a dot (.) only at the end of the last 2 statements, see the effect by replacing Next Sentence with Continue.     

Wednesday, October 3, 2012

SYNCSORT or DFSORT: Part 2

SORT Function and Examples

SORT

SORT Fields: The syntax is given below:


SORT FIELDS=(p1,l1,f1,o1,p2,l2,f2,o2,.....) ¦         
FIELDS=(p1,l1,o1,p2,l2,o2...),FORMAT=x 
FIELDS={(} COPY {)} ¦                             
{,CKPT}                                           
{,DYNALLOC{=(d ¦ ,n ¦ d,n ¦ OFF)}}                
{,EQUALS ¦ ,NOEQUALS}                             
{,FILSZ={n ¦ En ¦ Un} }                           
{,SIZE={n ¦ En ¦ Un} }                            
{,SKIPREC=n}                                      

Tuesday, October 2, 2012

SYNCSORT or DFSORT: Part 1

The sort program is used to sort data into a desired sequence based on  business requirement. Also, it can be used to merge many files into one single file.

Features of the SYNCSORT utility

  • Copy Function
  • Merge function capable of merging up to 32 data sets into one sequence provided those data sets are sorted. Latest versions allow up to 100 data sets to be merged.
  • Sort facility which can sort single or concatenated data sets into one data set.
  • Conversion of the packed decimal fields to printable formats.