hardei
17th April 2008, 09:01
Hello Friends,

I am working on one program in which i am displaying data from all companies.In the program I want to check whether the company exsist or not in that specific comapny.How should i go about it?

please see the code

select ttaad100.comp:company
from ttaad100
where ttaad100._compnr = 0
selectdo
select xxyyyzzz.*
from xxyyyzzz
where xxyyyzzz._compnr = :company
function()
endselect
endselect

If table xxyyyzzz doesnt exixst in any comapany then it is giving error ERROR 506.I want to skip that comapny if it is not present in that comapny.I cant hardcord any specific comapny as there ane many companies which will be not having table xxyyyzzz

Please Advice

Hardei

bdittmar
17th April 2008, 14:02
Hello Friends,

I am working on one program in which i am displaying data from all companies.In the program I want to check whether the company exsist or not in that specific comapny.How should i go about it?

please see the code

select ttaad100.comp:company
from ttaad100
where ttaad100._compnr = 0
selectdo
select xxyyyzzz.*
from xxyyyzzz
where xxyyyzzz._compnr = :company
function()
selectempty

endselect
endselect

If table xxyyyzzz doesnt exixst in any comapany then it is giving error ERROR 506.I want to skip that comapny if it is not present in that comapny.I cant hardcord any specific comapny as there ane many companies which will be not having table xxyyyzzz

Please Advice

Hardei

Use a selectempty !

Regards

zardoz
17th April 2008, 14:36
Use db.bind function to know if table exists:


select ttaad100.comp:company
from ttaad100
where ttaad100._compnr = 0
selectdo
if not db.bind("txxyyyzzz", "", company) then
select xxyyyzzz.*
from xxyyyzzz
where xxyyyzzz._compnr = :company
selectdo
function()
endselect
endif
endselect

mark_h
17th April 2008, 17:32
Or use dynamic sql. I used this to see if a specific field was being used. I think all you need to do is take this statement sql = sql & " where " & table.field & " <> """" as set with 1 rows" to something like this sql = sql & " where " & table.field & " = " & str$(company) & " as set with 1 rows" --- where table.field is set to xxyyyzzz._compnr

| Errors should now return false - so unallocated tables will be skipped.
error.bypass = 1
found = false
sql = "select " & table.field & " from " & table.name
sql = sql & " where " & table.field & " <> """" as set with 1 rows"
sql_id = sql.parse(sql)
sql.exec(sql_id)
while true
on case sql.fetch(sql_id)
case eendfile:
found = false
break
case 0:
found = true
break
default:
found = false
endcase
break
endwhile
error.bypass = 0
sql.break(sql_id)
sql.close(sql_id)

NPRao
17th April 2008, 19:48
Also, refer to the thread - check on table existance (http://www.baanboard.com/baanboard/showthread.php?t=14727&highlight=error.bypass)

hardei
22nd April 2008, 08:16
zardoz,

Thanks for your reply.but db.bind function is not working.after writing db.bind also it is giving me error 506.I am wrting a 3GL program.that could be a problem?

Regards,
Hardei