I recommend that you read and process the first data set, creating and filling stems of field tag, field type, starting position, and length (although in the sample data that you present the fields are contiguous and presumably start in position 1, this may not always be the case). Then process the second data set; for each input record iterate through the stems and use the SUBSTR function and concatenation operator to create an output record.
Aside from the obvious return code checks, there are at least two potential error conditions that you have to handle:
- What if the data record is of a different length than the layout?
- What if the data are different from the field definition (i.e., the field is defined as 9(6), but the data are "ABCXYZ")?
There are likely others, but I'm not moved to do a thorough job of analysis just now.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day