How can i load all the data from a file to Table (array) in
cobol.How i manage the occurs clause with out reading the
file.Any options avilable ? Please can any one help me it
is urgent?



How can i load all the data from a file to Table (array) in cobol.How i manage the occurs clause w..

Answer / Jaideep Choudhary

In COBOL, you can use the READ statement to read data from a file into an array. Here's an example:nn 01 WORKING-STORAGE SECTION.n 02 FILE-CONTROL. n SELECT INPUT-FILE ASSIGN TO 'INPUT.DAT' ORGANIZATION IS LINE SEQUENTIAL.n 03 DATA DIVISION.n 04 WORKING-STORAGE SECTION.n 05 01 DATA-RECORD.n 06 FIELD1 PIC X(20).n 07 FIELD2 PIC S9(4)V99 VALUE ZEROS. n 08 01 TABLE.n 09 03 WORK-TABLE OCCURS DEPENDING ON SIZE OF DATA-RECORD.n 05 FILE SECTION.n 06 FILE-CONTROL. n SELECT OUTPUT-FILE ASSIGN TO 'OUTPUT.DAT' ORGANIZATION IS LINE SEQUENTIAL.n 07 PROCEDURE DIVISION.n 01 READ-INPUT. n 02 DISPLAY 'Reading Input File'.n 03 OPEN INPUT INPUT-FILE.n 04 PERFORM READ-RECORD UNTIL END-OF-FILE.n 05 CLOSE INPUT-FILE.n 06 END-READ-INPUT.n 07 WRITE-OUTPUT. n 08 DISPLAY 'Writing Output File'.n 09 OPEN OUTPUT OUTPUT-FILE.n 10 PERFORM WRITE-RECORD FOR EACH WORK-TABLE.n 11 CLOSE OUTPUT-FILE.n 12 END-WRITE-OUTPUT.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More COBOL Interview Questions

IF there 5 to 6 files in a JCL and there is some space abends, how can we identify which file has space abend and what can be done to get off that abend or rectify that abend.

2 Answers   ADNA, CSC,


What is the difference between a binary search and a sequential search what are the pertinent cobol?

1 Answers  


Consider the below example call a-test1. -- -- -- a-test1. if a=b perform a-test through a-exit next sentence else if b=c perform c-test through c-exit. if a=d perform d-test through d-exit. a-test. -- -- a-exit. exit. can u tell me what will happen if a=b after looping into a-exit will the control go back to a- test1. will the condition a=d be checked???

5 Answers   IBM,


how can we find total no of records in a file ....is there any utility......?

3 Answers   IBM,


What does the IS NUMERIC clause establish ?

2 Answers  


what is subscript in cobol?give realtime example?

2 Answers   Wipro,


I have two files , file1 is input file it contains 10,20,30,....,records but i want to display the records in file 2 as reverse order .how can we do by using jcl& cobol(dont use array) please any one can tell me the answer

3 Answers   GreenTree, IBM,


what is the purpose of linkage section?

10 Answers  


what are the limitations of Inline Perform?

3 Answers   Zensar,


How do you differentiate between cobol and cobol-ii?

1 Answers  


what happens if we dont close cursor in db2-cobol pgm?

6 Answers  


I have a files containing both duplicate and non-duplicate records.The file is already sorted by a key.I want to determine those records that are duplicate and records that are non-duplicate.If duplicate the record is move to a duplicate file and if non-duplicate that will be move to valid file.thank you

1 Answers  


Categories