View previous topic :: View next topic
|
Author |
Message |
arien
New User
Joined: 02 Nov 2006 Posts: 43 Location: London
|
|
|
|
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 |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
Back to top |
|
|
arien
New User
Joined: 02 Nov 2006 Posts: 43 Location: London
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Good luck
Someone will be here if there are questions. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 ), 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 |
|
|
|