View previous topic :: View next topic
|
Author |
Message |
erhema
New User
Joined: 07 Oct 2008 Posts: 23 Location: Chennai
|
|
|
|
I used strip function in QMF and it works and in cobol program the same query is not working.
Will Cobol support this scalar function ?
Here is my query, Please help
ws-variable pic x(3).
EXEC SQL
select *
from tablename
where
strip(field_name1) like : ws-variable
END-EXEC
When ws-variable holds the value of 3 bytes, it works fine. when a two byte value is passed to this variable, it fails. ( I have used LIKE because i want to use it as a search function, if ws-variable is spaces '%%%' will be passed for search to pick all the data in the cobol program, if ws-variable is not spaces, the exact value has to be searched. )
Thanks. |
|
Back to top |
|
|
singhju
New User
Joined: 01 Dec 2010 Posts: 25 Location: Gurgaon
|
|
|
|
What is field_name1? Shouldn't you strip the :ws-variable instead fo column?
Please make your requirement more clear. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
What is the value in :ws-variable? |
|
Back to top |
|
|
erhema
New User
Joined: 07 Oct 2008 Posts: 23 Location: Chennai
|
|
|
|
Hi,
I got the result by using the below query (using STRIP on both sides)
EXEC SQL
select *
from tablename
where
strip(field_name1) like strip( :ws-variable )
END-EXEC
My Previous query worked for the value of ws-variable 'ABC' etc.. (i.e of 3 bytes), but it failed for 'AB' or 'CD' (any value that is less than 3 bytes).
Now, using STRIP on both sides, it is working for values less than or equal to 3.
Thanks for your reply. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
ws-variable will always be 3 bytes , thus never 'AB' or 'CD' but 'AB ' or 'CD '
I'll assume that field_name1 is defined as char(3).
field_name1 can be 'AB ' or 'CD '
strip(field_name1) will then be 'AB' or 'CD'
'AB' like 'AB ' will return FALSE
'AB ' like 'AB ' will return TRUE
strip('AB ') like strip('AB ') will return TRUE
thus actually you should not use STRIP() anywhere. adding strip() will only make performance worse.
If field_name1 is a varchar then it is a different story. Then you should use a different definition for ws-variable. |
|
Back to top |
|
|
|