David is right - I would only say, the I would completely avoid OVRDBF as a command from inside a RPG program - or better - I try to avoid OVRDBF completely - especially with SQL.

The easiest solution to open files from different libraries is to create the SQL statement dynamically - like:

#sql = 'INSERT INTO '+lib+'.TABLENAME VALUES(?, ?, ?, ?, ...';
exec sql prepare stmInsert from #sql;
exec sql execute stmInsert using :col1, :col2, :col3, :col4, ...;

This should work - you have to prepare the statement once per library/table and then execute it once for each record.

No OVRDBF needed.

HTH
Daniel


Am 02.02.2026 um 14:51 schrieb David Gibbs via RPG400-L <rpg400-l@xxxxxxxxxxxxxxxxxx>:

On Mon, Feb 2, 2026 at 7:46 AM Luca Giammattei <luca.giammattei@xxxxxxxxx>
wrote:

doU MyDS(x).companyLib = *blanks;
If %trim(MyDS(x).companyLib) <> defaultCompany;
rc=DoCmd('OVRDBF FILE(MyFILE00F) TOFILE(' +
%trim(MyDS(x).companyLib) + '/MyFILE00F)');


Are you closing the file before the OVRDBF and reopening it after?

The way I've always done that is...

1. Code the file as usropn.
2. Close the file if it's open (use %open bif)
3. Run the OVRDBF
4. Reopen the file
5. Close the file when done

david

Am 02.02.2026 um 14:46 schrieb Luca Giammattei <luca.giammattei@xxxxxxxxx>:

Hellò everybody.
In my IBM i we manage multiple companies.
Each company has its own data library, and the company data libraries all
have more or less the same files.
I receive an ascii file from outside and need to manage it by writing some
data to some companies, but not all of them.
So, in my program I have a situation like this (in semipseudocode):

dcl-ds MyDS qualified Inz dim(20);
companyLib char(10);
foo char(2);
bar char(12);
rtw likeds(rowsToWrite) dim(25);
End-DS;

---
doU MyDS(x).companyLib = *blanks;
If %trim(MyDS(x).companyLib) <> defaultCompany;
rc=DoCmd('OVRDBF FILE(MyFILE00F) TOFILE(' +
%trim(MyDS(x).companyLib) + '/MyFILE00F)');
if rc <> 0;
logError(yabadaba);
iter;
else;
rc=insertCompanyData(MyDS(x).rtw);
if rc=0;
exec sql commit;
else;
logError(anotheryabadaba);
endif
rc=DoCmd('DLTOVR FILE(MyFILE00F)');
if rc <> 0;
logError(yabadabadoo);
endif;
endif;
endIF;
x +=1;
endDo;


The program runs with a user who has associated a job description that
contains the list of libraries for company A, let's call it the default or
main company, but it must also be able to write to the file present in the
data library of company B and company C o D, one of the many other
companies we manage. Program is an sqlrpgle, data insert is done via "exec
sql insert into", pgm has no dcl-f or any f spec used, when running the
first over dub file it works like a charm, while the second time (or the
third or the fourth) the OVRDBF command does not work, and I don't see
anything in the DSPJOBLOG, substitions checked via DSPOVR command shows
nothing happened, I am for surely missing something, can any kind soul out
there point me to what i am missing? TIA


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.