IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

usage of strip function in cobol embedded query


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
erhema

New User


Joined: 07 Oct 2008
Posts: 23
Location: Chennai

PostPosted: Mon Dec 27, 2010 3:11 pm
Reply with quote

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
View user's profile Send private message
singhju

New User


Joined: 01 Dec 2010
Posts: 25
Location: Gurgaon

PostPosted: Mon Dec 27, 2010 4:34 pm
Reply with quote

What is field_name1? Shouldn't you strip the :ws-variable instead fo column?
Please make your requirement more clear.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Dec 27, 2010 10:19 pm
Reply with quote

Hello,

What is the value in :ws-variable?
Back to top
View user's profile Send private message
erhema

New User


Joined: 07 Oct 2008
Posts: 23
Location: Chennai

PostPosted: Tue Dec 28, 2010 3:13 pm
Reply with quote

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
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed Jan 05, 2011 3:23 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top