outra9e
28th June 2002, 12:59
Hi guys
I have written some custom sessions and am trying to validate between them.
I have written this function;
function check.fcn.status()
{
SELECT tssma912.fcnno, tssma912.msno, tssma912.ptor, tssma912.bncdr, tssma912.cldt, tssma912.cpln
FROM tssma912
WHERE tssma912.msno = :tdsls901.msno and tssma912.fcnno = :tdsls901.fcnno
selectdo
If not isspace (tssma912.ptor) and isspace (tssma912.bncdr) and isspace (tssma912.cldt) and isspace (tssma912.cpln) then
set.input.error("tdsls90003")
endif
endselect
}
It does not work!!!
On compiling the script I am getting no errors and I am a little confused!!
I have run it through the debugger and it is picking up and running through the function, but I am still having no luck
Can anyone help?
Cheers Guys
Maxali
28th June 2002, 14:13
Hi you have also to select in table 901
and it will work
by
evesely
28th June 2002, 16:02
The problem isn't tssma901. Is does not need to be part of the "from" statement since your are only using values of its fields for comparison (as if they were regular variables).
It's hard to know the problem since I can't see the structure of your table (tssma912). However, based on your field naming, I'm going to guess. Is tssma912.cldt a date field? If so, you need to make a numeric comparison. So, replace isspace(tssma912.cldt) with tssma912.cldt = 0. If any of your other fields are numeric in nature, similar changes should also be made.
outra9e
28th June 2002, 16:21
Thank you for all these suggesstions.
I have tried this ...
function check.fcn.status()
{
SELECT tdsls901.msno, tdsls901.fcnno, tssma912.fcnno, tssma912.msno, tssma912.ptor, tssma912.bncdr, tssma912.cldt, tssma912.cpln
FROM tssma912
WHERE tssma912.msno = :tdsls901.msno and tssma912.fcnno = :tdsls901.fcnno
selectdo
If tssma912.ptor = 0 and tssma912.cldt = 0 and tssma912.cpln = 0 then
set.input.error("tdsls90003")
endif
endselect
}
As you can see I have now made the changes as you suggested on the fields that are dates.
It still did not work...
Any more ideas?
Cheers
gfasbender
28th June 2002, 16:33
Shouldn't your set.input.error("tdsls90003") statement be in a field check.input section?
Your function should return a value if there's an error condition.
field.my.field:
check.input:
if check.fcn.status() then
set.input.error("tdsls90003")
endif
function long check.fcn.status()
{
SELECT tssma912.fcnno, ...
FROM tssma912
WHERE tssma912.msno = :tdsls901.msno ...
selectdo
If not isspace(tssma912.ptor) .. then
return(true)
else
return(false)
endif
endselect
return(false)
}
FransG
28th June 2002, 16:52
Make sure to check numeric variables to '0' and string variables to "". For performance reasons it's better to do this kind of checking by the database itself.
outra9e
28th June 2002, 17:43
Hi guys
right I have given it a try...
here is the code now ...
***********************************************
field.tdsls901.fcnno:
check.input:
force.fcnno.input()
if check.fcn.status() then
set.input.error("tdsls90003")
endif
***********************************************
function check.fcn.status()
{
SELECT tdsls901.msno, tdsls901.fcnno, tssma912.fcnno, tssma912.msno, tssma912.ptor, tssma912.bncdr, tssma912.cldt, tssma912.cpln
FROM tssma912
WHERE tssma912.msno = :tdsls901.msno and tssma912.fcnno = :tdsls901.fcnno
selectdo
If tssma912.ptor = 0 and tssma912.cldt = 0 and tssma912.cpln = 0 then
return(true)
else
return(false)
endif
endselect
return(false)
}
I have got the attached error...
SOrry if some if this seems really simple, im a bit new with scripting..
Cheers everyone
isimeon
28th June 2002, 18:26
Replace
function check.fcn.status()
with
function domain tcbool check.fcn.status()
or
function long check.fcn.status()
outra9e
1st July 2002, 14:26
I have made the changes as suggested and now the script compiles with no errors.
However it is not displaying the error message.
The data that I am looking up has no dates entered. Therefore the message should show.
Where a date hasn't been entered in all the required fields, it is at that point that the error message should come up.
I have checked the record that I am validating against.
It doesn't work :( any clues?
outra9e
1st July 2002, 15:31
Guys
Thank you for all your help.
Ignore the previous post, the function is now working correctly, I was in fact testing with a wrong record as per the last post.
Once again many thanks.
mark_h
1st July 2002, 15:33
In debug mode where is it failing? I am looking at this code.
field.my.field:
check.input:
if check.fcn.status() then
set.input.error("tdsls90003")
endif
function check.fcn.status()
{
SELECT tssma912.fcnno, tssma912.msno,
tssma912.ptor, tssma912.bncdr,
tssma912.cldt, tssma912.cpln
FROM tssma912
WHERE tssma912.msno = :tdsls901.msno and tssma912.fcnno = :tdsls901.fcnno
selectdo
If tssma912.ptor = 0 and tssma912.cldt = 0 and tssma912.cpln = 0 then
return(true)
else
return(false)
endif
endselect
return(false)
}
Where is it returning false? Step through the code and see what is in the tssma912 fields in the if statement.
Good Luck!
Mark
gous99
2nd July 2002, 20:11
If your code is the following...
***********************************************
field.tdsls901.fcnno:
check.input:
force.fcnno.input()
if check.fcn.status() then
set.input.error("tdsls90003")
endif
***********************************************
function check.fcn.status()
{
SELECT tdsls901.msno, tdsls901.fcnno, tssma912.fcnno, tssma912.msno, tssma912.ptor, tssma912.bncdr, tssma912.cldt, tssma912.cpln
FROM tssma912
WHERE tssma912.msno = :tdsls901.msno and tssma912.fcnno = :tdsls901.fcnno
selectdo
If tssma912.ptor = 0 and tssma912.cldt = 0 and tssma912.cpln = 0 then
return(true)
else
return(false)
endif
endselect
return(false)
}
I believe the problem might be in your select statement. you select tdsls901.msno and tdsls901.fcnno, but in the FROM section, it's only from tssma912.
Also, in your WHERE clause, you refer to "tssma912.msno = :tdsls901.msno" and "tssma912.fcnno = :tdsls901.fcnno"..
Once you've added tdsls901 in the FROM section, remove the ":" from your table fields in the WHERE clause, your SELECT, I believe, should look like this:
***********************************************
field.tdsls901.fcnno:
check.input:
force.fcnno.input()
if check.fcn.status() then
set.input.error("tdsls90003")
endif
***********************************************
function check.fcn.status()
{
SELECT tdsls901.msno, tdsls901.fcnno, tssma912.fcnno, tssma912.msno, tssma912.ptor, tssma912.bncdr, tssma912.cldt, tssma912.cpln
FROM tssma912, tdsls901
WHERE tssma912.msno = tdsls901.msno and tssma912.fcnno = tdsls901.fcnno
selectdo
If tssma912.ptor = 0 and tssma912.cldt = 0 and tssma912.cpln = 0 then
return(true)
else
return(false)
endif
endselect
return(false)
}
I might be wrong, but, if you did not solve it yet, maybe you should give it a try.
outra9e
3rd July 2002, 12:13
Thank you guys, this function is now up and running smoothly.
I was missing the "long" declaration in my function naming.
Cheers