Re: Trouble managing OVRDBF inside a program
Daniel Gross <[email protected]>
| Newsgroups | gmane.comp.lang.as400.rpg |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]>: > > On Mon, Feb 2, 2026 at 7:46 AM Luca Giammattei <[email protected]> > 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 <[email protected]>: > > 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 > -- This is the RPG programming on IBM i (RPG400-L) mailing list To post a message email: [email protected] To subscribe, unsubscribe, or change list options, visit: https://lists.midrange.com/mailman/listinfo/rpg400-l or email: [email protected] Before posting, please take a moment to review the archives at https://archive.midrange.com/rpg400-l. Please contact [email protected] for any subscription related questions.