Neal Matthews
30th June 2004, 17:07
Hello,
When running the following piece of code I am getting the following error as a result of the qss.search.
qss.start(a.sort.def, 1, 1)
qss.way(a.sort.def, 1, QSS.DOWN)
qss.type(a.sort.def, 1, DB.STRING)
qss.length(a.sort.def, 1, 6)
ret = qss.sort(dim4arr,a.sort.def)
ret = qss.search(QSS.SRC.IS.SORTED + QSS.EQUAL,tfgld106.dim4,dim4arr,a.sort.def)
Use of nul pointer on ''
What does this error mean in the case of the qss.search function.
Cheers
Neal Matthews
Intier Automotive - IT Support Analyst
mark_h
1st July 2004, 15:11
How are all the variables declared?
Mark
Neal Matthews
1st July 2004, 15:27
Hello Mark,
The variables are declared within the report script itself
string dim4arr(6,20)
long a.sort.def(1,4)
The tfgld106.dim4 is from the select statement within which the qss.search is running.
Cheers
Neal
mark_h
1st July 2004, 16:26
The only thing different that I can see to some code I use is the depth. It looks like the from my code they track how many elements are in the current array and then enter that into the last element of the qss.search.
Mark
Neal Matthews
1st July 2004, 17:48
Hi Mark,
Any chance you could post your code I think I really need another example to look at to try and get my head around what could be going wrong.
Cheers
Neal
mark_h
1st July 2004, 19:58
Lets see if I can get all the pieces.
function initialize.qss()
{
long ldum
long len.field
| sort definitions for contract charge no array
ldum = rdi.domain.string(domainof(cccn.tab), len.field, ldum)
qss.start(def.cccn, 1, 1)
qss.type(def.cccn, 1, DB.STRING)
qss.way(def.cccn, 1, QSS.UP)
qss.length(def.cccn, 1, len.field)
| sort definitions for cost price component array
ldum = rdi.domain.string(domainof(ccco.tab), len.field, ldum)
qss.start(def.ccco, 1, 1)
qss.type(def.ccco, 1, DB.STRING)
qss.way(def.ccco, 1, QSS.UP)
qss.length(def.ccco, 1, len.field)
}
function determine.table.index.for.cost.price.component()
{
domain tcbool ccco.found
ccco.found = false
check.cost.price.comp(ccco.found)
if not ccco.found then
search.cost.price.comp.table.index(ccco.found)
endif
if not ccco.found then
add.cost.price.comp.table.index()
endif
}
function check.cost.price.comp(ref domain tcbool found)
{
if ccco.i > 0 then
if ccco.tab(1,ccco.i) = cost.comp then
found = true
endif
endif
}
function search.cost.price.comp.table.index(ref domain tcbool found)
{
long i
i = qss.search(flag.ccco, cost.comp, ccco.tab, def.ccco, max.ccco.i)
if i > 0 then
ccco.i = i
found = true
endif
}
function add.cost.price.comp.table.index()
{
max.ccco.i = max.ccco.i + 1
ccco.i = max.ccco.i
ccco.tab(1,ccco.i) = cost.comp
if ccco.i > 1 and cost.comp < ccco.tab(1, ccco.i-1) and
bit.in(QSS.SRC.IS.SORTED, flag.ccco) then
flag.ccco = flag.ccco - QSS.SRC.IS.SORTED
endif
}
Just a note I have never really messed with or tried to understand that last routine. I am not sure what exactly it does other than track the last element and add to the array. The reason I mentioned the depth or last argument was because I just thought that the search may hit an element that was null(or not set) and maybe that was causing the error.
Mark
Neal Matthews
2nd July 2004, 10:50
Mark,
The problem does appear to be the value of tfgld106.dim4. I have the following code below to add up ytd values.
|* Save pos of rec pointer
db.row.length(ttfgld106,row.length)
alloc.mem(buf.tfgld106,row.length)
buf.tfgld106 = rcd.ttfgld106
|*
|select tfgld106.fprd,tfgld106.rprd,tfgld106.leac,tfgld106.fyer,tfgld106.ryer,
|tfgld106.dim1,tfgld106.dim2,tfgld106.dim4,tfgld106.otyp,tfgld106.odoc,tfgld106.amth
|from tfgld106
|where tfgld106._index5 = {:m_dim2} and
| tfgld106.dim4 = :m_dim42 and
| tfgld106.dim1 >= :dim1.f and tfgld106.dim1 <= :dim1.t and
| tfgld106.dim2 >= :dim2.f and tfgld106.dim2 <= :dim2.t and
| tfgld106.dim4 >= :dim4.f and tfgld106.dim4 <= :dim4.t
|selectdo
| if tfgld106.dbcr = tfgld.dbcr.debit then
| m_totald6 = m_totald6 + tfgld106.amth
| else
| m_totalc6 = m_totalc6 + tfgld106.amth
| endif
|endselect
|*Restore rec pointer
rcd.ttfgld106 = buf.tfgld106
free.mem(buf.tfgld106)
If I remove the piece of code that restores the record pointer then the code runs although I need to be sure that taking this out will not have any effect on the select statement. If there any easy way to test for the condition that is causing the problem so I can avoid resetting rcd.ttfgld106 in this circumstance.
Cheers
Neal
mark_h
2nd July 2004, 15:33
I guess I am missing something - where does the qss code run in relationship to code you posted? Second from the code you posted it looks like you have a tfgld106 record you want to use, then you go and get the ytd totals. One way to avoid using the record buffers is to use aliases. You select a bunch of fields but only use 2 in the selectdo. I also assumed you accidently left tfgld106.dbcr off the select by mistake. You could do something like this:
select tfgld106_a.amth:amth, tfgld106_a.dbcr:dbcr
from tfgld106 tfgld106_a
where tfgld106_a._index5 = {:m_dim2} and
tfgld106_a.dim4 = :m_dim42 and
tfgld106_a.dim1 >= :dim1.f and tfgld106_a.dim1 <= :dim1.t and
tfgld106_a.dim2 >= :dim2.f and tfgld106_a.dim2 <= :dim2.t and
tfgld106_a.dim4 >= :dim4.f and tfgld106_a.dim4 <= :dim4.t
selectdo
if dbcr = tfgld.dbcr.debit then
m_totald6 = m_totald6 + amth
else
m_totalc6 = m_totalc6 + amth
endif
endselect
This would leave the original tfgld106 record untouched. Do not forget you have to declare dbcr and amth appropriately.
Mark