Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Statement to find a specific character in a field using COBOL 1

Status
Not open for further replies.

bhl

IS-IT--Management
Aug 22, 2001
27
US
I am writing a COBOL program and I need to find an asterisk in a field. It can appear in any position in a 50 character field.

What is the best way to accomplish this.

Thank you
 
bhl,

if all you need is to find out is if there is an asterisk anywhere in this 50-character field, you can use the cobol verb INSPECT - syntax:

INSPECT 50-char-field-name TALLYING numeric-field-name FOR ALL '*'

if the asterisk is present, your numeric-field-name will contain a non-zero value after the statement is executed.

if you need more in terms of information, such as where the asterisk is in the field, then you can use other formats of the INSPECT verb. you can find those formats in your COBOL manuals.

hope this helps.
 
EXAMPLE:

Code:
000600 01  CHECK1 PIC X(10) VALUE '----+----*'.

001600      MOVE ZERO TO TALLY.
001700      INSPECT CHECK1 TALLYING TALLY FOR
001800        CHARACTERS BEFORE INITIAL '*'.

if tally is zero, the '*' is found at position 1. If tally = 50, the '*' is not found.

Tally +1 is the position within variable CHECK1 where the '*' is, so in this example, tally will contain 9.

Regards,

Crox
 
Hey Crox,

Thanks! I think we'll make a good tag team. Happy New Year!

winzip
 
Thanks for the help. My COBOL is a little rusty.
 
Hi,

I wish you all a happy, healthy and prosperous 2002.

Regards,

Crox
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top