Ajesh
25th July 2016, 13:08
Hello there
i want to compare records from different tables using record buffer but i am not able to see anything in the record buffer.
PS: Both the tables have same structure.Heres my code below.
db.retry.point()
tfgld110_id = db.bind("ttfgld110",rcd.ttfgld110)
select tfgld110.*
from tfgld110
where tfgld110._index6 inrange {:bpid.f,:hold.comp} and
{:bpid.t,:hold.comp}
and tfgld110.dcdt inrange :date.f and :date.t
and tfgld110.vlac inrange :led.f and :led.t
and tfgld110.pvat <> 0
|order by tfgld110.vlac,tfgld110.bpid ASC
selectdo
ret = db.columns.to.record(tfgld110_id)
hold.gld.110 = rcd.ttfgld110
tfkmv110_id = db.bind("ttfkmv110",rcd.ttfkmv110)
select tfkmv110.*
from tfkmv110 for update
where tfkmv110._index1 = {:tfgld110.cono,:tfgld110.ttyp,:tfgld110.docn,
:tfgld110.lino,:tfgld110.serl,:tfgld110.sern}
selectdo
ret = db.columns.to.record(tfkmv110_id)
hold.kmv.110 = rcd.ttfkmv110
|if rcd.ttfgld110 <> rcd.ttfkmv110 then
if hold.gld.110 <> hold.kmv.110 then
populate.temporary.tax.table()
endif
selectempty
populate.temporary.tax.table()
endselect
endselect
commit.transaction()
Why i am not able to see anything in Record Buffer?
mark_h
25th July 2016, 15:07
Not sure I get the question. What do you mean you are not seeing anything in the record buffer? You should be able to display table fields to make sure the code is working. Not sure if ln is different or not. In 4c4 I use this to set record buffers - before the subroutine is called I have found a record. Granted I am not comparing it to another record buffer, but this is how I set them up.
string record.buf(1) based
function store.tpppc291.record.buffer()
{
if not record.len then
db.row.length(ttpppc291, record.len)
alloc.mem(record.buf, record.len)
endif
record.buf = rcd.ttpppc291
}
Ajesh
25th July 2016, 15:52
after binding the record Buffer to the Pointer to the table and transferring data from column to record buffer using db.columns.to.record ,the record buffer is still empty..
rcd.ttfkmv110="" and rcd.ttfgld110 = ""
Not sure if get the binding and the db.columns.to.record command right. If anybody can confirm?
mark_h
25th July 2016, 16:40
Comment out one of the db.columns.to.record commands and just check like rcd.ttfgld110. From reading the help I am not sure the command is necessary - see below - it mentions db.bind.
The record buffer of a table is used for reading records from that table. When you bind to a table (see db.bind()) and specify that the default record buffer is to be used, the contents of the table fields are automatically copied to the buffer. This does not happen when you specify a record buffer other than the default buffer. Consequently, you must call this function to copy the field values to the buffer if you have filled the fields before reading from the database.
Ajesh
25th July 2016, 16:57
commented out but its not coming as expected. The default buffers still come as blank..
mark_h
25th July 2016, 17:50
I am beginning to think the db.bind might need to be inside the loop. I found another example which shows it inside the selectdo statement with only db.bind(tablename) since the other parameters are optional. Try that for the first select statement.
Ajesh
26th July 2016, 09:22
Have included db.bind in the select statement as well as tried the below code which declares the variable as base and assigns memory location on runtime.
string rec.tfgld110(1) based,rec.tfkmv110(1) based
long rec.length.gld110,rec.length.kmv110
db.retry.point()
select tfgld110.*
from tfgld110
where tfgld110._index6 inrange {:bpid.f,:hold.comp} and
{:bpid.t,:hold.comp}
and tfgld110.dcdt inrange :date.f and :date.t
and tfgld110.vlac inrange :led.f and :led.t
and tfgld110.pvat <> 0
|order by tfgld110.vlac,tfgld110.bpid ASC
selectdo
tfgld110_id = db.bind("ttfgld110")
db.row.length(ttfgld110,rec.length.gld110)
alloc.mem(rec.tfgld110,rec.length.gld110)
rec.tfgld110 = rcd.ttfgld110
select tfkmv110.*
from tfkmv110 for update
where tfkmv110._index1 = {:tfgld110.cono,:tfgld110.ttyp,:tfgld110.docn,
:tfgld110.lino,:tfgld110.serl,:tfgld110.sern}
selectdo
tfkmv110_id = db.bind("ttfkmv110")
db.row.length(ttfkmv110,rec.length.kmv110)
alloc.mem(rec.tfkmv110,rec.length.kmv110)
rec.tfkmv110 = rcd.ttfkmv110
if rec.tfgld110 <> rec.tfkmv110 then
populate.temporary.tax.table()
endif
selectempty
populate.temporary.tax.table()
endselect
endselect
commit.transaction()
The db.columns.to.record and the db.record.to.column doesnt seem to be working, i dont know why...
I just want to compare records from different table. Both have exactly the same structure. If any field in the table differ, there it should give me a boolean value , Yes or No. Thats it.
mark_h
26th July 2016, 14:23
I think you will have to wait for someone to show up that is familiar with those commands - I have never used them. In 4c4 I can just select a record and the rcd buffer is available for me to use.
Ajesh
26th July 2016, 14:32
You mean you can actually see the value of the Record buffer? Like the Values inside?
if Yes, then please post any value of the Record Buffer, of course according to your time and convenience.
mark_h
26th July 2016, 15:18
I could not get it to work using just the rcd buffer in 4c4. I found a record in tdpur041 and set like record.buf1 =rcd.ttdpur041 and then found another record in tdpur041 and stored it off in record.buf2. Then compared the two record buffers and they are always equal.
PS - no I could not see any values in rcd.tdpur041 or record.buf1.
Ajesh
26th July 2016, 16:48
Okkkk... I could finally compare records in different tables. I used db.record.changed command.
tfkmv110_id = db.bind("ttfkmv110")
db.columns.to.record(ttfkmv110)
db.store.record(ttfkmv110)
if records.unequal() then
.....................
function domain tcbool records.unequal()
{
rcd.ttfkmv110 = rcd.ttfgld110
db.record.to.columns(ttfkmv110)
if db.record.changed(ttfkmv110) then
return(true)
endif
return(false)
}
First used db.store.record
Then assigned the Record Buffer to the Buffer i wanted to compare it with.
Then used db.record.to.columns
Then i used db.record.changed command to check whether the record buffer has been changed. It has worked..
The record buffer values are not shown but it does contain values.
mark_h
26th July 2016, 17:55
Nice solution.