Frank,
I've a requirement to OMIT records with 167 consecutive zeros starting at byte position 1013 in the input file. Please suggest if there is a better way of writing this sort card. Thanks.
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
Quote:
I've a requirement to OMIT records with 167 consecutive zeros
If you mean character zeros (e.g. '0's), then you can use Krisprems INCLUDE statement, although I would use this OMIT statement to match your description better:
Frank and krisprems thanks for your responses. Indeed your sort card would solve my present problem.
I also wanted to learn a generic way to OMIT or INCLUDE records based on pattern of N consecutive characters in the input file. Often we have requirements where a record is omitted if there are N consecutive A's (B's or C's or '9' or AB's...) starting at particular position.
Please suggest if we can have generic sort card for these requirements.
szbhattacharjee
This SORT JOB in the first step creates an SYMNAMES with 10 consecutive A's
In the second step using the SYMNAME-CHECK_FOR you will be including only the records which have 10 consecutive A's in the position 5
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
Note that the technique shown by Krisprems to use a Symbol will only work for up to 64 characters since that's the limit for the length of a Symbol constant. So it won't work for your example of 167 repeating characters.
What would work is to use INREC to append the repeating constant to the end of each record and compare the field to it. For example, if your input file has RECFM=FB and LRECL=2000 and you want to compare a field starting in position 1013 to 167 A's, you could use these DFSORT control statements:
If in case we have to search for a string without knowing the position, may be we can accomplish like this
Code:
OPTION COPY
INCLUDE COND=(1,<LRECL>,SS,EQ,CHECK_FOR)
But frank, how a substring search can be in your case. If we could do that, then it would be a very helpful trick for us.
Quote:
Note that the technique shown by Krisprems to use a Symbol will only work for up to 64 characters since that's the limit for the length of a Symbol constant.
I was neither aware/nor thouhgt of limits, thanks for letting us know.
Quote:
So it won't work for your example of 167 repeating characters.
I think we can, For example if we have to check for a string of 100 A's in 1st position, the we can build an SYMNAMES having 50 A's
Code:
CHECK_FOR,C'AAAA.....A'
In the include cond
Code:
INCLUDE COND=(1,50,CH,EQ,CHECK_FOR,&,51,50,CH,EQ,CHECK_FOR)
I know this is tedious compared to your solution but just a thought
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
Quote:
If in case we have to search for a string without knowing the position, may be we can accomplish like this Code:
OPTION COPY
INCLUDE COND=(1,<LRECL>,SS,EQ,CHECK_FOR)
But frank, how a substring search can be in your case. If we could do that, then it would be a very helpful trick for us.
Since a substring search requires a constant, my method of creating a field with 167A's wouldn't work for substring search (but that wasn't what the OP asked for).
You could "generate" an INCLUDE statement with the required constant in one step and use that in SYSIN of another step, but the constant wouldn't fit on one line so you'd have to be careful to get the continuation syntax right.
Code:
INCLUDE COND=(1,50,CH,EQ,CHECK_FOR,&,51,50,CH,EQ,CHECK_FOR)
Yes, you could do that kind of thing with Symbols. Of course, for 167A's it would require a 64 character symbol (used twice) and a 39 character symbol. That's not too bad if you can hardcode the lengths, e.g.
Frank and Krisprems,
I tried all your solutions with some more permutations and combinations from my side. I'm overwhelmed by the results of all these sort cards.