Error with Search in table



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Error with Search in table

Postby gowthamgyaa » Thu Oct 25, 2012 4:00 pm

Hi everyone,
while executing the below search coding, i got an error as Index name was no uniquely defined.
I kindly request you to guide me what may be the error.
 000001        IDENTIFICATION DIVISION.
 000002        PROGRAM-ID. READPS.
 000003        ENVIRONMENT DIVISION.
 000004        DATA DIVISION.
 000005        WORKING-STORAGE SECTION.
 000006        01 SREC.
 000007          02 STAB OCCURS 10 TIMES INDEXED BY SEARI.
 000008             05 SNAME PIC A(7).
 000009             05 SNO PIC 9(2).
 000010             05 FILLER PIC 9(2).
 000011             05 SMOB PIC 9(10).
 000012             05 SM1 PIC 9(3).
 000013             05 SM2 PIC 9(3).
 000014             05 SM3 PIC 9(3).
 000015             05 STOT PIC 9(4).
 000016             05 FILLER PIC A(3).
 000017             05 SAVG PIC 9(4)V9(4).
 000018             05 RES PIC X(10).
 000019        77 SIND PIC 9(2) VALUE 1.
 000020        77 SEARI PIC 9(2) VALUE 1.
 000021        77 PNO PIC 9(2).
 000022        PROCEDURE DIVISION.
 000023        MAIN-PARA.
 000024            PERFORM TAB-PARA VARYING SIND FROM 1 BY 1 UNTIL SIND > 10.
 000025            PERFORM SEARCH-PARA VARYING SEARI FROM 1 BY 1
 000026                UNTIL SEARI > 10.
 000027            STOP RUN.
 000028        TAB-PARA.
 000029            ACCEPT SNAME(SIND).
 000030            ACCEPT SNO(SIND).
 000031            ACCEPT SMOB(SIND).
 000032            ACCEPT SM1(SIND).
 000033            ACCEPT SM2(SIND).
 000034            ACCEPT SM3(SIND).
 000035            COMPUTE STOT(SIND) = SM1(SIND) + SM2(SIND) + SM3(SIND).
 000036            COMPUTE SAVG(SIND) = STOT(SIND) / 3.
 000037            IF (SAVG(SIND) > 50)
 000038              DISPLAY "PASS"
 000039            ELSE
 000040              DISPLAY "FAIL"
 000041            END-IF.
 000042            DISPLAY RES(SIND).
 000043            DISPLAY STAB(SIND).
 000044        SEARCH-PARA.
 000045            ACCEPT PNO.
 000046            SEARCH STAB AT END DISPLAY "SEARCH FAILED"
 000047             WHEN SNO(SIND) = PNO(SEARI)
 000048             DISPLAY "SEARCH SUCCESS:" STAB(SIND)
 000049            END-SEARCH.


MY ERROR CODE.


 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
 
 
 ==000025==> IGYPS0037-S "SEARI" was not a uniquely defined name.  The definitio
                         not be determined from the context.  The reference to t
                         discarded.
 
   000026                        UNTIL SEARI > 10.
 
 ==000026==> IGYPS0037-S "SEARI" was not a uniquely defined name.  The definitio
                         not be determined from the context.  The reference to t
                         discarded.
 
 
     25  IGYPS0037-S   "SEARI" was not a uniquely defined name.  The definition
                       The reference to the name was discarded.
 
                       Same message on line:     26     47
 
     47  IGYPS2120-S   Expected a reference-modification specification but found




Kind Regards
gyaa
gowthamgyaa
 
Posts: 101
Joined: Wed Sep 05, 2012 11:18 pm
Has thanked: 67 times
Been thanked: 0 time

Re: Error with Search in table

Postby Pandora-Box » Thu Oct 25, 2012 4:12 pm

Hi gowthamgyaa,

When you declare something like

 000007          02 STAB OCCURS 10 TIMES INDEXED BY SEARI.


You dont need to define

 000020        77 SEARI PIC 9(2) VALUE 1.


Which is confusing the compiler as it does not able to use SEARI uniquely as Index or a numeric variable


To Initialise the value you need to do something like

SET  SEARI     TO 1.


To increment it you need

SET  SEARI  UP BY 1.

These users thanked the author Pandora-Box for the post:
gowthamgyaa (Thu Oct 25, 2012 4:36 pm)
User avatar
Pandora-Box
 
Posts: 65
Joined: Fri Feb 10, 2012 8:30 pm
Location: Mars
Has thanked: 3 times
Been thanked: 6 times

Re: Error with Search in table

Postby BillyBoyo » Thu Oct 25, 2012 4:15 pm

When you use INDEXED BY the compiler generates its own storage for the index. You mustn't. So remove your definition. Your other message for line 47 may go away when you fix this.

These users thanked the author BillyBoyo for the post:
gowthamgyaa (Thu Oct 25, 2012 4:36 pm)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Error with Search in table

Postby Robert Sample » Thu Oct 25, 2012 4:30 pm

COBOL allows a programmer to define the same variable name more than once in a program -- as long as the name can be uniquely identified. This means that all 77 and 01 level names must be unique in the program. However, elementary variables in a group can have the same name since they can be referred to as <variable> IN <group name> (assuming the group name is unique, or the group name is the 01-level name). Your code does not allow for such references and hence the compiler error messages.

These users thanked the author Robert Sample for the post:
gowthamgyaa (Thu Oct 25, 2012 4:36 pm)
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Error with Search in table

Postby gowthamgyaa » Thu Oct 25, 2012 5:10 pm

Hi everyone,
Do i need to use seperate index for search?


Kind regards
gyaa
gowthamgyaa
 
Posts: 101
Joined: Wed Sep 05, 2012 11:18 pm
Has thanked: 67 times
Been thanked: 0 time

Re: Error with Search in table

Postby Robert Sample » Thu Oct 25, 2012 6:23 pm

COBOL has two forms of the SEARCH verb: SEARCH and SEARCH ALL. The first does a sequential search of the table and allows you to specify a subscript or index variable to use; the second requires the table to be sorted into ascending sequence and uses a table index variable.

If you write your own search, of course, you may do it however you want -- but using the verb is less code and lets you learn more.

And by the way, you have ACCEPT PNO in your SEARCH-PARA. which means you will have to provide as many as 10 input values for every table search.

Your code should be something like
 000023        MAIN-PARA.
 000024            PERFORM LOAD-TABLE VARYING SIND FROM 1 BY 1 UNTIL SIND > 10.
 000025            ACCEPT PNO
                   SET SEARI TO 1
                   SEARCH STAB
                       WHEN SNO (SEARI) = PNO
                               ...
 
Using ACCEPT to input data values is a very tedious and error-prone way of getting data into your program. Placing the data in a file and reading the file would be MUCH easier and less likely to have errors.

These users thanked the author Robert Sample for the post:
gowthamgyaa (Thu Oct 25, 2012 6:37 pm)
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post