Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

SEARCH Variable Length tables

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 189
Location: INDIA

PostPosted: Fri Jun 08, 2012 7:32 pm    Post subject: SEARCH Variable Length tables
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: 189
Location: INDIA

PostPosted: Fri Jun 08, 2012 7:34 pm    Post subject:
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    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Fri Jun 08, 2012 8:25 pm    Post subject:
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: 189
Location: INDIA

PostPosted: Fri Jun 08, 2012 9:05 pm    Post subject: Reply to: SEARCH Variable Length tables
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    Post subject:
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    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Fri Jun 08, 2012 9:17 pm    Post subject:
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: 189
Location: INDIA

PostPosted: Fri Jun 08, 2012 9:43 pm    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Fri Jun 08, 2012 10:12 pm    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
No new posts Joinkeys operation when key1 and key2... Susanta DFSORT/ICETOOL 5 Wed Nov 02, 2016 5:35 pm
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm
No new posts Getting list of tables defined under ... kishpra DB2 2 Wed Aug 24, 2016 10:36 am
No new posts Variable for cursor names ravikumar15 DB2 5 Sun Jul 17, 2016 7:08 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us