问题
I am trying to write a COBOL program to read an input file "INPUT.TXT" and display the details of students whose RATING='B'.I am using [ http://www.compileonline.com/compile_cobol_online.php ] for my program. The records in "INPUT.TXT" (please note that the input file is a simple text file) are:
EMPID NAME COMPANY RATING
112211 UMESH CAPGEMINI A
221122 ISHAN ZALONI A
134231 AJMERA GOOGLE B
232144 NIYANTA WIPRO B
561144 KANKANA ZETA A
324556 CHRISTOPHER TCS C
123443 SIDDIKA TCS A
So far, I have been successful in just displaying the details of all the employees( that too after making a lot of adjustments of the records in the input file). So, I need a fix to the following problems-
1. inserting the records in the form of a table in 'input.txt'
2. searching for a particular record
I am completely unaware as to how to solve my 1st problem.
I don't need the complete program/code. I just need some "specific" advice regarding the topic(s) need I need to cover for my 2nd Problem.
回答1:
For the first question, you could simply use a separator like ; and then you can import the file into excel by giving the separator:
01 NEWFILE.
05 EMPID PIC 9(6).
05 FILLER PIC X VALUE ';'.
05 NAME PIC A(10).
05 FILLER PIC X VALUE ';'.
05 COMPANY PIC X(17).
05 FILLER PIC X VALUE ';'.
05 RATING PIC X(1).
To search you can simply go through the file with the same read you used and find the record. If you want to read the file only once, you could store it's content in an array, and use the PERFORM VARYING statement to search in it.
Also, to write into the file, you open it as input/output:
OPEN I-O filename
Another thing, these things can be found simply in Google, this is basic COBOL.
来源:https://stackoverflow.com/questions/25821859/how-to-insert-records-in-a-table-in-a-text-file-using-cobol-and-search-and-displ