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

SEARCH Variable Length tables


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 216
Location: USA

PostPosted: Fri Jun 08, 2012 7:32 pm
Reply with quote

Hi,

I have a variable length table defined as below.

20 WS-MS-TABLE OCCURS 0 TO 200 TIMES
DEPENDING ON WS-MS-CNT
INDEXED BY MSNDX.
30 WS-MS-START PIC X(10).
30 WS-MS-STOP PIC X(10).

Now in the code I am doing SEARCH as below. I have loaded the table for 2 occurrences.

SEARCH WS-MS-E-MKT-ARR VARYING ENDX
AT END NEXT SENTENCE

WHEN WS-MS-START (ENDX) <= '2012-06-08' CONTINUE
END-SEARCH.

But while debugging the code, I've observed that it is only checking on first occurrence and quitting the process.

Question is, can't we use SEARCH/ SEARCH ALL on varibale lengt Tables. Please clarify.

I've checked the cobol manual. It is given as below.

Quote:
To do serial searches, use SEARCH and indexing. For variable-length tables, you can
use PERFORM with subscripting or indexing


Is he indirectly saying that we can't use SEARCH/SEARCH ALL for variable length tables?
Back to top
View user's profile Send private message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 216
Location: USA

PostPosted: Fri Jun 08, 2012 7:34 pm
Reply with quote

Sorry, the SEARCH is coded as below.

Code:


SET MSNDX TO 1.
SEARCH WS-MS-TABLE VARYING MSNDX           
  AT END CONTINUE                           
                                           
 WHEN WS-MS-START (MSNDX) = '2012-01-01'
   GO TO XXXX-EXIT                         
END-SEARCH.                                 
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jun 08, 2012 8:22 pm
Reply with quote

do you populate WS-MS-CNT with 2 before your search?
what is the PIC clause of WS-MS-CNT?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Fri Jun 08, 2012 8:25 pm
Reply with quote

It's a PEBKAC error -- I tried searching a variable length table and COBOL did it just fine.
Code:
       77  WS-TBL-COUNT                PIC 9(03) VALUE 6.
       01  WS-TABLE-TOP.
           05  WS-TABLE                OCCURS 0 TO 200
                                       DEPENDING ON WS-TBL-COUNT
                                       INDEXED BY WS-TBL-NDX.
               19  WS-TBL-DATE         PIC X(10).
               19  WS-TBL-VALUE        PIC X(01).
      /
       PROCEDURE DIVISION.
       S1000-MAIN       SECTION.
           MOVE 6                      TO  WS-TBL-COUNT.
           MOVE '2012-01-01'           TO  WS-TBL-DATE (1).
           MOVE 'A'                    TO  WS-TBL-VALUE (1).
           MOVE '2012-03-01'           TO  WS-TBL-DATE (2).
           MOVE 'C'                    TO  WS-TBL-VALUE (2).
           MOVE '2012-02-01'           TO  WS-TBL-DATE (3).
           MOVE 'B'                    TO  WS-TBL-VALUE (3).
           MOVE '2012-04-01'           TO  WS-TBL-DATE (4).
           MOVE 'D'                    TO  WS-TBL-VALUE (4).
           MOVE '2012-05-01'           TO  WS-TBL-DATE (5).
           MOVE 'E'                    TO  WS-TBL-VALUE (5).
           MOVE '2012-06-01'           TO  WS-TBL-DATE (6).
           MOVE 'F'                    TO  WS-TBL-VALUE (6).
           SET WS-TBL-NDX              TO  1.
           SEARCH WS-TABLE
               AT END
                   DISPLAY 'NOT FOUND'
               WHEN WS-TBL-DATE (WS-TBL-NDX) = '2012-05-01'
                   DISPLAY WS-TBL-VALUE (WS-TBL-NDX)
           END-SEARCH.
which produces results of
Code:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---->
 E
exactly as expected.
Back to top
View user's profile Send private message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 216
Location: USA

PostPosted: Fri Jun 08, 2012 9:05 pm
Reply with quote

Hi dbzTHEdinosauer,

I have loaded WS-MS-CNT to 2.

HI Robert Sample,

Can you please tell what is PEBKAC error?

Regards
Amar
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jun 08, 2012 9:09 pm
Reply with quote

still no pic clause
and
Meaning of PEBKAC
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jun 08, 2012 9:16 pm
Reply with quote

may as well tell us with what you are populating your table.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Fri Jun 08, 2012 9:17 pm
Reply with quote

1. Why are you using SEARCH ... VARYING?
2. If the SEARCH is checking only the first occurrence and quitting, then I think only three things can be going on:
(a) the value matched the search condition and went to the XXXX-EXIT paragraph, or
(b) your table OCCURS DEPENDING ON variable is set wrong and the AT END condition is being raised, or
(c) your VARYING variable is set wrong when the SEARCH starts and the AT END condition is being raised.

The other possibility is that your SEARCH is working fine but your use of your debugging tool (whatever it is) does not properly indicate this to you, either because you expect something that isn't happening, or you didn't expect the tool to do what it did.
Back to top
View user's profile Send private message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 216
Location: USA

PostPosted: Fri Jun 08, 2012 9:43 pm
Reply with quote

Hi Robert Sample,

I thinking I am doing point b).

I am first loading variable length table 1 and I am loading variable length table 2.

Now from variable length table 2 I am loading variable length table 1.

To perform this, I am simply moving ZERO to ODO clause of the first table and then started loading process. (Will this cause any problem?)

At end I am performing SEARCH on this table. Am I missing something?

Regards
Amar
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Fri Jun 08, 2012 10:12 pm
Reply with quote

Quote:
To perform this, I am simply moving ZERO to ODO clause of the first table and then started loading process. (Will this cause any problem?)
It is quite possible that it will cause problems. Have you read section 1.4.5 Creating Variable-length tables (DEPENDING ON) in the COBOL Programming Guide manual?

For safety, you need to set the ODO object (MSNDX in your post) to the next value BEFORE moving anything to the table occurrence.

I don't think we can take this much further without seeing actual code. There's a lot of ways to misuse and otherwise mess up ODO tables.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jun 08, 2012 10:29 pm
Reply with quote

the ODO object (item counter) must be populated prior
to a SEARCH or SEARCH ALL
or any PERFORM VARYING ... UNTIL > item-counter

to populate a table via an INDEX BY indentifier
you must SET the INDEX to the appropriate value before referencing.

simple rules, follow them and you will have little problem with ODO structures.
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 Store the data for fixed length COBOL Programming 1
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
Search our Forums:

Back to Top