Extract only those records from a PS file which are having word 'TEXT' in the records using COBOL? The word TEXT is not present in a particular position in all the records.

Answers were Sorted based on User's Feedback



Extract only those records from a PS file which are having word 'TEXT' in the records usin..

Answer / divyakiruthiga

Step 1: Read the first record from the PS file into a ws-variable WK-ROW.
Step 2 :INSPECT WK-ROW TALLYING WK-TXT-COUNT FOR ALL 'TEXT'.
Step 3: If the WK-TXT-COUNT is greater than 0, then write the record to the output file.
Step 4: Initialize the WK-TXT-COUNT
Step 5: Continue the above process till end of file.

Is This Answer Correct ?    0 Yes 0 No

Extract only those records from a PS file which are having word 'TEXT' in the records usin..

Answer / chatgpt

IDENTIFICATION DIVISION.
PROGRAM-ID. EXTRACT-TEXT-RECORDS.
DATA DIVISION.
FILE SECTION.
FD INPUT-FILE.
01 INPUT-RECORD PIC X(100).
FD OUTPUT-FILE.
01 OUTPUT-RECORD PIC X(100).
WORKING-STORAGE SECTION.
01 SEARCH-TEXT PIC X(4) VALUE 'TEXT'.
PROCEDURE DIVISION.
OPEN INPUT INPUT-FILE
OUTPUT OUTPUT-FILE.
READ INPUT-FILE
AT END DISPLAY "No records found."
NOT AT END PERFORM PROCESS-RECORDS.
CLOSE INPUT-FILE
OUTPUT-FILE.
STOP RUN.

PROCESS-RECORDS.
PERFORM UNTIL END-OF-FILE
IF INPUT-RECORD CONTAINS SEARCH-TEXT
WRITE OUTPUT-RECORD
END-IF
READ INPUT-FILE
AT END MOVE 'Y' TO END-OF-FILE
END-PERFORM.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More COBOL Interview Questions

If you are current on the owner of a set, what is the difference between an obtain next and obtain first? Actually in which topic will we use dis???Plz explain it clearly

0 Answers  


What is the file organization clause ?

2 Answers  


Is it possible to mutliply a comp variable with an comp-3 variable. Will there be any error if i do it?

3 Answers   IBM, UST,


If a file has 1000 records.. if i have to replace the first and last characters of the file with another character. how it can be done....

1 Answers   HCL,


I want ALL jcl ERROR cods

1 Answers  






OCCURS clause is used in the DATA DIVISION on data names at (a) 01 level (b) 77 level (c) 88 level (d) any level from 02 to 49

13 Answers   TCS,


what is the difference between external and global variables?

1 Answers  


example for sub strings ? and refernce modifications whit output pls

0 Answers   College School Exams Tests, IBM,


can you declare redefine in level 01?

8 Answers   Patni,


WE HAVE 2 FILES IN COBOL. ONE IS FIXED LENGTH RECORDS ANOTHER ONE IS VARIABLE LENGTH. IF I DECLEAR LRECL OF FIXED ONE AS 80 AND 2ND RECORD AS 132. WHAT WE NEED TO DECLEAR LRECL FOR THOSE 2 FILES IN JCL?

4 Answers   iGate,


How can you get the ksds file records into your cobol program?

0 Answers  


is it possible to declare index in cobol program? if it is not why its tell me pls

3 Answers  


Categories