Try this.
01 RECORD-TO-BE-SEARCHED REDEFINES INPUT-RECORD.
05 FILLER OCCURS x TIMES DEPENDING ON BYTES-BEFORE-ITEM-IDENTIFIER.
10 FILLER PIC X.
05 ITEM-ITSELF.
10 ITEM-LENGTH COMP PIC S9(9) (maybe, doesn't specify).
10 FILLER OCCURS x TIMES DEPENDING ON LENGTH-OF-ITEM-LESS-ITS-LENGTH. (note, not ITEM-LENGTH)
15 FILLER PIC X.
05 DATA-TO-SEARCH-FOR PIC XX.
To start processing a new record,
Set BYTES-BEFORE-ITEM-IDENTIFIER to the fixed number of bytes before it could be item data
Set LENGHT-OF-ITEM to zero (yes, zero)
Then you can test ITEM-ITSELF against your table of requests. If it matches, put your key into your ouput record, calculate lenght-of-item-less... and move ITEM-ITSELF to output record. Write. Add ITEM-LENGTH to
BYTES-BEFORE-ITEM-IDENTIFIER and then you'll basically be there.
Of course, you'll need to be checking the length of your input record itself, or number of items on it, whatever you have and have not mentioned (or not obviously enough).
05 FILLER OCCURS x TIMES DEPENDING ON BYTES-BEFORE-ITEM-IDENTIFIER.
10 FILLER PIC X.
05 ITEM-ITSELF.
10 ITEM-LENGTH COMP PIC S9(9) (maybe, doesn't specify).
10 FILLER OCCURS x TIMES DEPENDING ON LENGTH-OF-ITEM-LESS-ITS-LENGTH. (note, not ITEM-LENGTH)
15 FILLER PIC X.
05 DATA-TO-SEARCH-FOR PIC XX.
To start processing a new record,
Set BYTES-BEFORE-ITEM-IDENTIFIER to the fixed number of bytes before it could be item data
Set LENGHT-OF-ITEM to zero (yes, zero)
Then you can test ITEM-ITSELF against your table of requests. If it matches, put your key into your ouput record, calculate lenght-of-item-less... and move ITEM-ITSELF to output record. Write. Add ITEM-LENGTH to
BYTES-BEFORE-ITEM-IDENTIFIER and then you'll basically be there.
Of course, you'll need to be checking the length of your input record itself, or number of items on it, whatever you have and have not mentioned (or not obviously enough).