IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Search an array inside an array


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
amitc23

New User


Joined: 05 Nov 2014
Posts: 95
Location: India

PostPosted: Thu Jan 24, 2019 4:19 pm
Reply with quote

Friends

I have a data structure as follows

Code:


01  BATCH-FILE-INFO.                                       
    03 FILLER OCCURS 25 TIMES.                             
       05 BATCH-COUNT                     PIC 9(5).       
       05 DEP-COUNT                       PIC 9(5).       
       05 DEP-NUM-BATCHES                 PIC 9(5).       
       05 XXX-SOURCE-CRITERIA OCCURS 50 TIMES             
                              INDEXED BY XXX-IDX.         
          07 XXX-SOURCE-ENTITY-ID         PIC X(15).       
          07 XXX-SOURCE-ENTITY-TYPE       PIC X.           
          07 XXX-SOURCE-AMOUNTS.                           
             09 XXX-NUM-CR-TRAN           PIC 9(6).       
             09 XXX-CR-AMT-TOT            PIC 9(15)V9(3). 
             09 XXX-NUM-DB-TRAN           PIC 9(6).       
             09 XXX-DB-AMT-TOT            PIC 9(15)V9(3). 
 


I need to search second array i.e. XXX-SOURCE-CRITERIA but when i do that using index it gives me following COMPILE error

Code:

"SEARCH" IDENTIFIER "XXX-SOURCE-CRITERIA (GROUP)" WAS SUBORDINATE TO AN ITEM THAT HAS NOT DEFINED WITH
"OCCURS" AND "INDEXED BY" CLAUSES.  THE STATEMENT WAS DISCARDED.               
[/code]

Please suggest how can i perform search.
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Thu Jan 24, 2019 5:36 pm
Reply with quote

Shouldn't you have
Code:
03 FILLER OCCURS 25 TIMES.
indexed by something?

Garry
Back to top
View user's profile Send private message
amitc23

New User


Joined: 05 Nov 2014
Posts: 95
Location: India

PostPosted: Thu Jan 24, 2019 5:45 pm
Reply with quote

Thanks for response Garry. I was also thinking that as an option, but this is an existing code and I need to change at many places. Second occurs I have added now.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1041
Location: Richmond, Virginia

PostPosted: Fri Jan 25, 2019 2:15 am
Reply with quote

It's been a long time, so I'll just question:
If an array is indexed, can one also reference elements with subscripts?
If so, then your existing code should be ok if COBOL requires you to index the top level?
Back to top
View user's profile Send private message
amitc23

New User


Joined: 05 Nov 2014
Posts: 95
Location: India

PostPosted: Fri Jan 25, 2019 11:18 am
Reply with quote

Thanks Phil. I was in doubt about that. But for the meanwhile I have indexed the first occurs as well. That resolves compile issue. Will see at run time now. Thanks for help.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 25, 2019 7:59 pm
Reply with quote

From the Enterprise COBOL Language Reference manual, V6.2, page 448:
Quote:
Before using a serial search on a multidimensional table, you must also set the value of the index for each superordinate dimension
So the compiler is telling you that your syntax is invalid since you cannot set the index value for the FILLER OCCURS.

SEARCH can be tricky when dealing with tables that have more than one dimension. From the same page of the manual:
Quote:
The SEARCH statement modifies only the value in the search index, and, if the VARYING phrase is specified, the value in index-name-1 or identifier-2. Therefore, to search an entire two-dimensional to seven-dimensional table, you must execute a SEARCH statement for each dimension. In the WHEN phrases, you must specify the indexes for all dimensions. Before the execution of each SEARCH statement, you must initialize the associated indexes with SET statements.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts first column truncated in search result IBM Tools 13
No new posts ISRSUPC search utility - using high l... TSO/ISPF 2
No new posts To search DB2 table based on Conditio... DB2 1
Search our Forums:

Back to Top