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

another special scenario for string searching.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Keanehelp

New User


Joined: 27 May 2008
Posts: 71
Location: USA, CA.

PostPosted: Tue Dec 30, 2008 4:09 am
Reply with quote

Hi,

I have a different problem now. How can I search for a substring in a string. For ex what should I do for searching 'GHI' from 'ABCDEFGHIJKLMN'.

Thanks
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 Dec 30, 2008 4:21 am
Reply with quote

Hello,

Similar to the "other" solution. . .

Loop thru the string using reference modification and each time thru compare the current location against "GHI". If you get to the "end", GHI is not in the string.

You might also look at INSPECT. At the top of the page is a link to "IBM Manuals" of which is the COBOL Language Reference. If you find something in the manual that is not clear, post what you found and your question about it and someone will be able to clarify.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Dec 30, 2008 4:22 am
Reply with quote

If you just want to know if the substring exists in the string, INSPECT will work perfectly fine. If you want to know where the substring is in the string, use reference modification again checking substring against the right number of characters of the string. Your loop will run from 1 to (length of string - length of substring + 1).
Back to top
View user's profile Send private message
SHAILESH OZA

New User


Joined: 10 Jun 2005
Posts: 21
Location: Mumbai

PostPosted: Tue Dec 30, 2008 7:15 pm
Reply with quote

Hi Keaan,

Either you can Inspect as follows

Inspect String1 for all 'GHI' tallying counter which will give how many times this verb is repeated.

and if you want to find out the location then you can do one thing as mentioned below.

Intialize I,

01 J OCCURS UPTO LENGTH OF STING LETS SAY 12
02 K PIC X(1)
perform varying i from 1 by 1 until Lengh of string

If (I:3) = 'GHI'
MOVE I TO J(K)
ADD 1 TO K
ELSE
CONTINUE
END-IF.

BECAUSE OF THIS WHAT WILL HAPPEN YOU COMES TO KNOW THE STARTING POSITION OF 'GHI' I.E G which is stored in the Array J.

lets check the positions in the J(K) what are the values theres and the

J(3) = 5 so if in the main string you check (5:3) you will get GHI. let's try this, if didn't get just reply back to me
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Dec 30, 2008 10:05 pm
Reply with quote

Shailesh: have you tested this code? You cannot run up to the length of the string because reference modification doesn't work past the end of the variable. Furthermore, I don't think checking one character to be 3 characters will work, and you're using J(K) as if K is numeric, which is very clearly will not be according to the sample given by the o/p.
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: Wed Dec 31, 2008 1:13 am
Reply with quote

Hello Shailesh,

Please do not post untested code. It is far too easy to test code like this and know that it works (rather than merely believing it could work).

Thank you,
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 Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts file manager is doing string conversion IBM Tools 3
No new posts Search string in job at regular Spool... CLIST & REXX 0
Search our Forums:

Back to Top