Actually my requirement is just to move header and trailer
How does one "move" a header or trailer?
What you call junk appears to be packed-decimal or binary data.
Suggest you post those 8 input records using HEX ON (before the code executes).
If the code did what you believe you want, what would these records look like?
Then post these records after the code executes.
It is not at all clear what you are asking. . .