MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to search a word in a field - Inspect
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
SAHANA
Beginner


Joined: 18 Jul 2007
Posts: 18
Topics: 5
Location: United Kingdom

PostPosted: Tue Feb 24, 2009 7:40 am    Post subject: How to search a word in a field - Inspect Reply with quote

Hi All,

01 Name-Field PIC X(91).

Ex:

Name-Field: William Roberts Father

I have to find out if the word 'Father' is present in the Name-Field and if present it should be the last word as in the case above.

I am using Inspect to find out if father is present, but how to check if its the last word?

Thanks!!
Back to top
View user's profile Send private message
SAHANA
Beginner


Joined: 18 Jul 2007
Posts: 18
Topics: 5
Location: United Kingdom

PostPosted: Tue Feb 24, 2009 8:27 am    Post subject: Reply with quote

01 FATHER PIC X(07) VALUE 'FATHER'.

INSPECT WS-NAME-FLD TALLYING TALLY-C FOR ALL FATHER
BEFORE SPACE-FIELD

NAME : WILLIAM FAYE FATHERSHEAD

My requirement is to find out if word 'FATHER' is present in the name field as a separate word...But the inspect is picking up the above record as well...pls lemme know if this is correct as well...Thanks!!
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Tue Feb 24, 2009 8:39 am    Post subject: Reply with quote

I would unstring ws-name-fld, and would check last non-space unstring object for 'FATHER'.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Tue Feb 24, 2009 11:41 am    Post subject: Reply with quote

SAHANA,

Unless this is a trick question searching for for Father followed by space should work. untested code

Code:

MOVE 0 TO TALLY-C
INSPECT WS-NAME-FLD TALLYING TALLY-C FOR ALL 'FATHER '
IF TALLY-C > 0
    MOVE to output or write to output
END-IF
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SAHANA
Beginner


Joined: 18 Jul 2007
Posts: 18
Topics: 5
Location: United Kingdom

PostPosted: Tue Feb 24, 2009 11:42 am    Post subject: Reply with quote

sorry i did not understand this part......can u pls temme...

"would check last non-space unstring object for 'FATHER'"
Back to top
View user's profile Send private message
SAHANA
Beginner


Joined: 18 Jul 2007
Posts: 18
Topics: 5
Location: United Kingdom

PostPosted: Tue Feb 24, 2009 11:56 am    Post subject: Reply with quote

Hii Kolusu,

when I use the below code, only 2 records are written...

MOVE 0 TO TALLY-C
INSPECT WS-NAME-FLD TALLYING TALLY-C FOR ALL 'FATHER '
IF TALLY-C > 0
MOVE to output or write to output
END-IF

whereas when i use

INSPECT WS-NAME-FLD TALLYING TALLY-C FOR ALL 'FATHER' , many records are written... but records like below are also written which should have not been ideally..

WILLIAM ROBERTS GRANDFATHER

JULIA ROBERTS G-FATHER

I have to write records only if its a single word 'FATHER' AND it has to be the last word as well

pls help me..
Back to top
View user's profile Send private message
SAHANA
Beginner


Joined: 18 Jul 2007
Posts: 18
Topics: 5
Location: United Kingdom

PostPosted: Tue Feb 24, 2009 12:04 pm    Post subject: Reply with quote

The data in the file is like below...is that the reason why it is not picking up ???


..
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Tue Feb 24, 2009 12:37 pm    Post subject: Reply with quote

SAHANA,

If you want to check if FATHER is the last word in the record and write only those records then you need to use Inspect reverse to find the first non blank character and then get the last 7 characters and check it is ' FATHER' and if it is then write the record

Code:

01 TALLY-C             PIC S9(04) COMP.
01 CHK-STRING          PIC X(7).       

INITIALIZE TALLY-C CHK-STRING                         
                                                     
INSPECT FUNCTION REVERSE(WS-NAME-FLD)                 
        TALLYING TALLY-C FOR LEADING SPACES           
                                                     
MOVE WS-NAME-FLD(91 - TALLY-C - 6 : 7 ) TO CHK-STRING
                                                     
IF CHK-STRING = ' FATHER'                             
   MOVE to output or write to output
END-IF                                               
.     
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SAHANA
Beginner


Joined: 18 Jul 2007
Posts: 18
Topics: 5
Location: United Kingdom

PostPosted: Wed Feb 25, 2009 7:43 am    Post subject: Reply with quote

Thanks a lott Kolusu.... It Worked!!!!
Back to top
View user's profile Send private message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Wed Feb 25, 2009 10:57 am    Post subject: Reply with quote

kolusu,
I had to work this out on paper to understand this. I can't believe how simple your solution is for such a complex problem.

Once again you get a GOLD STAR! Very Happy
_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Wed Feb 25, 2009 12:51 pm    Post subject: Reply with quote

If NAME-FIELD might change to a value other than 91, replace 91 in the solution by LENGTH OF NAME-FIELD.
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
slade
Intermediate


Joined: 07 Feb 2003
Posts: 266
Topics: 1
Location: Edison, NJ USA

PostPosted: Thu Mar 05, 2009 5:50 pm    Post subject: Reply with quote

Or you could use LENGTH OF NAME-FIELD or the intrinsic function to handle any valid length variable.

You might have to move it to its own variable field first because you're using it as part of a ref/mod phrase.
_________________
Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Thu Mar 05, 2009 7:25 pm    Post subject: Reply with quote

slade wrote:
You might have to move it to its own variable field first because you're using it as part of a ref/mod phrase.


Slade,

Not really. You don't even have to use reference modification Wink

Code:

WORKING-STORAGE SECTION.                         
01 WS-NAME-FLD         PIC X(91).                 
01 TALLY-C             PIC S9(04) COMP.           
01 CHK-STRING          PIC X(7) VALUE ' FATHER'. 

INITIALIZE TALLY-C                                 
                                                   
INSPECT FUNCTION REVERSE(WS-NAME-FLD)             
        TALLYING TALLY-C FOR LEADING SPACES       
                                                   
IF WS-NAME-FLD(LENGTH OF WS-NAME-FLD -             
               TALLY-C               -             
               LENGTH OF CHK-STRING  + 1 :         
               LENGTH OF CHK-STRING) =  CHK-STRING

   MOVE to output or write to output
ELSE                                               
   DISPLAY 'discard record'
END-IF                                             
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Thu Mar 05, 2009 8:22 pm    Post subject: Reply with quote

Do I hear an echo in here? Laughing
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
slade
Intermediate


Joined: 07 Feb 2003
Posts: 266
Topics: 1
Location: Edison, NJ USA

PostPosted: Fri Mar 06, 2009 10:57 pm    Post subject: Reply with quote

Sorry Terry, I didn't catch your reference to LENGTH OF NAME-FIELD in your reply... getting careless. Embarassed

Kolusu,

The reason I made the ref/mod mention was that there is a restriction of its use in/as a subscript and I didn't have the ability to test its use.
_________________
Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group