OMIT Substring Search


A substring search allows us to filter records by looking for specific substrings within a larger character field. DFSORT treats a substring as a portion of a field within a record that we can isolate based on its starting position and length. Substring searches are performed using the OMIT statements, focusing on a specific portion of a field.

Syntax -

//SYSIN DD * 
    SORT FIELDS=COPY
    OMIT COND=(field1_starting_position, field1_length, SS,
		 relational_operator, substring_constant)
/*
field1_starting_positionSpecifies the starting position of field1 to be compared
field1_lengthSpecifies the length of the field1 to be compared
SSSpecifies the search and filtering should be done based on the substring_constant.
relational_operatorused for condition comparison. The available operators are -
EQ 		Equal to
NE 		Not equal to
GT 		Greater than
GE 		Greater than or equal to
LT 		Less than
LE 		Less than or equal to
substring_constantSpecifies the substring used to filter.

Examples -


Scenario1 - Basic Substring Search.

OMIT COND=(10,2,CH,SS,C'HI')

This statement includes records where the 2-character field starting at position 10 not equals 'HI'. It looks at only the 2 bytes starting at position 10 in the record, rather than comparing the entire field.

Scenario2 - Using Multiple Substring Conditions with AND

OMIT COND=(5,3,CH,SS,C'XYZ',AND,20,4,CH,SS,C'ABCD')

This includes records where - the substring starting at position 5 (3 bytes long) is not equal to 'XYZ', and the substring starting at position 20 (4 bytes long) is not equal to 'ABCD'. Both conditions must be true for a record to be included.

Scenario3 - Substring Search with OR

OMIT COND=(1,2,CH,SS,C'AA',OR,10,3,CH,SS,C'999')

This example includes records where - the substring starting at position 1 (2 bytes) is not equal to 'AA', or the substring starting at position 10 (3 bytes) is not equal to '999'. If either condition is true, the record is included.