View previous topic :: View next topic
|
Author |
Message |
sashi
New User
Joined: 14 Sep 2005 Posts: 54 Location: Chennai
|
|
|
|
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 |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
Back to top |
|
|
sashi
New User
Joined: 14 Sep 2005 Posts: 54 Location: Chennai
|
|
|
|
What to do if I have 100 invalid names?
Do I need to include all in the INSPECT ? |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
AFAIK, yes, either as literals or datanames..... |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
sashi
New User
Joined: 14 Sep 2005 Posts: 54 Location: Chennai
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
sashi
New User
Joined: 14 Sep 2005 Posts: 54 Location: Chennai
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
sashi
New User
Joined: 14 Sep 2005 Posts: 54 Location: Chennai
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Thanks CG... |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
|