MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to view/display the index of a SEARCH on an array

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
gkreth
Beginner


Joined: 28 May 2004
Posts: 29
Topics: 10

PostPosted: Thu Jul 22, 2004 2:01 pm    Post subject: How to view/display the index of a SEARCH on an array Reply with quote

I have the following array defined:
Code:
01  WS-SCHOOL-TABLE1.
    05  WS-SCHOOL-TBL1 OCCURS 10500 TIMES
                      ASCENDING KEY IS WS-SCHL-TG-ID
                      INDEXED BY SCHIDX1.
        10  WS-SCHL-ENTRY1.
            15  WS-SCHL-TG-ID      PIC X(09).
01  WS-SCHOOL-TABLE2.
    05  WS-SCHOOL-TBL2 OCCURS 10500 TIMES
                      ASCENDING KEY IS WS-SCHL-HOME-TG-ID
                      INDEXED BY SCHIDX2.
        10  WS-SCHL-ENTRY2.
            15  WS-SCHL-HOME-TG-ID PIC X(09).
            15  WS-SCHL-TYPE       PIC X(03).
01  WS-SCHIDX PIC 9(5)                                   

I also have the following code that searches this array:
Code:
SEARCH ALL WS-SCHOOL-TBL1
   AT END
       MOVE '999999000' TO EXT-SCHL-HOME-TG-ID
       MOVE '999' TO EXT-SCHL-TYPE
   WHEN WS-SCHL-TG-ID (SCHIDX1) = EXT-SCHL-TG-ID
       SET SCHIDX2 TO SCHIDX1
       DISPLAY 'SCHIDX1: ' SCHIDX1
       MOVE WS-SCHL-HOME-TG-ID (SCHIDX2) TO
           EXT-SCHL-HOME-TG-ID
       MOVE WS-SCHL-TYPE (SCHIDX2) TO EXT-SCHL-TYPE
.                                                 

What I'd like to know is: How do I view the contents of SCHIDX1? I have tried to DISPLAY the field, but I get this compile error:
Code:
51250  IGYPS2074-S   "SCHIDX1" was defined as a type that was invalid in this context.  The statement was discarded.

I have also tried moving SCHIDX1 to a numeric variable, but I get the same compile error.

Surely there must be a way to do this, but how?

Thanks,

--Greg
Back to top
View user's profile Send private message
programmer1
Beginner


Joined: 18 Feb 2004
Posts: 138
Topics: 14

PostPosted: Thu Jul 22, 2004 2:08 pm    Post subject: Reply with quote

Hi Greg,

I am not sure if we can display the value of the index.

I have always used Xpediter to look at the value of the index. If you have Xpediter at your shop, try that out.
_________________
Regards,
Programmer
Back to top
View user's profile Send private message
dhruv
Beginner


Joined: 01 Jun 2004
Posts: 10
Topics: 1

PostPosted: Thu Jul 22, 2004 3:06 pm    Post subject: Reply with quote

Since INDEX variables are actually register notations, they must be in their native binary format.

So, the following statements should work

SET Working-storage-pic-9-variable TO SCHIDX1
DISPLAY working-storage-pic-9-variable

OR

SET working-storage-pic-9-comp-variable TO SCHIDX1
MOVE working-storage-pic-9-comp-variable TO working-storage-pic-9-disp
DISPLAY working-storage-pic-9-disp

I dont see why the above should not work.

Thanks
Back to top
View user's profile Send private message
vijaythomson
Beginner


Joined: 23 Jul 2004
Posts: 1
Topics: 0

PostPosted: Fri Jul 23, 2004 11:07 am    Post subject: Reply with quote

SET Working-storage-pic-9-variable TO SCHIDX1
DISPLAY working-storage-pic-9-variable

OR

SET working-storage-pic-9-comp-variable TO SCHIDX1
MOVE working-storage-pic-9-comp-variable TO working-storage-pic-9-disp
DISPLAY working-storage-pic-9-disp

