One way to do this is to write a pre-xlate tcl to do the sorting of the IN1 segments. I am assuming here, that while they aren’t coming out in order, they are coming all together.
First, split your message into segments. Grab the IN1 segments and their index’s (you will need to put them back into the message in the proper spots.
Second, loop through each IN1 segment, split on the field separator (|), and do an lappend to a list variable. Each split IN1 segment will be an element in the list. Also, while you are doing this, you can check the insurance date to make sure it is in effect. If it is, then you lappend to the list variable. IF it isn’t, then dont.
Third, perform an lsort using the -index option. For example:
lsort -index 22 $ins_grps
Fourth, grab the first four elements (IN segments) in the list, join each one back together with the field separator and place it back in the proper place in the message.
Remember, before you join the message back together, you need to accommodate for any IN1 segments you may have removed from the message list variable. You will need to remove any empty list elements.
Hope this gets your started!
Tom Rioux