simona
16th January 2012, 18:57
Hello,

I have a problem and I don't know how to handle it. I hope you can help...

My DAL script for table tiitc102, when updating a line, should insert/update/delete also in tirou102. But it doesn't... only sometimes (~2 times from 10). I attached the script.

I debugged the dal script and my function after.save.object() is executing... but not writing in tirou102.
Could you please advise? Thank you!

Kind regards,
Simona


|*************************************************************
|* tiitc102 0 VRC B61U l rom
|* dal tiitc102
|* diciu
|* 10-02-01 [11:20]
|*************************************************************
|* Script Type: DAL
|*************************************************************

#include <bic_dal2>
#include <bic_text>


function extern long before.open.object.set()
{
return(0)
}

function extern long after.save.object(long type)
{
table ttirou102, ttiitc102
long ret

if type = DAL_NEW then
select tirou102.*
from tirou102 |||for update
where tirou102._index1 = {:tiitc102.mitm, :tiitc102.opro, :tiitc102.opno, :tiitc102.seqn}
selectempty

|dal.new.object ("tirou102")

tirou102.mitm = tiitc102.mitm
tirou102.opro = tiitc102.opro
tirou102.opno = tiitc102.opno
tirou102.seqn = tiitc102.seqn
tirou102.tano=tiitc102.tano
tirou102.cwoc=tiitc102.cwoc
tirou102.mcno=tiitc102.mcno
tirou102.sutm=tiitc102.sutm
tirou102.rutm=tiitc102.rutm
tirou102.mcoc=tiitc102.mcoc
tirou102.subr=0
tirou102.suba=""
tirou102.whsa=""
if tiitc102.rutm <> 0.0 then
tirou102.prte=60/tiitc102.rutm
else
tirou102.prte=0
endif
tirou102.indt=tiitc102.indt
tirou102.exdt=tiitc102.exdt
tirou102.efco=""
tirou102.exco=""
tirou102.bfls=tiitc102.bfls
tirou102.cont=""
tirou102.crem=""
tirou102.qpnt=0
tirou102.nnts=0
tirou102.desn=""
tirou102.copo=tiitc102.copo
tirou102.scpq=0
tirou102.ploc=""
tirou102.ydtp=tiydtp.not.applicable
tirou102.yldp=100
tirou102.stcf=tcyesno.yes
tirou102.unef=tcyesno.no
tirou102.exin=""
tirou102.fxsu=0
tirou102.fdur=tcyesno.no
tirou102.tlyn=tcyesno.no
tirou102.trls=0
tirou102.most=tiitc102.most
tirou102.mopr=tiitc102.mopr
tirou102.cact=""
tirou102.tuni=tctope.days
tirou102.qutm=0
tirou102.trdl=0
tirou102.mvtm=0
tirou102.dmso=tcyesno.no

dal.new("tirou102", ttirou102, e, true, db.retry)

endselect
endif

if type = DAL_UPDATE then
select tirou102.*
from tirou102 for update
where tirou102._index1 = {:tiitc102.mitm, :tiitc102.opro, :tiitc102.opno, :tiitc102.seqn}
selectdo
tirou102.tano=tiitc102.tano
tirou102.cwoc=tiitc102.cwoc
tirou102.mcno=tiitc102.mcno
tirou102.sutm=tiitc102.sutm
tirou102.rutm=tiitc102.rutm
tirou102.mcoc=tiitc102.mcoc
tirou102.subr=0
tirou102.suba=""
tirou102.whsa=""
if tiitc102.rutm <> 0.0 then
tirou102.prte=60/tiitc102.rutm
else
tirou102.prte=0
endif
tirou102.indt=tiitc102.indt
tirou102.exdt=tiitc102.exdt
tirou102.efco=""
tirou102.exco=""
tirou102.bfls=tiitc102.bfls
tirou102.cont=""
tirou102.crem=""
tirou102.qpnt=0
tirou102.nnts=0
tirou102.desn=""
tirou102.copo=tiitc102.copo
tirou102.scpq=0
tirou102.ploc=""
tirou102.ydtp=tiydtp.not.applicable
tirou102.yldp=100
tirou102.stcf=tcyesno.yes
tirou102.unef=tcyesno.no
tirou102.exin=""
tirou102.fxsu=0
tirou102.fdur=tcyesno.no
tirou102.tlyn=tcyesno.no
tirou102.trls=0
tirou102.most=tiitc102.most
tirou102.mopr=tiitc102.mopr
tirou102.cact=""
tirou102.tuni=tctope.days
tirou102.qutm=0
tirou102.trdl=0
tirou102.mvtm=0
tirou102.dmso=tcyesno.no

|||ret=TEXT.COPY("tirou102.txta", "tiitc102.txtb", "", "", "", "", "", "")

dal.update("tirou102", ttirou102, e, false, db.retry)
endselect
endif

return(0)
}


|simona:
function extern long before.destroy.object()
{
long ret
select tirou102.*
from tirou102 for update
where tirou102._index1 = {:tiitc102.mitm, :tiitc102.opro, :tiitc102.opno, :tiitc102.seqn}
selectdo
|||ret=text.delete("tirou102.txta", "")

dal.destroy("tirou102", ttirou102, e, false, db.retry)
endselect
return(0)
}





function extern long after.get.object(long dir)
{
return(0)
}

