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

How to find out last element in an internal table


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

New User


Joined: 26 Sep 2006
Posts: 38
Location: India

PostPosted: Mon Feb 15, 2010 4:16 pm
Reply with quote

Hello,

I have one internal table as below. I would like to store new record in to this table if sapce is available in this. For checking the space availability I was doing the below steps.


Code:
01 TAX-TABLE.                                             
   10 TAB-TAX-REC OCCURS 3.                             
      15 TAX-DATE.                             
         20 TAX-DATE-J  PIC S9(04) COMP-3.             
         20 TAX-DATE-M  PIC S9(02) COMP-3.             
         20 TAX-DATE-T  PIC S9(02) COMP-3.             
      15 TAX-VALUE      PIC S9(16)V9(2) COMP-3.


MOVE 03                             TO MAX-I.

PERFORM VARYING I FROM 1 BY 1 UNTIL       
                I > MAX-I OR END-I
                                                 
   IF TAX-DATE-J (I) = ' ' AND
      TAX-VALUE (I) = ' '                   
                                                 
      SET END-I                  TO TRUE     
                                                 
   END-IF                                       
                                                 
END-PERFORM.

IF I <=  MAX-I

 Moving values in to internal-table

END-IF.                     



But I am getting an error saying "IGYPA3022-S " (PACKED NON-INTEGER)" was compared with "' '". for both the array elements.

Could anybody please suggest how to find out whether the internal table will have space to hold new record, if so the postion in the table.
Back to top
View user's profile Send private message
Mathiv Anan

Active User


Joined: 23 Jul 2008
Posts: 106
Location: USA

PostPosted: Mon Feb 15, 2010 4:33 pm
Reply with quote

You cannot check for spaces in comp variables.

Please see the Bill's post on using dynamic array.

http://www.ibmmainframes.com/viewtopic.php?t=46547
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: Mon Feb 15, 2010 5:56 pm
Reply with quote

You need to add a flag variable to your table to denote whether or not that set of elements has been used. Set it when loading a row into the array, and then test it to determine how many active elements the table has.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Mon Feb 15, 2010 8:14 pm
Reply with quote

Another method is to set a variable with the element count of elements that have a value.

This method is only applicable if you populate the elements in sequence from the start or end of the array.

The loop testing for values should not go beyond that number. If you are inserting new elements, you should use this value to determine the next empty element, and update the count accordingly.

The count value field should be communicated with the array to all programs accessing the array.
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 Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top