I am not sure why you have the last CONTINUE, as far as I can see that is not necesary and may be causing a part of the problem.
The other thing you will have to do is to manage your own outbound iteration counter. Using %g1 will not give you the results you want.
For each new message you create, your outbound iteration counter needs to restart at 0 and never be larger than 2.
So if you have 9 inbound iterations of the OBR:
Iteration 1: %g1 = 0 %(your counter) = 0
Iteration 2: %g1 = 1 %(your counter) = 1
Iteration 3: %g1 = 2 %(your counter) = 2
email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.