I have a seq file with different fields one field is address
with pic x(50) as input in a cobol program. In address there is
'PUNE' at any different positions in the address field ( form 1
t0 50) . My requirement is select the fields with address 'PUNE'
by using cobol. Please suggest

Answers were Sorted based on User's Feedback



I have a seq file with different fields one field is address with pic x(50) as input in a cobol p..

Answer / jagan

IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-3270.
OBJECT-COMPUTER. IBM-3270.

INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT IN-FILE ASSIGN TO INFILE

SELECT OUT-FILE ASSIGN TO OUTFILE

DATA DIVISION.

FILE SECTION.
FD IN-FILE.
01 INPUT-REC.
05 IN-NAME PIC X(20).
05 IN-ADDRESS PIC X(50).

FD OUT-FILE.
01 OUT-REC.
05 OUT-NAME PIC X(20).
05 OUT-ADDRESS PIC X(50).

WORKING-STORAGE SECTION.

01 NO-MORE-RECORDS PIC X(1).
88 END-OF-FILE VALUE 'Y'.
88 NOT-END-OF-FILE VALUE 'N'.

01 COUNT PIC 9(1).

PROCEDURE DIVISION.
MAIN-PARA.
PERFORM READ-FILE UNTIL END-OF-FILE.
STOP RUN.

READ-FILE.
MOVE 0 TO COUNT.
READ IN-FILE AT END SET END-OF-FILE TO TRUE
NOT AT END
IF IN-ADDRESS NOT EQUAL TO SPACES OR LOW-VALUES
INSPECT IN-ADDRESS TALLYING COUNT FOR ALL
'PUNE'.
IF COUNT > 0
WRITE OUT-REC FROM INPUT-REC
END-IF
END-IF
END-READ.
END-READ-FILE.

The above piece of code should do what you have asked .
Correct me incase there are any errors.

Is This Answer Correct ?    22 Yes 2 No

I have a seq file with different fields one field is address with pic x(50) as input in a cobol p..

Answer / garry

@Jagan.

Good Reply.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More COBOL Interview Questions

TYPES OF SORTINGS. which is more prefarable.

2 Answers   Syntel, TCS,


I have to write to a outfile where the number of records in that file should be the header of that file using IMS.. can anyone help me in this issue

0 Answers   IBM,


What are the different rules to perform a Search?

0 Answers  


why we are using set in searchall?

4 Answers   IBM,


here is my requirement A1 is alphanumeric with value 'A1B2C3D4' as defined below 05 A1 PIC X(8) VALUE IS 'A1B2C3D4' but i need to have A2,A3 as ABCD & 1234 repectively...... A2 = ABCD A3 = 1234 Can you please explain me what are the different ways to do it?

2 Answers   IBM,






How to declare if emp-name = AAAAA""BBB in working-storage section. After display emp-name should print like AAAAA""BB

6 Answers   Polaris,


there is a file whose ORGANISATION is INDEXED.you want to read the records from the file in RANDOM fashion as well as sequentially.then which of the access mode would you specify? a.SEQUENTIAL b.RANDOM c.DYNAMIC D.ACCESS MODE has nothing to do with it

3 Answers   TCS,


What will happen if we move SPACES to numeric field and ZEROES to alphabetic field?

7 Answers   T systems,


How can I find the maximum value of a field in a file while reading the file dynamically? without using sort function. Suppose i have a file with fields Timestamp, description, teamname, teamnumber.. i have read the file till end and find the maximun value of timestamp which is not in sorted order.. can we use function max(timestamp)?

1 Answers   CGI,


How will 128 be saved in s9 (3) comp-3 How will 12 be saved in s9 (2) comp

3 Answers   CTS,


01 a pic x(6) value is abcdef 01 b pic x(3) move a to b wht will be the value in b ?

3 Answers   Patni,


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,


Categories