Darren,
To count the number of repetitions in any repeating ele4ment (segment, group, field, list) simply have an ITERATE with a MATH ADD Action inside that adds to your own counter (a temp field @).
At the end of that ITERATE you have a total of the number of repeating elemnts.
Yopu can ITERATE over that element set as many times as you need to accomplish your goals.
To accomplish your specific goal, the knowledge that you can maintain your own iteration counter (say %f99) may help.
So you could do something like :
MATH ADD $%f99 =1 —> $%f99
COPY MSH-4 —> OBX-5(%f99)
MATH ADD $%f99 =1 —> $%f99
COPY =random text —> OBX-5(%f99)
MATH ADD $%f99 =1 —> $%f99
COPY PID-3 —> OBX-5(%f99)
MATH ADD $%f99 =1 —> $%f99
COPY =random text —> OBX-5(%f99)
I suppose you will use some sort of condition to determine where inside the OBX-5 set to add other data. That would be inside an ITERATE over the OBX-5 field (using something other than %f99 – say %f1 in the ITERATE configuration and in the inbound address path and still using %f99 for the outbound address path remembering to manage your %f99 counter with MATH Actions as appropriate.
Note the $%xnn (in this case $%f99) is used when you want to directly reference the counter (such as in a MATH ACTION or a COPY Action or a CONCAT Action, etc.). The %xnn (no $ such as %f99) is used within an address path to indicate repetition.
If you would like more clarification contact me via email.
email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.