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
 

 

To find the position of character in a given string

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

New User


Joined: 29 Jan 2007
Posts: 33
Location: chennai

PostPosted: Fri Nov 28, 2008 12:58 pm    Post subject: To find the position of character in a given string
Reply with quote

Can someone please help in finding out the position where the phrase is encountered in the text.

for examle : Mainframe Forum is very useful for programming.

Here i need to know the position where the word programming is appeared. This word can occur at different position dynamically based on the input text.

Thanks.
Back to top
View user's profile Send private message

Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Fri Nov 28, 2008 1:29 pm    Post subject: Reply to: To find the position of character in a given strin
Reply with quote

Hi, you can try this:
Code:

01 MATCH-STATUS   PIC X(1) VALUE 'N'.
   88 NO-MATCH             VALUE 'N'.
   88 MATCH-FOUND          VALUE 'Y'.

PERFORM UNTIL Z = LENGTH OF A OR MATCH-FOUND   
COMPUTE Z = Z + 1                             
IF A(Z:11) = 'PROGRAMMING'                           
SET MATCH-FOUND  TO TRUE                       
MOVE Z TO K                                 
END-IF                                         
END-PERFORM                                   
DISPLAY " VALUE OF K :" K

Hope this helps

Cris
Back to top
View user's profile Send private message
bamohan

New User


Joined: 29 Jan 2007
Posts: 33
Location: chennai

PostPosted: Fri Nov 28, 2008 2:44 pm    Post subject:
Reply with quote

Thanks Chris..

Do you have any idea of the below ?

Is there any way we can do the same logic with INSPECT or STRING / UNSTRING command.. I'm trying out with UNSTRING WITH POINTER but it seems doesnt working.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2177
Location: @my desk

PostPosted: Fri Nov 28, 2008 3:03 pm    Post subject:
Reply with quote

Quote:
Can someone please help in finding out the position where the phrase is encountered in the text.
bamohan,

If you want to know the position of initial occurrence of a string, you can try this.
Code:
----+----1----+----2----+----3----+----4----+--
MAINFRAME FORUM IS VERY USEFUL FOR PROGRAMMING.

Code:
     05  I                               PIC  9(02)       
                       VALUE   0.                         
     05  STRING-1                        PIC  X(80)       
                       VALUE                               
         'MAINFRAME FORUM IS VERY USEFUL FOR PROGRAMMING.'.
                                                           
***********************************************************
 PROCEDURE DIVISION.                                       
***********************************************************
                                                           
 0000-MAIN-PARA.                                           
          INSPECT STRING-1 TALLYING I FOR CHARACTERS       
                  BEFORE INITIAL 'PROGRAMMING'             
          COMPUTE I = I + 1                               
          DISPLAY 'I :' I       

SYSOUT
Code:
I :36
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 find particular member name in PDS us... ravi243 CLIST & REXX 10 Mon Dec 19, 2016 6:44 pm
No new posts How to find the first monday of the w... abdulrafi COBOL Programming 10 Fri Nov 25, 2016 3:24 pm
No new posts Find out a active PGM jpsager JCL & VSAM 10 Fri Oct 07, 2016 4:32 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
This topic is locked: you cannot edit posts or make replies. DSList (3.4) cannot display Chinese c... jacobdng TSO/ISPF 4 Wed Oct 05, 2016 2:51 pm


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