Use a combination of CPYTOIMPF and the sort command to export sorted, fixed-format files.
Written by Tom Snyder
No matter how many ways I find to do something, I always run into a situation where I need to get creative. In various articles, I used SQL to export a physical file to a text file on the IFS, which gave me a lot of control over how I could sort the data that is being exported, but it didn't easily give me one thing that I needed, and that was to have the results in fixed format. Qshell to the rescue.
The QECCVTEC and QECEDT APIs offer flexibility in terms of providing run-time editing of numeric values.
Written by Bruce Vining
Back on May 5, Jeff Y. posed the following question on midrange-l (a popular i-related mailing list that you can access here):
"Does anyone have a UDF (or other SQL method) of taking a numeric field and returning a character value representing the value as edited via an edit code or edit word in RPG? I know that if I use CAST/SUBSTR/CONCAT that I can do this, but was looking for a neater way. Needs to be supported on V5R4 or earlier."