function extern long before.get.object(long dir)
{
return(0)
}

function extern long after.change.object ()
{
return(0)

}

function extern after.commit.transaction ()
{
long r
r=2

}

function extern long after.new.object ()
{
return(0)
}

function extern long before.change.object ()
{
return(0)
}


function extern long before.new.object()
{
| The DAL now knows that a new record is about to be created.
return(0)
}


function extern long before.save.object(long mode)
{
long r
if mode = DAL_NEW then
| this is code from before.write subsection
r=2

else
| this is code from before.rewrite subsection
r=2

endif
return(0)
}

v_kewl
17th January 2012, 08:06
Hi Simona,

What is the error code you are getting ? And just a suggestion as you have included <bic_dal2> it will be better if you use "dal.new.object" followed by field value assignment then "dal.save.object" in case of DAL_NEW and for DAL_UPDATE you can use initially "dal.change.object" followed by field value assignment then "dal.save.object".

Regards,
Gaurav

ipineda
17th January 2012, 18:53
Hi simona,

You have the following errors:

1. You have to assign the values of tirou102 with DAL function dal.set.field().
2. I suggest you to replace:
dal.new() --> dal.new.object()
dal.update() --> dal.change.object()
dal.destroy() --> dal.destroy.object()
This is because these ones are new versions of the ones you are using.
3. Don“t delete the tirou102 record form before.destroy.object(), instead use after.destroy.object() hook.


Here i suggest you how the code should look like:


function extern long after.save.object(long type)
{
if type = DAL_NEW then
dummy.ret = dal.new.object("tirou102")

dal.set.field("tirou102.field1", value)
dal.set.field("tirou102.field2", value)
...

dummy.ret = dal.save.object("tirou102")
endif

if type = DAL_UPDATE then
select tirou102.*
from tirou102 for update
where .....
selectdo
dummy.ret = dal.change.object("tirou102")

dal.set.field("tirou102.field1", value)
dal.set.field("tirou102.field2", value)
...

dummy.ret = dal.save.object("tirou102")
endselect
endif
}
function extern long afer.destroy.object()
{
select tirou102.*
from tirou102 for update
where .....
selectdo
dummy.ret = dal.destroy.object("tirou102")
endselect
}



Also remember that errors may occur so it is a good idea to see if DAL is giving you messages, you can do it with dal.get.error.message().

I hope this information will help you.

vahdani
17th January 2012, 19:10
Hi,

if I'm right you are on LN. Then you should use the beautiful DAL2 methods.

Here is the script as it should be


extern long after.save.object(long type)
{
table ttirou102, ttiitc102
long ret

ret = 0
if type = DAL_NEW then
select tirou102.*
from tirou102
where tirou102._index1 = {:tiitc102.mitm, :tiitc102.opro, :tiitc102.opno, :tiitc102.seqn}
selectempty
dal.new.object ("tirou102")
dal.set.field("tirou102.mitm", tiitc102.mitm)
dal.set.field("tirou102.opro", tiitc102.opro)
dal.set.field("tirou102.opno", tiitc102.opno)
dal.set.field("tirou102.seqn", tiitc102.seqn)
set.tirou102.fields()
ret = dal.save.object("tirou102")
endselect
endif

if type = DAL_UPDATE then
select tirou102.*
from tirou102 for update
where tirou102._index1 = {:tiitc102.mitm, :tiitc102.opro, :tiitc102.opno, :tiitc102.seqn}
selectdo
dal.change.object("tirou102")
set.tirou102.fields()
ret = dal.save.object("tirou102")
endselect
endif

return(ret) |return dal.save.object result!!!
}

function set.tirou102.fields()
{
dal.set.field("tirou102.tano", tiitc102.tano)
dal.set.field("tirou102.cwoc", tiitc102.cwoc)
dal.set.field("tirou102.mcno", tiitc102.mcno)
dal.set.field("tirou102.sutm", tiitc102.sutm)
dal.set.field("tirou102.rutm", tiitc102.rutm)
dal.set.field("tirou102.mcoc", tiitc102.mcoc)
if tiitc102.rutm <> 0.0 then
|this may be calculated in DAL so comment it out
dal.set.field("tirou102.prte", 60/tiitc102.rutm)
endif
dal.set.field("tirou102.indt", tiitc102.indt)
dal.set.field("tirou102.exdt", tiitc102.exdt)
dal.set.field("tirou102.bfls", tiitc102.bfls)
dal.set.field("tirou102.copo", tiitc102.copo)
dal.set.field("tirou102.ydtp", tiydtp.not.applicable)
dal.set.field("tirou102.yldp", 100)
dal.set.field("tirou102.stcf", tcyesno.yes)
dal.set.field("tirou102.unef", tcyesno.no)
dal.set.field("tirou102.fdur", tcyesno.no)
dal.set.field("tirou102.tlyn", tcyesno.no)
dal.set.field("tirou102.most", tiitc102.most)
dal.set.field("tirou102.mopr", tiitc102.mopr)
dal.set.field("tirou102.tuni", tctope.days)
dal.set.field("tirou102.dmso", tcyesno.no)
}

simona
19th January 2012, 14:50
Hi,

Replacing old functions with the new ones and making from type Dal to Dal2 solved my problems.

Thank you everybody!

Sim