Page 1 of 1

EXTFILE Use

Posted: Tue Dec 28, 2021 6:07 pm
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?

Re: EXTFILE Use

Posted: Tue Dec 28, 2021 8:35 pm
by jonboy49
As I said on the Code400 list the answer is Yes. See that post for more comments.

Re: EXTFILE Use

Posted: Tue Dec 28, 2021 8:38 pm
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"?

Re: EXTFILE Use

Posted: Tue Dec 28, 2021 10:47 pm
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.

Re: EXTFILE Use

Posted: Thu Dec 30, 2021 2:06 am
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.