Hi, in the below input file (LRECL=49,RECFM=FB) there are few records with value "2651" appearing twice in the same line. The 6 byte key starts at 4th column and is followed by 4 digit numbers till 49th column. So, I need to search for value "2651" in between 10th and 49th column and if any record has two of "2651" appearing then write such ones to output.
Joined: 09 Mar 2011 Posts: 7312 Location: Inside the Matrix
What if there are more that two occurrences?
For two, or for the size of your record, PARSE is going to be the correct way.
Have a look at STARTAT in PARSE, and ensure you know how PARSE works. Experiment if necessary.
If the field from the second STARTAT is non-blank, then you have two (or more) of that particular value. You have fixed-length records, so extend at the end of each record. You only need one byte from the PARSEd field, as it will be just blank or non-blank.
If you arrive at an answer, please post it.
If you have difficulties, please show what you have tried, what went wrong, and what you expected to happen.
You shouldn't need two PARSEd fields. If you are going to use a field, give it a %nn, if you are just using it for positioning, give it a simple %.
From the second PARSE, all you are interested in is when a value was found. If a value was not found, then the PARSEd result with a length of 1 will be space. If a value was found (that value being 2651) then the length of 1 will give "2", which is non-blank.
The first part of the PARSE locates 2651 if present, and advances the parse pointer by four bytes.
The second part of the PARSE locates a second 2651 if present, and allows you to reference the first byte found, by name (%01 here).
Ensure that you test with consecutive "2651"s and more than two on the same record.