spartacus
20th February 2002, 15:48
I would like to copy a selected range of a table, from one company to the same table in an other company.

I know a solution with selecting data in the first company, assign the data to variables, switch to the second company, assign the varibles to the tables fields, and insert this in the second company.

Is there no faster way? I mean assinging always all fields of the table needs a lot of typing work.
Isn't there a way, just select a table in one company, switch to the other company and just insert the previous selected data in the new companies table?

Thanks
spartacus

naabi0
20th February 2002, 16:54
You can use GTM to copy a range of records from the same table in another company to the current company/table you have open, but I believe it has to be the same Package Combination.

günther
20th February 2002, 16:56
As far as I remember, I've been doing it the following way:

switch.to.company( <your source company> )
db.retry.point()
select tiitm001.*
from tiitm001
where tiitm001._index1 = {<some item>}
selectdo
tiitm001._compnr = <your destination company>
db.insert(ttiitm001, db.retry)
endselect
commit.transaction()

For more details on the special field _compnr check the tools documentation / baan sql.

Günther

lbencic
20th February 2002, 16:56
You can set up an exchange if you are going to do the process a lot. That type of exchange is the easiest: just plug in the table names and you can have most of it generated. You run the export in one company, then the import in another. There is standard documentation on the baan support site that's easy to follow for this type of exchange. Post your email back if you do not have access. You can set up ranges to export.

Another method is through Create Sequential Dump from Table (ttaad4226m000) and Create Table through Sequential Dump (ttaad4227m000). That dumps the whole table. It's also a little confusing, as you also have all those options to repair tables.

A quick and dirty way to dump the table is in General Table Maintenance. When inside, hit the space bar...you get to a menu. Choose "Application" / "Export Data". It will only ask for a directory. It will dump the whole table. You can actually modify that dump if you need to delete anything... Then, switch to your new company in GTM, and run the "Import Data". The file is in the exact format it wants then.

So..sure, lots of options. Good luck!

spartacus
20th February 2002, 17:50
A big thanks to all for your quick answers.

I tried Günthers solution, because it fits the most to my demand, and it works very fine.

Thanks and regards
spartacus

MrMarco
25th March 2002, 18:08
Actually, this has been very helpful with something I have been trying to do myself.

A big "Thank you" from me too!

abattoir
9th August 2015, 03:24
I have a requirement which is an extension to this thread, so making it alive.
After i have copied the data from parent company to target company, i want to delete the record from parent company. Its like archiving. you insert a record in another company and delete the same record from current company.

Is there a code to do this efficiently and not having me to assign all field values to variable, then insert those variables to new company and then go back to current company to delete the same record using variables?

Thanks in advance,

bhushanchanda
9th August 2015, 07:55
Hi,

Try this-

switch.to.company( <your source company> )
db.retry.point()
select tiitm001.*
from tiitm001
where tiitm001._index1 = {<some item>}
selectdo
tiitm001._compnr = <your destination company>
db.insert(ttiitm001, db.retry)
endselect
commit.transaction()

switch.to.company( <your source company> )
db.retry.point()
select tiitm001.*
from tiitm001 for update
where tiitm001._index1 = {<some item>}
selectdo
db.delete(ttiitm001, db.retry)
endselect
commit.transaction()

OR


switch.to.company( <your source company> )
db.retry.point()
select tiitm001.*
from tiitm001 for update
where tiitm001._index1 = {<some item>}
selectdo
tiitm001._compnr = <your destination company>
db.insert(ttiitm001, db.retry)
tiitm001._compnr = <your source company>
db.delete(ttiitm001,db.retry)
endselect
commit.transaction()

Ajesh
10th March 2016, 09:12
I pretty much think that using <table_field>._compnr is the easiest and simplest way to perform it but i was just wondering if we can do the above requirement using db.record.to.column and db.column.to.record



long tab_id_old,tab_id_new
string rec.buffer_old,rec.buffer_new

select tdsls870.*
from tdsls870 for update
where tdsls870._index1 = {:hold.orno,:hold.pono
selectdo
tab_id_old = db.bind("tdsls870",rec.buffer_old)
db.columns.to.record(tab_id_old)
switch.to.company(600)
tab_id_new = db.bind("tdsls870",rec.buffer_new)
rec.buffer_new = rec.buffer_old
db.record.to.column(tab_id_new)
db.insert(ttdsls870,db.retry)
commit.transaction()
endselect

shah_bs
10th March 2016, 23:44
Keep in mind that, for any table in BAAN, unless it is a small free-standing table with no references, copying records across company numbers or deleting records (ESPECIALLY deleting records) is not always a very simple task, due to referential integrity enforced within BAAN.

For example: take Item Master (this is the worst case example, in any case). This table has several references like Unit of Measure, Item Group, Buyer, Planner, etc. which are MANDATORY. UNLESS the TARGET Company has ALL Of the references required by the Item Master Record being copied, it will fail due to missing references.

As far as deletion is concerned: Item Master is the MOST DIFFICULT record to delete, because first, it is necessary to DELETE ALL of the related 'child reference' records: Purchase Orders, Production Orders, Sales Orders, Planned Orders, etc. etc.

I would extend the db.insert as follows to allow for handling the error (usually duplicate record error) instead of a catastrophic failure of the session:


db.insert(ttiitm001, db.retry, db.return.error)

And then handle or ignore errors as appropriate.

Also, for multiple tables, switch.to.company() may not quite fit in. So, instead, in my experiments with archiving, I was doing as follows (in which tisfc001 is the 'driving' table and its record is archived first):


function archive.tisfc951()
{
select tisfc951.*
from tisfc951 for update
where tisfc951._index1 = {:tisfc001.pdno}
and tisfc951._compnr = :p.source.ncmp.c
order by tisfc951._index1
selectdo
tisfc951._compnr = p.archive.ncmp.c
db.insert(ttisfc951, db.retry)
endselect
}