I TRIED BOTH THE WAYS BUT STILL ITS NOT SHOWING THE VALUE OF THE INDEX VARIABLE Rolling Eyes I THINK ONLY WAY IS XPEDITOR.
Back to top
View user's profile Send private message
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Fri Jul 23, 2004 11:16 am    Post subject: Reply with quote

Try this
Code:

Define SUB1 PIC S9(8) COMP.
Define WS-SUB1 PIC 9(6).

PERFORM
  VARYING SUB1
  FROM +1 BY +1
  UNTIL WS-SCHL-TG-ID (SUB1) = EXT-SCHL-TG-ID
  OR SUB1 > +10500
END-PERFORM

MOVE SUB1 TO WS-SUB1
DISPLAY 'SUB1:' WS-SUB1
Back to top
View user's profile Send private message
programmer1
Beginner


Joined: 18 Feb 2004
Posts: 138
Topics: 14

PostPosted: Mon Jul 26, 2004 12:54 pm    Post subject: Reply with quote

Bithead,

You are right, but this would be a case while using sub-scripts.

Do we have a way out to display the value of an Index ?
_________________
Regards,
Programmer
Back to top
View user's profile Send private message
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Mon Jul 26, 2004 1:10 pm    Post subject: Reply with quote

Add the subscript code to get at the value of the index. I know of no way to get at the index itself.
Back to top
View user's profile Send private message
gkreth
Beginner


Joined: 28 May 2004
Posts: 29
Topics: 10

PostPosted: Tue Jul 27, 2004 3:28 pm    Post subject: Reply with quote

vijaythomson and dhruv win the golden cigar!

Here's the code:
Code:
01  WS-SCHOOL-TABLE1.                               
    05 WS-SCHOOL-TBL1 OCCURS 100 TIMES               
                     ASCENDING KEY IS WS-SCHL-TG-ID 
                     INDEXED BY SCHIDX1.             
       10 WS-SCHL-ENTRY1.                           
          15 WS-SCHL-TG-ID      PIC 9(4) VALUE 0.   
01  I                           PIC 9(4) VALUE 0.   
01  J                           PIC 9(4) VALUE 0.   
01  FOUND                       PIC X(1) VALUE SPACE.
...
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 100           
   ADD 2 TO J                                         
   SET SCHIDX1 TO I                                   
   MOVE J TO WS-SCHL-TG-ID (I)                         
END-PERFORM                                           
                                                       
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 100           
   SEARCH ALL WS-SCHOOL-TBL1                           
      AT END MOVE 'N' TO FOUND                         
      WHEN WS-SCHL-TG-ID (SCHIDX1) = I                 
          SET J TO SCHIDX1                             
          MOVE 'Y' TO FOUND                           
   END-SEARCH                                         
   IF FOUND = 'Y'                                     
      DISPLAY 'Found        ' I ' in     array slot ' J
   ELSE                                               
      DISPLAY 'Did not find ' I ' in any array slots' 
   END-IF                                             
END-PERFORM                                           

This gives me the following output:
Code:
Did not find 0001 in any array slots   
Found        0002 in     array slot 0001
Did not find 0003 in any array slots   
Found        0004 in     array slot 0002
Did not find 0005 in any array slots   
Found        0006 in     array slot 0003
Did not find 0007 in any array slots   
Found        0008 in     array slot 0004
Did not find 0009 in any array slots   
Found        0010 in     array slot 0005
Did not find 0011 in any array slots   
Found        0012 in     array slot 0006
Did not find 0013 in any array slots   
Found        0014 in     array slot 0007
Did not find 0015 in any array slots   
Found        0016 in     array slot 0008
Did not find 0017 in any array slots   
Found        0018 in     array slot 0009
Did not find 0019 in any array slots   
Found        0020 in     array slot 0010
Did not find 0021 in any array slots   
Found        0022 in     array slot 0011
Did not find 0023 in any array slots   
...
Did not find 0099 in any array slots   
Found        0100 in     array slot 0050

So, the SET is the key to the whole thing!
Thanks so much for your help!

--Greg
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group