How to insert records in a table in a text file using COBOL and search and display record(s) which satisfy a condition?

北城以北 提交于 2019-12-08 09:12:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!