Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
String Search in a variable

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
arien

New User


Joined: 02 Nov 2006
Posts: 43
Location: London

PostPosted: Tue Oct 28, 2008 8:23 am    Post subject: String Search in a variable
Reply with quote

Hi all,

I need to perform a string search in a variable of length X(40). The search string can be "cleardown" or "clrdwn"etc and it can be starting at any position in the variable. Eg.

"cleardown 27/10"
"w/o cleardown "
"2007 clrdown"

Based on the presence or absence of the search string in this variable, I have to do some calculations.

Is it possible to perform a string search to determine absence /presence of a string?

Regards,
Arien
Back to top
View user's profile Send private message

Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Tue Oct 28, 2008 8:58 am    Post subject:
Reply with quote

If you're talking COBOL, you can search for a string using subscript, indexes, or reference modification but it's very tedious. Also, COBOL can't do "fuzzy" searches. Can you elaborate a bit on your requirement?
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Tue Oct 28, 2008 8:59 am    Post subject:
Reply with quote

Hello,

Quote:
Is it possible to perform a string search to determine absence /presence of a string?
Yes, but it will take a bit of code.

I'd suggest you set up an array that contains the search strings and their lengths.

Then, using reference modification, search the x(40) variable for each entry in the array. If the code moves completely thru the variable and none of the search strings are found, it is a no-hit. If a search string is found, it is a hit and the scanning of the variable should end.

Will the search string be constant or will different strings be used for different executions?
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Oct 28, 2008 12:17 pm    Post subject:
Reply with quote

Have a look at this thread
http://ibmmainframes.com/viewtopic.php?t=34435&highlight=
Back to top
View user's profile Send private message
arien

New User


Joined: 02 Nov 2006
Posts: 43
Location: London

PostPosted: Tue Oct 28, 2008 7:32 pm    Post subject:
Reply with quote

dick scherrer wrote:
Hello,

Yes, but it will take a bit of code.

I'd suggest you set up an array that contains the search strings and their lengths.

Then, using reference modification, search the x(40) variable for each entry in the array. If the code moves completely thru the variable and none of the search strings are found, it is a no-hit. If a search string is found, it is a hit and the scanning of the variable should end.

Will the search string be constant or will different strings be used for different executions?


I think I would have to go for this option and parse it for the 3 different strings -cleardown, clrdwn, cleardwn per reference modification.
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Tue Oct 28, 2008 7:58 pm    Post subject:
Reply with quote

Hello,

Good luck icon_smile.gif

Someone will be here if there are questions.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1243
Location: Israel

PostPosted: Tue Oct 28, 2008 9:43 pm    Post subject:
Reply with quote

Did I miss something ?
I took my test program and tried the following code:

Code:
    MOVE 'W/O CLEARDOWN AND DOWN' TO CONV-FROM       
    DISPLAY '<' CONV-FROM '>'                         
                                                     
    MOVE 0 TO GLBL-4                                 
    INSPECT CONV-FROM TALLYING GLBL-4 FOR ALL 'CLEAR'
    DISPLAY 'CLEAR tally is ' GLBL-4                 
                                                     
    MOVE 0 TO GLBL-4                                 
    INSPECT CONV-FROM TALLYING GLBL-4 FOR ALL 'CLEAN'
    DISPLAY 'CLEAN tally is ' GLBL-4                 
                                                     
    MOVE 0 TO GLBL-4                                 
    INSPECT CONV-FROM TALLYING GLBL-4 FOR ALL 'DOW'   
    DISPLAY 'DOW   tally is ' GLBL-4                 
                                                     
    MOVE 0 TO GLBL-4                                 
    INSPECT CONV-FROM TALLYING GLBL-4 FOR ALL 'DOM'   
    DISPLAY 'DOM   tally is ' GLBL-4                 

Then I took my test jcl and ran it. The output was:
Code:
<W/O CLEARDOWN AND DOWN
                       
                 >     
CLEAR tally is 0001     
CLEAN tally is 0000     
DOW   tally is 0002     
DOM   tally is 0000     

Is there any reason why INSPECT has not been suggested ???
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Tue Oct 28, 2008 10:27 pm    Post subject:
Reply with quote

Hi Marso,

Quote:
Is there any reason why INSPECT has not been suggested ???
In my case, personal preference. Whenever i've had a requirement to search text data for "things", my requirement has always been more than to just identify if the value existed or not.

Also, the first many years i coded such routines, they were written in assembler (before reference modification and using byte-by-byte parsing could dim the lights on the mainframe icon_smile.gif ), so i basically "upgraded" the parse process to cobol and reference modification so that non-assembler programmers could maintain the code after it was implemented.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Search for a string in many PDS KARTHIGADEVI CLIST & REXX 5 Fri Sep 08, 2017 2:32 pm
No new posts Moving values to a variable of copybo... Vignesh Sid COBOL Programming 6 Wed Sep 06, 2017 1:04 pm
No new posts Updating the Trailer count in variabl... satheshbabur DFSORT/ICETOOL 6 Wed Aug 30, 2017 9:49 pm
No new posts How to change a string containing the... chong.zhou TSO/ISPF 6 Tue Aug 29, 2017 4:54 pm
No new posts String after '.' (period) is not copy... balaji81_k SYNCSORT 6 Wed Aug 23, 2017 9:35 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us