Jill,
I don’t think you need to count up the PR1 group.
Based on your description and without the attachments which I don’t see, here is what I would do:
Will need to manage our own counter for the appending of PR1 to DG1 – let’s say %s99. So at the beginning of the Xlate initialize %s99 to 0 (zero).
ITERATE the DG1 segments Copying whatever is needed. Inside that ITERATE COPY the counter from the ITERATE (let’s say %s1) to our counter %s99.
At the end of the ITERATE the %s99 counter has the value of the last repetition of the DG1.
ITERATE over the PR1 group using %g1. First Action in the ITERATE do an IF Action – IF the %s99 is greater than 0 (use the IF action for this) then add 1 to %s99 (use the MATH Action with the ADD function for this). After the IF %s99 now points to the next DG1 segment to be created.
Now COPY (not PATHCOPY, COPY) each field from the PR1 (referenced by %g1) needed to go to the DG1 using %s99 for the DG1 reference.
You don’t need to worry about if there are no PR1 segments because the ITERATE won’t activate so no harm done.
The IF for greater than zero should take care of the situation where there are no inbound DG1 segments so that your PR1 information begins with the first repetition of DG1.
This may need some tweaking but I think the above approach will work – this can be done in the Xlate using only Xlate Actions if I understand the challenge correctly.
email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.