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 is the compute verb? How is it used?

0 Answers  


How to replace the GOTO statement in COBOL without changing the structure of program. e.g. consider following code... I.D. E.D. D.D. P.D. compute C = A + B. GOTO para 100-display. compute D = C - D. GOTO 200-display. some other logic...... ........ GOTO 300-para. ...... ...... GOTO 400-para. Now I want to replacce all GOTO statements without changing the structure and otput of program.

6 Answers   Accenture,


what is qualification on occurs clause?

2 Answers  


what is level 66 means??

7 Answers  


I have a source program compiled with Cobol-2. The output file has a record length of 100 defined in the program but a record of 60 bytes getting written into it. i.e. The rest of 40 bytes I am not Writing anything. But it by default puts some values into the last 40 bytes. However it does not impact anything. But when Compiled the module with Enterprise Cobol the last 40 bytes were spaces as fillers. Can anyone explain?

5 Answers   Cognizant,


) what is the difference between AID and HANDLE AID?

0 Answers   IBM,


level number 77 is used to define a)group data b)elementary data c)redefine d)none

8 Answers   TCS,


What are the rules of the move verb?

0 Answers  


is it mandatory to give data division before procedure division ? wht happens if i give procedure division first thn data division ? reply soon

2 Answers   Patni,


What is amode(31)

0 Answers  


What is the default value(s) for an initialize? What keyword will allow for an override of the default?

0 Answers  


88 class is used for

5 Answers   CTS, EDS,


Categories