I have the file which is having the extension no as records.
sample file will look like below.

2310
3410
3256
4350
3781
5408

I need to replace the record which is starting with 3 to 5
(i.e) 3410 to 5410. How can we do it through cobol

and cobol-db2 program? I need the possible logic?

Answers were Sorted based on User's Feedback



I have the file which is having the extension no as records. sample file will look like below. 2..

Answer / santy

You can solve this problem using the Referencial Intigrity.

Let consider these extension no. in WS section.
01 WS-EXTN PIC X(4).

IF WS-EXTN(1,1)='3'
ISPECT WS-EXTN replacng first '3' by '5'
END-IF.

read the next record.

Is This Answer Correct ?    5 Yes 0 No

I have the file which is having the extension no as records. sample file will look like below. 2..

Answer / jagan

Thavasi ,
In your case , check the record number 1 and 4 which has 3
in the second position of it . As your have given LEADING .
As it encounters the first '3' in any of the position in
the record , it will change it to '5' .

Please correct me if i am wrong...

Is This Answer Correct ?    5 Yes 1 No

I have the file which is having the extension no as records. sample file will look like below. 2..

Answer / pa

read the record to the WS varible defined below
01 ws-var1.
05 ws-var2 pic x(1).
05 ws-var3 pic x(2).

if ws-var2 = '3'
inspect ws-var replacing first '3' by '5'
end -if

read the next record.

Hope it works

Is This Answer Correct ?    5 Yes 2 No

I have the file which is having the extension no as records. sample file will look like below. 2..

Answer / reena

Define the working storage variable in the following way:

01 ws-var1.
05 ws-var2 pic x(1).
05 ws-var3 pic x(3).

Read the database file.

Move the database field value to the working storage
variable (i.e. ws-var1)

Then preform the following

if ws-var2 = '3'
move '5' to ws-var2
move ws-var1 to the database field
rewrite database record
end -if

read the next record.

Preform the above routine till eof..

Is This Answer Correct ?    1 Yes 0 No

I have the file which is having the extension no as records. sample file will look like below. 2..

Answer / thavasi

The answer is:

move each record to WS-REC PIC X(04).


then write the below statment to be executed for each rec.

INSPECT WS-REC REPLACING LEADING '3' by '5'.

why am i using LEADING instead of FIRST is that the
requirement says that 'STARTING with 3 by 5'

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More COBOL Interview Questions

What is Pic 9v99 Indicates in COBOL?

0 Answers   SwanSoft Technologies,


I have a occurs for 100 times but it has executed 101 time what could be the reason?

4 Answers  


What is the size of s9(19)comp3? explain

8 Answers  


what r the types of perform statement

4 Answers  


what is the use of outrecord?

0 Answers  






In an array processing what is the thing that can be done by using subscripts but not by using index

4 Answers   JPMorgan Chase,


how to refer the data field?

0 Answers  


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,


Difference between ps, esds

3 Answers  


How can you add a particular field/coloumn in copybook?

3 Answers   ADP, DELL, L&T,


which is faster either static call or dynamic call ? and specify the reasons for it ? reply fast

1 Answers  


what is the maximum error code in mainframe

2 Answers  


Categories