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

how to find a word in a string


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

New User


Joined: 14 Sep 2005
Posts: 54
Location: Chennai

PostPosted: Fri Mar 26, 2010 6:15 pm
Reply with quote

Hi All,

How to find a list of word are there in string?

example:
I have one field
WS-LAST-NAME PIC X(50)

I have list of invalid words like 'PRIVACY','REGISTRAR','SALES','SECURITY','SPAM.','SUPPORT'

WS-LAST-NAME should not contain any of the invalid words


I tryied like this but its not working

INSPECT WS-LAST-NAME TALLYING WS-COUNT
FOR ALL WS-NOT-INVALID-LIST

All the invalid name are declared with 88 clause under WS-NOT-INVALID-LIST

Can any one please find out what is the problem?
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri Mar 26, 2010 6:31 pm
Reply with quote

Where did you get the idea that INSPECT allowed a list for the identifier-3 or literal-1 Is the tallying field (the item whose occurrences will be tallied)?
Wouldn't it be more like:
Code:
INSPECT WS-LAST-NAME
   TALLYING WS-COUNT
   FOR ALL 'PRIVACY'
           'REGISTRAR'
           'SALES'
           'SECURITY'
           'SPAM.'
           'SUPPORT'
Back to top
View user's profile Send private message
sashi

New User


Joined: 14 Sep 2005
Posts: 54
Location: Chennai

PostPosted: Fri Mar 26, 2010 7:34 pm
Reply with quote

CICS Guy wrote:
Where did you get the idea that INSPECT allowed a list for the identifier-3 or literal-1 Is the tallying field (the item whose occurrences will be tallied)?
Wouldn't it be more like:
Code:
INSPECT WS-LAST-NAME
   TALLYING WS-COUNT
   FOR ALL 'PRIVACY'
           'REGISTRAR'
           'SALES'
           'SECURITY'
           'SPAM.'
           'SUPPORT'



What to do if I have 100 invalid names?
Do I need to include all in the INSPECT ?
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri Mar 26, 2010 7:40 pm
Reply with quote

AFAIK, yes, either as literals or datanames.....
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Mar 26, 2010 7:55 pm
Reply with quote

It would be wise to define WS-COUNT as a binary-fullword and ALWAYS initialize it to ZERO before each INSPECT.

Otherwise, you can substitute WS-COUNT with the TALLY Special-Register, but it ALSO needs to be initialized to ZERO before each INSPECT.

Binary-fullwords are ===> PIC 9(09) COMP or COMP-5.

COMP-5 was introduced with OS/390 COBOL version/release 2.1.1 or 2.2.1. Can't recall exactly, but it was one of these.

Bill
Back to top
View user's profile Send private message
sashi

New User


Joined: 14 Sep 2005
Posts: 54
Location: Chennai

PostPosted: Fri Mar 26, 2010 7:59 pm
Reply with quote

CICS Guy wrote:
AFAIK, yes, either as literals or datanames.....


Thanks its working......

but is there any other why to implement this without writing the invaild names list in the procedure division?
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Mar 26, 2010 8:07 pm
Reply with quote

You could define them to a file or to an external Assembler table.

A pre-defined COPYBOOK could work also.

What version of COBOL are you running?

Is this logic for Batch, CICS or both, because for other than a COPYBOOK, there are different accesses to a file or an Assembler table for Batch and CICS.

Several choices to ponder....

Bill
Back to top
View user's profile Send private message
sashi

New User


Joined: 14 Sep 2005
Posts: 54
Location: Chennai

PostPosted: Fri Mar 26, 2010 8:26 pm
Reply with quote

Bill O'Boyle wrote:
You could define them to a file or to an external Assembler table.

A pre-defined COPYBOOK could work also.

What version of COBOL are you running?

Is this logic for Batch, CICS or both, because for other than a COPYBOOK, there are different accesses to a file or an Assembler table for Batch and CICS.

Several choices to ponder....

Bill

Its a sub routine which is called by a COBOL+IMS program.
I don't think that we can access a file through a sub routine...
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: Fri Mar 26, 2010 8:32 pm
Reply with quote

Quote:
I don't think that we can access a file through a sub routine...
Nothing in COBOL prevents it. Also consider an EXTERNAL file?
Back to top
View user's profile Send private message
sashi

