We are using the searching a table which is indexed, once
the key is found, how can we get the occurance at which the
key was found.



We are using the searching a table which is indexed, once the key is found, how can we get the occ..

Answer / shobhit

Initialize the index and a variable to 1 before search.

SET IDX VAR-POS TO 1.

SEARCH TABLE VARYING VAR-POS
AT END DISPLAY "Not Found"
WHEN TABLE(IDX) = <SEARCH STRING>
MOVE VAR-POS TO RESULT-VAR
DISPLAY "FOUND AT POSITION" RESULT-VAR
END-SEARCH.

Now the position is available in the variable RESULT-VAR.

Is This Answer Correct ?    5 Yes 0 No

Post New Answer

More COBOL Interview Questions

Write a program to enter and display the names of students in a class using the occurs clause.

0 Answers  


What is the difference between a binary search and a sequential search? What are the pertinent cobol commands?

0 Answers  


COBOL program to read the string ' BOMBAY' in reverse order as 'YABMOB'

8 Answers   Barclays, IBM,


What is different between variable length and fixed length?

2 Answers   TCS,


what is the use of comp2 ? where can we use it with example ?

3 Answers   Covansys,






What are the access modes of START statement?

0 Answers  


What is EIBCALEN? Why it is used?

9 Answers   ADP,


study the following 01 A PIC 99V0 VALUE 5 01 B PIC 9V9 VALUE 6 01 C PIC 99V9 VALUE 2.5 01 D PIC 99 VALUE 3 COMPUTE A ROUNDED B C = A+B*C/D ON SIZE ERROR PERFORM PRINT-ERROR the comments of A.B.C after execution of the above statement are a.A=10 B=0 C=10 b.A=10 B=9.9 C=9.9 c.A=10 B=0 C=9.9 d.A=10 B=6 C=10

4 Answers   TCS,


how will u pass dadta to cobol+db2 program...?

4 Answers   IBM,


Hi, My interviewer ask A calls B and C calls B, a and b are static c and b are dynamic.what happens if they compile and execute at same time.

3 Answers   iGate,


what is Pic 9v99 Indicates?

2 Answers  


What is the difference between SEARCH and SEARCH ALL?

6 Answers   Cognizant,


Categories