EXTFILE Use

Discussions relating to writing software in ILE RPG (RPG IV). This includes both fixed and free format RPG.
Post Reply
kathan.p@gmail.com
Posts: 19
Joined: Wed Aug 04, 2021 7:27 pm

EXTFILE Use

Post by kathan.p@gmail.com »

Hi,
I am working on a program and it goes like below:-
1) It will read a definition file which have library name/file name in it ( around 50 different files)
2) Now based on the data received from external application i have to populate one of the file from step 1)
3) Now once i figure out which file to populate can i use EXTFILE(variable name) and populate that file name in variable in EXTFILE keyword using usropn and then open and close. and do the same step again and again with different file names?

I do understand i have to declare a dummy file in rpgle, is there any other better way of handling above case?
jonboy49
Posts: 200
Joined: Wed Jul 28, 2021 8:18 pm

Re: EXTFILE Use

Post by jonboy49 »

As I said on the Code400 list the answer is Yes. See that post for more comments.
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: EXTFILE Use

Post by Scott Klement »

kathan.p@gmail.com wrote: Tue Dec 28, 2021 6:07 pm 3) Now once i figure out which file to populate can i use EXTFILE(variable name) and populate that file name in variable in EXTFILE keyword using usropn and then open and close. and do the same step again and again with different file names?
Yes, that should work fine, provided that they have the same record layout.

If you wanted to handle different layouts (but still use external definitions) you'd need to use dynamic SQL, or API calls instead.
kathan.p@gmail.com wrote: Tue Dec 28, 2021 6:07 pm I do understand i have to declare a dummy file in rpgle, is there any other better way of handling above case?
I don't understand the "dummy file" comment. What do you mean by "dummy file"?
jonboy49
Posts: 200
Joined: Wed Jul 28, 2021 8:18 pm

Re: EXTFILE Use

Post by jonboy49 »

I don't understand the "dummy file" comment. What do you mean by "dummy file"?
I'm guessing he means the file declared on the DCL-F (F-pec) Scott - "dummy" in the sense that the file itself will never be used for data.
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: EXTFILE Use

Post by Scott Klement »

jonboy49 wrote: Tue Dec 28, 2021 10:47 pm I'm guessing he means the file declared on the DCL-F (F-pec) Scott - "dummy" in the sense that the file itself will never be used for data.
That's not a requirement. His EXTDESC could reference one of the files he plans to switch between. Or he could temporarily build a file in QTEMP, compile the program using its external definition, then remove it. Or he could use program described files. Or he could use dynamic SQL. Or....

The way he said it, it sounded like he was positive we'd tell him it was a requirement and wanted to save us the trouble.
Post Reply