View previous topic :: View next topic |
Author |
Message |
SAHANA Beginner
Joined: 18 Jul 2007 Posts: 18 Topics: 5 Location: United Kingdom
|
Posted: Tue Feb 24, 2009 7:40 am Post subject: How to search a word in a field - Inspect |
|
|
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 |
|
|
SAHANA Beginner
Joined: 18 Jul 2007 Posts: 18 Topics: 5 Location: United Kingdom
|
Posted: Tue Feb 24, 2009 8:27 am Post subject: |
|
|
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 |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Tue Feb 24, 2009 8:39 am Post subject: |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Tue Feb 24, 2009 11:41 am Post subject: |
|
|
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 |
|
|
SAHANA Beginner
Joined: 18 Jul 2007 Posts: 18 Topics: 5 Location: United Kingdom
|
Posted: Tue Feb 24, 2009 11:42 am Post subject: |
|
|
sorry i did not understand this part......can u pls temme...
"would check last non-space unstring object for 'FATHER'" |
|
Back to top |
|
|
SAHANA Beginner
Joined: 18 Jul 2007 Posts: 18 Topics: 5 Location: United Kingdom
|
Posted: Tue Feb 24, 2009 11:56 am Post subject: |
|
|
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 |
|
|
SAHANA Beginner
Joined: 18 Jul 2007 Posts: 18 Topics: 5 Location: United Kingdom
|
Posted: Tue Feb 24, 2009 12:04 pm Post subject: |
|
|
The data in the file is like below...is that the reason why it is not picking up ???
.. |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Tue Feb 24, 2009 12:37 pm Post subject: |
|
|
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 |
|
|
SAHANA Beginner
Joined: 18 Jul 2007 Posts: 18 Topics: 5 Location: United Kingdom
|
Posted: Wed Feb 25, 2009 7:43 am Post subject: |
|
|
Thanks a lott Kolusu.... It Worked!!!! |
|
Back to top |
|
|
NASCAR9 Intermediate
Joined: 08 Oct 2004 Posts: 274 Topics: 52 Location: California
|
Posted: Wed Feb 25, 2009 10:57 am Post subject: |
|
|
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! _________________ Thanks,
NASCAR9 |
|
Back to top |
|
|
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Wed Feb 25, 2009 12:51 pm Post subject: |
|
|
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 |
|
|
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Thu Mar 05, 2009 5:50 pm Post subject: |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Thu Mar 05, 2009 7:25 pm Post subject: |
|
|
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
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 |
|
|
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Thu Mar 05, 2009 8:22 pm Post subject: |
|
|
Do I hear an echo in here? _________________ ....Terry |
|
Back to top |
|
|
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Fri Mar 06, 2009 10:57 pm Post subject: |
|
|
Sorry Terry, I didn't catch your reference to LENGTH OF NAME-FIELD in your reply... getting careless.
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 |
|
|
|
|