OMIT: Substring search
OMIT: Substring search
Summary
- Substring search is used to filter the records which contain the substring anywhere from the starting position and length specified.
Syntax -
OMIT COND=(Field1 starting position, Field1 Length, SS,
Relational Operator, Substring constant)
Let’s discuss in detail.
Field1 starting position | Starting position of field1 to be compared |
Field1 Length | Length of the field1 to be compared |
SS | Specifying to SORT the filtering should be done based on the Substring search. |
Relation operator | Relational operators like GT, EQ, NE, LT etc,.
|
Substring constant | Substring constant |
Example -
Scenario - From the below data, filter the records not having Srinivas in the entire file.
Input File - MTH.SORT.INPUT
--+----1----+----2---+---3---+----4---+----5----+---6----+---7---+---8
********************************* Top of Data ******************************
00002 Srinivas Employee
test test test
00001 Pawan kumar Student
******************************** Bottom of Data ****************************
Input Record Layout -
01 INPUT-REC.
05 ID PIC X(05).
05 FILLER PIC X(05).
05 NAME PIC X(15).
05 FILLER PIC X(05).
05 OCCUPATION PIC X(10).
05 FILLER PIC X(40).
JCL -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//Job-card
//*
//*******************************************************************
//*
//* SORT FOR STRING SEARCH IN THE FILE
//*
//*******************************************************************
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=MTH.SORT.INPUT,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OMIT COND=(1,80,SS,EQ,C'Srinivas')
SORT FIELDS=COPY
/*
**************************** Bottom of Data **************************
Output -
--+----1----+----2----+----3---+----4----+----5----+---6---+---7---+----8
********************************* TOP OF DATA ******************************
test test test
00001 pawan kumar student
******************************** BOTTOM OF DATA ****************************
Explaining Example -
- As a first step, need to get the position NAME in the file.
- As per requirement, the string can be anywhere in the file. So the starting position is file starting position and the length is the file length which is 80.
- As a second step, need to get the type of the String.
- From the requirement,the string is alphabetic. So the type is character (CH).
- Lastly, the job requirement is to ignore the data with Srinivas. So the constant is "Srinivas".
- The OMIT condition for the above requirement with all the data gathered is
OMIT COND=(1,80,SS,EQ,C'Srinivas')
- The above condition specifies that ignore the records where the string found as Srinivas. The remaining records will be copied to output file.
- The output would have the records where the record not contains Srinivas anywhere in the record.