c_siek
4th May 2004, 17:53
Hi all,

I want to copy all data from one record of a file to another (existing) record of the same file.
How can I manage this?

Thanks in advance
Christiane

lbencic
4th May 2004, 18:15
If you are sure you want to overwrite the existing one, you can remove the target record (db.delete) change the key field of the source to the target key field, then do a db.insert.

Edited: You could also read the new record for update, then assign the new values field by field, then use db.update to update that record. If you are changing key fields, even secondary indexes, you should use the delete / reinsert.

c_siek
5th May 2004, 10:57
Hi Lisa,

sorry, your solution didn't work because I get a reference error when deleting the target record.

Is there any chance to work with db.bind(), db.columns.to.record() and db.record.to columns() ?
Just to store the values from the source record into a buffer and then changing the key and do an update?

I don't want to copy field by field because then I have to change my script each time the Table definition changes

mark_h
5th May 2004, 15:29
I do something like that using the table record buffer:


function store.tpppc210.record.buffer()
{
if not record.len then
db.row.length(ttpppc210, record.len)
alloc.mem(record.buf, record.len)
endif
record.buf = rcd.ttpppc210
}


Then you can go delete the original record. Restore the table buffer using rcd.ttpppc210 = record.buf, change fields, then do a db.insert.

Mark

cherokee
16th June 2004, 22:53
Hello,

I am using the example you gave here.

I defined the buffer record.buf as:

string record.buff(1,1) based

then I stored some records in there.
should I use the function "load" to retrieve values in my record.buff? or how can i retrieve the values in my record.buff array?

Thanks,

Carlos

mark_h
16th June 2004, 23:25
More info on what you are trying to do may help someone answer your question. In the example above I actual declare record buffer like this:

string record.buf(1) based


I only use it to hold the current record. So for example if I want to copy a record with only a key change then I can set rcd.<tablename> to record.buf, then insert. I have never used it to hold multiple records. I am not sure how you would search this string array.

Mark

cherokee
17th June 2004, 15:40
Mark,

Yes, can store several records in the buffer and use the original table to retrieve the values in my buffer by doing rcd.<table> = record.buf(1,i), no commits, not inserts, just reading.

Acctually I wanted to use it as tempory table. I am almost sure that there is another way to create a ram table, isn't?


Thanks,

Carlos

mark_h
17th June 2004, 16:41
Yeah - I can see where that would work. Store a bunch of records in the buffer array, reset each record with rcd.<tablename> = record.buff(1,i), then do some checks on the table fields. I can see where that would work. I can not think of anything better if you have to have a ram table and do not want to create and actual table.

Mark

NPRao
18th June 2004, 00:22
Acctually I wanted to use it as tempory table. I am almost sure that there is another way to create a ram table, isn't?

Carlos,

I see that you are on BaaN-4 I am not sure if these options are available to you.

BaanERP Application Software Engineering Guides
Caching table data and table boosters
--------------------------------------------------------------------------------

There is a close relationship to the table boosters, which can be maintained by the Table Boosters (tcmcs0598m000) session.

A table is cached by:

Activating a table booster in the Table Boosters (tcmcs0598m000) session.
An application program always uses table caching for a table.
If functionality of this DLL tccomdll0201 is applied in an application program, and the table booster is set to:

Full the table is loaded fully in internal memory, on the first access of that table. Each other access will be an access to internal memory.
Incremental, each accessed row of that table is stored in internal memory.
However, if a table cache is hard programmed in an application program, that table is loaded as programmed, independent of the table booster. In most times these tables are used as scratch tables, i.e. only internal memory will be used for writing, updating, deleting and sorting data.

An table booster will be written into tcmcs098 as inactive when one of the idb functions from DLL tccomdll0201 has been called for the first time for the currently running session.
When the same session has been ran for the second time the session will search for an active table booster on next priority:
1. table, session, user
2. table, session
3. table, user
4. table

So, by default an inactive table boosters will be written with only table and session filled.
Note: When record(s) has been found in one of the 4 situations, no default record will be generated anymore.
One can activate a booster by setting the value of the field VALID from 'inactive' to 'manual', 'manual/job' or 'job'.

And after that one can optionally perform the next different actions:

Make the booster user specific by copying the booster and fill the user code. A booster will become user dependent.
Make the booster more general by copying the booster and make session empty. This means that the specific table will be cached for all sessions for one user only.
The boosters per table, session (2) and table, session, user (1) should be removed in that case.
Make the booster more general by copying the booster and empty the session code and user code. This means that the specific table will be cached for all sessions.
The boosters per table, user (3) and table, session (2) and table, session, user (1) should be removed in that case.

Function idb.init()
--------------------------------------------------------------------------------

Syntax
function extern long idb.init(string table.name(8), string where.condition(512), long index.number, long number.of.fields,const string table.columns(,) [, long company.number [, const long full.load [, const long max.nr.rows [, const long physical.access]]]])

Description
This function initializes the caching functionality. The given table will be accessed in right index and memory will be allocated.
An initial 'where' condition can be given, which is valid for each read access on a table. It is possible to enter a selected list of fields, that should be cached.
Also can be specified if the caching will be done by setting the table boosters or not. If not, the load option (full/incremental) and the number of rows can be specified by function parameters.
Also can be specified if the caching is done physically or not.
The implementation of this function is optional.

Arguments
table.name Table name e.g. "ppmmm000"
where.condition Where condition as data filter (can be empty).
index.number The index number in the table on what all operations should be performed on.
number.of.fields The number of colums that has to be cached. Default is 0 (zero), which means that all columns should be cached.
table.columns An array with table columns. This can be empty when all columns are required.
company.number The company number where the cache functions should operate with. This argument is optional. Default is the current company number.
full.load TRUE means that all records will be loaded (where.condition will be taken into account). FALSE means that 'incremental' cache is active. -1 means that this value has to be taken from the table booster setting.
max.nr.rows The maximum number of rows to be cached. -1 means that this value has to be taken from the table booster setting.
physical.access This parameter indicates whether physical access should be done or not. When it is set to FALSE, only function idb.load() will perform physical access. The other idb functions are only accessing the internal memory.

Output
0 : OK
-1: Index doesn't exist.
I heard the terms Virtual Tables in BaaN, but I dont have much information. I believe the table exist but do not have any data in it.

BaanForever
18th June 2004, 16:43
Mark is right - it's the best way.
Also In the function itfgld0038 present universal solution.

#define itfgld0038.dim.rcd(X)
^ static string itfgld0038.buf##X(1) based
^ static long itfgld0038.len##X

#define itfgld0038.store.rcd.fields(X) {
^ if not itfgld0038.len##X then
^ db.row.length(##X, itfgld0038.len##X)
^ alloc.mem(itfgld0038.buf##X, itfgld0038.len##X)
^ endif
^ itfgld0038.buf##X = rcd.##X
^ }

#define itfgld0038.store.rcd.fields.no.lock.info(X) {
^ if not itfgld0038.len##X then
^ db.row.length(##X, itfgld0038.len##X)
^ alloc.mem(itfgld0038.buf##X, itfgld0038.len##X-6)
^ endif
^ itfgld0038.buf##X = rcd.##X
^ }

#define itfgld0038.restore.rcd.fields(X) {
^ rcd.##X = itfgld0038.buf##X
^ }

so you can use

itfgld0038.store.rcd.fields(YourTableName)
itfgld0038.restore.rcd.fields(YourTableName)