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

String Search in a variable


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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

Moderator Emeritus


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

PostPosted: Tue Oct 28, 2008 8:59 am
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
Reply with quote

Have a look at this thread
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
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

Moderator Emeritus


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

PostPosted: Tue Oct 28, 2008 7:58 pm
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: 1353
Location: Israel

PostPosted: Tue Oct 28, 2008 9:43 pm
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

Moderator Emeritus


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

PostPosted: Tue Oct 28, 2008 10:27 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
Search our Forums:

Back to Top