New User


Joined: 14 Sep 2005
Posts: 54
Location: Chennai

PostPosted: Fri Mar 26, 2010 8:51 pm
Reply with quote

Robert Sample wrote:
Quote:
I don't think that we can access a file through a sub routine...
Nothing in COBOL prevents it. Also consider an EXTERNAL file?

Can you explain in more detail way??
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Fri Mar 26, 2010 9:34 pm
Reply with quote

sashi wrote:
Robert Sample wrote:
Quote:
I don't think that we can access a file through a sub routine...
Nothing in COBOL prevents it. Also consider an EXTERNAL file?

Can you explain in more detail way??
COBOL Sub-programs(routines) are essentially/just another COBOL program, (from your question per se) all the things your main-program can do, sub-module can also do.

And this might be a starting point, too: external file in cobol
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri Mar 26, 2010 9:42 pm
Reply with quote

Anuj Dhawan wrote:
And this might be a starting point, too: external file in cobol
Or more directly Sharing data by using the EXTERNAL clause
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Mon Mar 29, 2010 9:27 pm
Reply with quote

Thanks CG...
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Mon Mar 29, 2010 10:36 pm
Reply with quote

In Batch COBOL (COBOL 370 and greater) you can use a PROCEDURE-POINTER to dynamically load an external static/shareable Assembler Table/CSECT into memory, followed by addressing it via an "01" LINKAGE level.

Code:

03  WS-INVALID-TBL PIC  X(08) VALUE 'INVWORDS'.
03  WS-INVALID-TBL-PP PROCEDURE-POINTER.
03  FILLER REDEFINES WS-INVALID-TBL-PP.
    05  WS-INVALID-TBL-PTR POINTER.
    05  FILLER PIC  X(04).
03  WS-WORK-STRING PIC  X(50).
03  WS-TALLY-TOTAL PIC  9(09) COMP.
LINKAGE SECTION.
01  LS-INVALID-WORDS-REC.
    03  LS-INVALID-WORDS-MAX PIC  9(09) COMP.
    03  LS-INVALID-WORD-TBL  OCCURS 1 TO 81 TIMES
                             DEPENDING ON LS-INVALID-WORDS-MAX
                             INDEXED BY X-LS-IWT, X-LS-IWT-MAX
                             PIC  X(50).

SET WS-INVALID-TBL-PP TO ENTRY WS-INVALID-TBL.
SET ADDRESS OF LS-INVALID-WORDS-REC TO WS-INVALID-TBL-PTR.
SET X-LS-IWT-MAX TO LS-INVALID-WORDS-MAX.
MOVE ZERO TO WS-TALLY-TOTAL.
SET X-LS-IWT TO 1.

PERFORM UNTIL X-LS-IWT > X-LS-IWT-MAX
    MOVE LS-INVALID-WORD-TBL (X-LS-IWT) TO WS-WORK-STRING
    MOVE ZERO TO TALLY
    INSPECT WS-LAST-NAME TALLYING TALLY FOR ALL WS-WORK-STRING
    ADD  TALLY TO WS-TALLY-TOTAL
    SET  X-LS-IWT UP BY 1
END-PERFORM.

INVWORDS  CSECT
          DC   A(INVWORDL/L'INVWORDE) NUMBER OF TABLE-ENTRIES
INVWORDE  DC   CL50'PRIVACY'
          DC   CL50'REGISTRAR'
          DC   CL50'SALES'
          DC   CL50'SECURITY'
          DC   CL50'SPAM.'
          DC   CL50'SUPPORT'
INVWORDL  EQU  *-INVWORDE             TABLE-LENGTH
          END

When the loop is complete, WS-TALLY-TOTAL will contain a ZERO or non-ZERO value.

An OCCURS of 81 + the length of the binary-fullword totals 4054 bytes or just less than one BLL cell. This should be plenty.

When you're done with the table, page it out of memory via a CANCEL WS-INVALID-TBL and then set the ADDRESS OF LS-INVALID-WORDS-REC and WS-INVALID-TBL-PP to NULL.

PROCEDURE-POINTER must NEVER be used in CICS. You'll crash and burn. Instead, use the LOAD PROGRAM API.

Bill
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 2
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts To find whether record count are true... DFSORT/ICETOOL 6
Search our Forums:

Back to Top