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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable Length Fields

Status
Not open for further replies.

andygee

Programmer
Nov 3, 2003
1
GB
Hi everyone,

Bet you have heard this before but I am new to COBOL and need some help (its true).

I am reading in from a file of fixed length and parsing for the titles ie Mr, Miss, Doctor etc. There can be anything upto around twenty titles so I don't want to hardcode these in (not just lazy but bad style).

So I need to build an array of the Titles I read in, not a problem, but I need the field lengths to match that of the Title read in. So I would have an array of TITLES where TITLE(1) contains 'Mr' of length PIC X(2) and TITLE(2) contains 'Miss' of length PIC x(4) etc. Does this make sense? And if so any ideas?
 
I believe all you need is the maximum length of any title, such as :
01 title1 pic x(10) value "Doctor".
01 title2 pic x(10) value "Mr".
01 title3 pic x(10) value "Mr and Mrs".
If you unstring your file, then "Mr " (with 1 trailing spaces matches "Mr " with 8 trailing spaces. If you still need length, then the title size is simply the maximun length less the number of trailing spaces.
 
try something like this.
Store your table in a text file so you can update it when you see you have additional titles.
each time your program runs it will read the text file into a cobol (array) table to compare names against.

01 ARRAY-TABLE.
05 FILLER PIC X(200).
01 EACH-TITLE REDEFINES ARRAY-TABLE.
05 ET PIC X(20) OCCURS 20.

YOU WILL PUT YOUR TEXT ENTRIES IN ET(1) THRU ET(20)

01 MATCH-AREA PIC X(20) VALUE SPACES.

INITIALIZE THE MATCH AREA AND THEN
UNSTRING YOU NAME INTO MATCH AREA DELIMITED BY A SPACE OR COMMA OR WHATEVER. NEXT COMPARE YOUR MATCH-AREA TO YOUR
ET(1) THRU (20) TO SEE IF YOU HAVE ANY MATCHES. THE SIZE OF THE MATCH AREA AND THE ET AREA NEED TO BE THE SAME BUT CAN BE OF ANY LENGTH. lET ME KNOW IF YOU NEED MORE CLARIFICATION.
Enjoy Bob
 
Hi Bob,

Minor math error tbl s/b 400 (i.e. 20X20). NBD.

Andy,

If you can keep your titles to one word you can STRING the title into a WS-FULL-NAME field along w/the other info for the name.

If the title can contain spaces, e.g. "Your (His?) Excellency, Mr. and MRS." you've got a bigger pgming challenge to deal with. With those you can't delimit the field w/a space because you use a space as a separator.

Here's something you can try:

Since you control what goes into the table you can delimit the title phrase w/an X'FF' instead of a space, and use that as the delim char in the STRING.

If you can't control the table's content, do a search here for "reverse" and/or "string". This has been done to death here.

Regards, Jack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top