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

What are 77 levels used for?

0 Answers  


What are the cobol coding sheets?

0 Answers  


How to get the last record in vsam file in cluster? And how can you get the ksds file records into cobol program?

0 Answers  


How can you submit a job from COBOL programs?

2 Answers   ITC Infotech,


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

0 Answers  


How to retrive the 9th records out of ten records using the cobol program ?

3 Answers   UST,


input:-AABBCCDDEFGHIIJ output:- ABCDEFGHIJ Here in input we hav the duplicate characters i.e repeating characters.SO we should eliminate the duplicate characters and should display the output in ascending order.

6 Answers  


.How to add one input & one Out file in existing cobol program. how approach tell me step by step.

2 Answers   Syntel,


what is dynamic array in cobol? what is the difference b/w array and table in cobol?

2 Answers  


How do you get the data to code the BMS macro?

0 Answers   IBM,


Suppose i have a Cobol field of 10 byte. it contains a decimal sign.How to know where is the point location?

1 Answers  


can we use the two 01 level in file discription ?

6 Answers  


Categories