Using SEARCH without setting INDEX in COBOL.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Ramnath
Registered Member
Posts: 20
Joined: Thu Aug 01, 2013 6:57 pm

Using SEARCH without setting INDEX in COBOL.

Post by Ramnath »

Hi,

What happens if we donot set the index before search, will this work?
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Using SEARCH without setting INDEX in COBOL.

Post by William Collins »

It depends on what you are trying to do. Have you looked at the documentation, it should be clear what will happen.
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: Using SEARCH without setting INDEX in COBOL.

Post by zprogrammer »

Also suggest to try it yourself if you have access to Mainframes.
zprogrammer
Ramnath
Registered Member
Posts: 20
Joined: Thu Aug 01, 2013 6:57 pm

Re: Using SEARCH without setting INDEX in COBOL.

Post by Ramnath »

I came to know that for SEARCH to work in COBOL defining INDEX is mendatory but I could not test it, as I don't have the mainframe access yet.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Using SEARCH without setting INDEX in COBOL.

Post by William Collins »

You could try to install GNU COBOL (formerly OpenCOBOL) to try things out.

It is unclear what you mean exactly by "definiing INDEX is mandatory". SEARCH does no definitions at all.
Ramnath
Registered Member
Posts: 20
Joined: Thu Aug 01, 2013 6:57 pm

Re: Using SEARCH without setting INDEX in COBOL.

Post by Ramnath »

I wrote a post but i am not able to see it now...

If want the table to be in specific order then the INDEX needs be defined..right?
User avatar
Anuj Dhawan
Founder
Posts: 2801
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: Using SEARCH without setting INDEX in COBOL.

Post by Anuj Dhawan »

Ramnath wrote:I wrote a post but i am not able to see it now...
Did you click on the Submit button or just complied a reply? I doubt it was the later case! :)
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Using SEARCH without setting INDEX in COBOL.

Post by William Collins »

There is no necessary relationship between the order of data and whether an INDEX is defined.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1891
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Using SEARCH without setting INDEX in COBOL.

Post by Robert Sample »

If want the table to be in specific order then the INDEX needs be defined..right?
A COBOL table, unlike a VSAM KSDS, does not order the data in the table by the index. Data in a COBOL table is in the order your program loads it. Whether or not an INDEX is defined in the DATA DIVISION has nothing to do with the order of the data.
User avatar
Anuj Dhawan
Founder
Posts: 2801
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: Using SEARCH without setting INDEX in COBOL.

Post by Anuj Dhawan »

Hello Ramnath

The thread seems to go nowhere - are you, by chance, talking about SEARCH ALL and the table declaration with INDEX and KEY ASCENDING/DESCENDING?
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Ramnath
Registered Member
Posts: 20
Joined: Thu Aug 01, 2013 6:57 pm

Re: Using SEARCH without setting INDEX in COBOL.

Post by Ramnath »

Yes, I have askedthe same??
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1891
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Using SEARCH without setting INDEX in COBOL.

Post by Robert Sample »

Yes, I have askedthe same??
No, you have not. COBOL has the SEARCH verb, which does a sequential search of a table, as well as SEARCH ALL, which does a binary search of a table. The binary SEARCH will fail if the data in the table is not sorted by the index whereas a sequential SEARCH can succeed no matter whether the data is sorted or not. You asked about SEARCH without specifying whether or not you are doing a binary search -- and the SEARCH works very differently compared to SEARCH ALL. If you read the Enterprise COBOL Language Reference manual, you will find that a sequential SEARCH uses an index but that index does not have to be defined on the table you are searching.
Ramnath
Registered Member
Posts: 20
Joined: Thu Aug 01, 2013 6:57 pm

Re: Using SEARCH without setting INDEX in COBOL.

Post by Ramnath »

I re-read my posts and understand that how less I was making sense in getting the answer. Thanks for your all help, it really heped me to understand about SEARCH and SEARCH ALL.
User avatar
Anuj Dhawan
Founder
Posts: 2801
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: Using SEARCH without setting INDEX in COBOL.

Post by Anuj Dhawan »

That's great and thanks for the feedback. Nothing to worry, as you progress in your career you'll learn to explain better yourself. :)
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Ramnath
Registered Member
Posts: 20
Joined: Thu Aug 01, 2013 6:57 pm

Re: Using SEARCH without setting INDEX in COBOL.

Post by Ramnath »

Thanks Anuj!
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”