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 SET TO TRUE all about, anyway?

5 Answers  


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

3 Answers   ADP, DELL, L&T,


if a dataset is already created with fixed length but after that i want to change fixed length to variable length then how is it possible

3 Answers   IBM,


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

2 Answers  


What is LENGTH in COBOL II?

2 Answers   CSC,






hai friends ,i have HSBc exam on this sunday,my platform is Mainframe,i have 1 year exp,pls any one send me placement papers of Hsbc and technical questions on mainframe

6 Answers   Citi Bank, CitiGroup, HSBC, iNautix, Wipro,


Discuss about changing dataset name in proc.

0 Answers  


input:- 12233344445555566666... output:- 1=1,2=4,3=9... Here firstno i.e 1 should be displayed and after that the alikeno.s should be added n displayed.i.e 2+2=4 like tat it goeson.

1 Answers  


what happens of we dont give time stamp in precompilation process

2 Answers  


What are declaratives and what are their uses in cobol?

0 Answers  


Following questions were asked in Capegemini on 8th sep,2012 mainframe test 1.)Condition code for dul recors in VSAM- 2.) Is NULL or =NULL in Select statement 3.)max size of CI 4.)What happens after CI is full 5.)Ques on COND parameter 6.)which among following can not be rolled back a)delete table b.)droptable c)Update d.)insert 7.)groupby and orderby sql querries 8.)Max extents in VSAM file 9.)quesn on DPRTY=(1,10) 10.)range of condition codes in COBOL 11.)occurs clase can not be used at which level? 12.)delimiter in jcl 13.)sort card for file in PGM=SORT 14.)PIC(6) value 120056 possible? 15)question on BLKSIZE Is (20,20) and (20,10) possible? 16.)number of bytes in RDF 17.)Can we use index in WS-section or LK-section 18.)Verify command in IDCAMS used for? 19.)question on Alternate Index 20.)Return code of file attribute mismatch 21.)In which format COBOL variables stored? 22.)what is Alternate of HANDLE? 23.)can SUM,AVG,MIN,ROUND used in numeric and char variable data types? 24.)What is the datatype of FILE STATUS codes in WS-section?

2 Answers   Cap Gemini,


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

8 Answers   CTS,


Categories