Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

another special scenario for string searching.

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

New User


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

PostPosted: Tue Dec 30, 2008 4:09 am    Post subject: another special scenario for string searching.
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

Site Director


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

PostPosted: Tue Dec 30, 2008 4:21 am    Post subject:
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: 7997
Location: Bellevue, IA

PostPosted: Tue Dec 30, 2008 4:22 am    Post subject:
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    Post subject:
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: 7997
Location: Bellevue, IA

PostPosted: Tue Dec 30, 2008 10:05 pm    Post subject:
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

Site Director


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

PostPosted: Wed Dec 31, 2008 1:13 am    Post subject:
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    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 Replacing same string with different ... vickey_dw DFSORT/ICETOOL 6 Wed Feb 22, 2017 10:44 pm
No new posts Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us