Bryan's RPG IV Journal
Processing Several Files with the Same File Specifcation
Q. I have an RPG program that needs to read a large number of files and perform the same processing for each of them. I may not know the file names at compile time. Some of the files have different record lengths, and some of them even have different formats, although the critical fields correspond in each file (e.g., each file format has a field called Tranamount, Signed(13.2). How can I accomplish this requirement without having to code separate file specifications for each
file?
A. You can probably do what you want with a combination of the EXTFILE and USROPN F-spec keywords. If you can identify the the record format with a record identification field, you can describe each format with input specifications. In the file specification, use the record length of the longest record.
Here's a skeleton of what your code might look like:
FInput IF F 1028 Disk Extfile(Inputfile)
F Usropn
// ------------------------------ Standalone variables
D Inputfile S 21
// ------------------------------ Input specifications
// Transtype = 22 Savings debit
IInput NS 22 1 C2 2 C2
I 1 2 Trantype
I 15 27 2Tranamount
// Transtype = 23 Checking debit
I NS 23 1 C2 2 C3
I 1 2 Trantype
I 35 47 2Tranamount
// Transtype = 24 Misc debit
I NS 24 1 C2 2 C4
I 1 2 Trantype
I 63 75 2Tranamount
// ---------------------------------------------------
/Free
Dou *Inlr;
// For each file to be processed,
// assign name to Inputfile.
// Library name is optional.
Inputfile = 'MYLIBRARY' + '/' + 'MYFILE';
Open Input;
Dou %Eof(Input);
Read Input;
If %Eof(Input);
*Inlr = *On;
Else;
// Process record
Endif;
Enddo;
Close Input;
Enddo;
Return;
/End-free
Posted Tuesday, March 21, 2006
Log of Journal Entries |
|
Use this scrollable blog map to view other journal entries: |
|
| It is your responsibility to ensure procedures, techniques, and code used from this website are accurate and appropriate for your installation. No warranty or support is implied or expressed. |
![]() |
| Privacy and Email Policy |
| AS/400®, eServer, i5/OS, IBM i, Integrated Language Environment®, iSeries, OS/400®, RPG/400®, System i5, VisualAge®, and WebSphere® are trademarks of IBM Corporation. Note: IBM® System i is the latest member of the family of eServer iSeries. This site might refer to System i as System i5, iSeries, or AS/400. |
|
If you are having trouble navigating the menu at the top of this page, you may use the following scrollable site map instead: |
|
|











International visitors: