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

Consider the following: 77 A PIC 9(10) 77 B PIC 9(10) 77 C PIC 9(19) MULTIPLY AB BY B GIVING C Which of the following is true ? (a) The execution of the above may result in size error. (b) The execution of the above will result in size error. (c) The definition of C is invalid resulting in compilation error. (d) No error will be thee and the program would proceed correctly.

4 Answers   TCS,


How do define dynamic array in cobol.

0 Answers  


can we use COPY statement in w-s section? how?

3 Answers  


can you please let me know if there is any walkins for COBOL/PLI/DB2/IMS/JCL in pune other than IBM and ITC infotech

0 Answers  


whats the disadvantage of search all over search?

4 Answers   Patni, TCS,






how do you reference the variable unblock file formats from cobol programs

0 Answers  


I have put two write operations in a single para for two different conditions.Will that lead to an abend or run successfully and write two records?

1 Answers   CTS,


What are 77 levels used for?

0 Answers  


What is difference between static and dynamic call in cobol?

0 Answers  


How can you display the SPOOL information ?

2 Answers  


what is difference bt COND, REGION & TIME parameters at JOB & EXEC. give an exp.

1 Answers   Syntel,


If i initialize the 01 level variable in array, will it initialize all the array elements (occurs)?

8 Answers   CTS,


Categories