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!

separating words in one field 3

Status
Not open for further replies.

SiouxCityElvis

Programmer
Jun 6, 2003
228
US
I want to make a cross-reference database.
I am using RMCOBOL-85 on Linux.

Basically, I have an Indexed file I'll be reading from.

I want to store multiple records from 1 record read.
If the record read has:
"Bob and Tom Enterprises" as a name field and a file number of "01234"

I want to be able to write multiple records to another indexed file which I will use later for name search purposes.
So the name above would yield the following 4 records:

Enterprises
Tom Enterprises
and Tom Enterprises
Bob and Tom Enterprises

each of them with the same file number "01234".

Any suggestions?

Thanks.
-David


 
David,

Here is a hint (not enough time for more than that right now). You may accomplish what you want by using an UNSTRING (with POINTER clause) and a MOVE (using reference modification for the source operand), within a PERFORM loop.

Have a try at it...

Tom Morrison
 
[tt]Move Length of Input-Name to Ptr
Perform Until Ptr < 1
Perform Until Ptr < 1 or Input-Name(Ptr:1) not = Space
Subtract 1 from Ptr
End-Perform
If Ptr < 1
Exit Perform
End-If
Perform Until Ptr < 1 or (Input-Name(Ptr:1) = Space
Subtract 1 from Ptr
End-Perform
Move Input-Name(Ptr + 1:) to Output-Name
Move Input-File-Nbr to Output-File-Nbr
Write Output-Record
End-Perform
[/tt]
 
I think someting similar to this will do the trick.
Untested, done in 5 minutes, can't be bothered to test now, tell us if it works.

01 array1 occurs 20.
05 fieldx pic x(30).
01 w-i pic 99.
01 w-i2 pic 99.
01 tally1 pic 99.
01 var1 pic x(600).
01 var2 pic x(600).
01 pointer1 pic 999.

read record into var1

move 0 to tally1.
move 1 to pointer1

perform varying w-i from 1 by 1 until w-i > 20
or pointer1 > 599
or var1(pointer1: 601 - pointer1) = spaces
unstring var1 delimited by all " "
into fieldx(w-i)
pointer pointer1
tallying tally1
end-perform.

perform varying w-i from 1 by 1 until w-i > tally1
move 1 to pointer1
move spaces to var2
perform varying w-i2 from w-i until w-i2 > tally1
string fieldx(w-i2) delimited by spaces
" " delimited by size
into var2
pointer pointer1
end-perform
write record (var2 + number(01234) fields)
end-perform.




Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Frederico:

I'm getting "reserved word 'BY' expected" compile time error regarding line:

perform varying w-i2 from w-i until w-i2 > tally1
 
Okay.
I added "BY 1" in

perform varying w-i2 from w-i BY 1 until w-i2 > tally1

and it works.

Thanks.
 
Everyone has been answering the question from the coding needed to create the record structures. I read a different need. You can’t have multiple records in an index file with the same primary key. You can create an indexed file with multiple duplicate values in an alternate index. This way you could create the new file with the company names as the primary key and the file number as the alternate key. You can then look in the file on unique primary keys or all the records for a unique part number repeated because they are defined as an alternate index.

May I am on the wrong but it would allow you to maintain one file retrievable on either key structure. I hop this is of some use.
 
I guess it's left up to me to ask the obvious question - What is a primary key?
In my world, it's a key which uniquely identifies a record.
 
Yep, and if you decide to use DUPLICATES in the primary key, then you forfeit random operations that require a unique value, namely DELETE and REWRITE, are not permitted.
 
Interesting - I use Microsoft COBOL 4.1 and Microfocus Object COBOL and in both, WITH DUPLICATES is only a option on ALTERNATE KEY (ie secondary key) ie neither allow the WITH DUPLICATES option on RECORD KEY (ie the primary key).
 
Fujitsi and RM/COBOL offer this. Apparently Micro Focus does not.
 
You can simulate the duplicates yourself by creating a dummy primary key, for example a number and use the secundairy key with duplicates for the real processing.
 
How about a record with one primary key '12345'
and multiple search fields nth characters long.
01 record-here.
05 record-key pic x(5).
05 field-1 pic x(??).
then have as many field-1's as you want.
Enjoy Bob.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top