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
 

 

how to find a word in a string

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: how to find a word in a string
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: 2150
Location: At my coffee table

PostPosted: Fri Mar 26, 2010 6:31 pm    Post subject:
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    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Fri Mar 26, 2010 7:40 pm    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Mar 26, 2010 7:55 pm    Post subject: Reply to: how to find a word in a string
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Mar 26, 2010 8:07 pm    Post subject: Reply to: how to find a word in a string
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    Post subject: Re: Reply to: how to find a word in a string
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: 7914
Location: Bellevue, IA

PostPosted: Fri Mar 26, 2010 8:32 pm    Post subject:
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    Post subject:
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

Senior Member


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

PostPosted: Fri Mar 26, 2010 9:34 pm    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Fri Mar 26, 2010 9:42 pm    Post subject:
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

Senior Member


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

PostPosted: Mon Mar 29, 2010 9:27 pm    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Mon Mar 29, 2010 10:36 pm    Post subject: Reply to: how to find a word in a string
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    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 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
No new posts How to find a CICS resource used in C... Arunkumar Chandrasekaran CICS 8 Thu Sep 29, 2016 1:45 pm
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm


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