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

Retrieving data from txt file.

Status
Not open for further replies.

lucashii

Programmer
Jan 15, 2008
3
0
0
MY
Hi this is my first time here.

I trying to write a program that will search throught the txt file for a name specified by the user. Say if user enter "Lucas", the program would then display all the name of "Lucas".

Currently I am using SEARCH which only retrieve a single "Lucas" name value while there are several other same name within it.

Any suggestion or guidance would be greatly appreciated~Thanks~
 
You may want to clarify what you're looking to do. You're looking for a text string in any position in a whole file? Is the file treated as a set of records or a stream? SEARCH is for a table, is that what you're doing? Or something different?

It probably wouldn't hurt to describe the point you're at, too.
 
Thanks for the reply. Sorry for the lack of input as I am still new to Cobol so there is still some terms I not familiar with.

I am trying to search for a text string within a txt file.

001000 SELECT VENDOR-FILE
001100 ASSIGN TO "name"
001200 ORGANIZATION IS INDEXED
001300 RECORD KEY IS VENDOR-NAME WITH DUPLICATES
001400 ACCESS MODE IS DYNAMIC.

001900 FD NAME-FILE
002000 LABEL RECORDS ARE STANDARD.
002100 01 NAME-RECORD.
002200 05 DEALER-NUMBER PIC X(5).
002300 05 DEALER-NAME PIC X(30).
002400 05 DEALER-ADDRESS-1 PIC X(30).
002500 05 DEALER-ADDRESS-2 PIC X(30).

002800 01 TABLE-NAME-RECORD OCCURS 1000 TIMES
002900 ASCENDING KEY IS TABLE-PE-NAME
003000 INDEXED BY NAME-INDEX.
003100 05 TABLE-PE-NUMBER PIC X(5).
003200 05 TABLE-PE-NAME PIC X(30).
003300 05 TABLE-PE-ADDRESS-1 PIC X(30).
003400 05 TABLE-PE-ADDRESS-2 PIC X(30).


I would read all the records from NAME-FILE which is then moved into TABLE-NAME-RECORD. Using SEARCH to display the name where the user entered.

However I wish to retrieve and display all the same name within the txt file. Any suggestion would be appreciated. Thanks~


 
If SQL is an option, you could use SELECT LIKE statement that will do the search on the stream file (txt).
 
maybe something like this?


set name-index to 1.
perform until name-index > 1000
if table-pe-name (name-index) = input-name
display whatever
set name-index up by 1
else set name-index up by 1
end-perform.
 
However I wish to retrieve and display all the same name within the txt file

Again it does pay to learn the proper terms for what you are working with, especially the ability to state your problem. A well-stated problem is half-solved as Ketterling wrote. You are working with a file with fixed-length records - more properly this is a binary file which happens to have records constituted of nothing but text.

Knowing what you are working with changes the answers considerably, along with its requirements. Take this problem you posted, for example.

1) You are looking for a fixed block of text within a defined field of a record. This is a simple task within COBOL (one word: IF).
2) Since you are working with a binary file, you need to be blocking the records. Add "BLOCK CONTAINS XX RECORDS" to the file def where XX is the number of records it can read at one time.
3) Given your problem, if I were your supervisor I would fail the code upon review. You have no need to read this file into a table. Read each record in turn, and then access the field you are interested in and do a simple test. Reading this file into the table limits the size of the file, uses much memory that you do not need to use, and unnecessarily complicates the code.

How were you introduced to COBOL? You could do far worse than to seek out a good book and study it for a while, especially if you will continue in COBOL.
 
Thanks for all the suggestion. I got it sorted out.

Now I wish to do something like "SELECT * FROM NAME-FILE WHERE DEALER-NAME LIKE USER-INPUT". If user would input "JA" it will display out all the name starting with "JA", is that possible?Any guidance would be appreciated thanks~
 
Hi,
I'm trying to make a quick search for Vendor names
using COBOL,,

just like the autosearch in VB or SQL,
I mean when the user enter the first character let say "b",, I will get all vendors their first character name is "b", and when the next is entered let say "a", I will get all verdors started with "ba" etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top